Task scheduling method, device, equipment and storage medium based on CFS scheduler
By assigning variables to each task and processor, stripping out interrupt processing time, and optimizing virtual time, the problem of interrupt processing time in CFS scheduling is solved, and the fairness of task scheduling and system performance are improved.
Patent Information
- Application Number
- CN202111074402.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-14
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2041-09-14
AI Technical Summary
In the traditional CFS scheduling algorithm, the time when the processor executes interrupt processing is counted into the actual execution time of the task, resulting in the fairness of the task scheduling, and the virtual time cannot accurately reflect the actual processing logic time of the task, affecting system performance.
Assign variables to each task and processor, track and optimize actual run time, strip off interrupt processing time, calculate accurate total virtual time for task scheduling to be more fair.
By accurately reflecting task priority execution time information, the fairness of the CFS scheduling mechanism and the overall performance of the system are improved.
Smart Images

Figure CN113886038B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a task scheduling method, device, electronic device and storage medium based on a CFS scheduler. Background Art
[0002] Since its introduction, the Completely Fair Scheduler has been widely used in the field of operating systems for its advantages such as high efficiency and fairness. Its basic idea is to provide a unified time standard, namely virtual time, for tasks of different priorities; to describe the running time information of tasks through virtual time, and to provide a direct basis for operating system task scheduling. Virtual time is calculated based on the actual running time of the task, and the calculation method is related to the task priority and weight. The higher the priority, the greater the weight, and the slower the virtual time grows; the smaller the priority, the smaller the weight, and the faster the virtual time grows. Each time a task is scheduled, the task with the smallest virtual time in the ready queue is always selected to run. Therefore, from a statistical period, tasks with higher priorities get more scheduling opportunities, and their actual execution time is also longer. The calculation relationship between the actual running time of a task and the virtual time is:
[0003] Virtual time = actual task running time × task weight with priority 0 / task weight
[0004] From the above formula, we can see that virtual time can reflect the task execution time information based on priority.
[0005] The CFS algorithm usually uses a red-black tree to manage the ready tasks on the processor. These tasks are attached to the red-black tree according to the size of their virtual time. The smaller the virtual time, the closer it is to the left side of the tree. Each time scheduling is performed, the task on the far left of the red-black tree is selected to run. The fairness of CFS ensures that each ready task has the opportunity to be scheduled to run at least once within a certain period, and this period is recorded as the scheduling period. During the scheduling period, each ready task will be assigned an execution time corresponding to its priority. The higher the priority, the longer the time. At certain points in the system operation, such as when a task in the ready queue changes or a system clock tick interrupt occurs, the virtual time of the current task will be updated and a determination will be made as to whether scheduling is required.
[0006] During the current task, various interruptions may be processed, such as the interruption of background network data transmission, the interruption of system clock beat, etc. Interrupt processing is generally divided into the upper half and the lower half. After the hardware interrupt occurs, it enters the upper half for processing, which mainly registers the interrupt and takes less time; the lower half executes the actual task of the interrupt, which takes more time. After the execution, the lower half ends, the interrupt processing is completed, and the task context is returned.
[0007] The content of interrupt processing may not be directly related to the current task itself, so the time the processor spends on interrupt processing should be regarded as system common overhead, and should not be counted into the actual execution time of the current task, so that task scheduling is more fair. In the traditional CFS algorithm, the time the processor spends on interrupt processing is not separated from the task running time, resulting in a certain deviation in the statistics of the time the task actually spends on processing its own logic, resulting in the virtual time being unable to accurately reflect the time the task actually spends on processing its own logic, which in turn impairs the fairness of task scheduling and affects system performance. Summary of the invention
[0008] The purpose of the present invention is to provide a task scheduling method, device, electronic device and storage medium based on a CFS scheduler, aiming to solve the problem of task scheduling fairness being impaired due to the time when the processor executes interrupt processing being counted into the actual execution time of the current task.
[0009] On the one hand, the present invention provides a task scheduling method based on a CFS scheduler, the method comprising the following steps:
[0010] Tracking the actual running time of each task based on variables allocated to each task and each processor, wherein the actual running time does not include the time when the corresponding processor performs interrupt processing;
[0011] Based on the actual running time of each task, optimize the corresponding total virtual time;
[0012] According to the optimized total virtual time, the task scheduling based on the CFS scheduler is performed.
[0013] Preferably, the step of tracking the actual running time of each task based on variables allocated to each task and each processor comprises:
[0014] When the current task needs to update the total virtual time, the current first total time and the current second total time are obtained based on the variables allocated to the current task and the processor corresponding to the current task, wherein the current first total time is the total time actually run by the current task from the last time it was scheduled to run to the last time the total virtual time was updated, and the current second total time is the total time actually run by the current task from the last time it was scheduled to run to now;
[0015] The difference between the current second total time and the current first total time is set as the current third total time, wherein the current third total time is the total time of the current task from the last updated total virtual time to the current actual running time.
[0016] Preferably, the first variable allocated to each task is used to record the fourth total time actually run when the total virtual time of the task was last updated, and the second variable allocated to each task is used to record the fifth total time actually run when the task was last scheduled to run.
[0017] The step of obtaining the current first total time based on the variable allocated to the current task and the processor corresponding to the current task comprises:
[0018] The difference between the current fourth total time and the current fifth total time is set as the current first total time.
[0019] Preferably, the third variable allocated to each task is used to record the sixth total time of the corresponding processor executing interrupt processing when the task was last scheduled to run.
[0020] The step of acquiring the current second total time based on the variable allocated to the current task and the processor corresponding to the current task comprises:
[0021] Get the current sixth total time, the current seventh total time and the current eighth total time, wherein the current seventh total time is the total time that the current task has experienced since it was last scheduled to run, and the current eighth total time is the total time that the processor corresponding to the current task currently executes interrupt processing;
[0022] The difference between the current eighth total time and the current sixth total time is set as the current ninth total time, wherein the current ninth total time is the total time from the last time the current task was scheduled to the time when the corresponding processor executes interrupt processing;
[0023] The difference between the current seventh total time and the current ninth total time is set as the current second total time.
[0024] Preferably, the fourth variable allocated to each task is used to record the first time when the task was last scheduled to run, the fifth variable allocated to each processor is used to record the second time when the processor last entered the upper half of the interruption, and the sixth variable allocated to each processor is used to record the tenth total time when the processor last exited the lower half of the interruption to execute the interruption processing.
[0025] The steps for obtaining the current seventh total time include:
[0026] Set the difference between the current time and the current first time as the current seventh total time;
[0027] The steps for obtaining the current eighth total time include:
[0028] Determine whether the processor corresponding to the current task is executing interrupt processing;
[0029] If so, the current time is subtracted from the current second time and then summed with the current tenth total time to obtain the current eighth total time; otherwise, the current tenth total time is set as the current eighth total time.
[0030] Preferably, the method further comprises:
[0031] When the processor corresponding to the current task enters the interrupt upper half, updating the current second time of the processor corresponding to the current task based on the current time;
[0032] When the processor corresponding to the current task exits the interrupt lower half, the current tenth total time of the processor corresponding to the current task is updated based on the difference between the current time and the current second time.
[0033] Preferably, the method further comprises:
[0034] When switching to the current task, the current first time of the current task is updated based on the current time;
[0035] Set the obtained current tenth total time as the current sixth total time;
[0036] The obtained current fourth total time is set as the current fifth total time.
[0037] Preferably, the seventh variable allocated to each task is used to record the current total virtual time of the task, and the step of optimizing the corresponding total virtual time based on the actual running time of each task includes:
[0038] Get the virtual time corresponding to the current third total time;
[0039] Updating the current total virtual time of the current task based on the virtual time corresponding to the current third total time;
[0040] Based on the actual running time of each task, after the step of optimizing the corresponding total virtual time, it also includes:
[0041] The current fourth total time is updated based on the current third total time.
[0042] On the other hand, the present invention provides a task scheduling device based on a CFS scheduler, the device comprising:
[0043] A running time tracking unit, used for tracking the actual running time of each task based on the variables allocated to each task and each processor, wherein the actual running time does not include the time when the corresponding processor performs interrupt processing;
[0044] An optimization execution unit, for optimizing the corresponding total virtual time based on the actual running time of each task; and
[0045] The task scheduling unit is used to perform task scheduling based on the CFS scheduler according to the optimized total virtual time.
[0046] On the other hand, the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0047] On the other hand, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0048] The present invention tracks the actual running time of each task based on variables allocated to each task and each processor, wherein the actual running time does not include the time when the corresponding processor executes interrupt processing. Based on the actual running time of each task, the corresponding total virtual time is optimized, and according to the optimized total virtual time, task scheduling based on the CFS scheduler is performed, so that the total virtual time of each task can more accurately reflect the task execution time information based on the priority, thereby making the CFS scheduling mechanism fairer and the overall system performance higher. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1A is a flow chart of an implementation of a task scheduling method based on a CFS scheduler provided in Embodiment 1 of the present invention;
[0050] Figure 1B is an example diagram of a process for updating the total virtual time of a task provided in the first embodiment of the present invention;
[0051] Figure 2A is an example diagram of an implementation flow of updating the total time for a processor to execute interrupt processing provided by the second embodiment of the present invention;
[0052] Figure 2B This is an example diagram of the implementation process of the total actual running time of the update task provided in the second embodiment of the present invention;
[0053] Figure 2C is an example diagram of the implementation process of updating the total virtual time of a task provided in the second embodiment of the present invention;
[0054] Figure 2D This is an example diagram of an implementation process for obtaining the total time of a task from the last scheduled operation to the current actual operation, provided in the second embodiment of the present invention;
[0055] Figure 3 is a schematic diagram of the structure of a task scheduling device based on a CFS scheduler provided in Embodiment 3 of the present invention; and
[0056] Figure 4 It is a schematic diagram of the structure of an electronic device provided in Embodiment 5 of the present invention. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0058] The specific implementation of the present invention is described in detail below in conjunction with specific embodiments:
[0059] Embodiment 1:
[0060] Figure 1A The implementation process of the task scheduling method based on the CFS scheduler provided in the first embodiment of the present invention is shown. For the convenience of description, only the part related to the embodiment of the present invention is shown, which is described in detail as follows:
[0061] In step S101 , the corresponding total virtual time is optimized based on the actual running time of each task, wherein the actual running time does not include the time for the corresponding processor to execute interrupt processing.
[0062] The embodiments of the present invention are applicable to electronic devices, which may be terminal devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. The electronic devices may be single-processor or multi-processor devices. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.
[0063] The embodiment of the present invention counts the time of task processing interruption and the actual running time of the task (the time of the task processing its own logic) separately, and calculates the corresponding total virtual time according to the actual running time of each task, so that the total virtual time of each task can more accurately reflect the task execution time information based on priority, thereby making the CFS scheduling mechanism fairer and the overall system performance higher.
[0064] In the specific implementation, after the current task is scheduled to run, its total virtual time may need to be updated multiple times, and it can be used as a basis for judging whether the task needs to be suspended and other tasks are scheduled to run. For example, when the task is blocked due to waiting for resources, or when the ready task queue of the processor where the task is located changes, that is, when a task is added or removed, the total virtual time information of the task needs to be updated. The implementation process of updating the total virtual time of the current task can be as follows: Figure 1B shown. Figure 1B In the figure, the horizontal axis is the time axis, and the direction of time growth is shown in the figure. The total virtual time of the task is updated N times from being scheduled to being suspended. The task is scheduled to run at t0, the total virtual time is updated for the first time at t1, the total virtual time is updated for the second time at t2, the total virtual time is updated for the kth time at tk, and the total virtual time is updated for the Nth time at tn. The task is suspended after the total virtual time is updated for the Nth time.
[0065] When tracking the actual running time of each task based on the variables assigned to each task and each processor, preferably, when the current task needs to update the total virtual time, the current first total time and the current second total time are obtained based on the variables assigned to the current task and the processor corresponding to the current task, and the difference between the current second total time and the current first total time is set as the current third total time, so as to obtain the total actual running time of the current task from the last update of the total virtual time to the present. Among them, the current first total time is the total actual running time of the current task from the last time it was scheduled to run to the last time the total virtual time was updated, the current second total time is the total actual running time of the current task from the last time it was scheduled to run to the present, and the current third total time is the total actual running time of the current task from the last time the total virtual time was updated to the present. Figure 1B For example, if the current time is t2, the current first total time is the total time of the actual running of the current task from t0 to t1, and the current second total time is the total time of the actual running of the current task from t0 to t2.
[0066] Preferably, the first variable allocated to each task is used to record the fourth total time actually run when the task last updated the total virtual time, and the second variable allocated to each task is used to record the fifth total time actually run when the task was last scheduled to run. When obtaining the current first total time based on the variables allocated to the current task and the processor corresponding to the current task, the difference between the current fourth total time and the current fifth total time is set as the current first total time to achieve the acquisition of the current first total time. Figure 1B For example, if the current time is t2, the current fourth total time is the total time of the current task actually running at t1, and the current fifth total time is the total time of the current task actually running at t0.
[0067] Preferably, the third variable assigned to each task is used to record the sixth total time of the corresponding processor executing interrupt processing when the task was last scheduled to run. When obtaining the current second total time based on the variables assigned to the current task and the processor corresponding to the current task, the current sixth total time, the current seventh total time and the current eighth total time are obtained, and the difference between the current eighth total time and the current sixth total time is set as the current ninth total time to achieve the acquisition of the current second total time. Among them, the current seventh total time is the total time experienced by the current task from the last time it was scheduled to run to the present, the current eighth total time is the total time of the processor corresponding to the current task currently executing interrupt processing (interrupt upper half + lower half), and the current ninth total time is the total time of the current task from the last time it was scheduled to run to the present corresponding processor executing interrupt processing.
[0068] Preferably, the fourth variable assigned to each task is used to record the first time when the task was last scheduled to run, the fifth variable assigned to each processor is used to record the second time when the processor last entered the upper half of the interrupt, and the sixth variable assigned to each processor is used to record the tenth total time when the processor last exited the lower half of the interrupt to execute interrupt processing. When obtaining the current seventh total time, the difference between the current time and the current first time is set as the current seventh total time to achieve the acquisition of the seventh total time; when obtaining the current eighth total time, it is determined whether the processor corresponding to the current task is executing interrupt processing. If so, the current time is subtracted from the current second time and then summed with the current tenth total time to obtain the current eighth total time; otherwise, the current tenth total time is set to the current eighth total time to achieve the acquisition of the eighth total time.
[0069] Preferably, when the processor corresponding to the current task enters the upper half of the interrupt, the current second time of the processor corresponding to the current task is updated based on the current time; when the processor corresponding to the current task exits the lower half of the interrupt, the current tenth total time of the processor corresponding to the current task is updated based on the difference between the current time and the current second time, so as to realize automatic update of the total time of executing interrupt processing corresponding to each processor.
[0070] Preferably, when switching to the current task, the current first time of the current task is updated based on the current time, the current tenth total time obtained is set as the current sixth total time, and the current fourth total time obtained is set as the current fifth total time, so as to timely update the total time for the processor corresponding to each task to execute interrupt processing and the total time for each task to actually run when switching to the current task.
[0071] In step S102 , based on the actual running time of each task, the corresponding total virtual time is optimized.
[0072] In the embodiment of the present invention, when optimizing the corresponding total virtual time based on the actual running time of each task, preferably, the virtual time corresponding to the current third total time is obtained, and the current total virtual time of the current task is updated based on the virtual time corresponding to the current third total time, thereby achieving the optimization of the total virtual time of each task. Specifically, the virtual time corresponding to the third total time = the third total time × the task weight with a priority of 0 / the current task weight, and the updated total virtual time = the total virtual time before the update + the virtual time corresponding to the third total time.
[0073] After optimizing the corresponding total virtual time based on the actual running time of each task, preferably, the current fourth total time is updated based on the current third total time, so as to timely update the fourth total time corresponding to each task after the total virtual time is updated.
[0074] In step S103, task scheduling based on the CFS scheduler is performed according to the optimized total virtual time.
[0075] In the embodiment of the present invention, each time the CFS scheduler performs task scheduling, it selects the task with the smallest total virtual time in the ready queue to run. The total virtual time specifically refers to the optimized total virtual time. Therefore, it is only necessary to allocate variables for each task and each processor respectively, and the interrupt processing time can be separated from the task time statistics through simple addition and subtraction operations. The memory and processor computing overhead is small, and the actual running time of the task can be accurately tracked. In addition, as long as the processor manages its own variables, it can be expanded without locking and mutual exclusion, and the execution efficiency is high.
[0076] In an embodiment of the present invention, based on the variables allocated to each task and each processor, the actual running time of each task is tracked, wherein the actual running time does not include the time for the corresponding processor to execute interrupt processing. Based on the actual running time of each task, the corresponding total virtual time is optimized, and according to the optimized total virtual time, task scheduling based on the CFS scheduler is performed, so that the total virtual time of each task can more accurately reflect the task execution time information based on the priority, thereby making the CFS scheduling mechanism fairer and the overall system performance higher.
[0077] Embodiment 2:
[0078] This embodiment provides an example of an implementation process of optimizing the total virtual time of a task based on a CFS scheduler. For ease of description, only the part related to the embodiment of the present invention is shown, which is described in detail as follows:
[0079] Two variables cpu->prev_irq_start and cpu->irq_time are allocated to each processor in advance. Among them, cpu->prev_irq_start is used to record the timestamp of the processor's most recent entry into the upper half of the interrupt (the second time), and cpu->irq_time is used to record the total time the processor executes interrupt processing (the tenth total time). The update process of these two variables is as follows Figure 2A shown.
[0080] In step S201, when the processor enters the interrupt upper half, last_run_timestamp is set to the current timestamp: cpu->prev_irq_start=now.
[0081] In step S202, when the processor exits the lower half of the interrupt, the total time of the processor executing the interrupt processing is updated: cpu->irq_time+=(now-cpu->prev_irq_start), that is, the current interrupt processing time=now-cpu->prev_irq_start, and the updated cpu->irq_time=the cpu->irq_time before the update+(now-cpu->prev_irq_start).
[0082] Five variables task->last_run_timestamp, task->last_irq_time, task->last_rtime, task->rtime and task->vtime are pre-allocated to each task. Among them, task->last_run_timestamp is used to record the timestamp (first time) of the task's last scheduled run, task->last_irq_time is used to record the total time (sixth total time) of the corresponding processor executing interrupt processing when the task was last scheduled to run, task->rtime is used to record the total time (fourth total time) of the task's actual run when the total virtual time was last updated, task->last_rtime is used to record the total time (fifth total time) of the task's actual run when the task was last scheduled to run, and task->vtime is used to record the current total virtual time of the task.
[0083] At each task switch, update the variables task->last_run_timestamp, task->last_irq_time and task->last_rtime of the current task (new task). The update process of these three variables is as follows Figure 2B shown.
[0084] In step S211 , when switching to the current task, the last_run_timestamp of the current task is set to the current timestamp: task->last_run_timestamp=now.
[0085] In step S212, last_irq_time is set to the total time of the processor corresponding to the current task executing interrupts: task->last_irq_time=cpu->irq_time.
[0086] In step S213, the actual running time of the current task is backed up to last_rtime: task->last_rtime=task->rtime.
[0087] The total virtual time update process for each task is as follows: Figure 2C As shown in the figure, each time the total virtual time is updated, the total actual running time of the task is also updated at the same time.
[0088] In step S221, the total actual running time from the last time the current task was scheduled to run to the last time the total virtual time was updated is obtained: delta_rtime_prev = task->rtime-task->last_rtime.
[0089] Specifically, initially task->rtime saves the actual total running time of the current task when the total virtual time was last updated (when it was last suspended), and task->last_time represents the actual total running time of the current task when it was last scheduled to run. The two are subtracted to get delta_rtime_prev, which is the actual running time of the current task from the last time it was scheduled to run to the last time the total virtual time was updated.
[0090] In step S222, the total time delta_rtime_now from the last scheduled execution of the current task to the actual execution now is obtained.
[0091] The specific implementation process of obtaining delta_rtime_now is as follows Figure 2D shown.
[0092] In step S2221, the total time delta_now from the last scheduled execution of the current task to the present is obtained. Specifically, the timestamp task->last_run_timestamp of the last scheduled execution of the task is subtracted from the current system time now.
[0093] In step S2222, the total interrupt processing time cpu->irq-time of the processor corresponding to the current task is obtained and saved in the irq_time local variable.
[0094] In step S2223, it is determined whether the processor corresponding to the current task is executing interrupt processing.
[0095] In step S2224, if the interrupt processing is being executed, irq_time is updated to obtain the total time for the processor to execute the interrupt processing: irq_time + = (now-cpu->prev_irq_start). Specifically, the most recent interrupt processing time (since the cpu interrupt processing is not completed, this part of time has not been updated to cpu->irq_time) is added to irq_time, that is, the updated irq_time = irq_time before the update + (now-cpu->prev_irq_start).
[0096] In step S2225, the total interrupt processing time of the current task from the last scheduled execution to the present is calculated: delta_irq=irq_time-task->last_irq_time.
[0097] In step S2226, the total time from the last scheduled execution of the current task to the actual execution now is calculated: delta_rtime_now=delta_now-delta_irq.
[0098] In step S223, the total time of the current task from the last updated total virtual time to the current actual running time is calculated: delta_rtime=delta_rtime_now-delta_rtime_prev.
[0099] In step S224, the virtual time corresponding to delta_rtime is calculated: delta_vtime=delta_rtime×nice_o_weihgt / task_weight.
[0100] In step S225, the total virtual time of the current task is updated: task->vtime+=delta_vtime, that is, task->vtime after update=task->vtime before update+delta_vtime.
[0101] In step S226, the actual running time of the current task is updated: task->rtime+=delta_rtime, that is, task->rtime after update=task->rtime before update+delta_vtime.
[0102] From the above process, it can be seen that the method provided in this embodiment has the following advantages:
[0103] First, the memory overhead is small. Only five integer variables are allocated to each task and two integer variables are allocated to each processor, so that the interrupt processing time can be separated from the task time statistics and the actual running time of the task can be accurately tracked.
[0104] Secondly, the processor has low computing overhead. The process only includes some basic addition, subtraction, multiplication and division operations, most of which are addition and subtraction operations, which only consumes very few computing resources.
[0105] Thirdly, it has good scalability and can be easily expanded to multi-processor platforms. In a multi-processor platform, each processor manages its own two variables, which do not conflict with each other and do not require locking and mutual exclusion, so the execution efficiency is very high.
[0106] Embodiment three:
[0107] Figure 3 The structure of the task scheduling device based on the CFS scheduler provided in the third embodiment of the present invention is shown. For the convenience of description, only the part related to the embodiment of the present invention is shown, including:
[0108] A running time tracking unit 31, used for tracking the actual running time of each task based on the variables allocated to each task and each processor, wherein the actual running time does not include the time when the corresponding processor executes interrupt processing;
[0109] An optimization execution unit 32, configured to optimize the corresponding total virtual time based on the actual running time of each task; and
[0110] The task scheduling unit 33 is used to perform task scheduling based on the CFS scheduler according to the optimized total virtual time.
[0111] In the embodiment of the present invention, each unit of the task scheduling device based on the CFS scheduler can be implemented by a corresponding hardware or software unit, and each unit can be an independent software or hardware unit, or can be integrated into a software or hardware unit, which is not intended to limit the present invention. The specific implementation of each unit of the task scheduling device based on the CFS scheduler can refer to the description of the aforementioned method embodiment, which will not be repeated here.
[0112] Embodiment 4:
[0113] Figure 4 The structure of an electronic device provided by a fourth embodiment of the present invention is shown. For the convenience of description, only the parts related to the embodiment of the present invention are shown.
[0114] The electronic device 4 of the embodiment of the present invention includes a processor 40, a memory 41, and a computer program 42 stored in the memory 41 and executable on the processor 40. When the processor 40 executes the computer program 42, the steps in the above-mentioned method embodiments are implemented, for example: Figure 1A Alternatively, when the processor 40 executes the computer program 42, the functions of each unit in the above-mentioned device embodiments are realized, for example Figure 3 The functions of the units 31 to 33 are shown.
[0115] In an embodiment of the present invention, based on the variables allocated to each task and each processor, the actual running time of each task is tracked, wherein the actual running time does not include the time for the corresponding processor to execute interrupt processing. Based on the actual running time of each task, the corresponding total virtual time is optimized, and according to the optimized total virtual time, task scheduling based on the CFS scheduler is performed, so that the total virtual time of each task can more accurately reflect the task execution time information based on the priority, thereby making the CFS scheduling mechanism fairer and the overall system performance higher.
[0116] Embodiment five:
[0117] In an embodiment of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above method embodiment are implemented, for example, Figure 1A Alternatively, when the computer program is executed by a processor, the functions of each unit in the above-mentioned device embodiments are realized, for example Figure 3 The functions of the units 31 to 33 are shown.
[0118] In an embodiment of the present invention, based on the variables allocated to each task and each processor, the actual running time of each task is tracked, wherein the actual running time does not include the time for the corresponding processor to execute interrupt processing. Based on the actual running time of each task, the corresponding total virtual time is optimized, and according to the optimized total virtual time, task scheduling based on the CFS scheduler is performed, so that the total virtual time of each task can more accurately reflect the task execution time information based on the priority, thereby making the CFS scheduling mechanism fairer and the overall system performance higher.
[0119] The computer-readable storage medium of the embodiment of the present invention may include any entity or device or recording medium capable of carrying computer program code, for example, ROM / RAM, magnetic disk, optical disk, flash memory and other memories.
[0120] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A task scheduling method based on CFS scheduler, It is characterized in that The method comprises the following steps: Based on the variables assigned to each task and each processor, the actual running time of each task is tracked, wherein the actual running time does not include the time when the corresponding processor executes interrupt processing. Based on the variables assigned to each task and each processor, the actual running time of each task is tracked, including: when the current task needs to update the total virtual time, based on the variables assigned to the current task and the processor corresponding to the current task, the current first total time and the current second total time are obtained, wherein the current first total time is the total time when the current task is actually running from the last time it was scheduled to run to the last time the total virtual time was updated, and the current second total time is the total time when the current task is actually running from the last time it was scheduled to run to the present, and the difference between the current second total time and the current first total time is set as the current third total time, wherein the current third total time is the total time when the current task is actually running from the last time the total virtual time was updated to the present; Based on the actual running time of each task, the corresponding total virtual time is optimized, wherein after the current task is scheduled to run, the total virtual time of the task needs to be updated multiple times, and is used as a basis for judging whether the task needs to be suspended while other tasks are scheduled to run. Based on the actual running time of each task, the corresponding total virtual time is optimized, including: obtaining the virtual time corresponding to the current third total time, and updating the current total virtual time of the current task based on the virtual time corresponding to the current third total time; According to the optimized total virtual time, the task scheduling based on the CFS scheduler is performed.
2. The method according to claim 1, It is characterized in that The first variable allocated to each task is used to record the fourth total time actually run when the task last updated the total virtual time, and the second variable allocated to each task is used to record the fifth total time actually run when the task was last scheduled to run. The step of obtaining the current first total time based on the variables allocated to the current task and the processor corresponding to the current task includes: The difference between the current fourth total time and the current fifth total time is set as the current first total time.
3. The method according to claim 2, It is characterized in that The third variable allocated to each task is used to record the sixth total time of the corresponding processor executing the interrupt processing when the task was last scheduled to run, and the step of obtaining the current second total time based on the variable allocated to the current task and the processor corresponding to the current task includes: Get the current sixth total time, the current seventh total time and the current eighth total time, wherein the current seventh total time is the total time that the current task has experienced since it was last scheduled to run, and the current eighth total time is the total time that the processor corresponding to the current task currently executes interrupt processing; The difference between the current eighth total time and the current sixth total time is set as the current ninth total time, wherein the current ninth total time is the total time from the last time the current task was scheduled to the time when the corresponding processor executes interrupt processing; The difference between the current seventh total time and the current ninth total time is set as the current second total time.
4. The method according to claim 3, It is characterized in that The fourth variable allocated to each task is used to record the first time when the task was last scheduled to run, the fifth variable allocated to each processor is used to record the second time when the processor last entered the upper half of the interrupt, and the sixth variable allocated to each processor is used to record the tenth total time of executing interrupt processing when the processor last exited the lower half of the interrupt. The steps for obtaining the current seventh total time include: Set the difference between the current time and the current first time as the current seventh total time; The steps for obtaining the current eighth total time include: Determine whether the processor corresponding to the current task is executing interrupt processing; If so, the current time is subtracted from the current second time and then summed with the current tenth total time to obtain the current eighth total time; otherwise, the current tenth total time is set as the current eighth total time.
5. The method according to claim 4, It is characterized in that The method further comprises: When the processor corresponding to the current task enters the interrupt upper half, updating the current second time of the processor corresponding to the current task based on the current time; When the processor corresponding to the current task exits the interrupt lower half, updating the current tenth total time of the processor corresponding to the current task based on the difference between the current time and the current second time; The method further comprises: When switching to the current task, the current first time of the current task is updated based on the current time; Set the obtained current tenth total time as the current sixth total time; The obtained current fourth total time is set as the current fifth total time.
6. The method according to claim 2, It is characterized in that Based on the actual running time of each task, after the step of optimizing the corresponding total virtual time, it also includes: The current fourth total time is updated based on the current third total time.
7. A task scheduling device based on CFS scheduler, It is characterized in that The device comprises: A running time tracking unit is used to track the actual running time of each task based on the variables assigned to each task and each processor, wherein the actual running time does not include the time when the corresponding processor executes interrupt processing, and to track the actual running time of each task based on the variables assigned to each task and each processor, including: when the current task needs to update the total virtual time, based on the variables assigned to the current task and the processor corresponding to the current task, obtain the current first total time and the current second total time, wherein the current first total time is the total time when the current task is actually running from the last time it was scheduled to run to the last time the total virtual time was updated, and the current second total time is the total time when the current task is actually running from the last time it was scheduled to run to the present, and the difference between the current second total time and the current first total time is set as the current third total time, wherein the current third total time is the total time when the current task is actually running from the last time the total virtual time was updated to the present; The optimization execution unit is used to optimize the corresponding total virtual time based on the actual running time of each task, wherein after the current task is scheduled to run, the total virtual time of the task needs to be updated multiple times, and is used as a basis for judging whether the task needs to be suspended while other tasks are scheduled to run. Based on the actual running time of each task, the corresponding total virtual time is optimized, including: obtaining the virtual time corresponding to the current third total time, and updating the current total virtual time of the current task based on the virtual time corresponding to the current third total time; and The task scheduling unit is used to perform task scheduling based on the CFS scheduler according to the optimized total virtual time.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
