Thread scheduling method, electronic device and computer readable storage medium
By dynamically adjusting the thread scheduling strategy, the performance problem caused by the unchanged thread scheduling strategy in high load scenarios is solved, and the resource utilization rate and user experience of the terminal device are improved.
Patent Information
- Application Number
- CN202310614117.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-26
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-05-26
AI Technical Summary
In high-load scenarios, when terminal devices run applications with high resource requirements, the use of immutable thread scheduling strategies leads to insufficient performance.
Provide a thread scheduling method that dynamically sets a thread scheduling strategy based on the historical device load of the application. By modifying the priority and affinity of the thread, the thread scheduling is optimized to adapt to the running status of the device and improve resource utilization and user experience. .
It improves the performance and fluency of applications in high-load scenarios, reduces device power consumption, and improves user experience.
Smart Images

Figure CN117707716B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a thread scheduling method, an electronic device, and a computer-readable storage medium. Background Art
[0002] As a basic capability of the operating system, thread scheduling affects the performance and power consumption of terminal devices. Related thread scheduling solutions generally involve the scheduling of application threads. Scheduling strategies are generally predefined. In high-load scenarios where user usage scenarios are increasingly complex, the available resources of terminal devices when running applications with high resource requirements vary. For example, the available resources of the central processing unit (CPU) and memory vary. Using a fixed thread scheduling strategy will lead to insufficient performance. Summary of the invention
[0003] In view of the above, it is necessary to provide a thread scheduling method, an electronic device and a computer-readable storage medium to dynamically set a thread scheduling strategy based on the device load when the application is running in the foreground each time, so as to improve the problem of insufficient performance when the device runs applications with high resource requirements.
[0004] In the first aspect, the present application provides a thread scheduling method, which is applied to an electronic device, and the method includes: when the first application running in the foreground of the electronic device is an application of a preset type, determining a target thread that needs to be scheduled, and obtaining thread information of the target thread; obtaining a scheduling policy for the target thread, the scheduling policy of the target thread is determined based on the historical device load of the first application; scheduling the target thread based on the scheduling policy and the thread information, and the scheduling includes setting the thread attributes of the target thread. Using the above technical solution, thread scheduling is triggered when the application running in the foreground is an application of a preset type. For example, when the application running in the foreground belongs to a scene in a scene whitelist (each scene in the scene whitelist can correspond to a type of application, such as a game scene in the scene whitelist, that is, the application is a game application, and a video playback scene in the scene whitelist, that is, the application is a video playback application), thread scheduling is triggered. Thread scheduling can refer to modifying the thread attributes of the target thread. The thread attributes can include affinity and / or priority. By modifying the priority of the target thread, the target thread (for example, a thread belonging to the application running in the foreground) can obtain more CPU time slices. By modifying the affinity of the target thread, the target thread can be Threads are assigned to run on some CPUs or cores (for example, some kernel threads and operating system native threads are assigned to run on small cores, and some threads of applications running in the foreground are assigned to run on large cores). Based on the historical device load of the application, it is possible to estimate the actual running state of the device when this thread scheduling is triggered. The historical device load of the application can refer to the device load when the application is running in the foreground or the device load when the application is running in the foreground (including foreground and background). The thread scheduling policy is then set based on the running state that the device may be in this time. Dynamic thread scheduling policy setting is implemented, and the thread scheduling accuracy is high, which can effectively improve the user experience of using the application and reduce device power consumption.
[0005] In a possible implementation, when the first application program running in the foreground of the electronic device is an application program of a preset type, determining the target thread that needs to be scheduled includes: when the first application program running in the foreground of the electronic device is an application program of a preset type, obtaining the available resources of the electronic device, the available resources including the remaining available resources of the CPU and / or the remaining available resources of the memory; when the available resources meet the preset conditions, determining the target thread that needs to be scheduled. The above technical solution is adopted, by setting that when the application program running in the foreground of the electronic device is detected to be an application program of a preset type (i.e., a preset scene), and the available resources of the electronic device meet the preset conditions, the thread scheduling process is triggered, and the preset conditions can be set according to actual needs, for example, the preset conditions can be that the remaining available resources of the CPU of the electronic device and / or the remaining available resources of the memory are lower than the threshold. That is, when it is detected that the application program running in the foreground of the electronic device belongs to a scene in the scene whitelist, and the current resources of the electronic device are tight, the thread scheduling process is triggered to provide a better operating environment for the application program running in the foreground. If the available resources of the electronic device do not meet the preset conditions, it is considered that the current resources of the electronic device are relatively abundant, and the thread scheduling process is not triggered.
[0006] In one possible implementation, the thread scheduling method further includes: maintaining the identification of the target thread and the thread attributes before scheduling in a thread scheduling database based on the information obtained in a process control block (PCB); obtaining the thread attributes of the target thread after scheduling, and maintaining the thread attributes of the target thread after scheduling in the thread scheduling database, wherein the thread attributes of the target thread after scheduling are determined based on the historical device load of the first application. By adopting the above technical solution, the process control block records the management, control and other information of the process. By obtaining the process control blocks of each currently running process from the kernel of the operating system, and then based on the information in the PCB, the thread information under each process can be obtained. The obtained threads can be compared with the thread whitelist (the thread whitelist can save the thread names of all threads that need to be scheduled in the scene whitelist), and then the identification of the running threads that belong to the thread whitelist and the thread attributes before scheduling can be maintained in the thread scheduling database. The thread scheduling database can save the thread information (thread name, unique identity identifier, thread attributes before scheduling and thread attributes after scheduling, etc.) of all threads that need to be scheduled in the scene whitelist, so that the thread information of the target thread that needs to be scheduled in the current scene can be obtained based on the thread scheduling database, and the thread attributes can be restored before or after scheduling under specific circumstances.
[0007] In a possible implementation, obtaining the thread information of the target thread includes: obtaining the thread information of the target thread from a thread scheduling database. By adopting the above technical solution, the thread information of the target thread to be scheduled is obtained based on the thread scheduling database. Compared with the existing method of obtaining the thread information of the thread to be scheduled by traversing the file nodes, the time required is shorter, the resources occupied by the thread information acquisition process are lower, and the resource consumption of executing thread scheduling is greatly reduced, and the thread scheduling execution efficiency is high.
[0008] In a possible implementation, after scheduling the target thread based on the scheduling strategy and thread information, it also includes: when it is detected that the target thread is abnormally destroyed, restoring the recreated target thread to the thread properties after scheduling based on the thread scheduling database; or when it is detected that the application running in the foreground of the electronic device is changed from the first application to the second application, and the second application is not an application of the preset type, restoring the target thread to the thread properties before scheduling based on the thread scheduling database. Adopting the above technical solution, by constructing a thread escape mechanism, when the device scenario has not changed and the scheduled thread is abnormally destroyed, the recreated thread can be restored to the thread properties after scheduling based on the thread scheduling database to provide a better operating environment for the application running in the foreground, or when the device scenario changes, the scheduled thread can be restored to the thread properties before scheduling based on the thread scheduling database.
[0009] In a possible implementation, after scheduling the target thread based on the scheduling strategy and thread information, it also includes: when it is detected that the electronic device is in a screen-off state, restoring the target thread to the thread properties before scheduling based on the thread scheduling database; when it is detected that the electronic device is switched from the screen-off state to the screen-on state, or from the screen-off state to displaying the interface of the first application, restoring the target thread to the thread properties after scheduling based on the thread scheduling database. With the above technical solution, when the device screen is off, it indicates that the user is not using the application temporarily, and there is no need to schedule the target thread. The scheduled thread can be restored to the thread properties before scheduling based on the thread scheduling database, and the target thread can be scheduled again after the screen is turned on or unlocked. For example, the scheduled thread can be restored to the thread properties after scheduling based on the thread scheduling database.
[0010] In one possible implementation, determining a target thread that needs to be scheduled includes: identifying the scene to which the first application belongs; determining the target thread that needs to be scheduled based on the scene to which the first application belongs, and the electronic device stores scheduling threads corresponding to multiple scenes. Using the above technical solution, the electronic device can pre-store a table of scheduling threads corresponding to each scene, and the table can store identifiers of threads that need to be scheduled for each preset scene. After determining that the first application running in the foreground is an application of a preset type, by identifying the scene to which the first application belongs, the table can be searched based on the scene to which the first application belongs, and the target thread that needs to be scheduled can be obtained.
[0011] In a possible implementation, the thread scheduling method further includes: obtaining the historical device load of the first application, and obtaining the average device load of the first application based on the previous device loads; determining the predicted device load of the first application when it is running in the foreground next time based on the average device load and the device load of the first application when it was running in the foreground the most recent time; and determining the scheduling strategy of the target thread based on the predicted device load. With the above technical solution, the device load of the application when it is running in the foreground once in history may refer to the average load of the application during the foreground running process, or the maximum load that occurs during the foreground running process. By using the average load of the device during previous runs and the device load during the most recent foreground running process, the device load of the application when it is running in the foreground the next time can be predicted more accurately, so as to formulate a thread scheduling strategy that is suitable for the current running scenario.
[0012] In a possible implementation, the electronic device includes a kernel node, and the kernel node includes a data structure for storing the scheduling policy of the target thread. Obtaining the scheduling policy of the target thread includes: parsing the data stored in the data structure in the kernel node to obtain the scheduling policy of the target thread. The above technical solution is adopted, and by setting a data structure in the kernel node to store the thread scheduling policy, for electronic devices with CPUs / memory of different specifications, the differentiated hardware information of different devices can be dynamically obtained to eliminate the differentiation of electronic devices. For example, for electronic devices with CPUs / memory of different specifications, the remaining available resources of the CPU / memory and the computing power of each core in the CPU can be obtained. The thread scheduling scheme of the present application can be applied to the unified thread scheduling scheme design. When it is necessary to read the scheduling policy of a certain thread, the binary data corresponding to the thread identifier in the data structure can be parsed based on the thread identifier to obtain the scheduling policy of the thread.
[0013] In a possible implementation, the CPU of the electronic device includes multiple cores, the thread attributes include affinity, and the scheduling strategy of the target thread is determined based on the predicted device load, including: clustering the multiple cores to obtain multiple CPU clusters; based on the predicted device load, determining the operation strategy of the target thread in each CPU cluster in the multiple CPU clusters, and storing the operation strategy of the target thread in each CPU cluster in a data structure bit by bit. With the above technical solution, the thread affinity is set in a CPU cluster manner. For example, the CPU clustering method can be divided based on core computing power, and the operation strategy of the thread to be called in each CPU cluster in the multiple CPU clusters is determined based on the predicted device load when the application is running in the foreground next time. It can be achieved that some kernel threads and operating system native threads are assigned to run on small cores or other specific cores, freeing up large core resources so that the key threads of the application running in the foreground can be executed faster.
[0014] In a possible implementation, the thread attributes include priority, and the scheduling strategy of the target thread is determined based on the predicted device load, including: determining the priority of the target thread based on the predicted device load, and storing binary data with a mapping relationship with the priority of the target thread in a data structure. By adopting the above technical solution, by modifying the priority of the target thread, the target thread (for example, a thread belonging to an application running in the foreground) can obtain more CPU time slices. The priority can refer to a static priority. The priority value (also called a Nice value) ranges from -20 to 19, with a total of 40 levels. The larger the Nice value, the lower the priority. The lower the Nice value, the more CPU time slices are obtained. For -20 to 19, 6-bit binary data can be used to represent it. The specific mapping rules can be set according to actual needs.
[0015] In a possible implementation, thread attributes include affinity and / or priority. Using the above technical solution, thread attributes may include affinity and / or priority. By modifying the priority of the target thread, the target thread (e.g., a thread belonging to an application running in the foreground) can obtain more CPU time slices. By modifying the affinity of the target thread, the target thread can be assigned to run on a small core (e.g., some kernel threads and operating system native threads can be assigned to run on a small core), freeing up large core resources so that key threads of the application running in the foreground can execute faster. For example, affinity and priority can be stored separately in a data structure.
[0016] In a second aspect, the present application provides an electronic device, comprising a memory and a processor, wherein the memory is used to store program instructions; the processor is used to read and execute the program instructions stored in the memory, and when the program instructions are executed by the processor, the electronic device executes the above thread scheduling method.
[0017] In a third aspect, the present application provides a computer-readable storage medium storing program instructions. When the program instructions are executed on an electronic device, the electronic device executes the above thread scheduling method.
[0018] In addition, the technical effects brought about by the second to third aspects can be found in the descriptions related to the methods of each design in the above method part, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1A This is a schematic diagram of the usage status of an electronic device provided by an embodiment of the present application.
[0020] Figure 1B This is a schematic diagram of CPU resource occupancy of an electronic device under a high-load scenario provided by an embodiment of the present application.
[0021] Figure 2 It is a software architecture diagram of an electronic device provided in one embodiment of the present application.
[0022] Figure 3 It is a flowchart of a thread scheduling method provided by an embodiment of the present application.
[0023] Figure 4 This is a flowchart of a thread scheduling method provided by another embodiment of the present application.
[0024] Figure 5 It is a schematic diagram of a data structure provided by an embodiment of the present application.
[0025] Figure 6 It is a maintenance flow diagram of a thread scheduling database provided in an embodiment of the present application.
[0026] Figure 7 This is a flowchart of a thread scheduling method provided by another embodiment of the present application.
[0027] Figure 8 This is a flowchart of a thread scheduling method provided by another embodiment of the present application.
[0028] Fig. 9 It is a schematic diagram of a thread scheduling process provided by an embodiment of the present application.
[0029] Fig.10It is a schematic diagram of an application scenario of a thread scheduling method provided in an embodiment of the present application.
[0030] Fig.11 It is a schematic diagram of an application scenario of a thread scheduling method provided in another embodiment of the present application.
[0031] Fig.12 This is a hardware architecture diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0032] To facilitate understanding, some illustrations of concepts related to the embodiments of the present application are given by way of example for reference.
[0033] It should be noted that the terms "first" and "second" involved in the embodiments of the present application are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way.
[0034] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by technicians in the technical field in this application. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. It should be understood that, unless otherwise specified in this application, " / " means or. For example, A / B can represent A or B. "And / or" in this application is only a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. "At least one" means one or more. "Multiple" means two or more than two. For example, at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c, a, b and c seven situations.
[0035] To facilitate understanding of the following description of various embodiments of the present application, some common terms are first explained.
[0036] Operating System (OS): A computer program that manages computer hardware and software resources.
[0037] Kernel: It establishes a platform for communication between computer software and hardware. The kernel provides system services such as file management, virtual memory, and device input / output (I / O).
[0038] User space: also known as user state, the activity space of upper-level applications. The execution of applications depends on the resources provided by the kernel, such as CPU resources, storage resources, I / O resources, etc.
[0039] Kernel space: also known as kernel state, is used to control the computer's hardware resources and provide an environment for the running of upper-level applications.
[0040] Process: It is the basic unit of program operation. A process includes multiple threads and data blocks. Each process has independent memory space, system resources and execution status. In traditional operating systems, a process is both a basic allocation unit and a basic execution unit. A process can be considered as an instance of a running program. A process usually contains program code, data, stack and various system resources, such as file handles, network connections, etc. When a program is started, the operating system will create a new process for the program and allocate independent memory space and system resources.
[0041] Thread: It is the smallest unit that the operating system can schedule operations. Threads can be included in processes and are the actual operating units in processes. Multiple threads can run concurrently in a process, and each thread executes different tasks in parallel.
[0042] The user interface (UI) in the embodiments of the present application is a medium interface for interaction and information exchange between an application or operating system and a user, and can realize the conversion between the internal form of information and the form acceptable to the user (such as a visual operating environment). The user interface of an application is a source code written in a specific computer language such as JAVA and extensible markup language (XML). The interface source code is parsed and rendered on an electronic device, and finally presented as content that the user can recognize, such as pictures, text, buttons and other controls. Controls are the basic elements of the user interface. Typical controls include buttons, widgets, toolbars, menu bars, text boxes, scroll bars, images and text. The properties and contents of controls in the interface are defined by tags or nodes, such as XML through <textview> 、 <imgview> 、 <videoview>The controls contained in the interface are specified by nodes such as . A node corresponds to a control or attribute in the interface. After parsing and rendering, the node is presented as user-visible content. In addition, many applications, such as hybrid applications, usually also contain web pages in their interfaces. A web page, also known as a page, can be understood as a special control embedded in the application interface. A web page is source code written in a specific computer language, such as hypertext markup language (HTML), cascading style sheets (CSS), JAVA scripts (JavaScript, JS), etc. The web page source code can be loaded and displayed as user-recognizable content by a browser or a web page display component with similar functions to a browser. The specific content contained in a web page is also defined by tags or nodes in the web page source code. For example, HTML is defined by 、 、 <video> 、 <canvas>To define the elements and attributes of a web page. The display interface, application program interface, game interface and other interfaces in the embodiments of the present application are all user interfaces.
[0043] The most common form of user interface is graphical user interface (GUI), which refers to a user interface related to computer operation that is displayed in a graphical manner. It can be an icon, window, control or other interface element displayed on the display screen of an electronic device.
[0044] In some embodiments, the electronic device may be installed with one or more APPs (Applications). APP can be referred to as an application, which is a software program that can implement one or more specific functions. For example, instant messaging applications, video applications, audio applications, image capture applications, cloud desktop applications, etc. The applications mentioned in the following embodiments may be system applications installed when the electronic device leaves the factory, or may be third-party applications downloaded from the Internet or obtained from other electronic devices by the user during the use of the electronic device.
[0045] In order to better understand the thread scheduling method provided in the embodiment of the present application, Figure 1A , Figure 1B The application scenarios of the thread scheduling method of this application are described.
[0046] See also Figure 1A As shown, the electronic device 100 is introduced by taking a mobile phone as an example. In this embodiment, the electronic device 100 is installed with an operating system, such as an Android system. The electronic device 100 is also installed with one or more APPs. After the user clicks the icon of an APP, the electronic device 100 can start the APP and create a corresponding application process. The application process can implement various functions of the APP. For example, Figure 1A As shown, the multiple apps installed on the electronic device 100 include a first game app. When the user clicks the icon of the first game app, the electronic device 100 creates a process of the first game app, and the user can perform game operations through the process of the first game app. Figure 1A Displays the game character's movements, skill casting, etc.
[0047] Assume that the processor of the electronic device 100 is a multi-core CPU, and the cores of the multi-core CPU can be divided into small cores, medium cores, large cores, and super-large cores according to computing power. The super-large core has high-speed computing capability and can maximize the smoothness of running large APPs. Large APPs can refer to APPs that occupy a large amount of resources during APP operation, such as game APPs, video APPs, etc.
[0048] For example, for the first game APP, if the multi-core CPU includes a super-large core, in order to avoid problems such as game freezes and frame rate loss that affect the user's gaming experience, the process of the first game APP can be run in the super-large core, or the key thread of the process of the first game APP can be run in the super-large core. For example, a key thread may refer to a thread with high resource usage or high fluency requirements, such as a drawing thread, a thread that generates objects, a thread that moves objects, etc. Using a super-large core to execute a key thread can execute faster than other cores (small cores, medium cores, large cores), thereby improving the running fluency of the first game APP. Figure 1B As shown, it is assumed that the processor of the electronic device 100 is an 8-core CPU. Among the 8 cores CPU0-CPU7, CPU0-CPU3 are small cores, CPU4-CPU5 are medium cores, CPU6 is a super core, and CPU7 is a large core. During the operation of the first game APP process, more resources of CPU6 will be occupied, resulting in very tight resources of CPU6. For CPU6, which already has tight resources, there may be more kernel threads that maintain the operation of the operating system (such as kernel threads such as kswapd, rcc, and kcompactd) and native threads of the operating system (such as Android native threads: surfacefinger threads) occupying the resources of CPU6, which may lead to high game jitter rate and frame loss of the game screen, affecting the user's gaming experience.
[0049] In order to solve the problem that the APP runs unsmoothly or abnormally in the above-mentioned electronic device under high load scenarios, an embodiment of the present application provides a thread scheduling method.
[0050] See also Figure 2 As shown, it is a software architecture diagram of the electronic device provided in the embodiment of the present application. The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. The following is an example of an Android operating system installed in an electronic device, but the present application is not limited to this, and other types of operating systems can also be installed in the electronic device.
[0051] For example, the Android system is divided into four layers, which are, from top to bottom, an application layer 101 , a framework layer 102 , an Android runtime and system library 103 , a kernel layer 104 , and a hardware layer 105 .
[0052] The application layer can include a series of application packages. For example, an application package can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, device control service, etc.
[0053] The framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions. For example, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc.
[0054] Among them, the window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make the data accessible to the application. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build applications. The display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying pictures. The phone manager is used to provide communication functions for electronic devices. For example, the management of call status (including connected, hung up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify the completion of downloads, message reminders, etc. The notification manager can also be a notification that appears in the top status bar of the system in the form of an icon or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0055] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system. The core library contains two parts: one is the function that the Java language needs to call, and the other is the Android core library.
[0056] The application layer and framework layer run in the virtual machine. The virtual machine executes the java files of the application layer and framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0057] The system library may include multiple functional modules, such as a surface manager, a media library, a 3D graphics processing library (such as OpenGL ES), a 2D graphics engine (such as SGL), etc.
[0058] Among them, the surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of multiple commonly used audio and video formats, as well as static image files. The media library can support multiple audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing. The 2D graphics engine is a drawing engine for 2D drawing.
[0059] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0060] The kernel layer is the core of the operating system of an electronic device. It is the first layer of software expansion based on hardware. It provides the most basic functions of the operating system and is the basis for the operation of the operating system. It is responsible for managing the system's processes, memory, device drivers, files, and network systems, and determines the performance and stability of the system. For example, the kernel can determine the operating time of an application on a certain part of the hardware.
[0061] The kernel layer includes programs that are closely related to the hardware, such as interrupt handlers, device drivers, etc. It also includes basic, common, and high-frequency modules, such as clock management modules, process scheduling modules, etc. It also includes key data structures. The kernel layer can be set in the processor or solidified in the internal memory.
[0062] The hardware layer is the hardware of the electronic device, and the hardware layer at least includes a display screen.
[0063] See also Figure 3 , which is a flowchart of a thread scheduling method provided in an embodiment of the present application. The method can be applied in an electronic device, and the thread scheduling method may include:
[0064] S301, when the first APP running in the foreground of the electronic device is an application of a preset type, traverse the process directory under the first APP directory to find a specified task directory.
[0065] If the first APP running in the foreground of the electronic device is an application of a preset type, it means that the currently running first APP belongs to a scenario that can trigger a thread scheduling process, and the thread information of the thread to be scheduled is found by traversing the process directory under the first APP directory.
[0066] In some embodiments, a scene whitelist and a thread whitelist can be pre-built. The scene whitelist can record various scenes that can trigger the thread scheduling process. For example, the scene whitelist can include game scenes, video playback scenes, short video scenes, etc. The application type corresponding to the game scene is a game APP, the application type corresponding to the video playback scene is a video playback APP, and the application type corresponding to the short video scene is a short video APP. The thread whitelist can record the thread names of the threads that need to be scheduled for each scene. Scheduling can refer to setting priority and / or affinity for the thread. The higher the priority of the thread, the more CPU time slices can be obtained. The affinity of the thread can enable the thread to run as long as possible on the specified core without being migrated to other cores.
[0067] S302, traverse the thread directory under the specified task directory to search for threads.
[0068] S303: Match the thread name of the found thread with the thread names in the thread whitelist.
[0069] S304: If the thread name of the found thread successfully matches the thread name in the thread whitelist, the found thread is scheduled based on a preset scheduling policy.
[0070] If the thread name of the found thread fails to match the thread name in the thread whitelist, the process jumps to step S301 to search for other threads under the task directory again.
[0071] Figure 3 The method shown, by setting the priority and / or affinity for the target thread in the first APP, can to a certain extent improve the problem of unsmooth or abnormal APP operation in electronic devices under high-load scenarios. However, for the priority and / or affinity setting of each thread, a pre-defined scheduling strategy is still used for thread scheduling, and it is necessary to traverse the application directory in the electronic device to obtain the thread information of the thread to be scheduled, which is time-consuming. The traversal process will occupy additional CPU resources, further aggravating the CPU resource shortage. Figure 3 Since the method shown traverses the threads under the application directory, it is impossible to schedule the kernel threads or Android native threads that maintain the Android system.
[0072] See also Figure 4 FIG. 1 is a flowchart of a thread scheduling method provided in an embodiment of the present application. The method is applied in an electronic device, and the thread scheduling method includes:
[0073] S401, when the first APP running in the foreground of the electronic device is an application of a preset type, determining a target thread that needs to be scheduled, and obtaining thread information of the target thread.
[0074] In some embodiments, the preset type of application means that the electronic device is in a preset scene. The preset scene can be set according to actual needs. For example, a scene whitelist can be established. The scenes in the scene whitelist can be added and deleted by the user, or set by the developer. The scene whitelist can record various scenes that can trigger the thread scheduling process. For example, the scene whitelist can include game scenes, video playback scenes, short video scenes and other scenes with high resource occupancy or high fluency requirements. The application type corresponding to the game scene is a game APP, the application type corresponding to the video playback scene is a video playback APP, and the application type corresponding to the short video scene is a short video APP.
[0075] In some embodiments, a thread whitelist can be pre-built, and the thread whitelist can record the thread names of threads that need to be scheduled in various scenarios. The thread whitelist can be set by the developer and stored in the memory of the electronic device before the electronic device leaves the factory. For example, the thread whitelist stores the thread names of threads that need to be scheduled in the game scenario, the thread names of threads that need to be scheduled in the video playback scenario, and the thread names of threads that need to be scheduled in the short video scenario.
[0076] When it is detected that the first APP running in the foreground of the electronic device is an application of a preset type, it indicates that the electronic device is in a scenario that can trigger the thread scheduling process, and the target thread that needs to be scheduled is determined. For example, the electronic device can identify the scenario to which the first APP belongs, and then determine the target thread that needs to be scheduled based on the scenario to which the first APP belongs. The target thread may include one or more threads, and the target thread may refer to a thread determined to be required to be scheduled in the scenario to which the first APP belongs. The scheduling referred to in the embodiment of the present application includes setting the thread attributes of the thread, and the thread attributes may include affinity and / or priority.
[0077] For example, the first APP is a game application, and the target thread that needs to be scheduled may be a thread in the thread whitelist that corresponds to the game scene.
[0078] If the APP running in the foreground of the electronic device is not an application of the preset type, it indicates that the electronic device is not in a scenario that can trigger the thread scheduling process, and the electronic device does not trigger the thread scheduling process.
[0079] Assume that the first APP is a game application, and the user adds the game scene to the scene whitelist in advance. When the application running in the foreground of the electronic device is a game application, for example, the first APP, that is, the first APP belongs to a preset type of application, can trigger the thread scheduling process to perform thread scheduling, such as setting the target thread to run on the small core, freeing up the large core resources, so that the key threads of the game application (such as drawing threads, threads that generate objects, threads that move objects, etc.) execute faster, which can improve the smoothness of the game application process, thereby improving the user's gaming experience.
[0080] In some embodiments, it can also be set that when it is detected that the APP running in the foreground of the electronic device is an application of a preset type and the available resources of the electronic device (while the APP is in the foreground) meet the preset conditions, the thread scheduling process is triggered. Otherwise, if the APP running in the foreground of the electronic device is not an application of the preset type, or the available resources of the electronic device do not meet the preset conditions, the thread scheduling process is not triggered. The preset conditions can be set according to actual needs, and the embodiments of the present application are not limited to this. For example, the preset condition is that the available resources of the electronic device are lower than the threshold. That is, when it is detected that the APP running in the foreground of the electronic device is an application of a preset type and the current resources of the electronic device are tight, the thread scheduling process is triggered.
[0081] In some embodiments, the available resources of the electronic device meeting the preset conditions may refer to the remaining available resources of the CPU and / or the remaining available resources of the memory being lower than a threshold. For example, when the remaining available resources of the CPU are lower than the threshold, the CPU may not have enough resources to provide computing power support for the operation of the first APP, and the remaining available resources of the CPU being lower than the threshold indicates that the CPU is in a high load operation situation, and the heat will be more serious, which will further reduce the smoothness of the operation of the electronic device. By scheduling the target thread, for example, assigning some kernel threads and operating system native threads to run on the small core, the CPU power consumption can be reduced, the CPU heating situation can be alleviated, and the large core resources can be freed up, so that the key threads of the first APP are executed faster, and the running smoothness of the first APP is improved. For example, when the remaining available resources of the memory are lower than the threshold, the available storage space of the memory may not meet the requirements of the CPU, resulting in a jam in the CPU reading and writing data. By scheduling the target thread, for example, setting the thread of the first APP to a higher priority, the thread of the first APP obtains more CPU time slices, which can improve the running smoothness of the first APP.
[0082] In some embodiments, different thresholds may be set for the remaining available resources of the CPU and the remaining available resources of the memory, respectively. The available resources of the electronic device meeting the preset conditions may mean that either the remaining available resources of the CPU or the remaining available resources of the memory is less than the corresponding threshold.
[0083] In some embodiments, the available resources of the electronic device not meeting the preset conditions may mean that the remaining available resources of the CPU and the remaining available resources of the memory are both greater than the corresponding thresholds. When the remaining available resources of the CPU and the remaining available resources of the memory are both greater than the corresponding thresholds, it indicates that the computing power resources of the electronic device are sufficient, and there may be fewer programs running in the background. It can be considered that the current computing power resources of the electronic device can meet the operating requirements of the first APP, and the thread scheduling process may not be triggered.
[0084] For example, in one embodiment of the present application, step S401 may also include: a1. If the first APP running in the foreground of the electronic device is an application of a preset type, obtain the available resources of the electronic device, and the available resources include at least the remaining available resources of the CPU and / or the remaining available resources of the memory; b1. If the available resources meet the preset conditions, determine the target thread that needs to be scheduled. Assuming that the preset condition is that the remaining available resources of the CPU are less than 30% or the remaining available resources of the memory are less than 30%, that is, when the first APP running in the foreground of the electronic device is an application of a preset type and the remaining available resources of the CPU or the remaining available resources of the memory are less than 30%, the thread scheduling process is triggered to determine the target thread that needs to be scheduled.
[0085] In some embodiments, a thread scheduling database can be maintained in the electronic device to store information about threads that need to be scheduled in each scenario in the scenario whitelist, so that when the thread scheduling process is triggered, the thread information of the target thread that needs to be scheduled can be quickly obtained based on the thread scheduling database. Figure 3 By traversing the application directory in the electronic device, it has the advantages of short time consumption and low resource occupation. The resource consumption of executing thread scheduling is greatly reduced, the execution efficiency is high, and the threads saved in the thread scheduling database may include application threads, kernel threads that maintain the operation of the Android system, and Android native threads. In this way, the scheduling of application threads, kernel threads that maintain the operation of the Android system, and Android native threads can be realized.
[0086] Since the APP running scenarios of terminal devices are complex and changeable, for each triggered thread scheduling process, in order to accurately obtain the thread information of the target thread that needs to be scheduled, the maintenance of the thread scheduling database is crucial. The maintenance of the thread scheduling database should meet the characteristics of real-time and accuracy.
[0087] Threads in an operating system are always accompanied by a life cycle of continuous creation and destruction. When it is detected that a thread in a thread whitelist is created or destroyed, the thread scheduling database can be updated in real time. For example, the process control block (PCB) of each currently running process can be obtained from the kernel of the operating system. PCB is a data structure for storing process management and control information, and the thread scheduling database is maintained based on the information in the PCB of each process.
[0088] In some embodiments, the information stored in the thread scheduling database may include information such as thread name, thread unique identifier (TID), thread attributes before scheduling, and thread attributes after scheduling.
[0089] S402, obtaining a scheduling policy of a target thread, where the scheduling policy of the target thread is determined based on a historical device load of the first APP.
[0090] In some embodiments, the scheduling policy may refer to a policy for modifying the thread attributes of the target thread. After the thread attributes of the target thread are modified based on the scheduling policy, the thread attributes of the target thread are changed from "thread attributes before scheduling" to "thread attributes after scheduling".
[0091] The historical device load of the first APP may refer to the load information of the electronic device when the first APP is running in the foreground. Since the scheduling strategy of the target thread of this application is determined based on the historical device load of the first APP, that is, the generation timing of the scheduling strategy may be before or during the operation of the first APP, for example, the generation of the scheduling strategy of the target thread may be before the execution of step S401, during the execution of step S401, or after the execution of step S401.
[0092] The following is an example of load information of an electronic device including CPU usage and memory usage.
[0093] The electronic device can implement the scheduling strategy of determining the target thread based on the historical device load of the first APP in the following manner:
[0094] a2. Obtain the device load of the first APP during the previous foreground operation, that is, obtain the CPU usage and memory usage of the first APP during the previous foreground operation. For example, the historical device load of the first APP may refer to the average load of the first APP during the foreground operation, or the maximum load that occurs during the foreground operation;
[0095] b2. Based on the historical device load, the average device load of the first APP when it is running in the foreground is obtained. For example, after obtaining the CPU usage and memory usage of the first APP when it is running in the foreground, the average CPU usage and memory usage of the first APP when it is running in the foreground can be obtained by averaging;
[0096] c2. Based on the average device load and the device load of the first APP when it was most recently running in the foreground, the predicted device load of the first APP when it is running in the foreground next time;
[0097] For example, the predicted device load when the first APP runs in the foreground next time can be obtained by combining the following formulas (i) to (iii):
[0098]
[0099]
[0100] loading next =f(loading last , loading avg ) (iii);
[0101] Among them, loading avg is the average load of the device, count is the number of times the first APP is opened, is the CPU usage of the first APP when it is opened for the i-th time and is in the foreground. is the memory usage of the first APP after it is opened for the i-th time and is in the foreground, loading last The device load of the first APP when it was last opened and in the foreground. The CPU usage of the first APP when it was last opened and in the foreground. The memory usage of the first APP when it was last opened and in the foreground. next is the predicted device load when the first APP runs in the foreground next time, f(loading last ,loading avg ) is based on parameter loading last With loading avg The operation function of .
[0102] After obtaining the average device load and the device load of the first APP when it was last running in the foreground, the embodiment of the present application does not limit the algorithm used to calculate the predicted device load of the first APP. In different embodiments, the operation rules of the operation function can be set according to actual needs. For example, the predicted device load of the first APP when it is running in the foreground next time can be calculated based on the average device load and the device load of the first APP when it was last running in the foreground in a weighted average manner. The weight coefficient of the average device load and the weight coefficient of the device load of the first APP when it was last running in the foreground can be customized.
[0103] d2. Determine the scheduling strategy of the target thread based on the predicted device load of the first APP. Different scheduling strategies can be set for different device load situations. For example, multiple scheduling strategies can be set for each thread in advance, and each scheduling strategy corresponds to a device load situation. A device load situation may refer to a CPU usage rate and a memory usage rate within a preset type of interval range.
[0104] After predicting the predicted device load when the first APP runs in the foreground next time, the thread scheduling policy of the scenario to which the first APP belongs under the predicted device load (i.e., the scheduling policy of each thread that needs to be scheduled under the scenario) can be determined. After determining the thread scheduling policy of the scenario to which the first APP belongs under the predicted device load, the scheduling policy of each thread can be written to the kernel node, and the kernel node can refer to a file node located in the kernel. For example, the kernel node may include a data structure for storing the scheduling policy of each thread, and the data stored in the data structure may be binary data.
[0105] In some embodiments, when the first APP running in the foreground of the electronic device is an application of a preset type, the target thread to be scheduled can also be determined based on the thread currently actually created by the electronic device. For example, the first APP is a game application, and the target thread to be scheduled can be part of the threads or all of the threads in the thread whitelist corresponding to the game scene. After determining the target thread to be scheduled, the binary data stored in the data structure in the kernel node can be parsed to obtain the scheduling strategy of the target thread.
[0106] After the scheduling policy of the target thread is determined, the "post-scheduling thread attributes" of the target thread are determined, and the "post-scheduling thread attributes" of the target thread can be maintained in the thread scheduling database.
[0107] For example, the CPU of an electronic device includes multiple cores, and the thread attributes include affinity. The electronic device can determine the affinity of the target thread in the following ways: a3. Cluster the multiple cores in the CPU to obtain multiple CPU clusters. For example, the computing power of each core can be read and the cores can be classified according to the computing power. The cores of the same level of computing power or the same computing power are classified into one CPU cluster. Customized core clustering can also be performed, which is not limited in the embodiments of the present application; based on the predicted device load when the first APP runs in the foreground next time, the operation strategy of the target thread in each CPU cluster in the multiple CPU clusters is determined. The operation strategy can indicate whether the target thread can run on the CPU cluster, and the data structure can store the operation strategy of the target thread in each CPU cluster bit by bit.
[0108] For example, the CPU of an electronic device includes 8 cores CPU0~CPU7. According to the division of computing power, CPU0~CPU3 are small cores, CPU4~CPU5 are medium cores, CPU6 is an extra-large core, and CPU7 is a large core. CPU0~CPU3 can be divided into the first CPU cluster, CPU4~CPU5 can be divided into the second CPU cluster, CPU6 can be divided into the third CPU cluster, and CPU7 can be divided into the fourth CPU cluster.
[0109] The data structure ds1 of the kernel node is as follows Figure 5 As shown, the data structure ds1 stores the scheduling strategies of multiple threads. Figure 5 Taking the example of saving affinity information of p threads, p is a positive integer greater than 1. If the CPU core of the electronic device is divided into four CPU clusters (the first to fourth CPU clusters), the scheduling strategy of each thread can be represented by four bits of binary data, each bit of which represents whether it can be run on the corresponding CPU cluster. Binary data "1" represents that it can be run on the corresponding CPU cluster, and binary data "0" represents that it cannot be run on the corresponding CPU cluster. Figure 5 As shown, the scheduling policy corresponding to the thread with thread identifier TID_1 is "1011", indicating that thread TID_1 can run on the first, second and fourth CPU clusters, but not on the third CPU cluster; the scheduling policy corresponding to the thread with thread identifier TID_2 is "0010", indicating that thread TID_2 can run on the second CPU cluster, but not on the first, third and fourth CPU clusters. The electronic device adjusts the affinity of the thread so that the target thread can only run on the specified CPU cluster, thereby freeing up the resources of the super-large core, so that the key thread of the process of the first APP can be executed faster, and the smoothness of the operation of the first APP is improved. In addition, the method of saving the scheduling policy using the data structure of the kernel node can dynamically obtain the differentiated hardware information of different devices for electronic devices with CPU / memory of different specifications, so as to eliminate the differentiation of electronic devices. For example, for electronic devices with CPU / memory of different specifications, the remaining available resources of the CPU / memory, the computing power of each core in the CPU, the historical load and other information can be obtained, that is, the thread scheduling method of the embodiment of the present application can be applied to thread scheduling, so as to eliminate the differentiation of electronic devices and unify the design of thread scheduling schemes.
[0110] In some embodiments, taking the scheduling policy setting thread priority as an example, the priority generally includes static priority and dynamic priority. The higher the static priority, the more CPU time slices are obtained. The dynamic priority is used when the scheduler performs scheduling. For example, the scheduler selects the thread with the highest dynamic priority each time. The priority is generally 0 to 139, of which 0 to 99 are dynamic priorities. The smaller the value, the higher the priority, and the larger the value, the lower the priority; 100 to 139 are static priorities. The smaller the value, the higher the priority, and the larger the value, the lower the priority. The level of static priority can also be represented by Nice values. Nice values "-20 to 19" correspond to static priorities 100 to 139. The smaller the Nice value, the higher the priority, and the larger the Nice value, the lower the priority. In the embodiment of the present application, setting the priority of a thread may refer to setting the static priority of a thread. Nice values "-20 to 19" include 40 values, that is, the static priority of a thread can be stored by 6-bit binary data. The mapping rules between binary data and Nice values can be set according to actual needs, and the embodiment of the present application does not limit this. For example, you can set "000000" to represent a Nice value of "-20", corresponding to a static priority of 100, set "000001" to represent a Nice value of "-19", corresponding to a static priority of 101, set "000011" to represent a Nice value of "-18", corresponding to a static priority of 102, and so on.
[0111] In some embodiments, if the priority and affinity of the target thread need to be set simultaneously, the kernel node may include two data structures to store the priority information and the affinity information respectively.
[0112] S403, scheduling the target thread based on the scheduling policy and thread information of the target thread.
[0113] In some embodiments, after acquiring the thread information and scheduling policy of the target thread, the target thread may be scheduled based on the thread information and scheduling policy of the target thread. For example, if the scheduling policy is to set affinity, the affinity of the target thread may be set based on the affinity setting policy of the target thread stored in the data structure; if the scheduling policy is to set priority, the priority of the target thread may be set based on the priority setting policy of the target thread stored in the data structure.
[0114] For example, thread scheduling includes setting the affinity of the thread. The CPU of the electronic device is divided into four CPU clusters. The target thread includes the thread kswapd. The affinity of the thread kswapd before scheduling is: it can run on the first to fourth CPU clusters; assuming that the scheduling policy of the thread kswapd read from the data structure of the kernel node is "1011", scheduling the thread kswapd can refer to modifying the affinity of the thread kswapd in the kernel space, so that the thread kswapd can run on the first, second and fourth CPU clusters, but not on the third CPU cluster.
[0115] For example, thread scheduling includes setting thread priorities, and the target thread includes the thread surfaceflinger. The priority of the thread surfaceflinger before scheduling is: static priority 112; assuming that the scheduling policy of the thread surfaceflinger read from the data structure of the kernel node is "000001", scheduling the thread surfaceflinger may refer to modifying the static priority of the thread surfaceflinger in the kernel space, and the static priority of the thread surfaceflinger is modified from the static priority 112 to the static priority 101.
[0116] In some embodiments, after the target thread is scheduled, the scheduled target thread may be abnormally destroyed and recreated, or the first APP may abnormally exit, or the application running in the foreground may be normally switched, or the device screen may be turned off, etc. The thread attributes of the target thread may be set through the thread escape mechanism to restore the thread attributes of the target thread to the state before or after scheduling.
[0117] For example, the thread escape mechanism may include the following situations:
[0118] (1) If it is detected that the target thread is abnormally destroyed, after the target thread is recreated (the device scenario has not changed, that is, the application running in the foreground is still the first APP), the recreated target thread can be restored to the thread attributes after scheduling based on the thread scheduling database.
[0119] (2) If it is detected that the application running in the foreground of the electronic device is changed from the first APP to the second APP, and the second APP is not an application of the preset type, it indicates that the electronic device is not in a scenario that can trigger the thread scheduling process, and there is no need to schedule the target thread again. The target thread can be restored to the thread properties before scheduling based on the thread scheduling database; for example, the first APP exits abnormally (flashback occurs) or exits normally (the electronic device closes the first APP in response to the user's operation), resulting in the application running in the foreground of the electronic device being changed from the first APP to the second APP, or the first APP is switched to the background, resulting in the application running in the foreground of the electronic device being changed from the first APP to the second APP.
[0120] (3) If it is detected that the electronic device is in the screen-off state, it means that the user is not using the first APP for the time being and there is no need to schedule the target thread. The target thread can be restored to the thread attributes before scheduling based on the thread scheduling database. The target thread can be scheduled again after the screen is turned on or unlocked and the first APP is still running in the foreground. For example, if it is detected that the electronic device is switched from the screen-off state to the screen-on state, or from the screen-off state to displaying the interface of the first APP, the target thread can be restored to the thread attributes after scheduling based on the thread scheduling database.
[0121] Combine the following Figure 6 This section describes how to maintain the thread scheduling database. Figure 6 As shown, it is a maintenance flowchart of the thread scheduling database provided by an embodiment of the present application.
[0122] S601: Get the PCB of each currently running process.
[0123] For example, for the application process, kernel process (to maintain the operation of the Android system) and Android native process currently running on the electronic device, the PCB corresponding to each process can be obtained from the kernel of the operating system.
[0124] S602, parse the information in each PCB to obtain thread information of each process.
[0125] In some embodiments, a process may include one or more threads, and by parsing the information in each PCB, the creation information or destruction information of the threads under each process may be obtained.
[0126] S603: Maintain a thread scheduling database based on the thread information and thread whitelist of each process.
[0127] In some embodiments, after obtaining the creation information or destruction information of threads under each process, information of threads in a thread whitelist may be extracted therefrom, and the thread scheduling database may be maintained based on the extracted thread information.
[0128] Table 1 below illustrates thread information stored in a thread scheduling database in some embodiments. The content of Table 1 is merely exemplary, and the thread scheduling database may include more fields than Table 1 below.
[0129] Table 1
[0130]
[0131] In Table 1 above, the thread identifier may refer to the thread's unique identity identifier (thread identifier, TID). The thread attribute may refer to the thread's affinity and / or priority. The thread attribute before scheduling may refer to the thread attribute before the electronic device enters the preset scene, and the thread attribute after scheduling may refer to the thread attribute that needs to be set after the electronic device enters the preset scene. The scheduling mark is used to identify whether the thread is scheduled in the preset scene, so as to facilitate the subsequent restoration of the thread attribute based on the scheduling mark. For example, the scheduling mark is "true", indicating that the thread has been scheduled, and the scheduling mark is "false", indicating that the thread has not been scheduled. The scene is used to identify the scenes in which the thread needs to be scheduled. For threads in the thread scheduling database, some threads can be scheduled only in specific scenes. For example, the scenes that trigger the thread scheduling process include game scenes, video playback scenes, and short video scenes. The thread rcc can be set to be scheduled only in the game scene (scene A) and the video playback scene (scene C), while the short video scene (scene B) is not scheduled. The thread kswapd can be set to be scheduled in the game scene, the video playback scene, or the short video scene.
[0132] Table 2 below illustrates thread information stored in a thread scheduling database in some other embodiments. The content of Table 2 is merely exemplary, and the thread scheduling database may include more fields than Table 2 below.
[0133] Table 2
[0134]
[0135] In some embodiments, the thread name, thread identifier, and thread attributes before scheduling can be obtained by parsing the information in the PCB, or the information in the PCB and the thread control block (TCB). For example, the electronic device can parse the information in the PCB to maintain the name, identifier, and thread attributes before scheduling of the running target thread (a thread in the thread whitelist) in the thread scheduling database. The thread attributes after scheduling can be obtained by parsing the data stored in the data structure in the kernel node, for example, the binary data corresponding to the thread identifier in the data structure can be parsed based on the thread identifier to obtain the scheduling policy of the thread.
[0136] See also Figure 7 FIG. 1 is a flowchart of a thread scheduling method provided in an embodiment of the present application. The method is applied in an electronic device 100, and the thread scheduling method includes:
[0137] The electronic device 100 may include, from bottom to top, a kernel layer 104, a framework layer 102, and an application layer 101. The application layer 101 may run an application.
[0138] The user opens an application on the electronic device. For example, if a first APP is installed on the electronic device, the user can click the first APP icon on the electronic device to open the first APP.
[0139] S701 , the application layer 101 of the electronic device 100 sends information that the first APP is running in the foreground to the framework layer 102 of the electronic device 100 .
[0140] S702, the framework layer 102 of the electronic device 100 identifies whether the first APP is an application of a preset type.
[0141] For example, the framework layer 102 of the electronic device 100 may compare the application type of the first APP with the application type in the scenario whitelist to determine whether the first APP is an application of the preset type. If the application type of the first APP matches the application type in the scenario whitelist, it is determined that the first APP belongs to the preset type of application; if the application type of the first APP does not match the application type in the application whitelist, it is determined that the first APP does not belong to the preset type of application.
[0142] S703 , the framework layer 102 of the electronic device 100 sends the recognition result of the first APP to the kernel layer 104 of the electronic device 100 .
[0143] S704: If the first APP is an application of a preset type, the kernel layer 104 of the electronic device 100 determines a target thread that needs to be scheduled based on the scenario to which the first APP belongs.
[0144] If the first APP is an application of a preset type, the thread scheduling process can be triggered, and the kernel layer 104 of the electronic device 100 can determine the target thread to be scheduled based on the scenario to which the first APP belongs. For example, the thread whitelist can record the thread names of the threads that need to be scheduled in each scenario, and the kernel layer 104 of the electronic device 100 can determine the thread name of the target thread that needs to be scheduled by obtaining the thread whitelist.
[0145] S705, the kernel layer 104 of the electronic device 100 obtains a thread scheduling database, and obtains thread information of the target thread from the thread scheduling database.
[0146] The thread scheduling database stores thread information of threads that need to be scheduled in each scenario in the storage scenario whitelist, such as thread name, TID, etc. After determining the target thread, the kernel layer 104 of the electronic device 100 can obtain the thread information of the target thread from the thread scheduling database by obtaining the thread scheduling database.
[0147] S706, the kernel layer 104 of the electronic device 100 obtains the scheduling policy of the target thread.
[0148] After determining the target thread, the kernel layer 104 of the electronic device 100 may also parse the binary data stored in the data structure in the kernel node based on the TID of the target thread to obtain the scheduling policy of the target thread. For example, based on the TID of the target thread, the binary data corresponding to the TID of the target thread in the data structure may be parsed to obtain the scheduling policy of the target thread. The scheduling policy may refer to a policy for modifying the thread attributes of the target thread.
[0149] If the first APP is not an application of the preset type, the thread scheduling process will not be triggered and the process ends. For example, the kernel layer 104 of the electronic device 100 can ignore the identification result of the first APP transmitted by the framework layer 102 and does not respond.
[0150] S707, the kernel layer 104 of the electronic device 100 schedules the target thread based on the scheduling policy and thread information of the target thread.
[0151] After acquiring the thread information and the scheduling policy of the target thread, the kernel layer 104 of the electronic device 100 may modify the thread attributes of the target thread based on the thread information and the scheduling policy of the target thread.
[0152] See also Figure 8 FIG. 1 is a flowchart of a thread scheduling method provided in an embodiment of the present application. The method is applied in an electronic device, and the thread scheduling method includes:
[0153] S801, determining whether the application program running in the foreground of the electronic device is an application program of a preset type.
[0154] In some embodiments, a scenario whitelist may be used to determine whether an application running in the foreground of an electronic device is an application of a preset type.
[0155] S802: If the application program running in the foreground of the electronic device is an application program of a preset type, obtain available resources of the electronic device and determine whether the available resources meet preset conditions.
[0156] In some embodiments, the preset condition can be set according to actual needs, and the embodiments of the present application are not limited to this. For example, the preset condition is that the available resources of the electronic device are lower than the threshold. When the available resources meet the preset condition, it indicates that the current resources of the electronic device are tight (for example, the available CPU resources and / or the available memory resources are insufficient).
[0157] If the application running in the foreground of the electronic device is an application of a preset type, it indicates that the electronic device is in a scenario that can trigger the thread scheduling process. By further acquiring the available resources of the electronic device, it can be determined whether the current resources of the electronic device are tight. If the available resources meet the preset conditions, it indicates that the conditions for triggering the thread scheduling process are met, and the thread scheduling process is triggered. If the application running in the foreground of the electronic device is not an application of a preset type, it indicates that the electronic device is not in a scenario that can trigger the thread scheduling process. The application running in the foreground this time will not trigger the thread scheduling process. The process can jump back to step S701 to detect whether the application running in the foreground of the electronic device is switched to an application of a preset type. If the application running in the foreground of the electronic device is an application of a preset type, but the available resources do not meet the preset conditions, it indicates that although the electronic device is in a scenario that can trigger the thread scheduling process, the available resources of the device are sufficient to guarantee the running requirements of the application, and there is no need to trigger the thread scheduling process to provide the application with the required running environment. The process can jump back to step S701.
[0158] S803: If the available resources meet the preset conditions, determine the target thread that needs to be scheduled, and obtain thread information of the target thread.
[0159] In some embodiments, if the available resources meet the preset conditions, it indicates that the current resources of the electronic device are relatively tight, and the required operating environment is provided to the application through the thread scheduling process.
[0160] In some embodiments, the electronic device can identify the scene to which the application running in the foreground belongs, and then determine the target thread to be scheduled based on the scene to which the application belongs. The electronic device maintains a thread scheduling database, which stores information about threads to be scheduled in various scenes, and then the thread information of the target thread to be scheduled can be obtained from the thread scheduling database.
[0161] S804, parsing the information stored in the kernel node to obtain the scheduling policy of the target thread.
[0162] In some embodiments, the data structure in the kernel node stores the scheduling policies of each thread, and the scheduling policy of the target thread can be obtained by parsing the binary data stored in the data structure. For example, the binary data corresponding to the TID in the data structure can be parsed based on the TID of the target thread to obtain the scheduling policy of the target thread.
[0163] S805, scheduling the target thread based on the scheduling policy and thread information of the target thread.
[0164] S806: Determine whether to trigger the thread escape mechanism.
[0165] In some embodiments, after the target thread is scheduled, the scheduled target thread may be abnormally destroyed and recreated, or the first APP may abnormally exit, or the application running in the foreground may be normally switched, or the device screen may be turned off. When any of the above situations occurs, the thread properties of the target thread can be set through the thread escape mechanism.
[0166] S807: If the thread escape mechanism is triggered, the target thread is scheduled based on the thread escape mechanism.
[0167] In some embodiments, after the target thread is scheduled, if the thread escape mechanism is triggered, the thread attributes of the target thread can be modified based on the thread escape mechanism; if the thread escape mechanism is not triggered, that is, there is no need to modify the thread attributes of the target thread, and the process can jump back to step S801.
[0168] See also Fig. 9 , which is a schematic diagram of the thread scheduling process provided in an embodiment of the present application.
[0169] The electronic device 100 responds to the user's touch operation to open the first APP, and the first APP is running in the foreground, or the electronic device 100 responds to the user's touch operation to switch the first APP from the background to the foreground. The embodiment of the present application takes the first APP running in the foreground as an application of a preset type and triggers the thread scheduling process as an example for illustration.
[0170] The first APP runs in the application layer 101 .
[0171] The framework layer 102 includes a scene recognition module 1021 , which is used to recognize whether the first APP running in the foreground is an application of a preset type. The recognition result of the scene recognition module 1021 can be transmitted to the kernel layer 104 .
[0172] The kernel layer 104 includes a thread scheduling module 1041. The thread scheduling module 1041 is used to determine the target thread to be scheduled based on the scene to which the first APP belongs when the first APP running in the foreground is an application of a preset type. The thread scheduling module 1041 is also used to obtain a thread scheduling database, and obtain thread information of the target thread based on the thread scheduling database, and the thread information includes a TID.
[0173] After obtaining the thread information of the target thread, the thread scheduling module 1041 can parse the binary data stored in the data structure in the kernel node based on the TID of the target thread, obtain the scheduling policy of the target thread, and then schedule the target thread based on the scheduling policy and thread information of the target thread.
[0174] See also Fig.10 As shown, it is a schematic diagram of an application scenario of the thread scheduling method provided by an embodiment of the present application. The present application embodiment takes the APP running in the foreground as an application of a preset type, and triggers the thread scheduling process as an example for explanation. The preset type of application includes a game APP.
[0175] At the first moment t1, the electronic device responds to the user's first touch operation and opens the first instant messaging APP, and the first instant messaging APP is running in the foreground. The first instant messaging APP does not belong to the preset type of application and does not trigger the thread scheduling process. For example, the scene recognition module 1021 does not trigger the thread scheduling module 1041 to determine the thread that needs to be scheduled.
[0176] At the second moment t2, the electronic device opens the first game APP in response to the user's second touch operation. The first game APP is running in the foreground, and the first instant messaging APP is running in the background.
[0177] The scene recognition module 1021 located in the framework layer 102 can recognize that the first game APP running in the foreground is an application of a preset type, and the scene recognition module 1021 can transmit the first information that the first game APP running in the foreground is an application of the preset type to the kernel layer 104.
[0178] The thread scheduling module 1041 located at the kernel layer 104 responds to the first information and determines the target thread that needs to be scheduled in the game scene. For example, the target thread that needs to be scheduled in the game scene can be obtained by searching the thread whitelist. After determining the target thread that needs to be scheduled, the thread scheduling module 1041 can also obtain the thread information (including TID) of the target thread by searching the thread scheduling database. After obtaining the thread information of the target thread, the thread scheduling module 1041 can parse the binary data corresponding to each TID stored in the data structure in the kernel node based on the TID of each target thread that needs to be scheduled, and obtain the scheduling policy of each target thread that needs to be scheduled. The thread scheduling module 1041 schedules each target thread separately based on the scheduling policy and thread information of each target thread that needs to be scheduled.
[0179] See also Fig.11 As shown, it is a schematic diagram of an application scenario of the thread scheduling method provided by an embodiment of the present application. The present application embodiment takes the case where the APP running in the foreground is an application of a preset type and the available resources meet the preset conditions, and the thread scheduling process is triggered as an example for explanation. The preset type of application includes short video APP.
[0180] At or before the third time t3, the electronic device opens multiple APPs (APP1 to APP m ), assuming that APP1~APP m They are not applications of the preset type, that is, they will not trigger the thread scheduling process.
[0181] At the fourth moment t4, the electronic device responds to the user's touch operation and opens the first short video APP, which is running in the foreground. m All are running in the background.
[0182] The scene recognition module 1021 located in the framework layer 102 can recognize that the first short video APP running in the foreground is an application of a preset type, and the scene recognition module 1021 can transmit the second information that the first short video APP running in the foreground is an application of the preset type to the kernel layer 104.
[0183] The thread scheduling module 1041 located in the kernel layer 104 responds to the second information and obtains the current available resources of the electronic device, including the remaining available resources of the CPU and the remaining available resources of the memory. If it is determined that the available resources do not meet the preset conditions, it indicates that the available resources of the device are sufficient to ensure the operation requirements of the first short video APP, and there is no need to trigger the thread scheduling process to provide the first short video APP with the required operating environment, that is, the target thread to be scheduled is not determined.
[0184] If it is determined that the available resources meet the preset conditions, the thread scheduling module 1041 determines the target thread that needs to be scheduled in the short video scenario. For example, the target thread that needs to be scheduled in the short video scenario can be obtained by searching the thread whitelist. After determining the target thread that needs to be scheduled, the thread scheduling module 1041 can also obtain the thread information (including TID) of the target thread by searching the thread scheduling database. After determining the target thread that needs to be scheduled, the thread scheduling module 1041 can parse the binary data corresponding to each TID stored in the data structure in the kernel node based on the TID of each target thread that needs to be scheduled, and obtain the scheduling policy of each target thread that needs to be scheduled. The thread scheduling module 1041 can schedule each target thread separately based on the scheduling policy and thread information of each target thread that needs to be scheduled.
[0185] See also Fig.12 As shown, the electronic device 100 can be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, a vehicle-mounted device, a smart home device and / or a smart city device. The embodiments of the present application do not impose any special restrictions on the specific type of the electronic device 100.
[0186] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a Universal Serial Bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a Subscriber Identification Module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0187] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0188] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0189] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0190] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0191] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an Inter-integrated Circuit (I2C) interface, an Inter-integrated Circuit Sound (I2S) interface, a Pulse Code Modulation (PCM) interface, a Universal Asynchronous Receiver / Transmitter (UART) interface, a Mobile Industry Processor Interface (MIPI), a General-Purpose Input / Output (GPIO) interface, a Subscriber Identity Module (SIM) interface, and / or a Universal Serial Bus (USB) interface, etc.
[0192] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface to realize the touch function of the electronic device 100.
[0193] The I2S interface can be used for audio communication.
[0194] The PCM interface can also be used for audio communication to sample, quantize and encode analog signals.
[0195] The UART interface is a universal serial data bus used for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication.
[0196] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the display screen 194 communicate via the DSI interface to realize the display function of the electronic device 100.
[0197] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or a data signal.
[0198] The USB interface 130 is an interface that complies with USB standard specifications, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
[0199] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0200] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0201] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, Microled, Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0202] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0203] The internal memory 121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).
[0204] Random access memory may include static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM, for example, the fifth generation DDR SDRAM is generally referred to as DDR5 SDRAM), etc.;
[0205] Non-volatile memory may include disk storage devices and flash memory.
[0206] Flash memory can be divided into NOR FLASH, NAND FLASH, 3D NAND FLASH, etc. according to the operating principle. It can be divided into single-level cell (SLC), multi-level cell (MLC), triple-level cell (TLC), quad-level cell (QLC), etc. according to the storage unit potential level. It can be divided into universal flash storage (UFS), embedded Multi Media Card (eMMC), etc. according to the storage specification.
[0207] The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data.
[0208] The non-volatile memory may also store executable programs and user and application data, etc., and may be loaded into the random access memory in advance for direct reading and writing by the processor 110 .
[0209] The external memory interface 120 can be used to connect to an external non-volatile memory to expand the storage capacity of the electronic device 100. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos are stored in the external non-volatile memory.
[0210] The internal memory 121 or the external memory interface 120 is used to store one or more computer programs. The one or more computer programs are configured to be executed by the processor 110. The one or more computer programs include multiple instructions. When the multiple instructions are executed by the processor 110, the thread scheduling method executed on the electronic device 100 in the above embodiment can be implemented to implement the handwriting input display function of the electronic device 100.
[0211] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
[0212] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0213] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive a blood pressure beat signal. In some embodiments, the bone conduction sensor 180M can also be set in an earphone and combined into a bone conduction earphone. The audio module 170 can parse out a voice signal based on the vibration signal of the vibrating bone block of the vocal part obtained by the bone conduction sensor 180M to realize a voice function. The application processor can parse the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 180M to realize a heart rate detection function.
[0214] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0215] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0216] The indicator 192 may be an indicator light, which may be used to indicate the charging status, power changes, messages, missed calls, notifications, etc.
[0217] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
[0218] This embodiment further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on the electronic device 100, the electronic device 100 executes the above-mentioned related method steps to implement the thread scheduling method in the above-mentioned embodiment.
[0219] This embodiment also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement the thread scheduling method in the above-mentioned embodiment.
[0220] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory so that the chip executes the thread scheduling method in the above-mentioned method embodiments.
[0221] Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here.
[0222] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0223] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0224] The unit described as a separate component may or may not be physically separated, and the component shown as a unit may be one physical unit or multiple physical units, that is, it may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
[0225] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0226] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.
[0227] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.< / canvas> < / video> < / videoview> < / imgview> < / textview>
Claims
1. A thread scheduling method, applied to electronic equipment, It is characterized in that The method comprises: In the case where the first application program running in the foreground of the electronic device is an application program of a preset type, determining a target thread to be scheduled, and obtaining thread information of the target thread; Obtaining a scheduling policy for the target thread, where the scheduling policy for the target thread is determined based on a historical device load of the first application; The target thread is scheduled based on the scheduling policy and the thread information, wherein the scheduling includes setting thread attributes of the target thread, wherein the electronic device includes a thread scheduling database, and the thread scheduling database maintains the thread attributes of the target thread before scheduling and the thread attributes of the target thread after scheduling; When a preset event is detected, the thread attributes of the target thread are restored from the thread attributes after scheduling to the thread attributes before scheduling, or from the thread attributes before scheduling to the thread attributes after scheduling based on the process scheduling database.
2. The thread scheduling method according to claim 1, It is characterized in that In the case where the first application program running in the foreground of the electronic device is an application program of a preset type, determining a target thread to be scheduled includes: In a case where the first application program running in the foreground of the electronic device is an application program of a preset type, obtaining available resources of the electronic device, wherein the available resources include remaining available resources of a central processing unit CPU and / or remaining available resources of a memory; When the available resources meet the preset conditions, a target thread that needs to be scheduled is determined.
3. The thread scheduling method according to claim 1, It is characterized in that The method further comprises: Based on the information obtained in the process control block PCB, the identifier of the target thread and the thread attributes of the target thread before scheduling are maintained in the thread scheduling database; Obtaining thread attributes of the target thread after scheduling, and maintaining the thread attributes of the target thread after scheduling in the thread scheduling database, wherein the thread attributes after scheduling are determined based on the historical device load of the first application.
4. The thread scheduling method according to claim 3, It is characterized in that The obtaining thread information of the target thread includes: The thread information of the target thread is obtained from the thread scheduling database.
5. The thread scheduling method according to claim 3, It is characterized in that After scheduling the target thread based on the scheduling policy and the thread information, the method further includes: In the case where it is detected that the target thread is abnormally destroyed, the recreated target thread is restored to the thread attributes after scheduling based on the thread scheduling database.
6. The thread scheduling method according to claim 3, It is characterized in that The method of restoring the thread attributes of the target thread from the thread attributes after scheduling to the thread attributes before scheduling based on the process scheduling database when a preset event is detected includes: When it is detected that the application running in the foreground of the electronic device is changed from the first application to the second application, and the second application is not an application of the preset type, the thread attributes of the target thread are restored from the thread attributes after scheduling to the thread attributes before scheduling based on the thread scheduling database.
7. The thread scheduling method according to claim 3, It is characterized in that The method of restoring the thread attributes of the target thread from the thread attributes after scheduling to the thread attributes before scheduling based on the process scheduling database when a preset event is detected includes: When it is detected that the electronic device is in a screen-off state, the thread attributes of the target thread are restored from the thread attributes after scheduling to the thread attributes before scheduling based on the thread scheduling database.
8. The thread scheduling method according to claim 7, It is characterized in that The restoring the thread attributes before the scheduling to the thread attributes after the scheduling includes: When it is detected that the electronic device changes from a screen-off state to a screen-on state, or from a screen-off state to displaying the interface of the first application, the thread attributes of the target thread are restored from the thread attributes before the scheduling to the thread attributes after the scheduling based on the thread scheduling database.
9. The thread scheduling method according to any one of claims 1 to 8, It is characterized in that The determining of the target thread to be scheduled includes: Identifying a scenario to which the first application belongs; A target thread to be scheduled is determined based on the scenario to which the first application belongs, and the electronic device stores scheduling threads corresponding to a plurality of scenarios respectively.
10. The thread scheduling method according to any one of claims 1 to 8, It is characterized in that The method further comprises: Obtaining a historical device load of the first application, and obtaining an average device load of the first application based on the historical device load; Determine a predicted device load when the first application is run in the foreground next time based on the average load of the device and the load of the device when the first application is run in the foreground most recently; A scheduling policy for the target thread is determined based on the predicted device load.
11. The thread scheduling method according to claim 10, It is characterized in that The electronic device includes a kernel node, the kernel node includes a data structure for storing a scheduling policy of the target thread, and the obtaining the scheduling policy of the target thread includes: The data stored in the data structure in the kernel node is parsed to obtain the scheduling policy of the target thread.
12. The thread scheduling method according to claim 11, It is characterized in that The CPU of the electronic device includes multiple cores, the thread attribute includes affinity, and determining the scheduling strategy of the target thread based on the predicted device load includes: Clustering the multiple cores to obtain multiple CPU clusters; Based on the predicted device load, an operation strategy of the target thread in each CPU cluster in the multiple CPU clusters is determined, and the data structure stores the operation strategy of the target thread in each CPU cluster in bits.
13. The thread scheduling method according to claim 11, It is characterized in that The thread attribute includes a priority, and determining the scheduling strategy of the target thread based on the predicted device load includes: Based on the predicted device load, the priority of the target thread is determined, and the data structure stores binary data having a mapping relationship with the priority of the target thread.
14. The thread scheduling method according to any one of claims 1 to 8, It is characterized in that The thread attributes include affinity and / or priority.
15. An electronic device, It is characterized in that The electronic device comprises a memory and a processor: Wherein, the memory is used to store program instructions; The processor is used to read and execute the program instructions stored in the memory. When the program instructions are executed by the processor, the electronic device executes the thread scheduling method according to any one of claims 1 to 13.
16. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores program instructions, and when the program instructions are executed on an electronic device, the electronic device executes the thread scheduling method according to any one of claims 1 to 13.
