CN114168352B - Multi-core task scheduling method and device, electronic equipment and storage medium - Google Patents
Multi-core task scheduling method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114168352B CN114168352B CN202111659365.1A CN202111659365A CN114168352B CN 114168352 B CN114168352 B CN 114168352B CN 202111659365 A CN202111659365 A CN 202111659365A CN 114168352 B CN114168352 B CN 114168352B
- Authority
- CN
- China
- Prior art keywords
- task
- target
- running
- candidate
- preemption
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/505—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the application discloses a multi-core task scheduling method and device, electronic equipment and a storage medium. The method comprises the following steps: screening out a target running task with the lowest priority and the running CPU core without the second priority preemption attribute from the running task queue; the sub-optimal pre-preemption attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core; screening a target ready task with the highest priority from the ready tasks, and determining that the target ready task has preemption right if the priority of the target ready task is higher than that of a target running task; if the target ready task has preemption right, determining a candidate task of a CPU core operated by the target running task, and preempting the candidate task by using the target ready task based on the priority of the target ready task and the candidate task; the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
Description
Technical Field
The embodiment of the application relates to the technical field of task scheduling, in particular to a multi-core task scheduling method and device, electronic equipment and a storage medium.
Background
With the development of chip technology, the application of chips is more and more extensive, in order to improve the performance of chips, a plurality of processing cores are arranged in the chips, each core can be independently allocated to each task, and each task is processed at the same time, so that the efficiency of processing tasks is greatly improved compared with that of a single-core chip.
In the scenario of multiple processing cores, task scheduling between cores is usually implemented by a scheduler to ensure that task processing processes between multiple cores do not conflict. Task switching is strictly controlled by task priority in a real-time system, generally, a high-priority task can preempt the use right of a CPU (central processing unit) of a low-priority task, the preempted task can further preempt other tasks with lower priority in a multi-core environment, and if the preemption of the use right of the CPU is improperly controlled, redundant scheduling is caused, so that the multi-core processing performance is reduced.
Disclosure of Invention
Embodiments of the present application provide a method and an apparatus for task multi-core scheduling, an electronic device, and a storage medium, so as to avoid a problem that multi-core processing performance may be reduced in a task preemption process.
In a first aspect, an embodiment of the present application provides a method for multi-core scheduling of tasks, where the method includes:
screening out a target running task with the lowest priority and the running CPU core without the second priority preemption attribute from the running task queue; the second priority preemption attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
screening a target ready task with the highest priority from ready tasks, and determining that the target ready task has preemption if the priority of the target ready task is higher than that of the target running task;
if the target ready task has the preemption right, determining a candidate task of a CPU core operated by the target operation task, and preempting the candidate task by using the target ready task based on the priority of the target ready task and the candidate task; and the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
In a second aspect, an embodiment of the present application further provides a multi-core scheduling device for a task, where the multi-core scheduling device for the task includes:
the target running task determining module is used for screening out a target running task which has the lowest priority and the running CPU core of which does not have a second priority preemption attribute from the running task queue; the second priority preemption attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
the preemption determining module is used for screening a target ready task with the highest priority from ready tasks, and if the priority of the target ready task is higher than that of the target running task, determining that the target ready task has preemption;
a candidate task preemption module, configured to determine a candidate task of a CPU core in which the target running task runs if the target ready task has the preemption right, and preempt the candidate task by using the target ready task based on priorities of the target ready task and the candidate task; and the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
In a third aspect, an embodiment of the present application further provides an electronic device, where the electronic device includes:
one or more processors;
a storage device to store one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the multi-core scheduling method of tasks as provided in any embodiment of the present application.
In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is configured to, when executed by a processor, implement a multi-core scheduling method for tasks as provided in any embodiment of the present application.
According to the technical scheme, the affinity attribute is set between the global task and the CPU core, the sub-priority preemption attribute is set to indicate whether each CPU core has the global task with the affinity attribute, when task scheduling is carried out, the target running task with the lowest priority and the running CPU core without the sub-priority preemption attribute is screened out from the running task queue, then the target ready task with the highest priority in the ready tasks is used for preempting the candidate task of the core corresponding to the target running task, the running of the global task corresponding to the CPU core with the sub-priority preemption attribute is ensured, the global task with the affinity attribute with the CPU core is prevented from being preempted, and the redundant scheduling condition is reduced.
Drawings
Fig. 1 is a schematic flowchart of a multi-core task scheduling method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a bit field data representation of an affinity attribute according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a multi-core task scheduling apparatus according to a second embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to a third embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of and not restrictive on the broad application. It should be further noted that, for the convenience of description, only some of the structures related to the present application are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart illustrating a multi-core scheduling method for a task according to an embodiment of the present application, where the embodiment is applicable to a multi-core scheduling scenario for a task. The method can be executed by a multi-core scheduling device of tasks, the device can be implemented in a hardware and/or software manner, and can be generally integrated in an electronic device such as a computer with data operation capability, and specifically includes the following steps:
101, screening out a target running task with the lowest priority and without running CPU (Central processing Unit) cores with a second-priority preemption attribute from a running task queue; and the second-priority preemption attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core.
It should be noted that, before this step, the scheduler may initiate scheduling, and in order to ensure that the method of this embodiment can be performed effectively, the kernel lock may be acquired first, so that the task scheduling process of the scheduler is prohibited, the scheduler is a program entity that specifically implements task scheduling, and the scheduler is generally used to screen candidate tasks from ready tasks, balance CPU load, and perform switching between tasks. The candidate task is a task in a special state, which is extracted from an original ready task queue, and if the candidate task is consistent with the running task, the candidate task is indicated to be run, and if the candidate task is inconsistent with the running task, the candidate task is indicated to be run.
Generally, after a running task of a core is completed, the core calls a scheduler to perform task scheduling, that is, to extract a task from a ready task queue to make the task a candidate task. In order to avoid the situation that the low-priority task occupied by the high-priority task is not the lowest-priority task and the global task with high priority occupies the low-priority binding task, the present embodiment prohibits the task scheduling process of the scheduler first when the scheduler initiates scheduling.
Specifically, the present embodiment may utilize a kernel lock to disable a task scheduling process of the scheduler. It should be noted that, as for the way of implementing the task scheduling process prohibition by the kernel lock body, reference may be made to related technologies, which are not described herein.
It should be noted that, in this embodiment, an affinity attribute between the global task and the CPU core is set, and when the affinity attribute is set, the CPU core is set to have a second-best preemption attribute; the affinity attribute of the global task is a priority attribute of the global task running on the corresponding CPU core.
Specifically, the affinity attribute between the global task and the CPU core may be mapped through a 32-bit field, where the highest bit represents the binding relationship between the task and the CPU core, and the remaining bits represent the affinity between the task and the CPU core.
In a specific example, as shown in fig. 2, fig. 2 is a schematic diagram of a bit field data representation affinity attribute provided in the first embodiment of the present application. In this embodiment, the bit field data may be 32 bits of data, where the highest bit b31 represents task binding information, a value of 0 represents a non-binding task, and a value of 1 represents a binding task; the lower 31-bit data b30-b0 indicates that the task has affinity for a certain CPU core, specifically, b30-b0, each bit field indicates a core, for example, b0 indicates a core with a core number of 0, b1 indicates a core with a core number of 1, and b30 indicates a core with a core number of 30. When the task setting has an affinity attribute with a core with core number 3, b3 may be set to 1 and the bit fields in b30-b0 except b3 may be set to 0.
Accordingly, for the sub-optimal preemption attribute of each core, a parameter may be identified, such as ttosssecondarypriority set, and the parameter may also be identified in the form of a bit field, where each bit field represents a core, and if the core is provided with a global task having an affinity attribute, the bit field corresponding to the core in the parameter is set to 1.
Of course, to ensure real-time identification of the parameter, the affinity bit field data in the task may be periodically scanned and matched with the parameter. In addition, it may also occur that a plurality of global tasks have an affinity attribute for the same core, at this time, a counter may be used, each core should have a counter, and a new global task appears each time, if an affinity attribute is set for a certain core, 1 is added to the corresponding counter, and each time a global task is completed by a core, 1 is subtracted from the corresponding counter. Periodically scanning counters corresponding to the cores, and keeping the bit field of the sub-optimal pre-preemption attribute parameter corresponding to the core as '1' as long as the numerical value in the counter is not 0, otherwise, namely when a certain CPU core does not have a global task with CPU affinity, the sub-optimal pre-preemption attribute of the CPU core is cleared, and the bit field of the parameter is set as '0'.
In this step, the process of screening the target running tasks may specifically be that, according to the priority order, the current running tasks of each core are sorted to obtain a running task queue; acquiring at least one running task with the lowest priority from the running task queue, and judging whether a CPU core running each running task has a suboptimal preemptive attribute; and for any running task, if the CPU core running the running task does not have the second priority preemption attribute, determining the running task as the target running task.
Specifically, the current running tasks of all cores are sorted from high to low according to the priority to obtain a running task queue runningtaskpiortbl, and then the lowest priority task lowerpiorrrorruntask is obtained from the running task queue runningtaskpiortbl, and the CPU core number of the lowest priority task lowerpiorrrorruntask, where the core number can be obtained from the cpuIndex field of the lowest priority task lowerpiorrrorruntask.
Through the aforementioned parameter ttossSecondardryPrioritySet of the suboptimal priority preemption attribute, whether the bit field corresponding to the CPU core number of the lowest priority task lowerpiorRunTask is "1" is judged to judge whether the CPU core of the lowest priority task lowerpiorRunTask has the suboptimal priority preemption attribute, if yes, other tasks with the same priority as the lowest priority task lowerpiorRunTask are screened from the running task queue runningTaskPriorTbl, whether the CPU core running by the task has the suboptimal priority attribute is judged, and if not, the task is set as the lowest priority task lowerpiorPriorRunTask, namely, a target running task.
And 102, screening a target ready task with the highest priority from the ready tasks, and determining that the target ready task has preemption right if the priority of the target ready task is higher than that of the target running task.
In this step, the ready task refers to a task processed by a core to be allocated, and in this embodiment, the ready task list is split into a global task ready queue and a bound task queue, where a task in the global task ready queue is a global task, a task in the bound task queue is a bound task, the global task is different from the bound task, the global task can be run on any unreserved core, and the bound task can only run on a specific core bound to the global task.
In this step, the task with the highest priority (i.e., the target ready task) in the ready tasks is compared with the target running task in the previous step to determine whether the target ready task has preemption.
Specifically, a first task with the highest priority may be obtained from the global task ready queue; acquiring a core number of a CPU core running a target running task, and acquiring a second task with the highest priority of a binding core number from a binding task ready queue; and determining the task with the highest priority in the first task and the second task as the task with the highest priority in the ready tasks to acquire.
In a specific example, the highest priority task globalstask (i.e., the first task) in the global task is obtained from the ready queue, then the highest priority task privattask [ cpuIndex ] (i.e., the second task) bound to the core number is determined from the bound task queue according to the core number of the CPU core of the target running task obtained in the previous step, and the highest priority target ready task readyttask is determined from the highest priority task globalstask (i.e., the first task) and the highest priority task privatequeuetask [ cpuIndex ] (i.e., the second task) in the global task.
If the target ready task readyTask with the highest priority is higher than the priority of the task lowerpiorrrorRunTask with the lowest priority in the running task queue runningTaskPriorTbl, it can be determined that the target ready task readyTask has preemption capability, otherwise, the task lowerpiorRunTask is removed from the runningTaskPriorTbl, so as to perform subsequent repeated screening.
103, if the target ready task has the preemption right, determining a candidate task of a CPU core operated by the target operation task, and preempting the candidate task by using the target ready task based on the priority of the target ready task and the candidate task; the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
Although it is determined in the foregoing step that the target ready task has preemption, the target running task may not be a candidate task at this time, and therefore, in this step, if the target ready task has preemption, it needs to first determine whether a candidate task of a CPU core that the target running task runs is consistent with the target running task, and if the candidate task is consistent with the target running task, the target ready task is determined as a new candidate task.
If the candidate task is inconsistent with the target running task, comparing the priorities of the target ready task and the candidate task; and if the priority of the target ready task is higher than that of the candidate task, determining the candidate task as the ready task, and determining the target ready task as a new candidate task.
In this embodiment, an affinity attribute is set between the global task and the CPU core, and a sub-priority preemption attribute is set to indicate whether each CPU core has a global task having an affinity attribute with the CPU core, so that when task scheduling is performed, a target run task having a lowest priority and having no sub-priority preemption attribute with the CPU core running on the CPU core is screened from the run task queue, and then a candidate task of a core corresponding to the target run task is preempted by using a target ready task having a highest priority among ready tasks, so that running of the global task corresponding to the CPU core having the sub-priority preemption attribute is ensured, the global task having an affinity attribute with the CPU core is prevented from being preempted, and redundant scheduling is reduced.
In addition, the present embodiment may also perform task switching of the core based on the candidate task after preemption, where the task switching is to switch the task running on the core to the candidate task corresponding to the core. Of course, in this step, after the switching task is completed, the kernel lock is also released, so that the scheduler continues to operate normally.
Specifically, since the scheduler is called by a certain kernel, but the task switching process may need to be completed by a kernel that does not call the scheduler, in this step, if the kernel that performs candidate task preemption is the kernel that performs candidate task preemption, the target running task is switched to the candidate task after preemption; and if the core for executing the candidate task preemption is not the core for generating the candidate task preemption, sending an interrupt to the core for generating the candidate task preemption so as to inform the core for generating the candidate task preemption to switch the target running task into the preempted candidate task. It should be noted that the aforementioned interrupt may be an IPI interrupt.
Example two
Fig. 3 is a schematic structural diagram of a multi-core task scheduling device according to a second embodiment of the present application. The multi-core scheduling device for the tasks provided by the embodiments of the present application can execute the multi-core scheduling method for the tasks provided by any embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method. The device may be implemented in a software and/or hardware manner, and as shown in fig. 3, the multi-core task scheduling device specifically includes: a target running task determining module 301, a preemption determining module 302 and a candidate task preemption module 303.
The target running task determining module is used for screening out a target running task which has the lowest priority and does not have a second-priority preemption attribute in the running task queue; the second-best preemptive attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
the preemption determining module is used for screening a target ready task with the highest priority from the ready tasks, and determining that the target ready task has preemption if the priority of the target ready task is higher than that of a target running task;
the candidate task preemption module is used for determining the candidate task of the CPU core operated by the target running task if the target ready task has preemption right, and preempting the candidate task by using the target ready task based on the priority of the target ready task and the candidate task; the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
In this embodiment, an affinity attribute is set between the global task and the CPU core, and a sub-priority preemption attribute is set to indicate whether each CPU core has a global task having an affinity attribute with the CPU core, so that when task scheduling is performed, a target run task having a lowest priority and having no sub-priority preemption attribute with the CPU core running on the CPU core is screened from the run task queue, and then a candidate task of a core corresponding to the target run task is preempted by using a target ready task having a highest priority among ready tasks, so that running of the global task corresponding to the CPU core having the sub-priority preemption attribute is ensured, the global task having an affinity attribute with the CPU core is prevented from being preempted, and redundant scheduling is reduced.
Further, the apparatus further comprises:
the affinity attribute setting module is used for setting the affinity attribute between the global task and the CPU core, and setting the CPU core to have a suboptimal preemptive attribute when the affinity attribute is set; the affinity attribute of the global task is a priority attribute of the global task running on the corresponding CPU core.
Further, the apparatus further comprises: and the second priority preemption attribute clearing module is used for clearing the second priority preemption attribute of the CPU core when the CPU core does not have the global task with the CPU affinity.
Furthermore, the affinity attribute between the global task and the CPU core is mapped through a 32-bit domain, wherein the highest bit represents the binding relationship between the task and the CPU core, and the remaining bits represent the affinity between the task and the CPU core.
Further, the target operation task determination module includes:
the running task queue determining unit is used for sequencing the current running tasks of each core according to the priority sequence to obtain a running task queue;
a second priority preemption attribute judging unit, configured to obtain at least one running task with the lowest priority from the running task queue, and judge whether a CPU core running each running task has a second priority preemption attribute;
and the target running task determining unit is used for determining the running task as the target running task if the CPU core running the running task does not have the second priority preemption attribute for any running task.
Further, the preemption determination module comprises:
the first task determining module is used for acquiring a first task with the highest priority from the global task ready queue;
the second task determination module is used for acquiring the core number of the CPU core running the target running task and acquiring a second task with the highest priority of the bound core number from the bound task ready queue;
and the target ready task determining module is used for determining the task with the highest priority in the first task and the second task as the target ready task with the highest priority in the ready tasks.
Further, the candidate task preemption module comprises:
the first candidate task determining unit is used for determining the target ready task as a new candidate task if the candidate task is consistent with the target running task;
the priority comparison unit is used for comparing the priorities of the target ready task and the candidate task if the candidate task is inconsistent with the target running task;
and the second candidate task determination unit is used for determining the candidate task as the ready task and determining the target ready task as a new candidate task if the priority of the target ready task is higher than that of the candidate task.
Further, the apparatus further comprises:
the task switching module is used for switching the task of the core based on the candidate task after the preemption;
the task switching module comprises:
the first switching unit is used for switching the target running task into the preempted candidate task if the core executing the candidate task preemption is the core in which the candidate task is preempted;
and the second switching unit is used for sending an interrupt to the core with the candidate task preempted if the core for executing the candidate task preemption is not the core with the candidate task preempted so as to inform the core with the candidate task preempted to switch the target running task into the preempted candidate task.
EXAMPLE III
Fig. 4 is a schematic structural diagram of an electronic device according to a third embodiment of the present application, as shown in fig. 4, the electronic device includes a processor 410, a memory 420, an input device 430, and an output device 440; the number of the processors 410 in the electronic device may be one or more, and one processor 410 is taken as an example in fig. 4; the processor 410, the memory 420, the input device 430 and the output device 440 in the electronic apparatus may be connected by a bus or other means, and the connection by the bus is exemplified in fig. 4.
The memory 420 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the multi-core scheduling method of the task in the embodiment of the present invention (for example, the scheduling prohibition module 401, the task preemption module 402, and the task switching module 403 in the multi-core scheduling apparatus of the task). The processor 410 executes various functional applications and data processing of the electronic device, i.e., a multi-core scheduling method for implementing the above-described tasks, by executing software programs, instructions, and modules stored in the memory 420.
Screening out a target running task with the lowest priority and the running CPU core without the second priority preemption attribute from the running task queue; the second-best preemptive attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
screening a target ready task with the highest priority from the ready tasks, and determining that the target ready task has preemption right if the priority of the target ready task is higher than that of a target running task;
if the target ready task has preemption right, determining a candidate task of a CPU core operated by the target running task, and preempting the candidate task by using the target ready task based on the priority of the target ready task and the candidate task; the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
The memory 420 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 420 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 420 may further include memory located remotely from processor 410, which may be connected to an electronic device over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Example four
A fourth embodiment of the present application further provides a storage medium containing computer-executable instructions, where the computer-executable instructions are executed by a computer processor to perform a multi-core scheduling method for a task, and the method includes:
screening out a target running task with the lowest priority and without a second priority preemption attribute of a running CPU core from the running task queue; the second-best preemptive attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
screening a target ready task with the highest priority from the ready tasks, and determining that the target ready task has preemption right if the priority of the target ready task is higher than that of a target running task;
if the target ready task has the preemption right, determining a candidate task of a CPU core operated by the target operation task, and preempting the candidate task by using the target ready task based on the priorities of the target ready task and the candidate task; the candidate task is a task which is already put into the CPU core to run or is about to be put into the CPU core to run.
Of course, the storage medium provided in the embodiments of the present application and containing computer-executable instructions is not limited to the above method operations, and may also perform related operations in the multi-core scheduling method for tasks provided in any embodiment of the present application.
From the above description of the embodiments, it is obvious for those skilled in the art that the present application can be implemented by software and necessary general hardware, and certainly can be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods of the embodiments of the present application.
It should be noted that, in the embodiment of the above search apparatus, each included unit and module are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only used for distinguishing one functional unit from another, and are not used for limiting the protection scope of the application.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present application and the technical principles employed. Those skilled in the art will appreciate that the present application is not limited to the particular embodiments described herein, and that various obvious changes, rearrangements and substitutions will now become apparent to those skilled in the art without departing from the scope of the application. Therefore, although the present application has been described in more detail with reference to the above embodiments, the present application is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims (9)
1. A method for multi-core scheduling of tasks, the method comprising:
screening out a target running task with the lowest priority and the running CPU core without the second priority preemption attribute from the running task queue; the second priority preemption attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
screening a target ready task with the highest priority from ready tasks, and determining that the target ready task has preemption if the priority of the target ready task is higher than that of the target running task;
if the target ready task has the preemption right, determining a candidate task of a CPU core operated by the target operation task, and preempting the candidate task by using the target ready task based on the priority of the target ready task and the candidate task; the candidate tasks are tasks which are already put into the CPU core to run or are about to be put into the CPU core to run;
setting an affinity attribute between the global task and the CPU core, and setting the CPU core to have a second-best first-preemption attribute when setting the affinity attribute; the affinity attribute of the global task is a priority attribute of the global task running on a corresponding CPU core;
preempting the candidate task by using the target-ready task based on the priorities of the target-ready task and the candidate task, including:
if the candidate task is consistent with the target running task, determining the target ready task as a new candidate task;
if the candidate task is inconsistent with the target running task, comparing the priorities of the target ready task and the candidate task;
and if the priority of the target ready task is higher than that of the candidate task, determining the candidate task as a ready task, and determining the target ready task as a new candidate task.
2. The method of claim 1, further comprising: when a CPU core does not have a global task with CPU affinity, the sub-optimal preemption attribute of the CPU core is cleared.
3. The method according to claim 1 or 2, wherein the affinity attribute between the global task and the CPU core is mapped through a 32-bit domain, wherein the highest bit represents the binding relationship between the task and the CPU core, and the remaining bits represent the affinity between the task and the CPU core.
4. The method according to claim 1, wherein the step of screening out the target running task with the lowest priority and without the running CPU core having the sub-priority preemption attribute in the running task queue comprises:
sequencing the current running tasks of each core according to the priority sequence to obtain a running task queue;
acquiring at least one running task with the lowest priority from the running task queue, and judging whether a CPU core running each running task has a suboptimal preemption attribute;
and for any running task, if the CPU core running the running task does not have the second priority preemption attribute, determining the running task as a target running task.
5. The method according to claim 1, wherein the screening out the target ready tasks with the highest priority among the ready tasks comprises:
acquiring a first task with the highest priority from a global task ready queue;
acquiring a core number of a CPU core for operating the target operation task, and acquiring a second task with the highest priority for binding the core number from a binding task ready queue;
and determining the task with the highest priority in the first task and the second task as a target ready task with the highest priority in ready tasks.
6. The method of claim 1, further comprising:
performing task switching of the core based on the candidate task after the preemption;
the task switching of the core based on the candidate task after the preemption comprises the following steps:
if the core executing the candidate task preemption is the core generating the candidate task preemption, switching the target running task into the candidate task after the preemption;
and if the core for executing the candidate task preemption is not the core for generating the candidate task preemption, sending an interrupt to the core for generating the candidate task preemption so as to inform the core for generating the candidate task preemption to switch the target running task into the candidate task after the preemption.
7. An apparatus for multi-core scheduling of tasks, the apparatus comprising:
the target running task determining module is used for screening out a target running task which has the lowest priority and the running CPU core of which does not have the second priority preemption attribute from the running task queue; the second priority preemption attribute is used for indicating that the CPU core should have a global task with an affinity attribute with the CPU core;
the preemption determining module is used for screening a target ready task with the highest priority from ready tasks, and if the priority of the target ready task is higher than that of the target running task, determining that the target ready task has preemption;
a candidate task preemption module, configured to determine a candidate task of a CPU core in which the target running task runs if the target ready task has the preemption right, and preempt the candidate task by using the target ready task based on priorities of the target ready task and the candidate task; the candidate tasks are tasks which are already put into the CPU core to run or are about to be put into the CPU core to run;
the affinity attribute setting module is used for setting the affinity attribute between the global task and the CPU core, and setting the CPU core to have a second-best first preemption attribute when setting the affinity attribute; the affinity attribute of the global task is a priority attribute of the global task running on a corresponding CPU core;
the candidate task preemption module comprises:
the first candidate task determining unit is used for determining the target ready task as a new candidate task if the candidate task is consistent with the target running task;
the priority comparison unit is used for comparing the priorities of the target ready task and the candidate task if the candidate task is inconsistent with the target running task;
and the second candidate task determination unit is used for determining the candidate task as the ready task and determining the target ready task as a new candidate task if the priority of the target ready task is higher than that of the candidate task.
8. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a multi-core scheduling method of tasks as recited in any of claims 1-6.
9. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out a multi-core scheduling method of tasks according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111659365.1A CN114168352B (en) | 2021-12-30 | 2021-12-30 | Multi-core task scheduling method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111659365.1A CN114168352B (en) | 2021-12-30 | 2021-12-30 | Multi-core task scheduling method and device, electronic equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114168352A CN114168352A (en) | 2022-03-11 |
CN114168352B true CN114168352B (en) | 2022-11-11 |
Family
ID=80488736
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111659365.1A Active CN114168352B (en) | 2021-12-30 | 2021-12-30 | Multi-core task scheduling method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114168352B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114880075B (en) * | 2022-05-11 | 2023-01-06 | 科东(广州)软件科技有限公司 | Method and device for scheduling task between virtual cores of user-mode virtual machine |
CN116185582B (en) * | 2022-12-29 | 2024-03-01 | 国科础石(重庆)软件有限公司 | Multi-core scheduling method, device, vehicle, electronic equipment and medium |
Family Cites Families (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8495642B2 (en) * | 2008-04-23 | 2013-07-23 | Red Hat, Inc. | Mechanism for priority inheritance for read/write locks |
CN101414270A (en) * | 2008-12-04 | 2009-04-22 | 浙江大学 | Method for implementing assist nuclear task dynamic PRI scheduling with hardware assistant |
KR20110070299A (en) * | 2009-12-18 | 2011-06-24 | 한국전자통신연구원 | Appatus and method for scheduling tasks in multicore processor |
CN104090826B (en) * | 2014-06-30 | 2017-07-11 | 中国电子科技集团公司第三十二研究所 | Task optimization deployment method based on correlation |
US9852005B2 (en) * | 2014-10-02 | 2017-12-26 | Mediatek Inc. | Multi-core processor systems and methods for assigning tasks in a multi-core processor system |
KR102641520B1 (en) * | 2018-11-09 | 2024-02-28 | 삼성전자주식회사 | System on chip including multi-core processor and task scheduling method thereof |
CN113687909B (en) * | 2021-07-28 | 2024-01-30 | 华东计算技术研究所(中国电子科技集团公司第三十二研究所) | Time-sharing vcpu multi-core scheduling method and system based on microkernel |
-
2021
- 2021-12-30 CN CN202111659365.1A patent/CN114168352B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN114168352A (en) | 2022-03-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN114168352B (en) | Multi-core task scheduling method and device, electronic equipment and storage medium | |
EP3425502B1 (en) | Task scheduling method and device | |
CN106802826B (en) | Service processing method and device based on thread pool | |
CN103440173B (en) | The dispatching method of a kind of polycaryon processor and relevant apparatus | |
US8719834B2 (en) | Information processing system, method, program and integrated circuit for maintaining balance of processing loads with respect to real-time tasks | |
EP2701074A1 (en) | Method, device, and system for performing scheduling in multi-processor core system | |
CN111459659A (en) | Data processing method, device, scheduling server and medium | |
CN112214319B (en) | Task scheduling method for sensing computing resources | |
CN109992366B (en) | Task scheduling method and task scheduling device | |
CN114168271B (en) | Task scheduling method, electronic device and storage medium | |
CN113032101A (en) | Resource allocation method for virtual machine, server and computer readable storage medium | |
CN111932257A (en) | Block chain parallelization processing method and device | |
CN111597040A (en) | Resource allocation method, device, storage medium and electronic equipment | |
US9189279B2 (en) | Assignment method and multi-core processor system | |
CN111831408A (en) | Asynchronous task processing method and device, electronic equipment and medium | |
CN114064296B (en) | Kubernetes scheduling method, Kubernetes scheduling device and storage medium | |
CN113626173B (en) | Scheduling method, scheduling device and storage medium | |
CN108897858B (en) | Distributed cluster index fragmentation evaluation method and device and electronic equipment | |
CN107634978B (en) | Resource scheduling method and device | |
CN116881003A (en) | Resource allocation method, device, service equipment and storage medium | |
CN110618946A (en) | Stack memory allocation method, device, equipment and storage medium | |
CN114911538A (en) | Starting method of running system and computing equipment | |
CN115268713A (en) | Thread identification method and device, storage medium and electronic equipment | |
CN113132261B (en) | Traffic data packet classification method and device and electronic equipment | |
JP6285850B2 (en) | Process migration method and cluster system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |