Thread scheduling method and apparatus, storage medium, and electronic device
By setting the Android application's drawing thread and main thread to a deadline-based scheduling class, and the auxiliary thread to a fair scheduling class, and running them on different CPU cores, the stuttering problem caused by the preemption of the application's drawing thread in the Android system is solved, and the application runs smoothly.
Patent Information
- Application Number
- CN202111402516.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2041-11-19
AI Technical Summary
In the Android system, even if the application's drawing thread has the highest priority among threads in the fair scheduling class, its time slice may still be preempted by other threads, causing the application to lag.
Set the application's drawing thread type to the deadline scheduling class, the main thread to the deadline scheduling class, and the auxiliary threads to the fair scheduling class. Schedule according to the scheduling priority of each type of thread, and run real-time scheduling threads in different central processing units to improve the smoothness of the application.
It effectively avoids lag during application runtime and improves the smoothness of application use.
Smart Images

Figure CN114035926B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to an application thread scheduling method, apparatus, storage medium, and electronic device. Background Technology
[0002] In the Android system, application rendering threads are usually classified as threads with complete fair scheduling (CFS). There are hundreds or thousands of threads with complete fair scheduling in the Android system. When the system is busy, even if the application rendering thread has the highest priority among the threads with complete fair scheduling, there will still be situations where the allocated time slice is used up and it is preempted by other threads, resulting in the application running lag. Summary of the Invention
[0003] This application provides a solution that can effectively avoid application lag during runtime and improve the smoothness of application use.
[0004] To address the aforementioned technical problems, this application provides the following technical solutions:
[0005] According to one embodiment of this application, an application thread scheduling method includes: creating an application process for a target application, the application process including a secondary thread and a main thread; setting the type of the secondary thread to a fair scheduling class and the type of the main thread to a deadline scheduling class; creating an application rendering thread and setting the type of the application rendering thread to a deadline scheduling class; and scheduling the secondary thread, the main thread, and the application rendering thread according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class to run the target application.
[0006] In some embodiments of this application, the application drawing thread and the main thread of the deadline scheduling class are assigned to run in a first central processing unit; the method further includes: monitoring the target thread of the real-time scheduling class awakened in the operating system; and assigning the target thread to run in a second central processing unit, wherein the first central processing unit is different from the second central processing unit.
[0007] In some embodiments of this application, the step of assigning the target thread to the second central processing unit for execution includes: traversing all central processing units in the processor corresponding to the operating system to determine central processing units other than the first central processing unit as central processing units to be assigned; and determining the central processing unit with the smallest cumulative load from the central processing units to be assigned as the second central processing unit.
[0008] In some embodiments of this application, scheduling the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class includes: determining the scheduling parameters of each thread based on the tasks undertaken by the auxiliary thread, main thread, and application rendering thread; and scheduling the types of the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority and the scheduling parameters, wherein the thread scheduling priority corresponding to the deadline scheduling class is higher than that of the fair scheduling class.
[0009] In some embodiments of this application, scheduling the types of auxiliary threads, main threads, and application rendering threads according to the thread scheduling priority and the scheduling parameters includes: scheduling the main thread based on a deadline scheduler, according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the task handled by the main thread; scheduling the application rendering thread based on the deadline scheduler, according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the task handled by the application rendering thread; and scheduling the auxiliary threads based on fair scheduling, according to the thread scheduling priority corresponding to the fair scheduling class and the scheduling parameters corresponding to the task handled by the auxiliary thread.
[0010] In some embodiments of this application, the method further includes: scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class, wherein the thread scheduling priorities corresponding to the deadline scheduling class, the real-time scheduling class, and the fair scheduling class decrease sequentially.
[0011] In some embodiments of this application, scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class includes: scheduling the target thread based on the real-time scheduler according to the thread scheduling priority corresponding to the real-time scheduling class and the scheduling parameters corresponding to the task undertaken by the target thread.
[0012] According to one embodiment of this application, an application thread scheduling device includes: a first creation module for creating an application process of a target application, the application process including a secondary thread and a main thread; a setting module for setting the type of the secondary thread to a fair scheduling class and the type of the main thread to a deadline scheduling class; a second creation module for creating an application rendering thread and setting the type of the application rendering thread to a deadline scheduling class; and a scheduling module for scheduling the secondary thread, the main thread, and the application rendering thread according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class, so as to run the target application.
[0013] According to another embodiment of this application, a storage medium stores a computer program thereon, which, when executed by a computer's processor, causes the computer to perform the methods described in the embodiments of this application.
[0014] According to another embodiment of this application, an electronic device may include: a memory storing a computer program; and a processor reading the computer program stored in the memory to execute the methods described in the embodiments of this application.
[0015] In this embodiment, an application process for the target application is created and launched, the application process including a secondary thread and a main thread; the type of the secondary thread is set to a fair scheduling class, and the type of the main thread is set to a deadline scheduling class; an application rendering thread is created, and the type of the application rendering thread is set to a deadline scheduling class; the secondary thread, the main thread, and the application rendering thread are scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class to run the target application.
[0016] In this way, by setting the target application's rendering thread type to the deadline scheduling class, the main thread type to the deadline scheduling class, and other auxiliary threads to the fair scheduling class, based on the scheduling priority of these thread types in the Android system, the stuttering phenomenon during application runtime will be effectively avoided, and the smoothness of application usage will be improved. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 A schematic diagram of a system to which embodiments of this application can be applied is shown.
[0019] Figure 2 A flowchart of an application thread scheduling method according to an embodiment of this application is shown.
[0020] Figure 3 A block diagram of an application thread scheduling apparatus according to an embodiment of this application is shown.
[0021] Figure 4 A block diagram of an electronic device according to an embodiment of this application is shown. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0023] In the following description, specific embodiments of this application will be illustrated with reference to steps and symbols performed by one or more computers, unless otherwise stated. Therefore, these steps and operations will be referred to several times as being performed by a computer, and computer execution as referred to herein includes operations by a computer processing unit representing electronic signals of data in a structured format. This operation transforms the data or maintains it at a location in the computer's memory system, which can be reconfigured or otherwise alter the operation of the computer in a manner well known to those skilled in the art. The data structure maintained by the data is the physical location of the memory, which has specific characteristics defined by the data format. However, the principles of this application are described in the foregoing text, which is not intended to be limiting, and those skilled in the art will understand that many of the steps and operations described below can also be implemented in hardware.
[0024] Figure 1 A schematic diagram of a system 100 to which embodiments of this application can be applied is shown. For example... Figure 1 As shown, system 100 may include terminal 101 and terminal 102. Terminal 101 and terminal 102 can be any computer device, such as a computer, mobile phone, smartwatch, and home appliance. In one example, terminal 101 is a remote control, and terminal 102 is a smart TV.
[0025] In one embodiment of this example, terminal 102 may: create an application process for a target application, the application process including a secondary thread and a main thread; set the type of the secondary thread to a fair scheduling class and the type of the main thread to a deadline scheduling class; create an application rendering thread and set the type of the application rendering thread to a deadline scheduling class; schedule the secondary thread, the main thread, and the application rendering thread according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class to start the target application. The target application may be started by terminal 101 controlling terminal 102, or it may be started by terminal 102 under other control.
[0026] Figure 2 A flowchart illustrating an embodiment of an application thread scheduling method according to this application is shown. The execution entity of this application thread scheduling method can be any device, such as... Figure 1 Terminal 102 is shown.
[0027] like Figure 2 As shown, the application thread scheduling method may include steps S210 to S240.
[0028] Step S210: Create the application process of the target application to be launched, wherein the application process includes a secondary thread and a main thread;
[0029] Step S220: Set the type of the auxiliary thread to the fair scheduling class and set the type of the main thread to the deadline scheduling class;
[0030] Step S230: Create an application drawing thread and set the type of the application drawing thread to a deadline scheduling class;
[0031] Step S240: Schedule the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class to run the target application.
[0032] When a launch command is received for a target application, the system creates an application process for that application. The target application can be an application that is about to be launched, such as a TV playback application or a music application.
[0033] An application process is the program process corresponding to the target application, that is, the set of instructions active in the system corresponding to the target application. Typically, one application process has one application process. An application process can include at least one thread. The one thread that an application process must include is the main thread; the application process begins execution from the main thread. Other additional threads created within the application process are called auxiliary threads.
[0034] After creating the application process, set the type of the auxiliary threads in the application process to the complete fair scheduler class, and set the type of the main thread to the deadline scheduler class. The complete fair scheduler (CFS) schedules threads according to their allocated time slices, in descending order of priority. The deadline scheduler (DL) schedules threads according to their final deadline; it always selects the thread with the closest deadline to the current time and schedules it for execution.
[0035] Next, create an application rendering thread and set its type to a deadline-scheduled class. The application rendering thread is the thread that renders the application; improper scheduling of this thread can cause rendering stutters and consequently, application display lag.
[0036] Finally, the auxiliary thread, main thread, and application rendering thread are scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class. Based on the thread scheduling mechanism in Android, the target application can run very smoothly without lag.
[0037] In this way, based on steps S210 to S240, by setting the application drawing thread type of the target application to the deadline scheduling class, the main thread type to the deadline scheduling class, and other auxiliary threads to the fair scheduling class, based on the scheduling priority of these types of threads in the Android system, the phenomenon of application lag during operation will be effectively avoided, and the smoothness of application use will be improved.
[0038] The following describes the specific steps involved in application thread scheduling.
[0039] In step S210, an application process for the target application is created and started, the application process including a secondary thread and a main thread.
[0040] In this example implementation, when a launch command is received for the target application, the system creates an application process for the target application. The target application can be an application that is about to be launched, such as a TV playback application or a music application.
[0041] An application process is the program process corresponding to a target application, that is, the set of instructions active in the system corresponding to the target application. Typically, one application has one application process. An application process can include at least one thread. A thread is the basic unit for the system to allocate processor time resources, or in other words, an independently executing unit within a process.
[0042] An application process must include one thread, the main thread. A process begins with the execution of the main thread, and other additional threads are called auxiliary threads.
[0043] In step S220, the type of the auxiliary thread is set to the fair scheduling class, and the type of the main thread is set to the deadline scheduling class.
[0044] In this example implementation, after creating the application process, the type of the auxiliary thread in the application process is set to the fair scheduling class, and the type of the main thread is set to the deadline scheduling class.
[0045] Complete fair schedule (CFS) is a type of scheduling that arranges threads according to their allocated time slices, in descending order of their scheduling priority. For example, a thread A with the highest priority is scheduled and runs within its allocated time slice. After the time slice expires (thread A's task may not be completed), it stops running and is re-queued at the end of the queue of all threads in the complete fair schedule, waiting for the queue to be filled before being called again according to priority.
[0046] Deadline schedule (DL) is a type of scheduling that follows the thread’s last scheduling deadline. The deadline scheduler always selects the thread whose last scheduling deadline is closest to the current time and schedules it for execution.
[0047] In step S230, an application drawing thread is created, and the type of the application drawing thread is set to a deadline scheduling class.
[0048] In this example implementation, the application drawing thread is the thread that draws the application, such as the user interface (UI) drawing thread, the render thread, and the animation thread. Improper scheduling of the application drawing thread will cause application drawing to lag, which in turn will lead to application display lag.
[0049] In step S240, the auxiliary thread, main thread, and application rendering thread are scheduled according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class to run the target application.
[0050] In this example implementation, the scheduling priority of the deadline scheduling class thread in the Android system is higher than that of the fair scheduling class thread. Based on the thread scheduling mechanism in Android, by dynamically adjusting the thread type, especially adjusting the application drawing thread type to the highest scheduling priority type, the target application can run very smoothly without lag.
[0051] In one embodiment, the application rendering thread and the main thread of the deadline scheduling class are assigned to run in a first central processing unit; after step S240, the method further includes: monitoring the target thread of the real-time scheduling class that is woken up in the operating system; and assigning the target thread to run in a second central processing unit, wherein the first central processing unit is different from the second central processing unit.
[0052] Real-time schedule (RT) refers to threads that are scheduled in real time according to demand. In the Android system, the scheduling priority of RT threads is higher than that of fair schedule threads, and the scheduling priority of deadline schedule threads is higher than that of RT threads.
[0053] The target thread of the real-time scheduling class is placed to run in the second central processing unit, while the application rendering thread and the main thread of the deadline scheduling class are allocated to run in the first central processing unit. The central processing unit is the CPU core. Based on the CPU multi-core mechanism, the two types of threads run in different CPU cores, which further avoids the real-time scheduling thread and the deadline scheduling thread from competing for CPU resources and further improves the smoothness of application operation.
[0054] In one embodiment, the step of assigning the target thread to a second central processing unit (CPU) for execution includes: traversing all CPUs in the processor corresponding to the operating system to determine CPUs other than the first CPU as CPUs to be assigned; and determining the CPU with the lowest cumulative load from the CPUs to be assigned as the second CPU.
[0055] By traversing all central processing units (CPUs) in the processor, the CPU with the smallest cumulative number of CPU units among those CPUs that do not run threads with deadlines (i.e., CPUs other than the first CPU) is selected to run a real-time scheduling class linear operation, thereby further improving the reliability of application operation.
[0056] In one embodiment, step S240, scheduling the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class, includes:
[0057] The scheduling parameters for each thread are determined based on the tasks undertaken by the auxiliary thread, the main thread, and the application rendering thread. The types of the auxiliary thread, the main thread, and the application rendering thread are scheduled according to the thread scheduling priority and the scheduling parameters, wherein the thread scheduling priority corresponding to the deadline scheduling class is higher than that of the fair scheduling class.
[0058] In the Android system, threads scheduled under the deadline category have higher scheduling priority than threads scheduled under the fair category. During thread scheduling, the main thread and application rendering thread, which have higher priority, are prioritized. Each thread has scheduling parameters set based on its corresponding task. For example, threads scheduled under the fair category can set time slice parameters, while threads scheduled under the deadline category can set parameters such as period, runtime, and deadline. Therefore, the Android scheduler can effectively schedule each thread based on its priority and the scheduling parameters corresponding to each thread.
[0059] In one embodiment, scheduling the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority and the scheduling parameters includes:
[0060] Based on the deadline scheduler, the main thread is scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the tasks handled by the main thread; based on the deadline scheduler, the application rendering thread is scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the tasks handled by the application rendering thread; based on the fair scheduler, the auxiliary thread is scheduled according to the thread scheduling priority corresponding to the fair scheduling class and the scheduling parameters corresponding to the tasks handled by the auxiliary thread.
[0061] The deadline scheduler is used to schedule threads that are scheduled to have a deadline. For the deadline scheduler, users can set three scheduling parameters: period, runtime, and deadline. The period is related to the working mode of the real-time task corresponding to the thread. For example, for a video processing task, its main task is to process 60 frames of video data per second, that is, to process each frame of video every 16 milliseconds. Therefore, the period of this task is 16ms. For real-time tasks, there is always a fixed amount of "work" to be done within a period. For example, in a video task, the so-called work is to process one frame of video data. The runtime is the CPU execution time required to complete this "work," that is, the time value of CPU participation in computation within a period. When setting the runtime parameter, we cannot be too optimistic; the worst-case execution time (WCET) must be considered when setting the runtime. For example, in video processing, the situation of each frame may be different (on the one hand, the correlation between frames is different, and on the other hand, even for a single frame of data, the correlation between its image pixels is different), some will take longer and some will take shorter. If the video frame with the longest processing time requires 5 milliseconds to process, then its running time is set to five milliseconds.
[0062] Based on the deadline scheduler, the main thread can be scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters (three scheduling parameters: period, runtime, and deadline) corresponding to the task handled by the main thread; based on the deadline scheduler, the application rendering thread can be scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters (three scheduling parameters: period, runtime, and deadline) corresponding to the task handled by the application rendering thread.
[0063] The Complete Fair Scheduler (CFS) is a scheduler used to schedule threads that are part of the Complete Fair Scheduler (CFS) class. The scheduling parameters for CFS threads mainly include time slice parameters. For CFS threads, the CFS scheduler schedules threads according to their allocated time slices, in descending order of priority. For example, a thread A with the highest priority is scheduled and runs within its allocated time slice. After the time slice expires (thread A's task may not be completed), it stops running and is re-queued at the end of the queue of all CFS threads, waiting to be called again according to priority when the queue is reached.
[0064] In one embodiment, the method further includes: scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class, wherein the thread scheduling priorities corresponding to the deadline scheduling class, the real-time scheduling class, and the fair scheduling class decrease sequentially.
[0065] The thread scheduling priorities corresponding to the deadline scheduling class, the real-time scheduling class, and the fair scheduling class decrease sequentially. That is, in the Android system, the scheduling priority of the real-time scheduling class thread is higher than that of the fair scheduling class thread, and the scheduling priority of the deadline scheduling class thread is higher than that of the real-time scheduling class thread. Based on this, the scheduling priority of each thread includes the real-time priority of the thread corresponding to the task. The Android system schedules the target thread of the real-time scheduling class based on this order and real-time priority, further improving the rationality of thread scheduling.
[0066] In one embodiment, scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class includes: scheduling the target thread based on the real-time scheduler, according to the thread scheduling priority corresponding to the real-time scheduling class and the scheduling parameters corresponding to the task undertaken by the target thread.
[0067] The POSIX real-time scheduler, or RT scheduler, has two scheduling policies: FIFO (first-in-first-out) and RR (round-robin). Regardless of FIFO or RR, the RT scheduler schedules tasks based on their real-time priority (the `rt_priority` member in the Linux process descriptor). The thread corresponding to the task with the highest real-time priority will acquire CPU resources first. In real-time theory, this type of scheduler is classified as a fixed-priority scheduler (meaning each RT task is assigned a fixed priority). When real-time priorities are different, there is no difference between FIFO and RR; the difference only becomes apparent when two tasks have the same priority.
[0068] For a FIFO scheduler, the task that first enters the runtime state will acquire CPU resources and hold them until the process enters a sleep state. For a RR scheduler, tasks with the same priority will share processor resources in a round-robin fashion. Once an RR task starts running, if it doesn't block, it will run until its allocated time slice expires. When the time slice is used up, the scheduler will place the task at the end of the task list (note that only tasks with the same priority are placed in the same list; tasks with different priorities are placed in different lists), and then select the next task from the list to execute.
[0069] To facilitate better implementation of the application thread scheduling method provided in this application embodiment, this application embodiment also provides an application thread scheduling device based on the above application thread scheduling method. The meanings of the terms used are the same as in the above application thread scheduling method, and specific implementation details can be found in the description of the method embodiment. Figure 3 A block diagram of an application thread scheduling apparatus according to an embodiment of this application is shown.
[0070] like Figure 3 As shown, the application thread scheduling device 300 may include a first creation module 310, a setting module 320, a second creation module 330, and a scheduling module 340.
[0071] The first creation module 310 can be used to create an application process for the target application, which includes a secondary thread and a main thread. The setting module 320 can be used to set the type of the secondary thread to a fair scheduling class and the type of the main thread to a deadline scheduling class. The second creation module 330 can be used to create an application drawing thread and set the type of the application drawing thread to a deadline scheduling class. The scheduling module 340 can be used to schedule the secondary thread, the main thread, and the application drawing thread according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class to run the target application.
[0072] In some embodiments of this application, the application drawing thread and the main thread of the deadline scheduling class are assigned to run in a first central processing unit; the device further includes a monitoring module for: monitoring the target thread of the real-time scheduling class awakened in the operating system; and assigning the target thread to run in a second central processing unit, wherein the first central processing unit is different from the second central processing unit.
[0073] In some embodiments of this application, the monitoring module includes an allocation unit, configured to: traverse all central processing units (CPUs) in the processor corresponding to the operating system to determine CPUs other than the first CPU as CPUs to be allocated; and determine the CPU with the lowest cumulative load from the CPUs to be allocated as the second CPU.
[0074] In some embodiments of this application, the scheduling module 340 includes: a determining unit, configured to determine the scheduling parameters of each thread based on the tasks undertaken by the auxiliary thread, the main thread, and the application rendering thread; and a scheduling unit, configured to schedule the types of the auxiliary thread, the main thread, and the application rendering thread according to the thread scheduling priority and the scheduling parameters, wherein the thread scheduling priority corresponding to the deadline scheduling class is higher than that of the fair scheduling class.
[0075] In some embodiments of this application, the scheduling unit is configured to: schedule the main thread based on a deadline scheduler, according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the task handled by the main thread; schedule the application rendering thread based on the deadline scheduler, according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the task handled by the application rendering thread; and schedule the auxiliary thread based on fair scheduling, according to the thread scheduling priority corresponding to the fair scheduling class and the scheduling parameters corresponding to the task handled by the auxiliary thread.
[0076] In some embodiments of this application, the apparatus further includes a target scheduling unit, configured to: schedule the target thread according to the thread scheduling priority corresponding to the real-time scheduling class, wherein the thread scheduling priorities corresponding to the deadline scheduling class, the real-time scheduling class, and the fair scheduling class decrease sequentially.
[0077] In some embodiments of this application, the target scheduling unit is used to: schedule the target thread based on a real-time scheduler, according to the thread scheduling priority corresponding to the real-time scheduling class and the scheduling parameters corresponding to the task undertaken by the target thread.
[0078] In this way, based on the application thread scheduler 300, by setting the application drawing thread type of the target application to the deadline scheduling class, the main thread type to the deadline scheduling class, and other auxiliary threads to the fair scheduling class, based on the scheduling priority of these types of threads in the Android system, the phenomenon of application lag during operation will be effectively avoided, and the smoothness of application use will be improved.
[0079] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0080] Furthermore, embodiments of this application also provide an electronic device, which can be a terminal or a server, such as... Figure 4 As shown, it illustrates a structural schematic diagram of the electronic device involved in the embodiments of this application, specifically:
[0081] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will understand that... Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:
[0082] The processor 401 is the control center of the electronic device. It connects to various parts of the computer device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 402, and by calling data stored in the memory 402, it performs various functions of the computer device and processes data, thereby providing overall monitoring of the electronic device. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user page, and application programs, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 401.
[0083] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0084] The electronic device also includes a power supply 403 that supplies power to the various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 403 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0085] The electronic device may also include an input unit 404, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0086] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device loads the executable files corresponding to the processes of one or more computer programs into the memory 402 according to the following instructions, and the processor 401 runs the computer programs stored in the memory 402 to realize various functions. For example, the processor 401 can perform the following steps:
[0087] Create an application process for the target application, which includes a secondary thread and a main thread; set the type of the secondary thread to a fair scheduling class and the type of the main thread to a deadline scheduling class; create an application rendering thread and set the type of the application rendering thread to a deadline scheduling class; schedule the secondary thread, the main thread, and the application rendering thread according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class to run the target application.
[0088] In some embodiments of this application, the application drawing thread and the main thread of the deadline scheduling class are assigned to a first central processing unit (CPU) for execution; the processor 401 can perform: monitoring the target thread of the real-time scheduling class awakened in the operating system; and assigning the target thread to a second CPU for execution, wherein the first CPU and the second CPU are different.
[0089] In some embodiments of this application, when the target thread is assigned to the second central processing unit for execution, the processor 401 may perform the following: traverse all central processing units in the processor corresponding to the operating system to determine the central processing units other than the first central processing unit as the central processing units to be assigned; and determine the central processing unit with the smallest cumulative load from the central processing units to be assigned as the second central processing unit.
[0090] In some embodiments of this application, when scheduling the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class, the processor 401 may perform the following: determine the scheduling parameters of each thread based on the tasks undertaken by the auxiliary thread, main thread, and application rendering thread; schedule the types of the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority and the scheduling parameters, wherein the thread scheduling priority corresponding to the deadline scheduling class is higher than that of the fair scheduling class.
[0091] In some embodiments of this application, when scheduling the types of auxiliary threads, main threads, and application rendering threads according to the thread scheduling priority and the scheduling parameters, the processor 401 may perform the following: scheduling the main thread based on the deadline scheduler, according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the task handled by the main thread; scheduling the application rendering thread based on the deadline scheduler, according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the task handled by the application rendering thread; and scheduling the auxiliary threads based on fair scheduling, according to the thread scheduling priority corresponding to the fair scheduling class and the scheduling parameters corresponding to the task handled by the auxiliary thread.
[0092] In some embodiments of this application, the processor 401 may perform the following: scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class, wherein the thread scheduling priorities corresponding to the deadline scheduling class, the real-time scheduling class, and the fair scheduling class decrease sequentially.
[0093] In some embodiments of this application, when scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class, the processor 401 may execute: based on the real-time scheduler, scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class and the scheduling parameters corresponding to the task undertaken by the target thread.
[0094] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by a computer program, or by a computer program controlling related hardware. The computer program can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0095] Therefore, embodiments of this application also provide a storage medium storing a computer program that can be loaded by a processor to execute the steps in any of the methods provided in embodiments of this application.
[0096] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0097] Since the computer program stored in the storage medium can execute the steps of any of the methods provided in the embodiments of this application, the beneficial effects that the methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.
[0098] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0099] It should be understood that this application is not limited to the embodiments described above and shown in the accompanying drawings, but various modifications and changes can be made without departing from its scope.
Claims
1. An application thread scheduling method, characterized in that, include: Create and launch the application process of the target application, which includes a secondary thread and a main thread; Set the type of the auxiliary thread to the fair scheduling class, and set the type of the main thread to the deadline scheduling class; Create an application drawing thread and set the type of the application drawing thread to a deadline scheduling class; According to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class, the auxiliary thread, the main thread and the application rendering thread are scheduled to run the target application; The step of scheduling the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority corresponding to the deadline scheduling class and the fair scheduling class includes: The scheduling parameters for each thread are determined based on the tasks undertaken by the auxiliary thread, the main thread, and the application rendering thread; and the types of the auxiliary thread, the main thread, and the application rendering thread are scheduled according to the thread scheduling priority and the scheduling parameters, wherein the thread scheduling priority corresponding to the deadline scheduling class is higher than that of the fair scheduling class.
2. The method according to claim 1, characterized in that, The application rendering thread and the main thread of the deadline scheduling class are assigned to run in the first central processing unit. The method further includes: Monitor the target thread of the real-time scheduling class that is woken up in the operating system; The target thread is assigned to run in a second central processing unit, which is different from the first central processing unit.
3. The method according to claim 2, characterized in that, The step of allocating the target thread to the second central processing unit for execution includes: Traverse all central processing units in the processor corresponding to the operating system to determine the central processing units other than the first central processing unit as the central processing units to be allocated. The central processing unit with the smallest cumulative load among the central processing units to be allocated is selected as the second central processing unit.
4. The method according to claim 1, characterized in that, The step of scheduling the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priority and the scheduling parameters includes: Based on the deadline scheduler, the main thread is scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the tasks handled by the main thread. Based on the deadline scheduler, the application rendering thread is scheduled according to the thread scheduling priority corresponding to the deadline scheduling class and the scheduling parameters corresponding to the tasks undertaken by the application rendering thread. Based on fair scheduling, the auxiliary thread is scheduled according to the thread scheduling priority corresponding to the fair scheduling class and the scheduling parameters corresponding to the task undertaken by the auxiliary thread.
5. The method according to claim 2, characterized in that, The method further includes: The target thread is scheduled according to the thread scheduling priority corresponding to the real-time scheduling class, wherein the thread scheduling priority corresponding to the deadline scheduling class, the real-time scheduling class, and the fair scheduling class decreases in that order.
6. The method according to claim 5, characterized in that, The step of scheduling the target thread according to the thread scheduling priority corresponding to the real-time scheduling class includes: Based on the real-time scheduler, the target thread is scheduled according to the thread scheduling priority corresponding to the real-time scheduling class and the scheduling parameters corresponding to the task undertaken by the target thread.
7. An application thread scheduling device, characterized in that, include: The first creation module is used to create the application process of the target application to be launched, and the application process includes auxiliary threads and main threads; The configuration module is used to set the type of the auxiliary thread to the fair scheduling class and the type of the main thread to the deadline scheduling class. The second creation module is used to create an application drawing thread and set the type of the application drawing thread to a deadline scheduling class. A scheduling module is used to schedule the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class, so as to run the target application. The scheduling of the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priorities corresponding to the deadline scheduling class and the fair scheduling class includes: determining the scheduling parameters of each thread based on the tasks undertaken by the auxiliary thread, main thread, and application rendering thread; and scheduling the types of the auxiliary thread, main thread, and application rendering thread according to the thread scheduling priorities and the scheduling parameters, wherein the thread scheduling priority corresponding to the deadline scheduling class is higher than that of the fair scheduling class.
8. A storage medium, characterized in that, It stores a computer program that, when executed by the computer's processor, causes the computer to perform the method described in any one of claims 1 to 6.
9. An electronic device, characterized in that, include: Memory, which stores computer programs; A processor reads a computer program stored in memory to perform the method described in any one of claims 1 to 6.
Citation Information
Patent Citations
Optimization method and system for IO (Input Output) dispatching cfq (Complete Fairness Queueing) algorithm
CN106293917A
Data processing method and apparatus, and electronic device
WO2021013055A1