Task scheduling control method and device, electronic equipment and storage medium
By compensating and re-enqueuing the tasks in runnable state virtual runtime, the problem of difficulty in optimizing CPU performance in the prior art is solved, and faster task scheduling and improvement of CPU performance are achieved.
Patent Information
- Application Number
- CN202510125653.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-26
- Publication Date
- 2025-05-30
AI Technical Summary
The prior art is difficult to optimize performance of tasks in runnable states, resulting in the inability to effectively improve CPU performance.
Performance optimization of runnable state tasks is achieved by dequeuing target tasks from the ready queue corresponding to Fully Fair Scheduling (CFS), compensating their current virtual runtime to reduce virtual runtime, and re-enqueuing.
The duration of tasks in the runnable state is shortened, and the scheduling priority of tasks in the ready queue is increased, resulting in tasks being scheduled and executed by the CPU more quickly, thereby achieving improvements in CPU performance.
Smart Images

Figure CN120066716A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a task scheduling control method, apparatus, electronic device, and storage medium. Background Art
[0002] The performance of a Central Processing Unit (CPU) is one of the important indicators for measuring the performance of a computer, and its level directly affects the overall performance of the computer system. Therefore, CPU performance optimization has always been one of the key concerns. In CPU performance optimization, the optimization points are usually set at the task wake-up time and the running time of the CPU. For example, when waking up a task, the task is enqueued in a high-priority queue so as to be selected to run on the CPU as soon as possible. Another example is to execute a preemption prevention strategy for the task running on the CPU. However, for tasks in the runnable state, the above optimization methods are ineffective, and there is a large technical gap. Summary of the Invention
[0003] Embodiments of this application disclose a task scheduling control method, apparatus, electronic device, and storage medium, which can optimize the performance of tasks in the runnable state, thereby improving CPU performance.
[0004] In a first aspect, embodiments of this application disclose a task scheduling control method, including:
[0005] Dequeue a target task from a ready queue corresponding to a Completely Fair Scheduler (CFS), where the ready queue includes multiple tasks in the runnable state, the target task is one or more of the multiple tasks in the runnable state, and each of the multiple tasks in the runnable state corresponds to a current virtual running time;
[0006] Compensate the current virtual running time of the target task to obtain a target virtual running time, where the target virtual running time is less than the current virtual running time of the target task;
[0007] According to the target virtual running time, requeue the target task to the ready queue.
[0008] In some feasible embodiments, after requeuing the target task to the ready queue according to the target virtual running time, the method further includes:
[0009] Perform a trigger operation for rescheduling on a central processing unit (CPU) corresponding to the ready queue.
[0010] In some feasible embodiments, compensating the current virtual running time of the target task to obtain a target virtual running time includes:
[0011] Obtaining the type of the application scenario of the target task;
[0012] Obtaining a compensation value corresponding to the type of the application scenario;
[0013] Calculating the difference between the current virtual running time of the target task and the compensation value to obtain the target virtual running time.
[0014] In some feasible embodiments, obtaining the compensation value corresponding to the type of the application scenario includes:
[0015] Obtaining a compensation ratio corresponding to the target task;
[0016] Calculating the compensation value according to the current virtual running time of the target task and the compensation ratio.
[0017] In some feasible embodiments, before dequeuing the target task from the ready queue corresponding to the Completely Fair Scheduler (CFS), the method further includes:
[0018] When reaching a promotion set point, obtaining a task to be processed, where the task to be processed meets a preset performance promotion condition;
[0019] Setting a performance promotion flag for the task to be processed;
[0020] Waking up the task to be processed and obtaining the current virtual running time of the task to be processed, and enqueuing the task to be processed into the ready queue to become a task in a runnable state;
[0021] Dequeuing the target task from the ready queue corresponding to the Completely Fair Scheduler (CFS) includes:
[0022] After detecting that a new task in a runnable state enters the ready queue, determining whether the new task in a runnable state is set with the performance promotion flag;
[0023] After determining that the new task in a runnable state is set with the performance promotion flag, using the new task in a runnable state as the target task and dequeuing the target task from the ready queue.
[0024] In some feasible embodiments, the promotion set point at least includes: receiving a synchronous binder communication message of the previous drawing frame thread, or the previous drawing frame thread being blocked by a lock, or the application (APP) switching from the background to the foreground, or the APP being in focus, or the APP changing from not being in focus to being in focus.
[0025] In some feasible embodiments, the preset performance improvement conditions at least include a status condition and an operating condition. The status condition includes the user interface main thread or the Render thread of an APP in the foreground, or the user interface main thread or the Render thread of the APP currently in focus. The operating condition includes that the actual running time of a task for a single time is less than a time threshold.
[0026] In some feasible embodiments, the total number of all runnable tasks with the performance improvement identifier set in the ready queue does not exceed a preset quantity threshold.
[0027] In a second aspect, an embodiment of the present application discloses a task scheduling control device, which may include:
[0028] A dequeue module, configured to dequeue a target task from the ready queue corresponding to the Completely Fair Scheduling (CFS). The ready queue includes multiple runnable tasks, and the target task is one or more of the multiple runnable tasks. Each of the multiple runnable tasks corresponds to a current virtual running time.
[0029] A compensation adjustment module, configured to compensate the current virtual running time of the target task to obtain a target virtual running time, where the target virtual running time is less than the current virtual running time of the target task.
[0030] An enqueue module, configured to re-enqueue the target task to the ready queue according to the target virtual running time.
[0031] In a third aspect, an embodiment of the present application discloses an electronic device, which may include:
[0032] A memory storing executable program code;
[0033] A processor coupled to the memory;
[0034] The processor calls the executable program code stored in the memory to execute a task scheduling control method disclosed in the first aspect of the embodiments of the present application.
[0035] In a fourth aspect, an embodiment of the present application discloses a computer-readable storage medium, which stores a computer program. The computer program enables a computer to execute a task scheduling control method disclosed in the first aspect of the embodiments of the present application.
[0036] In a fifth aspect, an embodiment of the present application discloses a computer program product. When the computer program product runs on a computer, it enables the computer to execute some or all of the steps of any one of the methods in the first aspect.
[0037] In a sixth aspect, an embodiment of the present application discloses an application publishing platform for publishing a computer program product. When the computer program product runs on a computer, the computer is caused to execute some or all of the steps of any one of the methods in the first aspect.
[0038] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0039] In the embodiment of the present application, first, a target task is dequeued from the ready queue corresponding to CFS. The ready queue includes multiple runnable tasks, the target task is one or more of the multiple runnable tasks, and each of the multiple runnable tasks corresponds to a current virtual run time. Then, the current virtual run time of the target task is compensated to obtain a target virtual run time, which is less than the current virtual run time of the target task. Finally, according to the target virtual run time, the target task is re-queued to the ready queue. It can be seen that by implementing the embodiment of the present application, for a runnable task in the ready queue of CFS, its virtual run time can be reduced by first dequeuing it, compensating its virtual run time, and then re-queuing it to the ready queue. Since the virtual run time is reduced, the duration of its runnable state is shortened, so that the priority of the target task being scheduled in the ready queue is increased, and it can be scheduled and executed by the CPU faster, achieving performance improvement of the target task. Description of the Drawings
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0041] Figure 1 It is a schematic flowchart of a task scheduling control method disclosed in Embodiment 1 of the present application;
[0042] Figure 2 It is a schematic diagram of the application of a ready queue sorted according to the current virtual run time at the beginning disclosed in the embodiment of the present application;
[0043] Figure 3 It is disclosed in the embodiment of the present application that Figure 2 It is a schematic diagram of the application of the ready queue after the target task is compensated for the virtual run time and re-queued on this basis;
[0044] Figure 4 It is a schematic flowchart of a task scheduling control method disclosed in Embodiment 2 of the present application;
[0045] Figure 5 It is a schematic flowchart of the task scheduling control method disclosed in the third embodiment of this application;
[0046] Figure 6 It is a schematic structural diagram of the task scheduling control device disclosed in the first embodiment of this application;
[0047] Figure 7 It is a schematic structural diagram of the task scheduling control device disclosed in the second embodiment of this application;
[0048] Figure 8 It is a schematic structural diagram of the electronic device disclosed in the embodiment of the present invention. Detailed implementation manners
[0049] Next, the technical solutions in the embodiments of this application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application.
[0050] It should be noted that the terms "first", "second", "third", and "fourth", etc. in the description and claims of this application are used to distinguish different objects, rather than to describe a specific order. The terms "include" and "have" in the embodiments of this application and any of their deformations are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or are inherent to these processes, methods, products, or devices.
[0051] Exemplarily, the electronic device disclosed in the embodiments of this application includes devices such as terminal devices or servers. Among them, the terminal device can be a device such as a computer, a personal notebook, or a mobile phone. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms. The server can be directly or indirectly connected through wired or wireless communication methods.
[0052] The embodiments of the present application disclose a task scheduling control method, device, electronic device, and storage medium, which can shorten the duration of a task in the runnable state, accelerate the speed of being scheduled by the CPU, and improve the performance of the task.
[0053] In the embodiments of the present application, for the ready queue corresponding to the CFS of the CPU, the electronic device dequeues the runnable tasks with the performance improvement flag set from the ready queue, and then compensates the virtual run time (vruntime) of the dequeued runnable tasks. After compensation, the virtual run time decreases, and then the task is enqueued into the ready queue according to the virtual run time. Since the virtual run time decreases, the task will be closer to the head of the ready queue after enqueueing, and can be scheduled and executed by the CPU faster, shortening the duration of its runnable state, thereby improving its performance.
[0054] Among them, in the embodiments of the present application, in the CFS scheduling policy, CFS ensures the fairness of task scheduling through virtual run time. The CFS scheduler selects the task with the smallest virtual run time from the ready queue each time for scheduling, that is, it can be understood that: the virtual run time corresponds to the order of tasks in the ready queue being scheduled and executed. The smaller the virtual run time, the earlier the task is scheduled and executed, which is equivalent to a higher priority. The larger the virtual run time, the later the task is scheduled and executed, and the lower the priority. And in the embodiments of the present application, by reducing the virtual run time of the task, the order of the task being scheduled and executed (improving the priority) can be improved, so that the task is preferentially executed, realizing the performance improvement of the task.
[0055] It should be noted that the task disclosed in the embodiments of the present application is a thread. A thread is the smallest unit that the system can perform operation scheduling. Among them, a thread is included in a process and is the actual operation unit in the process. A thread refers to a single sequential control flow in a process. Through the orderly execution of each thread, the execution of system functions is realized.
[0056] Next, the technical solution of the present application will be introduced in detail through specific embodiments. First, please refer to Figure 1 , Figure 1 is a schematic flowchart of the task scheduling control method disclosed in Embodiment 1 of the present application; as Figure 1 shown, the task scheduling control method may include:
[0057] 101. Dequeue the target task from the ready queue corresponding to the CFS. The ready queue includes multiple runnable tasks, and the target task is one or more of the multiple runnable tasks. Each of the multiple runnable tasks corresponds to a current virtual run time.
[0058] Among them, the execution entities of the embodiments of the present application are terminal devices and / or servers. Exemplarily, the terminal devices and servers are as introduced above and will not be elaborated here. The target task is one or more of multiple tasks in a runnable state, and is a task that needs to improve performance.
[0059] The embodiments of the present application only target the tasks of the CFS corresponding to the CPU. For other types of tasks, such as Reaction Time (RT), DeadLine, etc., their priorities are already very high, and the embodiments of the present application do not need to be executed. Among them, one CPU corresponds to one CFS, and in the ready queue corresponding to the CFS, there can be multiple tasks in a runnable state. Each task in a runnable state corresponds to a current virtual running time. At the beginning, the tasks in the runnable state are sorted in the ready queue according to the size of the current virtual running time, that is, the smaller the current virtual running time, the closer to the head of the queue in the ready queue, and the larger the current virtual running time, the closer to the tail of the queue in the ready queue. Exemplarily, please refer to Figure 2 , Figure 2 is a schematic application diagram of the ready queue sorted according to the current virtual running time at the beginning, disclosed in the embodiments of the present application. In Figure 2 , there are 6 tasks in a runnable state in the ready queue (only taking 6 tasks as an example), namely Task A to Task F, including Task A, Task B, Task C, Task D, Task E, and Task F, and the corresponding virtual running times are Time 1, Time 2, Time 3, Time 4, Time 5, and Time 6 respectively. Among them, Time 2 < Time 6 < Time 4 < Time 1 < Time 5 < Time 3. Then the sorting of Task A to Task F in the ready queue (from the head of the queue to the tail of the queue) is: Task B - Task F - Task D - Task A - Task E - Task C, and the arrow direction is the dequeue direction.
[0060] Further, the scheduling order of the tasks in the runnable state in the ready queue by the CPU is also sorted according to the size of the virtual running time. The smaller the virtual running time, the more preferentially it is scheduled to be executed by the CPU, and the larger the virtual running time, the later it is scheduled to be executed by the CPU. Therefore, in combination with Figure 2 , the CPU will sequentially schedule tasks starting from the head of the ready queue.
[0061] 102. Compensate the current virtual running time of the target task to obtain a target virtual running time, and the target virtual running time is less than the current virtual running time of the target task.
[0062] In step 102, compensating the current virtual running time of the target task means adjusting the current virtual running time of the target task to adjust the current virtual running time to the target virtual running time.
[0063] It should be noted that the current virtual time of the target task is the virtual running time obtained when it is awakened. Among the other tasks in the ready queue except the target task, there may already be tasks that have undergone the compensation in step 102. At this time, the current virtual running time of this task is the time obtained after virtual running time compensation.
[0064] 103. According to the above target virtual running time, re-queue the target task to the ready queue.
[0065] Among them, after step 102, the target virtual running time finally corresponding to the target task is less than the current virtual running time. After re-queuing in step 103, the virtual running time of the target task in the ready queue is updated to the target virtual running time, which improves the priority of the target task to be scheduled and executed by the CPU, will accelerate the scheduling by the CPU, and can be reflected in that the sorting in the ready queue will move towards the head, getting closer to the queue head. Among them, re-queuing means re-hanging the target task to a suitable position in the ready queue, and the CPU schedules according to the current virtual running time of the tasks in the ready queue. After re-queuing, the current virtual running time of the target task is the target virtual running time.
[0066] Among them, at any time, the total number of tasks in the ready queue whose virtual running time has been adjusted in step 102 does not exceed a preset quantity threshold. Exemplarily, the preset quantity threshold is 6.
[0067] Combined Figure 2 Please refer to Figure 3 Figure 3 FIG. is an application schematic diagram of the ready queue after virtual running time compensation for the target task and then re-queuing based on what is disclosed in the embodiments of the present application; in Figure 2 On the basis of Figure 3 Among them, the target tasks are task A and task C. Combined Figure 2 with Figure 2 the current virtual running time of task A is time 1, and after compensation, the corresponding target virtual running time obtained is time 1'. Combined
[0068] Therefore, in the above embodiments, first dequeue the target task from the ready queue corresponding to CFS. The ready queue includes multiple tasks in the runnable state. The target task is one or more of the multiple tasks in the runnable state, and each of the multiple tasks in the runnable state corresponds to a current virtual run time. Then, compensate the current virtual run time of the target task to obtain a target virtual run time, where the target virtual run time is less than the current virtual run time of the target task. Finally, re-queue the target task to the ready queue according to the target virtual run time. Thus, for the target task in the ready queue of CFS, it can be dequeued first, its virtual run time can be compensated to reduce its virtual run time, and then it can be re-queued to the ready queue. Because the virtual run time is reduced, the duration of its runnable state is shortened, so that the priority of the target task being scheduled in the ready queue is increased and it can be scheduled and executed by the CPU faster, achieving performance improvement for the target task.
[0069] Please refer to Figure 4 , Figure 4 which is a schematic flowchart of the task scheduling control method disclosed in the second embodiment of this application. As Figure 4 shown, the task scheduling control method may include:
[0070] 401. Dequeue the target task from the ready queue corresponding to CFS. The ready queue includes multiple tasks in the runnable state. The target task is one or more of the multiple tasks in the runnable state, and each of the multiple tasks in the runnable state corresponds to a current virtual run time.
[0071] Among them, the execution subject of the embodiments of this application is a terminal device and / or a server. Exemplarily, the terminal device and the server are as introduced above and will not be elaborated here.
[0072] Optionally, the number of target tasks does not exceed a preset number threshold. Exemplarily, the number threshold is 6.
[0073] 402. Compensate the current virtual run time of the target task to obtain a target virtual run time, where the target virtual run time is less than the current virtual run time of the target task.
[0074] In step 402, compensating the current virtual run time of the target task means adjusting the current virtual run time of the target task to adjust the current virtual run time to the target virtual run time.
[0075] In some optional implementation manners, the above compensating the current virtual run time of the target task to obtain a target virtual run time includes:
[0076] Obtain the type of the application scenario of the target task;
[0077] Obtain the compensation value corresponding to the type of application scenario;
[0078] Calculate the difference between the current virtual running time of the target task and the compensation value to obtain the target virtual running time.
[0079] It should be noted that in the embodiments of the present application, for target tasks in different application scenarios, the compensation for virtual running time is different. Therefore, in this implementation manner, the corresponding compensation value will be specifically obtained according to the type of the application scenario of the target task, and then the difference between the current virtual running time of the target task and the compensation value will be calculated, that is, current virtual running time - compensation value = difference, and then the difference will be used as the target virtual running time.
[0080] Among them, the compensation value can be an empirical value and can be pre-stored in the local memory. The compensation values for tasks in different application scenarios are different. In the above implementation manner, first determine the type of the application scenario of the target task, and then directly read the compensation value corresponding to this type in the local memory.
[0081] Further, optionally, the obtaining the compensation value corresponding to the type of the application scenario includes:
[0082] Obtain the compensation ratio corresponding to the target task;
[0083] Calculate the compensation value according to the current virtual running time of the target task and the compensation ratio.
[0084] In this optional implementation manner, different compensation ratios can be given for tasks in different application scenarios, and then the compensation ratios are stored in the local memory. Among them, the compensation ratio is an empirical value and can be obtained through empirical settings.
[0085] Among them, calculating the compensation value according to the current virtual running time of the target task and the compensation ratio includes: calculating the product of the current virtual running time of the target task and the compensation ratio, and then using this product as the compensation value.
[0086] Thus, in the above optional implementation manner, after determining the type of the application scenario of the target task, first read the compensation ratio corresponding to this type in the local memory, calculate the product of the current virtual running time of the target task and the compensation ratio as the compensation value, and finally calculate the difference between the current virtual running time of the target task and the compensation value, and use the difference as the target virtual running time to accurately obtain the target virtual running time for improving the performance of the target task.
[0087] Exemplarily, the types of application scenarios include types such as startup scenarios and non-startup scenarios. Among them, the startup scenario refers to running in the foreground, and the non-startup scenario refers to running in the background.
[0088] Exemplarily, in a startup application scenario, the main thread of the user interface (UI) has a heavy load and can be compensated relatively more, that is, the compensation ratio is larger, and the obtained compensation value is also larger. The current virtual running time then needs to be reduced more, and the resulting target virtual running time will be even smaller. The order in which the target task is scheduled for execution by the CPU will move forward, and it will be scheduled faster. In a non-startup application scenario of the main thread of the user interface (UI), the compensation can be relatively less.
[0089] Therefore, in the above optional implementation, virtual running time compensation can be performed according to the type of application scenario of the target task, and the time for which the target task continuously remains in the runnable state can be obtained more reasonably, achieving a relatively reliable and precise performance improvement.
[0090] 403. Re-queue the target task to the ready queue according to the above target virtual running time.
[0091] Among them, after step 402, the target virtual running time finally corresponding to the target task is less than the current virtual running time. After re-queuing in step 403, the sorting of the target task in the ready queue will move towards the head, getting closer to the queue head, thus improving the order in which the target task is scheduled for execution by the CPU and accelerating the scheduling speed.
[0092] 404. Perform a trigger operation for re-scheduling on the CPU corresponding to the ready queue.
[0093] According to the previous steps, by de-queueing the target task from the ready queue, reducing the virtual running time and then re-queueing it, the sorting of the target task in the ready queue is advanced. However, at this time, if the task currently running on the CPU does not actively yield the CPU for a long time, then the target task still cannot be scheduled to the CPU for execution in a timely manner. Therefore, in step 404, by triggering re-scheduling on the CPU, the scheduler of CFS can be notified that there is a task with a higher priority ready on the current CPU, and please trigger task switching as soon as possible. Thus, when the next preemption point arrives, the currently running task is switched out, and then the CPU schedules tasks to execute in sequence from the head of the ready queue.
[0094] Optionally, the preemption points include but are not limited to: enabling preemption, enabling interrupts, enabling soft interrupts, returning from interrupts, returning from soft interrupts, returning to user space, etc.
[0095] It can be seen that through step 404, the duration of the target task in the ready queue is further shortened, and the scheduling for execution by the CPU is accelerated, which helps to improve the performance of the target task.
[0096] Therefore, for a target task in the ready queue of CFS, its virtual run time can be reduced by first dequeuing it, compensating its virtual run time, and then enqueuing it back to the ready queue. Since the virtual run time is reduced, the duration of its runnable state is shortened, increasing the priority of the target task to be scheduled in the ready queue and enabling it to be scheduled and executed by the CPU faster, thus improving the performance of the target task. Further, after the target task is re-enqueued, a re-scheduling is triggered on the corresponding CPU to notify the CFS scheduler to trigger a task switch as soon as possible to accelerate the scheduling of the target task for execution, which helps to further improve the performance of the target task.
[0097] Please refer to Figure 5 , Figure 5 which is a schematic flowchart of the task scheduling control method disclosed in Embodiment 3 of the present application; in Figure 5 , the task scheduling control method may include:
[0098] 501. When reaching the boost set point, obtain a task to be processed, where the task to be processed meets a preset performance improvement condition.
[0099] Wherein, the execution subject of the embodiments of the present application is a terminal device and / or a server. Exemplarily, the terminal device and the server are as described above and will not be elaborated herein.
[0100] In the embodiments of the present application, for a target task that can perform performance improvement processing in the runnable state, a performance boost hint will be given at the boost set point, that is, a performance boost flag is set for the task that needs to be performance improved. This setting can be automatically set by the system when reaching the boost set point, or actively triggered by the user program when reaching the boost set point, and is implemented before the task is woken up and enqueued. The task to be processed is selected from the tasks that need to be woken up and enqueued in the user space.
[0101] Wherein, the boost set point includes at least: receiving a synchronous binder communication message from the previous drawing frame thread, or the previous drawing frame thread being blocked by a lock (and just being blocked by itself), or the application APP switching from the background to the foreground, or the APP being in focus, or the APP switching from not being in focus to being in focus.
[0102] Exemplarily, taking the application APP switching from the background to the foreground as an example, when it is detected that the application APP switches from the background to the foreground, it is determined that the boost set point is entered.
[0103] It should be noted that in the embodiments of the present application, not all tasks that need to be woken up and enqueued will perform a performance boost hint, but need to meet a preset performance improvement condition.
[0104] Optionally, the preset performance improvement conditions include at least a status condition and a running condition. The status condition includes the main thread of the user interface of an APP in the foreground or the Render thread, or the main thread of the user interface of the currently focused APP or the Render thread. The running condition includes that the actual running time of a task for a single time is less than a time threshold. Exemplarily, the time threshold is 60 seconds.
[0105] Among them, the number of tasks to be processed will be controlled. In the above optional implementation manner, some tasks are filtered through the running condition. For example, the actual running time of the task for a single time needs to be less than the time threshold. If the actual running time is too long, it will occupy the CPU for a long time. Further, if a performance improvement hint is made so that it can be compensated for virtual running time in the runnable state to speed up being scheduled and executed by the CPU, it will easily cause some tasks in the ready queue to not be scheduled for a long time, resulting in starvation of these tasks. Therefore, in the embodiments of the present application, for tasks with an actual running time greater than the time threshold for a single time, no performance improvement hint will be made at the improvement setting point. Instead, the task will be directly woken up and the current virtual running time of the task will be obtained, and the task will be queued to the ready queue of CFS to be converted into a runnable state.
[0106] Among them, the actual running time of a task for a single time is determined by a Tick (also called "clock tick", or "heartbeat", or "tock") interrupt.
[0107] Furthermore, the status condition helps to select some tasks such as the main thread of the user interface of an APP in the foreground or the Render thread as tasks to be processed. The application scenarios of these tasks are startup scenarios, and the priority of being scheduled and executed can be appropriately increased.
[0108] Furthermore, the above tasks to be processed are tasks that meet the preset performance improvement conditions selected from the tasks corresponding to the following several situations in the user space. The tasks corresponding to these several situations can be:
[0109] 1. Tasks that need to be woken up for the first time after creation. New tasks that have not been woken up before and have not been executed by the CPU.
[0110] 2. Tasks that are in the sleep state and then need to be woken up. Tasks that have been woken up before but then entered the sleep state.
[0111] 3. Tasks that have not been completed after being scheduled and executed. For example, after being scheduled and executed, it may be cut out after the actual running time for a single time and needs to be woken up later.
[0112] In the above 3, for the tasks that have not been completed after scheduling, although the performance improvement flag was set last time, the actual running time of the last scheduled execution is greater than the above time threshold, so it will not be selected this time and will not be preferentially scheduled in the next round. This can also ensure that all tasks in the ready queue can be reasonably scheduled and executed in a certain scheduling order, without causing task starvation. If the task that has not been completed after scheduling has an actual running time greater than the above time threshold for the last scheduled execution and still carries the performance improvement flag, then the performance improvement flag is removed.
[0113] 502. Set a performance improvement flag for the task to be processed.
[0114] In step 502, set a performance improvement flag for the task to be processed to complete the performance improvement hint for the task to be processed. Among them, in the embodiments of the present application, the performance improvement flag is used to indicate that the corresponding task can improve performance in the runnable state, and the performance is improved by reducing the virtual running time of the task.
[0115] 503. Wake up the task to be processed and obtain the current virtual running time of the task to be processed, and enqueue the task to be processed into the ready queue of CFS to convert it into a runnable state task.
[0116] After the performance improvement hint is performed through steps 501 - 502, the task to be processed will be woken up, and then the current virtual running time will be obtained and enqueued into the ready queue to be converted into a runnable state.
[0117] Among them, obtaining the current virtual running time of the task to be processed includes: obtaining the single actual running time of the task to be processed and the weight of the task to be processed, and calculating the current virtual running time according to the actual running time and the weight; through this implementation method, the current virtual running time can be accurately calculated.
[0118] 504. After detecting that a new runnable state task is enqueued in the ready queue, determine whether the new runnable state task is set with a performance improvement flag; among them, after determining that the new runnable state task is set with the performance improvement flag, execute step 505, otherwise, after determining that the new runnable state task is not set with the performance improvement flag, do nothing.
[0119] Among them, the ready queue is detected in real time. If it is detected that a new runnable state task is enqueued, it will be determined whether the new runnable state task is set with a performance improvement flag.
[0120] 505. Use the above new runnable state task as the target task, and dequeue the target task from the ready queue.
[0121] Take the task that has the performance improvement identifier and is in a new runnable state as the target task, and dequeue the target task from the ready queue.
[0122] It should be noted that in the embodiment of the present application, by controlling the number of tasks to be processed, the number of tasks with performance improvement identifiers in the ready queue is controlled, that is, the total number of tasks after virtual run time compensation does not exceed the above-mentioned preset number threshold, so as to ensure that other tasks without virtual run time compensation in the ready queue will not be scheduled for a long time, avoiding starvation of other tasks.
[0123] 506. Compensate the current virtual run time of the target task to obtain a target virtual run time, where the target virtual run time is less than the current virtual run time of the target task.
[0124] Among them, the current virtual run time of the target task is the time obtained when it is awakened, and the current virtual run time of other tasks in the ready queue that have the performance improvement identifier and have been compensated for the virtual run time is the compensated target virtual run time.
[0125] In step 506, compensating the current virtual run time of the target task means adjusting the current virtual run time of the target task to adjust the current virtual run time to the target virtual run time.
[0126] 507. Re-queue the target task to the ready queue according to the above target virtual run time.
[0127] Among them, after step 506, the finally corresponding target virtual run time of the target task is less than the current virtual run time. After re-queuing in step 507, the sorting of the target task in the ready queue will move towards the head, getting closer to the queue head, which improves the order in which the target task is scheduled by the CPU and speeds up the scheduling speed.
[0128] 508. Perform a trigger operation for rescheduling on the CPU corresponding to the ready queue.
[0129] According to the previous steps, by dequeuing the target task from the ready queue, reducing the virtual run time and then re-queuing, the sorting of the target task in the ready queue is advanced. However, at this time, if the task running on the CPU does not actively yield the CPU for a long time, then the target task still cannot be scheduled to the CPU in time. Therefore, in step 508, by triggering a rescheduling on the CPU, the scheduler can be notified that there is a task with a higher priority ready on the current CPU, and the task should be switched as soon as possible. When the next preemption point arrives, the currently running task is cut out, and then tasks are read from the head of the ready queue in turn for execution.
[0130] Therefore, in the embodiments of the present application, a to-be-processed task that meets the preset performance improvement condition will set a corresponding performance improvement flag during the performance improvement hint stage, and then be awakened and enqueued into the ready queue of CFS, thus transitioning to the runnable state. Then, when the ready queue is detected in real time, it is detected that the newly enqueued task in the runnable state is set with a performance improvement flag, and it is extracted from the ready queue as the target task for virtual run-time compensation to reduce its virtual run time. Then, the target task is enqueued again, thereby shortening the duration of its runnable state, increasing the priority of the target task to be scheduled in the ready queue, and enabling it to be scheduled and executed by the CPU faster, achieving performance improvement for the target task. Further, after the target task is re-enqueued, a re-scheduling will be triggered on the corresponding CPU to notify the scheduler to trigger a task switch as soon as possible to accelerate the scheduling of the target task for execution, which helps to further improve the performance of the target task.
[0131] Exemplarily, for example, for a certain CFS task, after setting a performance improvement flag for it at the improvement setting point, it is awakened, and its current virtual run time is determined to be 60 seconds. Then, it is enqueued into the ready queue of CFS, and its scheduling order is 5, and there are 4 tasks in front that need to be scheduled. According to the normal process, this CFS task may need to wait for 80 seconds before being scheduled. After enqueuing, because of the performance improvement flag, it is dequeued, and then the current virtual run time is compensated to obtain a target virtual run time of 20 seconds. After re-enqueuing, because the corresponding virtual run time is 20 seconds, which is less than other tasks in the ready queue, the scheduling order changes from the original 5 to 1, and then it is scheduled and executed when the next preemption point arrives. The duration of being in the runnable state in the ready queue also changes from the original 80 seconds to 10 seconds, thereby shortening the duration of its runnable state and being scheduled faster, achieving performance improvement for this task.
[0132] Please refer to Figure 6 , Figure 6 which is a schematic structural diagram of the task scheduling control device disclosed in Embodiment 1 of the present application; as Figure 6 shown, the task scheduling control device may include:
[0133] A dequeue module 601, configured to dequeue a target task from the ready queue corresponding to the Completely Fair Scheduling (CFS), where the ready queue includes multiple tasks in the runnable state, the target task is one or more of the multiple tasks in the runnable state, and each of the multiple tasks in the runnable state corresponds to a current virtual run time;
[0134] A compensation adjustment module 602, configured to compensate the current virtual run time of the target task to obtain a target virtual run time, where the target virtual run time is less than the current virtual run time of the target task;
[0135] An enqueue module 603, configured to re-enqueue the target task into the ready queue according to the target virtual running time.
[0136] Therefore, when implementing the above device, the dequeue module 601 in the device first dequeues the target task from the ready queue corresponding to CFS. The ready queue includes multiple runnable tasks, and the target task is one or more of the multiple runnable tasks. Each of the multiple runnable tasks corresponds to a current virtual running time. Then, the compensation adjustment module 602 compensates the current virtual running time of the target task to obtain a target virtual running time, and the target virtual running time is less than the current virtual running time of the target task. Finally, the enqueue module 603 re-enqueues the target task into the ready queue according to the target virtual running time. It can be seen that when implementing the embodiments of the present application, for a runnable task in the ready queue of CFS, its virtual running time can be reduced by first dequeuing it and compensating its virtual running time, and then re-enqueuing it into the ready queue. Because the virtual running time is reduced, the duration of its runnable state is shortened, so that the priority of the target task being scheduled in the ready queue is increased, and it can be scheduled and executed by the CPU faster, realizing the performance improvement of the target task.
[0137] In some optional implementation manners, the manner in which the compensation adjustment module 602 compensates the current virtual running time of the target task to obtain the target virtual running time is specifically as follows:
[0138] Obtain the type of the application scenario of the target task;
[0139] Obtain the compensation value corresponding to the type of the application scenario;
[0140] Calculate the difference between the current virtual running time of the target task and the compensation value to obtain the target virtual running time.
[0141] It should be noted that in the embodiments of the present application, the compensation for the virtual running time is different for target tasks in different application scenarios. Therefore, in this implementation manner, the corresponding compensation value will be specifically obtained according to the type of the application scenario of the target task, and then the difference between the current virtual running time of the target task and the compensation value will be calculated, that is, current virtual running time - compensation value = difference, and then the difference will be used as the target virtual running time.
[0142] Among them, the compensation value can be an empirical value and can be pre-stored in the local memory. The compensation values for tasks in different application scenarios are different. In the above implementation manner, the type of the application scenario of the target task is first determined, and then the compensation value corresponding to this type is directly read locally.
[0143] Further, the specific manner in which the compensation adjustment module 602 obtains the compensation value corresponding to the type of the application scenario is as follows:
[0144] Obtain the compensation ratio corresponding to the target task;
[0145] Calculate the compensation value according to the current virtual running time of the target task and the compensation ratio.
[0146] In the above optional implementation manner, after determining the type of the application scenario of the target task, first read the compensation ratio corresponding to this type from the local memory, calculate the product of the current virtual running time of the target task and the compensation ratio as the compensation value, and finally calculate the difference between the current virtual running time of the target task and the compensation value, and use the difference as the target virtual running time to accurately obtain the target virtual running time for improving the performance of the target task.
[0147] Please refer to Figure 7 , Figure 7 which is a schematic structural diagram of the task scheduling control device disclosed in the second embodiment of the present application; Figure 7 The shown task scheduling control device is optimized on the basis of the task scheduling control device shown in Figure 6 . In Figure 7 , this device further includes: a scheduling control module 701 and a setting module 702.
[0148] Among them, the scheduling control module 701 is used to perform a triggering operation of re-scheduling on the central processing unit (CPU) corresponding to the ready queue after the enqueue module 603 re-enqueues the target task to the ready queue according to the target virtual running time.
[0149] In addition, the above setting module 702 is used to obtain a to-be-processed task that meets the preset performance improvement condition when reaching the improvement setting point before the dequeue module 601 dequeues the target task from the ready queue corresponding to the Completely Fair Scheduling (CFS); set a performance improvement flag for the to-be-processed task; wake up the to-be-processed task and obtain the current virtual running time of the to-be-processed task, and enqueue the to-be-processed task to the ready queue to convert it into a task in a runnable state;
[0150] Furthermore, the specific manner in which the dequeue module 601 dequeues the target task from the ready queue corresponding to the Completely Fair Scheduling (CFS) is as follows:
[0151] After detecting that a new runnable task has been queued in the ready queue, determine whether the new runnable task is set with the performance improvement flag; after determining that the new runnable task is set with the performance improvement flag, use the new runnable task as the target task, and dequeue the target task from the ready queue.
[0152] Optionally, the promotion setting points at least include: receiving a synchronous binder communication message from the pre-rendering thread, or the pre-rendering thread being blocked by a lock, or the application APP switching from the background to the foreground, or the APP being focused, or the APP changing from not being focused to being focused.
[0153] Optionally, the preset performance improvement conditions at least include a status condition and a running condition. The status condition includes that the task is the user interface main thread or the Render thread of an APP in the foreground, or the user interface main thread or the Render thread of the currently focused APP. The running condition includes that the actual running time of the task for a single time is less than the time threshold.
[0154] Through the above embodiments, the pending tasks that meet the preset performance improvement conditions will set the corresponding performance improvement flag in the performance improvement hint stage, then be awakened and queued into the ready queue of CFS, thus turning into a runnable state. Then, according to the set performance improvement flag, they are extracted from the ready queue as target tasks for virtual running time compensation to reduce their virtual running time, and then the target tasks are queued, thereby shortening the duration of their runnable state and increasing the scheduling priority of the target tasks in the ready queue.
[0155] Please refer to Figure 8 , Figure 8 which is a schematic structural diagram of the electronic device disclosed in the embodiment of the present invention; Figure 8 The shown electronic device may include:
[0156] A memory 801 storing executable program code;
[0157] A processor 802 coupled to the memory 801;
[0158] Wherein, the processor 802 calls the executable program code stored in the memory 801 and executes Figure 1 , Figures 4 to 5 partial steps of any one of the task scheduling control methods.
[0159] The embodiment of the present application also discloses a computer-readable storage medium storing a computer program, wherein the computer program enables the computer to execute Figure 1 ,Figures 4 to 5 Any one of the disclosed task scheduling control methods.
[0160] The embodiments of the present application also disclose a computer program product. When the computer program product runs on a computer, it causes the computer to execute Figure 1 , Figures 4 to 5 Some or all of the steps of any one of the disclosed methods.
[0161] The embodiments of the present application also disclose an application publishing platform. The application publishing platform is used to publish a computer program product. Among them, when the computer program product runs on a computer, it causes the computer to execute Figure 1 , Figures 4 to 5 Some or all of the steps of any one of the disclosed methods.
[0162] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing relevant hardware through a program. This program can be stored in a computer-readable storage medium. The storage medium includes read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc memories, magnetic disk memories, tape memories, or any other computer-readable medium capable of setting or storing data.
[0163] The above has introduced in detail a task scheduling control method, device, electronic device, and storage medium disclosed in the embodiments of the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. A task scheduling control method, characterized in that: include: Dequeue the target task from the ready queue corresponding to the completely fair scheduling CFS, the ready queue includes multiple tasks in runnable states, the target task is one or more of the multiple tasks in runnable states, and the multiple tasks in runnable states each correspond to a current virtual running time; Compensating the current virtual runtime of the target task to obtain a target virtual runtime, wherein the target virtual runtime is less than the current virtual runtime of the target task; According to the target virtual runtime, the target task is requeued to the ready queue.
2. The method according to claim 1, characterized in that After requeuing the target task to the ready queue according to the target virtual runtime, the method further comprises: A rescheduling triggering operation is executed on a central processing unit (CPU) corresponding to the ready queue.
3. The method according to claim 1, characterized in that The compensating the current virtual runtime of the target task to obtain the target virtual runtime includes: Obtaining the type of application scenario of the target task; Obtaining a compensation value corresponding to the type of the application scenario; The difference between the current virtual running time of the target task and the compensation value is calculated to obtain the target virtual running time.
4. The method according to claim 3, characterized in that The obtaining of the compensation value corresponding to the type of the application scenario includes: Obtaining the compensation ratio corresponding to the target task; The compensation value is calculated according to the current virtual running time of the target task and the compensation ratio.
5. The method according to any one of claims 1 to 4, characterized in that: Before dequeuing the target task from the ready queue corresponding to the completely fair scheduling CFS, the method further includes: When reaching the improvement setting point, obtaining a task to be processed, wherein the task to be processed satisfies a preset performance improvement condition; Setting a performance improvement flag for the task to be processed; Waking up the pending task and obtaining the current virtual running time of the pending task, and enqueuing the pending task to the ready queue to convert it into a task in an executable state; The step of dequeuing the target task from the ready queue corresponding to the completely fair scheduling CFS includes: After detecting that a new task in the ready queue is queued, determining whether the new task in the runnable state is set with the performance improvement flag; After determining that the task in the new runnable state is set with the performance improvement flag, the task in the new runnable state is used as the target task, and the target task is dequeued from the ready queue.
6. The method according to claim 5, characterized in that The raising setting point at least includes: receiving a synchronous binder communication message of the front drawing frame thread, or the front drawing frame thread is blocked, or the application APP is switched from the background to the foreground, or the APP is being focused, or the APP is changed from never being focused to being focused.
7. The method according to claim 6, characterized in that The preset performance improvement conditions include at least state conditions and running conditions. The state conditions include that the task is the user interface main thread or Render thread of the APP in the foreground, or the user interface main thread or Render thread of the APP that is currently focused. The running conditions include that the actual running time of a single task is less than a time threshold.
8. The method according to claim 5, characterized in that The total number of all tasks in the ready queue that are set with the performance improvement flag and are in the runnable state does not exceed a preset number threshold.
9. A task scheduling control device, characterized in that: include: A dequeue module is used to dequeue a target task from a ready queue corresponding to the completely fair scheduling CFS, wherein the ready queue includes multiple tasks in a runnable state, and the target task is one or more of the multiple tasks in the runnable state, and each of the multiple tasks in the runnable state corresponds to a current virtual running time; A compensation adjustment module, used for compensating the current virtual running time of the target task to obtain a target virtual running time, wherein the target virtual running time is less than the current virtual running time of the target task; The enqueuing module is used to re-enqueue the target task into the ready queue according to the target virtual runtime.
10. An electronic device, characterized in that: include: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the task scheduling control method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.