Multi-processor task scheduling method, device and storage medium
By dynamically binding tasks to the CPU in a multi-processor system, the problems of low CPU cache utilization and high scheduling resource consumption caused by frequent task migration are solved, and more efficient task scheduling and resource utilization are achieved.
Patent Information
- Application Number
- CN202011610552.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-30
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-12-30
AI Technical Summary
In the task scheduling process of existing multi-processor systems, frequent task migration results in low CPU cache utilization, and scheduling behavior consumes too many resources, affecting system efficiency.
The multi-processor task scheduling method is adopted, and through the dynamic binding of tasks and CPUs, it ensures that tasks establish a stable relationship with specific CPUs when they are created and restored, reducing task migration and optimizing CPU resource utilization.
It improves the utilization efficiency of CPU cache, reduces the resource consumption of task scheduling, improves the efficiency of task scheduling, and avoids the scheduling overhead caused by frequent task migration.
Smart Images

Figure CN112667380B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer task management, and in particular to a multi-processor task scheduling method, device and storage medium. Background Art
[0002] Multiprocessor refers to a group of processors (CPUs) gathered on a computer, and each CPU shares a memory subsystem and bus structure. It is used in various mid-to-high-end application fields, such as consumer electronics, video security, smart hardware and other product platforms. These application scenarios are often more complex, and each CPU will be assigned a certain number of tasks, which will be scheduled and run by the operating system according to actual needs. The scheduling efficiency of the operating system is the key to affecting the overall performance of the system. Each CPU has a cache unit (Cache), and the speed of CPU accessing the cache is much higher than accessing the main memory. During the task scheduling process of the operating system, the CPU cache should be fully utilized as much as possible to maximize its efficiency.
[0003] In actual application scenarios, each task handles different things and requires different CPU resources. Accordingly, the CPU is busy at different levels when handling these tasks. For example, when a task with a complex algorithm is running, the CPU needs to perform intensive calculations in a short period of time and execute a large number of instructions, so it is very busy. In other tasks, the CPU only needs to handle simple things. After processing, if there are no other tasks, the CPU will enter an idle state to save system power consumption. The CPU's busyness can be expressed by the load rate, which ranges from 0 to 100%. The higher the value, the busier the CPU is during this period.
[0004] Usually when the system is running, the operating system will reallocate tasks in real time according to the load rate of each CPU, migrating tasks from CPUs with high load rates to CPUs with low load rates. This process is called load balancing.
[0005] Since the task scheduling behavior of the operating system itself consumes CPU resources, the ideal situation for task scheduling is to maintain load balancing between CPUs while consuming as little CPU resources as possible. If the same task is frequently switched between different CPUs, not only will the CPU cache not be fully utilized, but too much CPU time will be spent on the scheduling behavior itself instead of the actual execution of the task, resulting in low task scheduling efficiency. Summary of the invention
[0006] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a multi-processor task scheduling method, which can realize dynamic binding between tasks and CPUs and improve the efficiency of task scheduling.
[0007] The present invention also provides a multi-processor task scheduling device having the multi-processor task scheduling method.
[0008] The present invention also provides a computer-readable storage medium having the multi-processor task scheduling method.
[0009] According to the multi-processor task scheduling method of the first aspect of the embodiment of the present invention, the following steps are included: S100, receiving a task creation instruction, allocating a CPU to the task, determining that the task is a common task, and dynamically binding the task to the CPU; S200, receiving a task recovery instruction, obtaining the CPU to which the recovery task is dynamically bound, and sending an instruction to the CPU to implement task scheduling.
[0010] According to some embodiments of the present invention, the S100 also includes: S110, receiving a task creation instruction; S120, determining that the task is a common task, dynamically binding the task to a CPU, and the CPU defaults to the CPU that receives the task creation instruction; S130, adding the task to the task queue of the CPU.
[0011] According to some embodiments of the present invention, the method further includes: S140, determining that the task is a CPU-specific task, and adding the task to a task queue of the corresponding CPU.
[0012] According to some embodiments of the present invention, S200 also includes: S210, receiving a task recovery instruction, obtaining the CPU to which the task is dynamically bound, and adding the task to the bound CPU task queue; S220, determining that the dynamically bound CPU is the CPU that receives the task recovery instruction, then setting a scheduling mark and scheduling at the next scheduling time point.
[0013] According to some embodiments of the present invention, the method further includes: S230, if it is determined that the dynamically bound CPU is not the CPU that receives the task recovery instruction, an interrupt instruction is sent to the dynamically bound CPU to notify the dynamically bound CPU to perform scheduling.
[0014] According to some embodiments of the present invention, the method further includes: S300, receiving a task reallocation instruction, migrating tasks from a CPU queue whose load rate is greater than a first threshold to a CPU queue whose load rate is less than a second threshold, and updating the CPU dynamic binding relationship.
[0015] According to some embodiments of the present invention, the first threshold is greater than the second threshold.
[0016] According to some embodiments of the present invention, the dynamic binding relationship remains stable under certain conditions.
[0017] According to the second aspect of the present invention, the multi-processor task scheduling device includes: a task allocation module, which is used to receive a task creation instruction, allocate a CPU to the task, and realize a dynamic binding relationship between the task and the CPU; a task recovery processing module, which is used to receive a task recovery instruction, obtain the CPU dynamically bound to the recovery task, and send instructions to the CPU to realize task scheduling.
[0018] According to a third aspect of an embodiment of the present invention, a computer-readable storage medium stores a computer program, which, when executed by one or more processors, can perform the steps of any of the multi-processor task scheduling methods described above.
[0019] The multi-processor task scheduling method according to the embodiment of the present invention has at least the following beneficial effects: through the method of the present invention, when a task is created, it will be dynamically bound to the CPU, and the binding relationship will not change due to the task being suspended or resumed, which effectively maintains the stability of the corresponding relationship between the task and the CPU. The task runs on the same CPU most of the time, thereby improving the utilization efficiency of the CPU cache, avoiding the scheduling overhead caused by the frequent migration of tasks between different CPUs, and thus improving the task scheduling efficiency.
[0020] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0022] Figure 1 A schematic diagram of a method according to an embodiment of the present invention;
[0023] Figure 2 A schematic diagram of a process for creating a task according to an embodiment of the present invention;
[0024] Figure 3 A flowchart of a method for restoring a task according to an embodiment of the present invention;
[0025] Figure 4 A flowchart of a task reallocation method according to an embodiment of the present invention;
[0026] Figure 5 The present invention is a schematic block diagram of a device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0027] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0028] In the description of the present invention, "several" means one or more, "more" means two or more, "greater than", "less than", "exceed" etc. are understood as not including the number itself, and "above", "below", "within" etc. are understood as including the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0029] Reference Figure 1 , Figure 1 A method illustrating an embodiment of the present invention comprises:
[0030] S100, receiving a task creation instruction, allocating a CPU to the task, determining that the task is a common task, and dynamically binding the task to the CPU;
[0031] S200, receiving a task recovery instruction, obtaining a CPU dynamically bound to the recovery task, and sending an instruction to the CPU to implement task scheduling.
[0032] It is understandable that for a symmetric multiprocessor, each CPU corresponds to a task queue waiting to be scheduled. In order to maintain load balance, the operating system periodically migrates tasks from the CPU with the highest load rate to the CPU with the lowest load rate. Tasks in a multiprocessor are divided into two categories. One category is CPU-specific tasks, which are fixedly bound to a certain CPU and cannot be migrated to other CPUs, such as tasks responsible for processing the current CPU interrupt. The second category is ordinary tasks, which are not bound to a specific CPU and can be dynamically migrated to other CPUs. The vast majority of tasks in the system are second-category tasks, and the present invention is mainly aimed at second-category tasks.
[0033] For the scheduling of the second type of tasks, in the traditional method, when the task is created, it is not dynamically bound to a certain CPU. Therefore, during the operation of the system, the task is dynamically migrated back and forth between CPUs. When the task runs on the CPU, a large amount of CPU cache will be generated. The CPU relies on the cache to improve the operating efficiency. Since the caches of each CPU are independent of each other, when the task is migrated to another CPU, the cache content on the previous CPU can no longer be used. The task needs to regenerate the cache on the new CPU. This process consumes more resources and leads to low system efficiency. At the same time, since the task is not bound to the CPU, it will cause the same task to migrate back and forth between different CPUs, and too many resources will be consumed in the task scheduling behavior itself.
[0034] It should be noted that, for these existing problems, the present invention dynamically binds common tasks to CPUs, so that a relatively stable relationship is formed between common tasks and bound CPUs under certain conditions, so that the CPU cache can be fully utilized, saving system resources consumed in system scheduling, and on the other hand, in the process of system task recovery, by obtaining the CPU dynamically bound to the recovery task and sending instructions to the bound CPU, system resources can be further saved. Thus, the technical problems existing in the prior art are solved.
[0035] like Figure 2 , Figure 2 The following is a flowchart of a method for creating a task according to an embodiment of the present invention, including:
[0036] S110, receiving a task creation instruction;
[0037] S120, if the task is determined to be a common task, the task is dynamically bound to a CPU, and the CPU is by default the CPU that receives the task creation instruction;
[0038] S130: Add the task to the task queue of the CPU.
[0039] S140: If it is determined that the task is a CPU-specific task, the task is added to a task queue of the corresponding CPU.
[0040] Specifically, when creating a task, if it is a CPU-specific task, it is fixedly bound to a certain CPU and cannot be migrated to other CPUs, such as a task responsible for processing the current CPU interrupt, then the specific task is added to the task queue of the corresponding CPU; otherwise, the task is dynamically assigned to the CPU to be bound, which defaults to the current CPU, that is, the CPU that is executing the task creation process, and then the task is added to the task queue of the CPU to be bound. In this way, a dynamic binding relationship is established between the new task and the current CPU, and this binding relationship rarely changes during the subsequent running of the task, so that the CPU cache can be fully utilized.
[0041] Figure 3 FIG. 4 is a flow chart of a method for restoring a task according to an embodiment of the present invention, comprising:
[0042] S210, receiving a task recovery instruction, obtaining a CPU dynamically bound to the task, and adding the task to a bound CPU task queue;
[0043] S220: If it is determined that the dynamically bound CPU is the CPU that receives the task recovery instruction, a scheduling mark is set and scheduling is performed at the next scheduling time point.
[0044] S230: If it is determined that the dynamically bound CPU is not the CPU that receives the task resumption instruction, an interrupt instruction is sent to the dynamically bound CPU to notify the dynamically bound CPU to perform scheduling.
[0045] Specifically, during the process of task running, the running task may be suspended because of waiting for a certain resource. After the task is suspended, it does not occupy CPU resources and is not in the CPU's task queue, but will be added to the waiting queue of the resource. When the resource is in place, the task will be resumed.
[0046] During task recovery, first obtain the CPU dynamically bound to the task, and then add the task to the task queue of the bound CPU. If the bound CPU is the current CPU, set the scheduling flag and schedule it at the next scheduling time point; if the bound CPU is not the current CPU, send an interrupt to the bound CPU to notify it to schedule, so as to ensure that the task being restored can be scheduled in time. At the same time, the bound CPU of the task does not change during this process, so the content in the original cache can still be used.
[0047] See Figure 4 , Figure 4 FIG. 8 is a flow chart of a task reallocation method according to an embodiment of the present invention, comprising:
[0048] A task reallocation instruction is received, tasks are migrated from a CPU queue whose load rate is greater than a first threshold to a CPU queue whose load rate is less than a second threshold, and the CPU dynamic binding relationship is updated.
[0049] Specifically, the operating system will reallocate tasks in real time according to the load rate of each CPU, migrating tasks from the task queue of the CPU with a high load rate to the task queue of the CPU with a low load rate. As tasks are migrated to another CPU, the corresponding dynamic binding relationship also changes, and the tasks will be rebound to the new CPU. First, the task is removed from the task queue of the source CPU (i.e., the CPU with a high load rate), then the task is added to the task queue of the destination CPU (i.e., the CPU with a low load rate), and finally the binding relationship is modified to change the task's bound CPU to the destination CPU.
[0050] It should be noted that both the first threshold and the second threshold can be flexibly set according to the actual operating conditions of the system. The first threshold can indicate the degree of high load rate, and the second threshold can indicate the degree of low load rate. When the system performs load balancing, the system schedules tasks in the CPU with a high load rate to the CPU with a low load rate. It can be understood that the first threshold is greater than the second threshold.
[0051] In some specific embodiments of the present invention, the dynamic binding relationship remains stable under certain conditions, thereby ensuring that once the dynamic binding relationship between the task and the CPU is established, it will not change due to the task being suspended or resumed, effectively maintaining the stability of the corresponding relationship between the task and the CPU, ensuring that the task will not frequently switch between different CPUs at will, improving the utilization efficiency of the CPU cache, reducing the overhead of the scheduling behavior itself, and thus improving the task scheduling efficiency.
[0052] Figure 5 : is a schematic block diagram of a module of an apparatus according to an embodiment of the present invention, comprising:
[0053] The task allocation module is used to receive task creation instructions, allocate CPUs to tasks, and implement dynamic binding between tasks and CPUs;
[0054] The task recovery processing module is used to receive the task recovery instruction, obtain the CPU dynamically bound to the recovery task, and send instructions to the CPU to implement task scheduling.
[0055] In some embodiments of the present invention, there is a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by one or more processors, the steps of any of the above-mentioned multi-processor task scheduling methods can be performed.
[0056] It should be noted that in the traditional method, tasks are not dynamically bound to the CPU, so during system operation, tasks may be dynamically migrated between CPUs, resulting in low CPU cache utilization and excessive consumption of resources in the task scheduling behavior itself.
[0057] The method of the present invention dynamically binds the task to the CPU when it is created, and the binding relationship will not change due to the task being suspended or resumed, and will only change when the task is migrated to another CPU, thereby effectively maintaining the stability of the corresponding relationship between the task and the CPU. The task runs on the same CPU most of the time, thereby improving the utilization efficiency of the CPU cache, avoiding the scheduling overhead caused by the frequent migration of tasks between different CPUs, and thus improving the task scheduling efficiency.
[0058] Although specific embodiments are described herein, those of ordinary skill in the art will recognize that many other modifications or alternative embodiments are also within the scope of the present disclosure. For example, any of the functions and / or processing capabilities described in conjunction with a particular device or component may be performed by any other device or component. In addition, although various exemplary implementations and architectures have been described according to embodiments of the present disclosure, those of ordinary skill in the art will recognize that many other modifications to the exemplary implementations and architectures described herein are also within the scope of the present disclosure.
[0059] Some aspects of the present disclosure are described above with reference to the block diagram and flow chart of the system, method, system and / or computer program product according to the exemplary embodiments.It should be understood that the combination of one or more blocks in the block diagram and the flow chart and the blocks in the block diagram and the flow chart can be realized by executing computer executable program instructions respectively.Equally, according to some embodiments, some blocks in the block diagram and the flow chart may not need to be executed in the order shown, or may not need to be executed in full.In addition, additional components and / or operations beyond those components and / or operations shown in the blocks in the block diagram and the flow chart may be present in certain embodiments.
[0060] Therefore, the blocks in the block diagrams and flow charts support the combination of devices for performing the specified functions, the combination of elements or steps for performing the specified functions, and the program instruction devices for performing the specified functions. It should also be understood that each block in the block diagrams and flow charts and the combination of blocks in the block diagrams and flow charts can be implemented by a special-purpose hardware computer system or a combination of special-purpose hardware and computer instructions that performs a specific function, element or step.
[0061] The program modules, applications, etc. described herein may include one or more software components, including, for example, software objects, methods, data structures, etc. Each such software component may include computer-executable instructions that, in response to execution, cause at least a portion of the functionality described herein (e.g., one or more operations of the illustrative methods described herein) to be performed.
[0062] Software components can be encoded with any of various programming languages. An exemplary programming language can be a low-level programming language, such as an assembly language associated with a specific hardware architecture and / or an operating system platform. The software component comprising assembly language instructions may need to be converted to executable machine code by an assembler before being executed by hardware architecture and / or platform. Another exemplary programming language can be a higher-level programming language, which can be transplanted across multiple architectures. The software component comprising a higher-level programming language may need to be converted to an intermediate representation by an interpreter or a compiler before execution. Other examples of programming languages include but are not limited to macro languages, shells or command languages, job control languages, scripting languages, database queries or search languages or report writing languages. In one or more exemplary embodiments, the software component comprising the instruction of one of the above-mentioned programming language examples can be directly executed by an operating system or other software components, without first being converted into another form.
[0063] Software components may be stored as files or other data storage structures. Software components of similar type or related functions may be stored together, such as in a specific directory, folder, or library. Software components may be static (e.g., preset or fixed) or dynamic (e.g., created or modified at execution time).
[0064] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge scope of ordinary technicians in the relevant technical field without departing from the purpose of the present invention.
Claims
1. A multi-processor task scheduling method, It is characterized in that The following steps are involved: S100, receiving a task creation instruction, allocating a CPU to the task, determining that the task is a common task, and dynamically binding the task to the CPU; S200, receiving a task resumption instruction, obtaining a CPU dynamically bound to the resumption task, and sending an instruction to the CPU to implement task scheduling; after the task is suspended, it does not occupy CPU resources, nor is it in the task queue of the CPU, but will be added to the waiting queue of the resource. When the resource is in place, the task is resumed; The recovery task includes: S210, receiving a task recovery instruction, obtaining the CPU dynamically bound to the task, and adding the task to the bound CPU task queue; S220, determining that the dynamically bound CPU is the CPU that receives the task recovery instruction, setting a scheduling mark, and scheduling at the next scheduling time point; S230, determining that the dynamically bound CPU is not the CPU that receives the task recovery instruction, sending an interrupt instruction to the dynamically bound CPU to notify the dynamically bound CPU to schedule.
2. The multi-processor task scheduling method according to claim 1, It is characterized in that The S100 further includes: S110, receiving a task creation instruction; S120, if the task is determined to be a common task, the task is dynamically bound to a CPU, and the CPU is by default the CPU that receives the task creation instruction; S130: Add the task to the task queue of the CPU.
3. The multi-processor task scheduling method according to claim 2, It is characterized in that Also includes: S140: If it is determined that the task is a CPU-specific task, the task is added to a task queue of the corresponding CPU.
4. The multi-processor task scheduling method according to claim 1, It is characterized in that Also includes: S300 , receiving a task reallocation instruction, migrating tasks from a CPU queue whose load rate is greater than a first threshold to a CPU queue whose load rate is less than a second threshold, and updating a CPU dynamic binding relationship.
5. The multi-processor task scheduling method according to claim 4, It is characterized in that The first threshold is greater than the second threshold.
6. The multi-processor task scheduling method according to claim 1, It is characterized in that The dynamic binding relationship remains stable under certain conditions.
7. A multi-processor task scheduling device, It is characterized in that include: A task allocation module, used for receiving a task creation instruction, allocating a CPU to the task, and realizing a dynamic binding relationship between the task and the CPU; The task recovery processing module is used to receive the task recovery instruction, obtain the CPU dynamically bound to the recovery task, and send instructions to the CPU to implement task scheduling; after the task is suspended, it does not occupy CPU resources, nor is it in the task queue of the CPU, but will be added to the waiting queue of the resource. When the resource is in place, the task is resumed; The recovery task includes: S210, receiving a task recovery instruction, obtaining the CPU dynamically bound to the task, and adding the task to the bound CPU task queue; S220, determining that the dynamically bound CPU is the CPU that receives the task recovery instruction, setting a scheduling mark, and scheduling at the next scheduling time point; S230, determining that the dynamically bound CPU is not the CPU that receives the task recovery instruction, sending an interrupt instruction to the dynamically bound CPU to notify the dynamically bound CPU to schedule.
8. A computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the method according to any one of claims 1 to 6 when executed by a processor.
