A task scheduling method, device, equipment and storage medium

By maintaining task lists of different priority tasks in the task scheduler and obtaining tasks from the highest priority list when needed, the problem of resource competition in hybrid deployments is solved, task scheduling efficiency is improved and delay and jitter is avoided.

CN113961348BActive Publication Date: 2025-04-29ALIBABA CLOUD COMPUTING CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111255116.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-27
Publication Date
2025-04-29
Estimated Expiration
2041-10-27

AI Technical Summary

Technical Problem

In hybrid deployments, tasks with the same priority may lead to resource competition, and the prior art solves this problem through task eviction, but may lead to reduced task scheduling efficiency, causing task delays and jitters.

Method used

By maintaining at least two task lists in the task scheduler, tasks with different priorities are stored, and tasks with the highest priority are obtained from the task list corresponding to the highest priority for execution, to avoid high overhead operations caused by resource competition and task eviction.

Benefits of technology

Improve task scheduling efficiency, avoid task delays and jitters, and ensure priority execution of the highest priority tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113961348B_ABST
    Figure CN113961348B_ABST
Patent Text Reader

Abstract

The present application proposes a task scheduling method, apparatus, device and storage medium. The method can be applied to the first CPU of at least two logical processors CPU obtained based on hyperthreading technology; the task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU. The method may include: obtaining the priority of the task being executed by the second CPU other than the first CPU among the at least two logical processors CPU. In response to the priority of the task being executed by the second CPU being the highest priority, the task scheduler obtains the task that meets the scheduling conditions from the first task list corresponding to the highest priority for execution to complete the task scheduling in the case where task eviction is required.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer vision technology, and in particular to a task scheduling method, device, equipment and storage medium. Background Art

[0002] Hyperthreading technology refers to a technology that provides at least two logical threads in a central processing unit (CPU) to simulate the CPU as at least two logical CPUs, and tasks can be executed separately in the at least two CPUs.

[0003] Hybrid deployment refers to deploying tasks of different priorities on the same physical resources to achieve the purpose of sharing resources. The priority of tasks can be set according to business needs. In hybrid deployment, tasks of the same priority require the same resources, while tasks of different priorities require different resources. If the at least two CPUs execute tasks of different priorities at the same time, resource competition may occur.

[0004] In order to avoid this phenomenon, when one of the at least two CPUs is executing the task with the highest priority, it is necessary to evict the task in the other CPU, that is, to evict other priority tasks, so as to ensure that the other CPU must also execute the task with the highest priority, thereby avoiding resource competition and ensuring that the task with the highest priority is executed first.

[0005] At present, when a task is expelled, other priority tasks can be temporarily moved out of the ready queue by the task scheduler on the CPU, so that the task scheduler can only schedule the highest priority task from the ready queue. After the task is expelled, the other priority tasks that have been moved out can be moved back to the ready queue, so as to ensure that the task scheduler can schedule tasks normally. In this way, in the case of task expulsion, high-overhead operations may be brought about by the entry and exit of tasks in the ready queue, thereby reducing the efficiency of task scheduling and causing task delays and jitters. Summary of the invention

[0006] In view of this, the present application discloses a task scheduling method. The method is applied to the first CPU of at least two logical processors CPU obtained based on hyperthreading technology; the task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU;

[0007] The method comprises:

[0008] Obtaining the priority of a task being executed by a second CPU of the at least two logical processors CPU except the first CPU;

[0009] In response to the priority of the task being executed by the second CPU being the highest priority, the task scheduler obtains tasks that meet the scheduling conditions from the first task list corresponding to the highest priority for execution to complete task scheduling when task eviction is required.

[0010] In some embodiments, the method further comprises:

[0011] In response to the priority of the task being executed by the second CPU not being the highest priority, the task scheduler obtains tasks that meet the scheduling conditions from the at least two task lists for execution to complete task scheduling without requiring task eviction.

[0012] In some embodiments, the task scheduler is a completely fair scheduler CFS; the first CPU maintains the virtual durations corresponding to the tasks of different priorities; the scheduling condition includes a minimum virtual duration;

[0013] The step of obtaining, by the task scheduler, a task satisfying a scheduling condition from a first task list corresponding to the highest priority level includes:

[0014] Obtaining, through the CFS, a task corresponding to a minimum virtual duration from the first task list;

[0015] The step of obtaining, by the task scheduler, tasks satisfying the scheduling condition from the at least two task lists comprises:

[0016] The task corresponding to the minimum virtual duration is obtained from the at least two task lists through the CFS.

[0017] In some embodiments, the at least two task lists further include a second task list corresponding to other priorities; the first task list includes a first red-black tree; the second task list includes a second red-black tree; the first red-black tree maintains the first minimum virtual duration corresponding to each task in the first task list; the second red-black tree maintains the second minimum virtual duration corresponding to each task in the second task list;

[0018] The first CPU also maintains a first variable and a second variable; wherein the first variable indicates the difference between the first minimum virtual duration and the second minimum virtual duration before the task is expelled; and the second variable indicates the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by the task expulsion when at least one task is expelled;

[0019] The method further comprises:

[0020] In the case where task eviction is required, before performing task scheduling, in response to the current scheduling being the first eviction scheduling, the first variable is updated according to the current first minimum virtual duration, the current second minimum virtual duration and the current second variable.

[0021] In some embodiments, the method further comprises:

[0022] In a situation where task eviction is not required, before performing task scheduling, in response to the fact that this scheduling is the first non-eviction scheduling after task eviction, the second variable is updated according to the current first minimum virtual duration, the current second minimum virtual duration and the current first variable.

[0023] In some embodiments, obtaining the task corresponding to the minimum virtual duration from the at least two task lists through the CFS includes:

[0024] Compare the sum of the second minimum virtual duration and the updated second variable with the first minimum virtual duration;

[0025] In response to the sum of the second minimum virtual duration and the updated second variable being less than the first minimum virtual duration, obtaining a task corresponding to the second minimum virtual duration from the second red-black tree through the CFS;

[0026] In response to the sum of the second minimum virtual duration and the updated second variable being greater than or equal to the first minimum virtual duration, a task corresponding to the first minimum virtual duration is acquired from the first red-black tree through the CFS.

[0027] In some embodiments, the method further comprises:

[0028] Obtaining the priority of the pending task; the pending task includes a task that needs to be migrated into or out of the first CPU;

[0029] When the priority of the task to be processed is the highest priority, performing corresponding processing on the task to be processed according to the first red-black tree;

[0030] In the case where the priority of the task to be processed is other priorities, the task to be processed is processed accordingly with respect to the second red-black tree.

[0031] In some embodiments, before migrating in the pending tasks or after migrating out the pending tasks, the process further includes:

[0032] In response to at least one of the first red-black tree and the second red-black tree not including any task, and the first CPU not executing the task of the priority corresponding to the at least one red-black tree, the first minimum virtual duration and the second minimum virtual duration are updated to the maximum value of the two.

[0033] In some embodiments, after updating the first variable, the method further includes:

[0034] In response to the updated first variable being less than or equal to 0, the first variable is set to a preset value to increase the second minimum virtual duration.

[0035] The present application also proposes a task scheduling device, which is applied to a first CPU of at least two logical processors CPU obtained based on hyperthreading technology; a task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU;

[0036] The device comprises:

[0037] An acquisition module is used to acquire the priority of a task being executed by a second CPU among the at least two logical processors CPU except the first CPU;

[0038] The first scheduling module, in response to the priority of the task being executed by the second CPU being the highest priority, obtains the task that meets the scheduling conditions from the first task list corresponding to the highest priority through the task scheduler for execution to complete task scheduling when task eviction is required.

[0039] In some embodiments, the apparatus further comprises:

[0040] The second scheduling module, in response to the priority of the task being executed by the second CPU being not the highest priority, obtains the task that meets the scheduling conditions from the at least two task lists through the task scheduler for execution to complete task scheduling without the need for task eviction.

[0041] In some embodiments, the task scheduler is a completely fair scheduler CFS; the first CPU maintains the virtual durations corresponding to the tasks of different priorities; the scheduling condition includes a minimum virtual duration;

[0042] The first scheduling module is specifically used to:

[0043] Obtaining, through the CFS, a task corresponding to a minimum virtual duration from the first task list;

[0044] The second scheduling module is specifically used for:

[0045] The task corresponding to the minimum virtual duration is obtained from the at least two task lists through the CFS.

[0046] In some embodiments, the at least two task lists further include a second task list corresponding to other priorities; the first task list includes a first red-black tree; the second task list includes a second red-black tree; the first red-black tree maintains the first minimum virtual duration corresponding to each task in the first task list; the second red-black tree maintains the second minimum virtual duration corresponding to each task in the second task list;

[0047] The first CPU also maintains a first variable and a second variable; wherein the first variable indicates the difference between the first minimum virtual duration and the second minimum virtual duration before the task is expelled; and the second variable indicates the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by the task expulsion when at least one task is expelled;

[0048] The device also includes:

[0049] The first variable updating module, when task eviction is required, before performing task scheduling, in response to the current scheduling being the first eviction scheduling, updates the first variable according to the current first minimum virtual duration, the current second minimum virtual duration and the current second variable.

[0050] In some embodiments, the apparatus further comprises:

[0051] The second variable updating module, when task eviction is not required, before performing task scheduling, in response to the fact that this scheduling is the first non-eviction scheduling after task eviction, updates the second variable according to the current first minimum virtual duration, the current second minimum virtual duration and the current first variable.

[0052] In some embodiments, the second scheduling module is specifically used to:

[0053] Compare the sum of the second minimum virtual duration and the updated second variable with the first minimum virtual duration;

[0054] In response to the sum of the second minimum virtual duration and the updated second variable being less than the first minimum virtual duration, obtaining a task corresponding to the second minimum virtual duration from the second red-black tree through the CFS;

[0055] In response to the sum of the second minimum virtual duration and the updated second variable being greater than or equal to the first minimum virtual duration, a task corresponding to the first minimum virtual duration is acquired from the first red-black tree through the CFS.

[0056] In some embodiments, the apparatus further comprises:

[0057] A task maintenance module, which obtains the priority of the task to be processed; the task to be processed includes a task that needs to be migrated into or out of the first CPU;

[0058] When the priority of the task to be processed is the highest priority, performing corresponding processing on the task to be processed according to the first red-black tree;

[0059] In the case where the priority of the task to be processed is other priorities, the task to be processed is processed accordingly with respect to the second red-black tree.

[0060] In some embodiments, the apparatus further comprises:

[0061] The synchronization module updates the first minimum virtual duration and the second minimum virtual duration to the maximum value thereof in response to at least one of the first red-black tree and the second red-black tree not including any task and the first CPU not executing the task of the priority corresponding to the at least one red-black tree.

[0062] In some embodiments, the apparatus further comprises:

[0063] The setting module sets the first variable to a preset value for increasing the second minimum virtual duration in response to the updated first variable being less than or equal to 0.

[0064] The present application also proposes an electronic device, comprising:

[0065] processor;

[0066] a memory for storing processor-executable instructions;

[0067] The processor implements the task scheduling method as shown in any of the above embodiments by running the executable instructions.

[0068] The present application also proposes a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to enable a processor to execute the task scheduling method as shown in any of the aforementioned embodiments.

[0069] In the technical solution disclosed in the aforementioned embodiment, since the task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU. Therefore, in the event of eviction, the highest priority task can be directly obtained from the first task list corresponding to the highest priority level for execution, avoiding high-overhead operations caused by tasks entering and exiting the queue, improving task scheduling efficiency, and thus possibly avoiding task delays and jitters.

[0070] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] In order to more clearly illustrate the technical solutions in one or more embodiments of the present application or related technologies, the drawings required for use in the embodiments or related technology descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in one or more embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0072] Figure 1 A method flow chart of a task scheduling method shown in this application;

[0073] Figure 2 A method flow chart of an image processing method shown in this application;

[0074] Figure 3 A flowchart of a non-eviction scheduling method shown in this application;

[0075] Figure 4 A flowchart of a method for maintaining tasks in a red-black tree is shown in this application;

[0076] Figure 5 A structural diagram of a task scheduling device shown in this application;

[0077] Figure 6 The following is a schematic diagram of the hardware structure of an electronic device shown in this application. DETAILED DESCRIPTION

[0078] The exemplary embodiments will be described in detail below, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.

[0079] The terms used in this application are only for the purpose of describing specific embodiments, and are not intended to limit the application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more associated listed items. It should also be understood that the word "if" used in this article, depending on the context, can be interpreted as "at the time of" or "when" or "in response to determining".

[0080] The present application proposes a task scheduling method. The method maintains at least two task lists that store tasks of different levels, so that in the event of eviction, the task with the highest priority can be directly obtained from the first task list corresponding to the highest priority level for execution, avoiding high-overhead operations caused by tasks entering and exiting queues, improving task scheduling efficiency, and thus possibly avoiding task delays and jitters.

[0081] See also Figure 1 , Figure 1 This is a method flow chart of a task scheduling method shown in this application. Figure 1 As shown, the method may include S102-S104.

[0082] The method can be applied to a first CPU among at least two logical processors CPU obtained based on hyperthreading technology; a task scheduler corresponding to the first CPU maintains at least two task lists; and the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU.

[0083] The first CPU may be any CPU among the at least two logical CPUs. The first CPU corresponds to a task scheduler.

[0084] The task scheduler may be used to schedule tasks from a task list for execution by the first CPU. The task scheduler may be any type of scheduler. In some embodiments, the task scheduler may be a Completely Fair Scheduler (CFS).

[0085] The task list can be used to store the tasks assigned to the first CPU in a preset data storage format. In the present application, the at least two task lists can be equivalent to the ready queue (queue for storing tasks) corresponding to the task scheduler. In some embodiments, the task list can store tasks in data storage formats such as linked lists, binary trees, and red-black trees.

[0086] The task may refer to a service executed by the CPU. The service may have different names at different stages. For example, in the ready queue stage, the service may be called an entity. In the CPU execution stage, the service may be called a process. This application refers to services as tasks.

[0087] The priority can indicate the execution order of tasks. When two CPUs under the same hyperthread execute tasks of different priorities, it is necessary to give priority to ensuring the execution of high-priority tasks. In this application, priorities can be assigned to tasks according to business needs. Task priorities can include at least two levels.

[0088] S102: Obtain the priority of a task being executed by a second CPU other than the first CPU among the at least two logical processors CPU.

[0089] The second CPU may be at least one CPU.

[0090] In some embodiments, a task identifier may be set in the first CPU. The identifier may indicate the priority of the task being executed in the second CPU. The second CPU may monitor the priority of the task being executed by itself, and if it is found that the task with the highest priority is being executed, an instruction may be sent to the first CPU to set the task identifier to the first identifier; if it is found that the task with other priorities is being executed, an instruction may be sent to the first CPU to set the task identifier to the second identifier.

[0091] When executing S102, the first CPU can obtain the priority of the task being executed by the second CPU by obtaining the current task identifier.

[0092] In some embodiments, when executing S102, the first CPU may send a task priority acquisition instruction to the second CPU, and the second CPU may send the priority of the task being executed to the first CPU in response to the instruction.

[0093] S104, in response to the priority of the task being executed by the second CPU being the highest priority, the task scheduler obtains a task that meets the scheduling conditions from the first task list corresponding to the highest priority for execution to complete task scheduling when task eviction is required.

[0094] If the priority of the task being executed by the second CPU is the highest priority, the first CPU needs to evict the task. Task eviction may include two scenarios.

[0095] Scenario 1: The first CPU is not currently executing a task and needs to obtain the next task to execute. At this time, the highest priority task that meets the scheduling conditions can be directly obtained from the first task list.

[0096] Scenario 2: The first CPU is currently executing other priority tasks. At this time, it is necessary to suspend the execution of other priority tasks and obtain the highest priority task that meets the scheduling conditions from the first task list.

[0097] The task scheduler usually has a task scheduling principle. When scheduling tasks, it will obtain tasks that meet the scheduling conditions based on the preset scheduling principles. The scheduling conditions shown in this application are the scheduling conditions corresponding to the task scheduler.

[0098] In the above scheme, since the task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU. Therefore, in the event of eviction, the highest priority task can be directly obtained from the first task list corresponding to the highest priority level for execution, avoiding high-overhead operations caused by tasks entering and exiting the queue, improving task scheduling efficiency, and thus possibly avoiding task delays and jitters.

[0099] In some embodiments, the task scheduler is a CFS. The first CPU maintains the virtual durations corresponding to the tasks of different priorities. The scheduling condition includes a minimum virtual duration.

[0100] CFS will assign a virtual duration to each task in the task list. If a task is scheduled for execution, its corresponding virtual duration will continue to increase, and the virtual duration of tasks that are not executed will remain unchanged. The higher the priority of the task, the smaller the initial virtual duration, and the slower the virtual duration increases when a task is executed.

[0101] The scheduling condition corresponding to CFS is the minimum virtual duration. That is, CFS can select the task corresponding to the minimum virtual duration for execution.

[0102] When executing S104, S1041 may be executed to obtain the task corresponding to the minimum virtual duration from the first task list through the CFS, so that the first CPU can obtain the task corresponding to the minimum virtual duration from the highest priority task for execution.

[0103] In some embodiments, when eviction is not required, the first CPU may obtain tasks that meet the scheduling conditions from the at least two task lists and normally obtain tasks for execution.

[0104] See also Figure 2 , Figure 2 FIG. 1 is a flow chart of an image processing method shown in this application. Figure 2 As shown, the method, in addition to S102 - S104 , further includes S106 which is parallel to S104 .

[0105] S106, in response to the priority of the task being executed by the second CPU being not the highest priority, obtaining, through the task scheduler, a task that meets the scheduling condition from the at least two task lists for execution to complete task scheduling without the need for task eviction.

[0106] If the priority of the task being executed by the second CPU is not the highest priority, the first CPU does not need to evict the task. Therefore, when the task eviction is not needed, the first CPU can obtain the task that meets the scheduling condition from the at least two task lists and execute the task that meets the scheduling condition normally.

[0107] In some embodiments, the task scheduler is a CFS. The first CPU maintains the virtual durations corresponding to the tasks of different priorities. The scheduling condition includes a minimum virtual duration.

[0108] When executing S106, S1061 may be executed to obtain the task corresponding to the minimum virtual duration from the at least two task lists through the CFS, thereby enabling the first CPU to obtain the task corresponding to the minimum virtual duration from tasks of all priorities for execution.

[0109] In some embodiments, at least two task lists corresponding to the task scheduler (CFS) may include a red-black tree. The red-black tree is a self-balancing binary search tree. The red-black tree can automatically maintain the minimum key value, that is, it can determine the node corresponding to the minimum key value in each node, and place the node in a preset position for easy query.

[0110] The key value of the node included in the red-black tree described in the present application can be determined based on the virtual duration of the task. The information stored in the node can be determined based on the task information. The red-black tree can maintain the current minimum virtual duration when migrating in and out of tasks, and when the CPU completes the task being executed, so as to facilitate the acquisition of the task corresponding to the minimum virtual duration.

[0111] In the event of eviction, the virtual duration of the highest priority task will gradually increase as the task is executed, so the minimum virtual duration of the red-black tree maintenance corresponding to the highest priority task will also increase. The virtual durations of other priority tasks will remain unchanged as the tasks are not executed, and the minimum virtual durations of the red-black trees maintenance corresponding to other priority tasks will also remain unchanged. In this way, the priority of tasks of other priorities may be increased through eviction. This is not allowed.

[0112] For example, suppose the first CPU needs to execute high-priority tasks A and B and low-priority tasks 1 and 2. Due to eviction in the first CPU, high-priority tasks AB are continuously executed, which will cause the virtual durations of low-priority tasks 1 and 2 to be much shorter than that of tasks AB. When eviction disappears, low-priority tasks 1 and 2 may be executed for a long time. This is equivalent to increasing the priority of low-priority tasks through eviction. This situation is not allowed.

[0113] In order to solve the above problem, the first variable and the second variable are added in the present application to record the difference between the minimum virtual duration maintained by the red-black tree corresponding to the highest priority and the red-black tree corresponding to other priorities due to eviction, so as to compensate the virtual duration of other priority tasks to offset the difference caused by eviction. In some embodiments, the real virtual duration after compensation can be obtained by adding the virtual duration of other priority tasks to the difference.

[0114] The following describes a method for updating the first variable and the second variable in conjunction with an embodiment.

[0115] In some embodiments, the at least two task lists also include a second task list corresponding to other priorities; the first task list includes a first red-black tree; the second task list includes a second red-black tree; the first red-black tree maintains the first minimum virtual duration corresponding to each task in the first task list; the second red-black tree maintains the second minimum virtual duration corresponding to each task in the second task list.

[0116] The first CPU also maintains a first variable and a second variable; wherein the first variable indicates the difference between the first minimum virtual duration and the second minimum virtual duration before the task is evicted; and the second variable indicates the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by the task eviction when at least one task is evicted. In this application, the first variable can be recorded as start and the second variable can be recorded as spread.

[0117] In the present application, the first variable may be updated through step S21.

[0118] S21, when task eviction is required, before performing task scheduling, in response to the current scheduling being the first eviction scheduling, updating the first variable according to the current first minimum virtual duration, the current second minimum virtual duration and the current second variable.

[0119] The first eviction scheduling refers to the first scheduling performed by CFS when task eviction is required.

[0120] In this way, the difference between the first minimum virtual duration and the second minimum virtual duration before the eviction occurs can be accurately recorded, so that after the eviction is completed, the cumulative difference (i.e., the second variable) between the first minimum virtual duration and the second minimum virtual duration caused by the task eviction can be determined, thereby facilitating compensation for the virtual duration difference caused by the eviction.

[0121] In some embodiments, when S21 is executed, S211 - S212 may be executed.

[0122] S211, when it is determined that task eviction is required, whether the current scheduling is the first eviction scheduling is determined by determining whether the first variable is an initial value (eg, may be 0).

[0123] On the one hand, in the present application, the first variable is set to an initial value in the following two situations.

[0124] First, in response to at least one of the first red-black tree and the second red-black tree not including any task, and the first CPU not executing the task corresponding to the priority of the at least one red-black tree, the first variable is set to an initial value. This can be understood as initializing the first variable.

[0125] Secondly, when the eviction is completed and the non-eviction situation is entered, the first variable can be set to the initial value after the second variable is updated (the method of updating the second variable will be described later).

[0126] On the other hand, the present application will update the first variable to another value (possibly a non-initial value) before the first eviction scheduling.

[0127] Due to the above two aspects, if the first variable is an initial value when it is determined that task eviction is required, it means that this scheduling is the first eviction scheduling. If the first variable is not the initial value, it means that this scheduling is not the first eviction scheduling.

[0128] S212: In response to the current scheduling being the first eviction scheduling, the first variable is updated according to the current first minimum virtual duration, the current second minimum virtual duration and the current second variable.

[0129] The first variable may be understood as the actual difference between the first minimum virtual duration and the second minimum virtual duration before the first eviction scheduling.

[0130] When executing S212, the real second minimum virtual duration after compensating for the previous expulsion can be obtained by summing the current second minimum virtual duration and the current second variable; and the first variable is updated by determining the difference between the real second minimum virtual duration and the current first virtual duration.

[0131] For example, assume that the aforementioned preset initial value is 0. When it is determined that task expulsion is required, it can be determined whether the current value of the first variable start is 0. If so, it can be indicated that this task expulsion is the first task expulsion, and then the start variable can be updated according to the following formula (1).

[0132] start=min_vrt under -min_vrt high +spread................1;

[0133] Among them, start represents the first variable, spread represents the second variable, min_vrt under Indicates the second minimum virtual duration, min_vrt high Indicates the first minimum virtual duration. under +spread can get the real second minimum virtual duration after compensating for the previous eviction, and then compare it with min_vrt high By subtracting them, we can obtain the actual difference between the first minimum virtual duration and the second minimum virtual duration before the first eviction scheduling, that is, the start at this moment.

[0134] In the present application, the second variable may be updated through step S22.

[0135] S22, when task eviction is not required, before performing task scheduling, in response to the fact that this scheduling is the first non-eviction scheduling after task eviction, the second variable is updated according to the current first minimum virtual duration, the current second minimum virtual duration and the current first variable.

[0136] The first non-eviction scheduling refers to the first scheduling performed by CFS when no task eviction is required after eviction.

[0137] In this way, the accumulated gap (ie, the second variable) between the first minimum virtual duration and the second minimum virtual duration caused by task expulsion after the expulsion is completed can be accurately recorded, thereby facilitating compensation for the virtual duration gap caused by the expulsion.

[0138] In some embodiments, when S22 is executed, S221 - S222 may be executed.

[0139] S221, when it is determined that task eviction is not required, determine whether this scheduling is the first non-eviction scheduling by determining whether the first variable is an initial value (eg, may be 0).

[0140] Based on the principle similar to that in S211, if it is determined that task eviction is not required, and the first variable is another value, it means that this scheduling is the first non-eviction scheduling after eviction occurs. If the first variable is the initial value, it means that this scheduling is not the first non-eviction scheduling.

[0141] S222: In response to the current scheduling being the first non-eviction scheduling after the task is evicted, the second variable is updated according to the current first minimum virtual duration, the current second minimum virtual duration and the current first variable.

[0142] The second variable may be understood as the accumulated difference between the first minimum virtual duration and the second minimum virtual duration after expulsion.

[0143] The first variable can be understood as the existing gap between the first minimum virtual duration and the second minimum virtual duration before the last eviction occurs.

[0144] When executing S222, the difference between the current second minimum virtual duration and the current first minimum virtual duration can be used to determine the additional difference between the second minimum virtual duration and the first minimum virtual duration after the last eviction. The additional difference is added to the existing difference before the last eviction (i.e., the first variable) to obtain the accumulated difference to update the second variable.

[0145] For example, assume that the aforementioned preset initial value is 0. When it is determined that task expulsion is not required, it can be determined whether the current value of the first variable start is 0. If not, it can be explained that this task expulsion is the first non-task expulsion, and then the spread variable can be updated according to the following formula (2).

[0146] spread=min_vrt high -min_vrt under +start................2;

[0147] Among them, start represents the first variable, spread represents the second variable, min_vrt under Indicates the second minimum virtual duration, min_vrt high Indicates the first minimum virtual duration. high -min_vrt underThe difference between the second minimum virtual duration and the first minimum virtual duration after the last eviction can be obtained, and then added to start, that is, the difference before the last eviction, to obtain the cumulative difference caused by task eviction, that is, spread. Then, start can be set to 0 so that spread does not need to be updated in the next non-eviction task.

[0148] After updating the second variable, the accumulated gap between the first minimum virtual duration and the second minimum virtual duration caused by the eviction can be recorded, so that the second minimum virtual duration can be compensated based on the accumulated gap to offset the virtual duration gap caused by the eviction.

[0149] In some embodiments, the first variable obtained by executing S21 may be less than or equal to 0. In this case, the second variable updated by executing S22 may also be less than or equal to 0. When compensating for the second virtual duration based on the second variable, the value of the second virtual duration may be reduced, thereby increasing the priority of other priority tasks, which is not allowed.

[0150] In the present application, in response to the updated first variable being less than or equal to 0, the first variable may be set to a preset value for increasing the second minimum virtual duration. In the present application, the preset value may be denoted as ∈.

[0151] The preset value ∈ is a preset positive number. Setting the first variable to the preset value can ensure that the second variable updated in S22 is a number greater than 0, thereby ensuring that when the second minimum virtual duration is compensated by the second variable, the second minimum virtual duration will be increased instead of reduced, thereby avoiding raising the priority of other priority tasks.

[0152] In some embodiments, when executing S1061, the CFS may perform non-eviction scheduling based on the compensated real second virtual duration. Non-eviction scheduling refers to task scheduling performed by the CFS when task eviction is not required.

[0153] See also Figure 3 , Figure 3 A flowchart of a non-eviction scheduling method shown in this application. Figure 3 The steps shown are detailed descriptions of S1061. Figure 3 As shown, when executing S1061, the method may include S301-S303.

[0154] S301: Compare the sum of the second minimum virtual duration and the updated second variable with the first minimum virtual duration.

[0155] The sum of the second minimum virtual duration and the updated second variable is the real second minimum virtual duration obtained after compensating for the gap caused by the expulsion.

[0156] S302: In response to the sum of the second minimum virtual duration and the updated second variable being less than the first minimum virtual duration, obtaining a task corresponding to the second minimum virtual duration from the second red-black tree through the CFS.

[0157] S303: In response to the sum of the second minimum virtual duration and the updated second variable being greater than or equal to the first minimum virtual duration, obtaining a task corresponding to the first minimum virtual duration from the first red-black tree through the CFS.

[0158] According to the CFS scheduling principle, if the sum of the second minimum virtual duration and the second variable after update is less than the first minimum virtual duration, it means that the task in the second red-black tree should be executed currently, and tasks of other priorities corresponding to the second minimum virtual duration can be obtained from the second red-black tree. If the sum of the second minimum virtual duration and the second variable after update is greater than or equal to the first minimum virtual duration, it means that the task in the first red-black tree should be executed currently, and the highest priority task corresponding to the second minimum virtual duration can be obtained from the second red-black tree.

[0159] For example, when selecting a non-eviction task, the sum of the second minimum virtual duration and the updated second variable may be compared with the first minimum virtual duration.

[0160] If the sum of the second minimum virtual duration and the updated second variable and the first minimum virtual duration satisfy formula 3, according to the CFS scheduling principle, the task can be selected from the second red-black tree. If formula 3 is not satisfied, the task can be selected from the first red-black tree.

[0161] min_vrt under +spread<min_vrt high ................3;

[0162] Among them, min_vrt under Indicates the second minimum virtual duration, min_vrt high represents the first minimum virtual duration, and spread represents the second variable, that is, the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by task eviction. under +spread can get the real min_vrt after compensating for the gap caused by evictionunder , if min_vrt under +spread<min_vrt high This indicates that the minimum virtual duration of the first red-black tree is greater than the actual minimum virtual duration of the second red-black tree. According to the CFS scheduling rule, tasks need to be selected from the second red-black tree.

[0163] In some embodiments, a method of maintaining tasks in a red-black tree is also included.

[0164] See also Figure 4 , Figure 4 The following is a flow chart of a method for maintaining tasks in a red-black tree as shown in this application. Figure 4 As shown, the method shown may include S401 - S403 .

[0165] S401, obtaining the priority of tasks to be processed; the tasks to be processed include tasks that need to be migrated into or out of the first CPU.

[0166] In this application, a priority identifier is assigned to a task, and the priority of the task to be processed can be determined by the identifier.

[0167] S402: When the priority of the task to be processed is the highest priority, the task to be processed is processed accordingly according to the first red-black tree.

[0168] In some embodiments, the virtual duration of the task maintained in the red-black tree has a conversion relationship with the virtual duration of the task maintained by the CFS, and this conversion relationship needs to rely on the minimum virtual duration maintained by the red-black tree. That is, when a task is migrated in or out, the virtual duration conversion needs to be performed based on the current minimum virtual duration of the red-black tree.

[0169] If it is a migration task, the first minimum virtual duration maintained by the first red-black tree can be updated according to the virtual duration of the task currently being scheduled, and then the virtual duration of the pending task maintained by the red-black tree is determined based on the first minimum virtual duration, and the pending task is added to the first red-black tree as a node based on the virtual duration to complete the task migration. If it is a migration task, the first minimum virtual duration maintained by the first red-black tree can be updated according to the virtual duration of the task currently being scheduled, and then the virtual duration of the pending task maintained by the CFS is determined based on the first minimum virtual duration, and the node corresponding to the pending task is deleted from the first red-black tree to complete the task migration.

[0170] In this application, the task being scheduled is recorded as curr, and the virtual duration of the task is recorded as vruntime curr Whether it is a migration task or an outgoing task, you can first update the vruntime of curr according to the CFS rules.curr , and update the minimum virtual duration of the red-black tree corresponding to curr. If curr is a task in the first red-black tree, update the first minimum virtual duration min_vrt of the first red-black tree high If curr is a task in the second red-black tree, update the second minimum virtual duration min_vrt of the second red-black tree under .

[0171] If a high-priority pending task is migrated, it can be based on min_vrt high Get the virtual duration of the task to be processed and insert it into the first red-black tree as a node high middle.

[0172] If you are migrating high-priority pending tasks, you can under Get the virtual duration of the task to be processed and delete the second red-black tree tree under The corresponding node in .

[0173] S403: When the priority of the task to be processed is other priorities, the task to be processed is processed accordingly with respect to the second red-black tree.

[0174] The corresponding processing of tasks to be processed of other priorities may refer to S402 and will not be described in detail here.

[0175] Through S401-S403, tasks can be accurately maintained in the first red-black tree and the second red-black tree, which facilitates subsequent accurate scheduling of tasks.

[0176] In some embodiments, during the maintenance task process, in response to at least one of the first red-black tree and the second red-black tree not including any task and the first CPU not executing the task of the corresponding priority of the at least one red-black tree, the first minimum virtual duration and the second minimum virtual duration are updated to the maximum value of the two.

[0177] Thus, after the execution of any priority task is completed, the minimum virtual durations maintained by the two red-black trees can be synchronized, thereby ensuring that the virtual durations corresponding to the tasks maintained by the two red-black trees are synchronized. In some embodiments, after the synchronization of the virtual durations of the two red-black trees is completed, the first variable indicating the difference between the virtual durations of the two red-black trees maintained by the first CPU and the second variable indicating the cumulative difference between the virtual durations of the two red-black trees caused by eviction are both set to initial values ​​(for example, 0).

[0178] The following is an example of hybrid deployment of online tasks and offline tasks.

[0179] The CPU executing the task can simulate the first CPU and the second CPU through hyperthreading. The first CPU is taken as the execution subject below.

[0180] The first CPU may use CFS to schedule tasks. The CFS may maintain a first red-black tree for storing online tasks and a second red-black tree for storing offline tasks. Among them, online tasks are high-priority tasks, and offline tasks are low-priority tasks.

[0181] The first CPU can maintain the first variable start and the second variable spread, and the maintenance methods thereof can refer to the aforementioned S21 and S22, respectively. By adding the first variable start and the second variable spread, the difference between the minimum virtual durations maintained by the red-black tree corresponding to the online task and the red-black tree corresponding to the offline task caused by the eviction can be recorded, so as to compensate the virtual duration of the evicted offline task to offset the difference caused by the eviction.

[0182] When the second CPU is executing an online task, it can send an instruction to the first CPU, so that the task indication mark maintained in the first CPU is set to the first mark, indicating that the second CPU is currently executing an online task.

[0183] When the second CPU is executing an offline task, the second CPU may send an instruction to the first CPU, so that the task indication identifier maintained in the first CPU is set to a second identifier, indicating that the second CPU is currently executing an offline task.

[0184] The first CPU may determine the priority of the task being executed by the second CPU through the task identifier.

[0185] If the task identifier is the first identifier, task eviction needs to occur, and the first CPU can obtain the online task corresponding to the minimum virtual duration from the first red-black tree through CFS.

[0186] If the task identifier is the second identifier, there is no need to evict the task. The second CPU can add the second minimum virtual duration maintained in the second red-black tree to the second variable to obtain the real second minimum virtual duration after compensation for eviction, and then compare it with the first minimum virtual duration maintained in the first red-black tree. If the real second minimum virtual duration and the first minimum virtual duration satisfy the aforementioned formula 3, the offline task is obtained from the second red-black tree. If the real second minimum virtual duration and the first minimum virtual duration do not satisfy the aforementioned formula 3, the online task is obtained from the first red-black tree.

[0187] In this example, since the CFS corresponding to the first CPU maintains two red-black trees that store online tasks and offline tasks respectively; therefore, in the event of eviction, the online tasks can be directly obtained from the first red-black tree, avoiding the high-overhead operations of task entry and exit queues in the prior art, improving the task scheduling efficiency, and thus possibly avoiding task delays and jitters.

[0188] In this example, the virtual duration corresponding to the evicted offline task can be compensated by the first variable and the second variable to ensure that the task can be obtained normally in the non-eviction scheduling.

[0189] Corresponding to the above-mentioned embodiment, the present application proposes a task scheduling device 50. The device can be applied to a first CPU among at least two logical processors CPU obtained based on hyperthreading technology; the task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU.

[0190] See also Figure 5 , Figure 5 This is a structural diagram of a task scheduling device shown in this application.

[0191] like Figure 5 As shown, the device 50 may include:

[0192] An acquisition module 51 is configured to acquire a priority of a task being executed by a second CPU other than the first CPU among the at least two logical processors CPU;

[0193] The first scheduling module 52, in response to the priority of the task being executed by the second CPU being the highest priority, obtains the task that meets the scheduling conditions from the first task list corresponding to the highest priority through the task scheduler for execution to complete task scheduling when task eviction is required.

[0194] In some embodiments, the apparatus 50 further comprises:

[0195] The second scheduling module, in response to the priority of the task being executed by the second CPU being not the highest priority, obtains the task that meets the scheduling conditions from the at least two task lists through the task scheduler for execution to complete task scheduling without the need for task eviction.

[0196] In some embodiments, the task scheduler is a completely fair scheduler CFS; the first CPU maintains the virtual durations corresponding to the tasks of different priorities; the scheduling condition includes a minimum virtual duration;

[0197] The first scheduling module 52 is specifically used for:

[0198] Obtaining, through the CFS, a task corresponding to a minimum virtual duration from the first task list;

[0199] The second scheduling module is specifically used for:

[0200] The task corresponding to the minimum virtual duration is obtained from the at least two task lists through the CFS.

[0201] In some embodiments, the at least two task lists further include a second task list corresponding to other priorities; the first task list includes a first red-black tree; the second task list includes a second red-black tree; the first red-black tree maintains the first minimum virtual duration corresponding to each task in the first task list; the second red-black tree maintains the second minimum virtual duration corresponding to each task in the second task list;

[0202] The first CPU also maintains a first variable and a second variable; wherein the first variable indicates the difference between the first minimum virtual duration and the second minimum virtual duration before the task is expelled; and the second variable indicates the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by the task expulsion when at least one task is expelled;

[0203] The device 50 further comprises:

[0204] The first variable updating module, when task eviction is required, before performing task scheduling, in response to the current scheduling being the first eviction scheduling, updates the first variable according to the current first minimum virtual duration, the current second minimum virtual duration and the current second variable.

[0205] In some embodiments, the apparatus 50 further comprises:

[0206] The second variable updating module, when task eviction is not required, before performing task scheduling, in response to the fact that this scheduling is the first non-eviction scheduling after task eviction, updates the second variable according to the current first minimum virtual duration, the current second minimum virtual duration and the current first variable.

[0207] In some embodiments, the second scheduling module is specifically used to:

[0208] Compare the sum of the second minimum virtual duration and the updated second variable with the first minimum virtual duration;

[0209] In response to the sum of the second minimum virtual duration and the updated second variable being less than the first minimum virtual duration, obtaining a task corresponding to the second minimum virtual duration from the second red-black tree through the CFS;

[0210] In response to the sum of the second minimum virtual duration and the updated second variable being greater than or equal to the first minimum virtual duration, a task corresponding to the first minimum virtual duration is acquired from the first red-black tree through the CFS.

[0211] In some embodiments, the apparatus 50 further comprises:

[0212] A task maintenance module, which obtains the priority of the task to be processed; the task to be processed includes a task that needs to be migrated into or out of the first CPU;

[0213] When the priority of the task to be processed is the highest priority, performing corresponding processing on the task to be processed according to the first red-black tree;

[0214] In the case where the priority of the task to be processed is other priorities, the task to be processed is processed accordingly with respect to the second red-black tree.

[0215] In some embodiments, the apparatus 50 further comprises:

[0216] The synchronization module updates the first minimum virtual duration and the second minimum virtual duration to the maximum value thereof in response to at least one of the first red-black tree and the second red-black tree not including any task and the first CPU not executing the task of the priority corresponding to the at least one red-black tree.

[0217] In some embodiments, the apparatus 50 further comprises:

[0218] The setting module sets the first variable to a preset value for increasing the second minimum virtual duration in response to the updated first variable being less than or equal to 0.

[0219] The embodiment of the task scheduling device shown in the present application can be applied to an electronic device. Accordingly, the present application discloses an electronic device, which may include: a processor.

[0220] Memory used to store processor-executable instructions.

[0221] The processor is configured to call the executable instructions stored in the memory to implement the task scheduling method shown in any of the above embodiments.

[0222] See also Figure 6 , Figure 6A schematic diagram of the hardware structure of an electronic device shown in this application.

[0223] like Figure 6 As shown, the electronic device may include a processor for executing instructions, a network interface for network connection, a memory for storing operation data for the processor, and a non-volatile memory for storing instructions corresponding to the task scheduling device.

[0224] The embodiments of the device may be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a logical device, the processor of the electronic device in which it is located reads the corresponding computer program instructions in the non-volatile memory into the memory and runs them. From the hardware level, in addition to Figure 6 In addition to the processor, memory, network interface, and non-volatile memory shown, the electronic device in which the device in the embodiment is located may also include other hardware according to the actual function of the electronic device, which will not be described in detail.

[0225] It is understandable that in order to improve the processing speed, the device corresponding instructions can also be directly stored in the memory, which is not limited here.

[0226] The present application proposes a computer-readable storage medium, which stores a computer program. The computer program can be used to enable a processor to execute the task scheduling method shown in any of the aforementioned embodiments.

[0227] Those skilled in the art will appreciate that one or more embodiments of the present application may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present application may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program code.

[0228] The term “and / or” used in the present application indicates at least one of the two. For example, “A and / or B” includes three options: A, B, and “A and B”.

[0229] Each embodiment in the present application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the data processing device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0230] The specific embodiments of the present application are described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0231] The embodiments of the subject matter and functional operations described in this application can be implemented in the following: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this application and their structural equivalents, or a combination of one or more of them. The embodiments of the subject matter described in this application can be implemented as one or more computer programs, i.e., one or more modules in computer program instructions encoded on a tangible non-temporary program carrier to be executed by a data processing device or to control the operation of the data processing device. Alternatively or additionally, the program instructions can be encoded on an artificially generated propagation signal, such as a machine-generated electrical, optical or electromagnetic signal, which is generated to encode information and transmit it to a suitable receiver device for execution by a data processing device. The computer storage medium can be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.

[0232] The processes and logic flows described in this application can be performed by one or more programmable computers executing one or more computer programs to perform corresponding functions by operating on input data and generating output. The processes and logic flows can also be performed by special purpose logic circuits, such as FPGAs (field programmable gate arrays) or ASICs (application specific integrated circuits), and the apparatus can also be implemented as special purpose logic circuits.

[0233] Computers suitable for executing computer programs include, for example, general and / or special microprocessors, or any other type of central processing system. Typically, the central processing system will receive instructions and data from a read-only memory and / or a random access memory. The basic components of a computer include a central processing system for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, the computer will also include one or more large-capacity storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, or the computer will be operably coupled to this large-capacity storage device to receive data from it or to transmit data to it, or both. However, the computer does not necessarily have such a device. In addition, the computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, just to name a few.

[0234] Computer readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including, for example, semiconductor memory devices (e.g., EPROM, EEPROM and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and 0xCD-00ROM and DVD-ROM disks. The processor and memory may be supplemented by or incorporated in special purpose logic circuitry.

[0235] Although the application includes many specific implementation details, these should not be interpreted as limiting any disclosed scope or the scope of protection claimed, but are mainly used to describe the features of specific disclosed specific embodiments. Certain features described in multiple embodiments in the application can also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment can also be implemented separately in multiple embodiments or implemented with any suitable sub-combination. In addition, although the feature can work in some combinations as described above and even initially claim protection, one or more features from the claimed combination can be removed from the combination in some cases, and the claimed combination can point to a variation of a sub-combination or a sub-combination.

[0236] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or requiring that all illustrated operations be performed to achieve the desired result. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system modules and components in the described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into multiple software products.

[0237] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the particular order or sequential order shown to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.

[0238] The above description is merely a preferred embodiment of one or more embodiments of the present application and is not intended to limit one or more embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present application shall be included in the scope of protection of one or more embodiments of the present application.

Claims

1. A task scheduling method, applied to a first CPU of at least two logical processors CPU obtained based on hyperthreading technology; a task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU; The first CPU maintains virtual durations corresponding to the tasks of different priorities respectively; The method comprises: Obtaining the priority of a task being executed by a second CPU of the at least two logical processors CPU except the first CPU; In response to the priority of the task being executed by the second CPU being the highest priority, the task with the smallest virtual duration is obtained from the first task list corresponding to the highest priority through the task scheduler; wherein the at least two task lists also include a second task list corresponding to other priorities; the first task list includes a first red-black tree; the second task list includes a second red-black tree; the first red-black tree maintains the first minimum virtual duration corresponding to each task in the first task list; the second red-black tree maintains the second minimum virtual duration corresponding to each task in the second task list; the first CPU also maintains a first variable and a second variable; the first variable indicates the difference between the first minimum virtual duration and the second minimum virtual duration before the task is expelled; the second variable indicates the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by the task expulsion in the case of at least one task expulsion; In the case where task eviction is required, in response to the fact that this scheduling is the first eviction scheduling, the first variable is updated according to the current first minimum virtual duration corresponding to the task with the smallest virtual duration maintained by the first red-black tree, the current second minimum virtual duration maintained by the second red-black tree, and the current second variable maintained by the first CPU, and the task with the smallest virtual duration is executed to complete the task scheduling.

2. The method according to claim 1, further comprising: In response to the priority of the task being executed by the second CPU not being the highest priority, the task scheduler obtains tasks that meet the scheduling conditions from the at least two task lists for execution to complete task scheduling without the need for task eviction.

3. The method according to claim 2, wherein the task scheduler is a completely fair scheduler CFS; The step of obtaining the task with the smallest virtual duration from the first task list by the task scheduler includes: Obtaining the task with the smallest virtual duration from the first task list through the CFS; The step of obtaining, by the task scheduler, tasks satisfying the scheduling condition from the at least two task lists comprises: The task with the smallest virtual duration is obtained from the at least two task lists through the CFS.

4. The method according to claim 3, further comprising: In a situation where task eviction is not required, before performing task scheduling, in response to the fact that this scheduling is the first non-eviction scheduling after task eviction, the second variable is updated according to the current first minimum virtual duration, the current second minimum virtual duration and the current first variable.

5. The method according to claim 4, wherein obtaining the task corresponding to the minimum virtual duration from the at least two task lists through the CFS comprises: Compare the sum of the second minimum virtual duration and the updated second variable with the first minimum virtual duration; In response to the sum of the second minimum virtual duration and the updated second variable being less than the first minimum virtual duration, obtaining a task corresponding to the second minimum virtual duration from the second red-black tree through the CFS; In response to the sum of the second minimum virtual duration and the updated second variable being greater than or equal to the first minimum virtual duration, a task corresponding to the first minimum virtual duration is acquired from the first red-black tree through the CFS.

6. The method according to claim 2, further comprising: Obtaining the priority of the pending task; the pending task includes a task that needs to be migrated into or out of the first CPU; When the priority of the task to be processed is the highest priority, performing corresponding processing on the task to be processed according to the first red-black tree; In the case where the priority of the task to be processed is other priorities, the task to be processed is processed accordingly with respect to the second red-black tree.

7. The method according to claim 6, before migrating in the pending tasks or after migrating out the pending tasks, further comprising: In response to at least one of the first red-black tree and the second red-black tree not including any task, and the first CPU not executing the task of the priority corresponding to the at least one red-black tree, the first minimum virtual duration and the second minimum virtual duration are updated to the maximum value of the two.

8. The method according to claim 1, after updating the first variable, further comprising: In response to the updated first variable being less than or equal to 0, the first variable is set to a preset value to increase the second minimum virtual duration.

9. A task scheduling device, applied to a first CPU of at least two logical processors CPU obtained based on hyperthreading technology; a task scheduler corresponding to the first CPU maintains at least two task lists; the at least two task lists are respectively used to store tasks of different priorities executed by the first CPU; The first CPU maintains virtual durations corresponding to the tasks of different priorities respectively; The device comprises: An acquisition module is used to acquire the priority of a task being executed by a second CPU among the at least two logical processors CPU except the first CPU; The first scheduling module, in response to the priority of the task being executed by the second CPU being the highest priority, obtains the task with the smallest virtual duration from the first task list corresponding to the highest priority through the task scheduler; wherein the at least two task lists also include a second task list corresponding to other priorities; the first task list includes a first red-black tree; the second task list includes a second red-black tree; the first red-black tree maintains the first minimum virtual duration corresponding to each task in the first task list; the second red-black tree maintains the second minimum virtual duration corresponding to each task in the second task list; the first CPU also maintains a first variable and a second variable; the first variable refers to indicates the difference between the first minimum virtual duration and the second minimum virtual duration before the task is evicted; the second variable indicates the cumulative difference between the first minimum virtual duration and the second minimum virtual duration caused by task eviction in the case of at least one task eviction; in the case where task eviction is required, in response to this scheduling being the first eviction scheduling, according to the current first minimum virtual duration corresponding to the task with the smallest virtual duration maintained by the first red-black tree, the current second minimum virtual duration maintained by the second red-black tree and the current second variable maintained by the first CPU, the first variable is updated, and the task with the smallest virtual duration is executed to complete the task scheduling.

10. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the task scheduling method according to any one of claims 1 to 8 by running the executable instructions.

11. A computer-readable storage medium storing a computer program, wherein the computer program is used to enable a processor to execute the task scheduling method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method and device of determining minimum scheduling granularity

    CN108268310A

  • Container task scheduling method and device, electronic equipment and computer readable medium

    CN112698920A

  • Task allocation method and device, storage medium and electronic equipment

    CN112925616A