Task scheduling method and device of processor and storage medium
By introducing a centralized queue mechanism into the Linux operating system, the highest priority task is selected and added to the target processor's execution queue, thus solving the problem of high performance overhead in task scheduling and achieving efficient and low-overhead task scheduling.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-30
- Publication Date
- 2026-03-27
AI Technical Summary
In the Linux operating system, the task scheduling performance overhead of the processor in the current technology is high and lacks a global view, resulting in poor scheduling decision efficiency.
A centralized queue mechanism is adopted. By acquiring and storing the tasks to be assigned and their priorities, when the target processor's run queue is empty, the highest priority task is selected from the centralized queue and added to the run queue. The queue is updated using atomic operations and memory mapping mechanisms to achieve customized task scheduling.
It reduces the intrusiveness of task scheduling on existing kernel processes, improves the efficiency and global visibility of task scheduling, reduces performance overhead, and is compatible with the original framework of the kernel scheduler.
Smart Images

Figure CN121029372B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of computer operating systems, in particular to a processor task scheduling method and device and storage medium. BACKGROUND
[0002] In the Linux operating system, the kernel scheduler framework usually adopts a per-cpu (a task scheduling mechanism) scheme to schedule tasks, specifically, each processor manages the local scheduling queue by itself, and then achieves cross-processor task adjustment through load balancing and other means. The advantage of this scheme is that the scheduling decision overhead is small, and the disadvantage is that it lacks a global perspective, and the needs of some processes cannot be well met, therefore, it is necessary to improve the global perspective of task scheduling.
[0003] In related technologies, some technical solutions are based on the scheduler framework and ebpf (entended Berkeley Packet Filter) capabilities to allow users to customize various scheduling strategies in user mode or kernel mode. This scheme relies on new kernel features and cannot be applied to existing production environments. Another technical solution is to pre-embed an interface in the kernel to receive scheduling decisions passed from the user mode. In the above technical solutions, scheduling strategies need to be received from the user mode, so the decision efficiency is not as simple as in the pure kernel mode, and additional performance overhead is brought in the process of scheduling tasks.
[0004] At present, no effective solution has been proposed to solve the problem of high performance overhead of the processor task scheduling. SUMMARY
[0005] The embodiments of the present application provide a processor task scheduling method, device and storage medium to at least solve the technical problem of high performance overhead of processor task scheduling.
[0006] In order to achieve the above purpose, according to one aspect of the present application, a processor task scheduling method is provided, which includes: acquiring a centralized queue, wherein the centralized queue is used to store a plurality of to-be-allocated tasks and priorities corresponding to the to-be-allocated tasks; when the running queue of a target processor is empty, selecting a to-be-allocated task stored in the centralized queue to obtain a first task, and pre-booking the first task for the target processor to add the first task to the running queue of the target processor; determining a target task to be executed by the target processor according to the first task, and controlling the target processor to execute the target task.
[0007] Further, the selecting the to-be-allocated task stored in the centralized queue to obtain the first task comprises: when there is at least one to-be-allocated task in the centralized queue, determining a head task in the centralized queue, wherein the head task is a to-be-allocated task with the highest priority in the centralized queue; if the predecessor task meets the first preset condition, determining the predecessor task as the first task, wherein the predecessor task is a task scheduled by a previous trigger process of the target processor, and the first preset condition comprises that the predecessor task belongs to the centralized queue, the predecessor task is in a ready state, and the priority of the predecessor task is higher than the priority of the head task; if the predecessor task does not meet the first preset condition, determining the head task as the first task.
[0008] Further, the selecting the to-be-allocated task stored in the centralized queue to obtain the first task comprises: in a case where the number of to-be-allocated tasks in the centralized queue is zero and the predecessor task meets the second preset condition, determining the predecessor task as the first task, wherein the predecessor task is a task scheduled by a previous trigger process of the target processor, and the second preset condition comprises that the predecessor task belongs to the centralized queue and the predecessor task is in a ready state.
[0009] Further, the reserving the first task for the target processor to add the first task to a running queue of the target processor comprises: if the first task is in the running queue of the target processor, configuring that the target processor has been reserved by the first task; if the first task is not in the running queue of the target processor, releasing a spin lock of the target processor, and acquiring a spin lock of a running queue to which the first task belongs; dequeuing the first task from the running queue to which the first task belongs, and releasing the spin lock of the running queue to which the first task belongs; acquiring the spin lock of the target processor, and adding the first task to the running queue of the target processor, and configuring that the target processor has been reserved by the first task.
[0010] Further, before the acquiring the centralized queue, the method further comprises: creating a plurality of different centralized queues, wherein a physical machine in which the target processor is located comprises a plurality of processors, and each centralized queue corresponds to at least one processor.
[0011] Further, before the acquiring the centralized queue, the method further comprises: receiving system call information written by a user-mode program through memory mapping; determining a new task and a priority corresponding to the new task according to the system call information; and adding the new task to the centralized queue by using the new task and the priority corresponding to the new task, so as to update the centralized queue.
[0012] Further, the adding the new task and the priority corresponding to the new task into the centralized queue to update the centralized queue comprises: determining a to-be-updated position of the new task in the centralized queue according to the priority corresponding to the new task; and updating the centralized queue by using the linked list of the atomic operation to add the new task into the to-be-updated position in the centralized queue.
[0013] Further, after obtaining the centralized queue, the method further comprises: when the running queue of the target processor is not empty, scheduling a task in the running queue by using a kernel scheduler of the physical machine where the target processor is located to determine a second task; if the second task is not a task in the centralized queue, determining the second task as a target task to be executed by the target processor, and controlling the processor to execute the target task; and if the second task is a task in the centralized queue, detecting whether the second task is a predetermined task of a second processor, and if yes, dequeuing the second task from the running queue, wherein the second processor is a processor other than the target processor in the physical machine.
[0014] To achieve the above object, according to another aspect of the present application, a task scheduling apparatus of a processor is provided, which comprises: a queue obtaining unit configured to obtain a centralized queue, wherein the centralized queue is configured to store a plurality of to-be-allocated tasks and priorities corresponding to the to-be-allocated tasks; a task selecting unit configured to select a to-be-allocated task in the centralized queue when a running queue of a target processor is empty, to obtain a first task, and to predefine the first task for the target processor to add the first task into the running queue of the target processor; and a task determining unit configured to determine a target task to be executed by the target processor according to the first task, and to control the target processor to execute the target task.
[0015] According to another aspect of the present application, a computer readable storage medium is provided, which comprises a stored program, wherein the program, when executed, controls a device where the computer readable storage medium is located to perform any of the task scheduling methods of the processor.
[0016] According to another aspect of the present application, an electronic device is provided, which comprises one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs comprise instructions for performing any of the task scheduling methods of the processor.
[0017] According to another aspect of the present application, a computer program product is provided, which comprises computer instructions, and the computer instructions, when executed by a processor, implement the steps of any of the task scheduling methods of the processor.
[0018] In the embodiment of the present application, the centralized queue is obtained, wherein the centralized queue is used for storing a plurality of to-be-allocated tasks and priorities corresponding to the to-be-allocated tasks; when the running queue of the target processor is empty, the to-be-allocated tasks stored in the centralized queue are selected to obtain a first task, and the first task is scheduled for the target processor to add the first task to the running queue of the target processor; the target task to be executed by the target processor is determined according to the first task, so that the target processor is controlled to execute the target task, thereby solving the technical problem of high performance overhead of task scheduling of the related art processor.
[0019] By selecting and scheduling the first task for the target processor according to the centralized queue, the target task of the target processor is determined, the task scheduling method only needs to receive the to-be-allocated tasks and the corresponding priorities from the user mode (that is, only needs to receive the tasks and the numbers representing the priorities), and therefore does not need to receive the scheduling strategy from the user mode; meanwhile, the centralized queue only needs to interact with the kernel scheduler main body when dequeuing / entering, and does not need to break the original scheduling framework of the kernel scheduler, and therefore the invasiveness of the task scheduling to the existing process of the kernel is reduced. Therefore, in the present solution, the program execution of the scheduling strategy is in the pure kernel mode, the customized centralized queue strategy is implemented in the Linux kernel, the defect that the original scheduling process of the kernel has a weak global view is compensated, and the performance overhead of the task scheduling is reduced. BRIEF DESCRIPTION OF DRAWINGS
[0020] The accompanying drawings, which are included to provide a further understanding of the present application and are incorporated in and constitute a part of this application, illustrate embodiments of the present application and serve to explain the present application. In the drawings:
[0021] Figure 1 Fig. 1 shows a hardware structure block diagram of a computer terminal for implementing a task scheduling method of a processor;
[0022] Figure 2 Fig. 2 is a flowchart of a task scheduling method of a processor according to an embodiment of the present application;
[0023] Figure 3 Fig. 3 is a flowchart of scheduling a task for a target processor in a task scheduling method of a processor according to an embodiment of the present application;
[0024] Figure 4 Fig. 4 is a flowchart of selecting a task for a target processor from a centralized queue in a task scheduling method of a processor according to an embodiment of the present application;
[0025] Figure 5 Fig. 5 is a flowchart of scheduling a task for a target processor in a task scheduling method of a processor according to an embodiment of the present application;
[0026] Figure 6 is a schematic diagram of a task scheduling device of a processor according to an embodiment of the present application;
[0027] Figure 7 is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the personnel in the art better understand the present application scheme, the technical scheme in the embodiments of the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by the person skilled in the art without creative labor should belong to the scope of protection of the present application.
[0029] It should be noted that the terms "first", "second" and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0030] It should be noted that the relevant information and data involved in the present application (including but not limited to data for training, analyzed data, etc.) are all information and data authorized by the user or authorized by all parties. For example, an interface is provided between the system and the relevant user or institution. Before obtaining the relevant information, the interface needs to send a request to the aforementioned user or institution, and after receiving the consent information feedback from the aforementioned user or institution, the relevant information is obtained.
[0031] Run queue: refers to a data structure maintained for each processor in the scheduling mechanism of the Linux kernel, which is used to manage all ready processes or threads on the corresponding processor. The run queue is the core component of the per-cpu model, which ensures the locality and low latency of scheduling decisions, and also supports load balancing and fair scheduling of multi-processors.
[0032] Embodiment 1
[0033] According to the embodiments of the present application, a task scheduling method for a processor is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0034] The method embodiments provided by the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or similar computing device. Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing the task scheduling method for a processor is shown. As shown in the figure, Figure 1 The computer terminal 10 (or mobile device 10) can include one or more processors 102 (the processor 102 can include but not limited to a microprocessor MCU or a programmable logic device FPGA processing device), a memory 104 for storing data, and a transmission module 106 for communication functions. In addition, it can also include a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which can be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. Those skilled in the art can understand that, Figure 1 The structure shown is only schematic, which does not limit the structure of the above-mentioned electronic device. For example, the computer terminal 10 can include more or less components than those shown in Figure 1 or have a different configuration than that shown in Figure 1 .
[0035] It should be noted that the one or more processors 102 and / or other data processing circuits described above can be referred to herein as "data processing circuits" in general. The data processing circuit can be embodied in whole or in part as software, hardware, firmware or any other combination. In addition, the data processing circuit can be a single independent processing module, or any one of the other elements combined into the computer terminal 10 (or mobile device) in whole or in part. As referred to in the embodiments of the present application, the data processing circuit as a kind of processor control (for example, the selection of the variable resistance terminal path connected with the interface).
[0036] The memory 104 can be used to store software programs of application software and modules, such as program instructions / data storage means corresponding to the task scheduling method of the processor in the embodiments of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, i.e. implements the task scheduling method of the processor as described above. The memory 104 can include a high-speed random access memory, and can further include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 104 can further include memories remotely arranged with respect to the processor 102, which can be connected to the computer terminal 10 through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0037] The transmission device 106 is used to receive or send data via a network. The specific examples of the network can include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network interface controller (NIC) which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module which is used to communicate with the Internet in a wireless manner.
[0038] The display can be, for example, a touch screen type liquid crystal display (LCD) which can enable a user to interact with the user interface of the computer terminal 10 (or a mobile device).
[0039] In the above operating environment, the present application provides a task scheduling method of a processor as shown in Figure 2 Figure 2 is a flowchart of the task scheduling method of the processor according to Embodiment One of the present application.
[0040] In step S201, a centralized queue is obtained, wherein the centralized queue is used to store a plurality of to-be-assigned tasks and priorities corresponding to the to-be-assigned tasks.
[0041] Optionally, the centralized queue can be based on a lock-free priority queue or a queue model supporting enqueuing / dequeuing, and the centralized queue is used to make the task scheduling aware of the global view. For example, a mapping relationship between the IDs of the to-be-assigned tasks and the priorities can be stored based on a data structure library. The priority of the to-be-assigned task can be in the form of a numerical value. The to-be-assigned tasks in the centralized queue and the corresponding priorities can be received from the user mode, that is, the user mode only needs to provide the to-be-assigned tasks and the corresponding numbers (numerical priorities). The plurality of to-be-assigned tasks can be arranged according to the size of the priority, and the priority is used to represent the execution order of the to-be-assigned tasks.
[0042] For example, the priority of the to-be-assigned task 1 (that is, the ID is 1) is 4, the priority of the to-be-assigned task 2 is 7, the priority of the to-be-assigned task 3 is 10, the priority of the to-be-assigned task 4 is 2, and the priority of the to-be-assigned task 5 is 5. In the centralized queue, the smaller the numerical value of the priority is, the higher the priority of the corresponding to-be-assigned task is. The arrangement order of the above-mentioned to-be-assigned tasks in the centralized queue is to-be-assigned task 4, to-be-assigned task 1, to-be-assigned task 5, to-be-assigned task 2, and to-be-assigned task 3. At this time, the to-be-assigned task 4 is the to-be-assigned task with the highest priority, that is, the head task of the centralized queue.
[0043] Step S202, when the running queue of the target processor is empty, selecting the to-be-assigned tasks stored in the centralized queue to obtain a first task, and reserving the first task for the target processor to add the first task to the running queue of the target processor.
[0044] Optionally, when the running queue of the target processor is empty, the task needs to be scheduled for the target processor, and the centralized queue can be selected to select the to-be-assigned task as the first task, and the first task is used to represent the task to be processed by the target processor. The first task can be the head task in the centralized queue, that is, the to-be-assigned task with the highest priority in the centralized queue. Reserving the first task for the target processor can be to add an attribute to the target structure variable. It should be noted that the processor in the embodiment can be a central processor.
[0045] For example, reserving the first task B for the target processor 3 can be to set the reserved_task field of the target processor 3 in the target structure variable struct rq to the first task B, indicating that the first task B is reserved by the target processor 3.
[0046] Optionally, Figure 3 is a flowchart of scheduling a task for a target processor in a task scheduling method of a processor provided by an embodiment of the present application, as shown in Figure 3As shown, before selecting the to-be-allocated task stored in the centralized queue, it can also be detected whether the target processor has a pre-booked task from the centralized queue, and if so, the pre-booked task is taken as the target task, and the target processor is controlled to execute the target task; if not, it can be detected whether the running queue of the target processor is empty, and if so, the first task can be selected for the target processor according to the above step S202.
[0047] In step S203, the target task to be executed by the target processor is determined according to the first task, and the target processor is controlled to execute the target task.
[0048] For example, when the running queue of the target processor is empty, the first task is pre-booked for the target processor through the above step S202, and the first task is added to the running queue of the target processor. At this time, it can be detected that the target processor has a pre-booked task from the centralized queue, i.e., the first task, and the target processor can be controlled to execute the first task (i.e., the target task).
[0049] Optionally, during the process of controlling the target processor to execute the target task, if a new task is woken up to the target processor, the current target task of the target processor can be obtained, and if the new task and the target task both belong to the centralized queue, the priority of the new task is compared with the priority of the target task. If the priority of the new task is higher than the priority of the target task, the target processor is controlled to execute the new task, and if the priority of the new task is lower than the priority of the target task, the target processor is controlled to execute the target task, so as to realize task preemption of different priorities according to the priority of the centralized queue.
[0050] Optionally, in the physical machine where the target processor is located, in the clock interrupt of a preset time period (for example, every 1 millisecond), it can be detected whether the target processor needs to re-adjust the task scheduling. The detection of whether the target processor needs to re-adjust the task scheduling includes: detecting whether the task being executed by the target processor belongs to the centralized queue, and if not, continuing to run according to the native scheduling process of the kernel scheduler; and if so, comparing the priority of the head task in the centralized queue with the priority of the task being executed, and if the priority of the head task is higher than the priority of the task being executed, triggering the preemption logic based on the centralized queue to schedule the head task as the target task to be executed by the target processor, so that the head task with a higher priority obtains the resource of the target processor, and if the priority of the head task is lower than the priority of the task being executed, the preemption logic does not need to be triggered.
[0051] In summary, by selecting and scheduling the first task as the target processor according to the centralized queue, the target task of the target processor is determined, and the task scheduling method only needs to receive the to-be-allocated task and the corresponding priority from the user mode (i.e., only needs to receive the task and the number representing the priority), and thus does not need to receive the scheduling strategy from the user mode. Meanwhile, the centralized queue only needs to interact with the kernel scheduler main body when dequeuing / entering, and does not need to break the original scheduling framework of the kernel scheduler, and thus the invasiveness of the task scheduling to the existing kernel process is reduced. Therefore, the program execution of the scheduling strategy in the present solution is in the pure kernel mode, and the customized centralized queue strategy is implemented in the Linux kernel, which not only makes up for the defect that the original scheduling process of the kernel has a weak global view, but also reduces the performance overhead of the task scheduling.
[0052] To reduce the performance overhead of the task scheduling, the to-be-allocated task stored in the centralized queue is optionally selected to obtain the first task, including: when there is at least one to-be-allocated task in the centralized queue, determining the head task in the centralized queue, wherein the head task is the to-be-allocated task with the highest priority in the centralized queue; if the predecessor task meets the first preset condition, the predecessor task is determined as the first task, wherein the predecessor task is a task scheduled by a previous trigger process of the target processor, and the first preset condition includes that the predecessor task belongs to the centralized queue, the predecessor task is in a ready state, and the priority of the predecessor task is higher than the priority of the head task; if the predecessor task does not meet the first preset condition, the head task is determined as the first task.
[0053] Optionally, Figure 4 is a flowchart of selecting a task for a target processor from a centralized queue in a task scheduling method of a processor according to an embodiment of the present application, as shown in Figure 4As shown, when the number of tasks to be allocated in the centralized queue is not zero, the highest priority task in the centralized queue, i.e., the head task, is taken out. The predecessor task refers to a task that has not been executed by the target processor before, and because the task triggers process scheduling, the task is managed by the kernel scheduler to make it give up the resources of the target processor to other tasks. In the present embodiment, the first task is determined by judging the first preset condition among the predecessor task and the head task. When the predecessor task meets all three judgments of the first preset condition, i.e., the predecessor task comes from the centralized queue, the predecessor task is in the ready state, and the priority of the predecessor task (for the centralized queue) is higher than that of the head task, the predecessor task is determined as the first task, i.e., the task to be run by the target processor, and the head task is not the first task, so the head task is added back to the centralized queue. If the predecessor task does not meet any of the judgments of the first preset condition, the head task is determined as the first task. It should be noted that the predecessor task can come from the centralized queue or a normal task allocated by the kernel scheduler, and the normal task follows the original scheduling process of the kernel in Linux, and the execution priority of the normal task is not managed by the centralized queue.
[0054] For example, the process of a task C can be in a ready state or a sleep state, the ready state indicating that the task needs to run on the target processor, and the sleep state indicating that the task does not need the target processor temporarily. When the target task C triggers process scheduling, the task is cut out from the previous thread by the kernel scheduler and then cut into the next thread. Before triggering process scheduling, if the thread of the task C is in the sleep state, it means that the thread actively gives up the target processor, and the moment when the thread actively gives up the target processor triggers scheduling to give the resources of the target processor to the next thread. If the thread of the task C is in the ready state, the reason for triggering process scheduling can be that the thread passively gives up the resources of the target processor, i.e., the kernel scheduler considers that the thread has occupied a large time slice on the target processor, so the task is kicked out to give the resources of the target processor to the next thread. The task C is the latest task that triggers process scheduling before the target processor determines the first task, i.e., the task C is the predecessor task.
[0055] In summary, when there is at least one task to be allocated in the centralized queue, the head task of the centralized queue is obtained, and the head task and the predecessor task are judged by the first condition, which not only can avoid unnecessary task switching, but also can ensure that the task with higher priority can be processed in time, realizes the compatibility and cooperation of the centralized queue and the kernel scheduler triggering process scheduling, improves the stability of task scheduling, and reduces the performance overhead.
[0056] To reduce the performance overhead of task scheduling, optionally, the selecting of the to-be-allocated task stored in the centralized queue to obtain the first task includes: in a case where the number of to-be-allocated tasks in the centralized queue is zero and the predecessor task meets a second preset condition, the predecessor task is determined as the first task, wherein the predecessor task is a task triggered by a previous process of the target processor, and the second preset condition includes that the predecessor task belongs to the centralized queue and the predecessor task is in a ready state.
[0057] Optionally, as shown in Figure 4 the two determinations of the second preset condition are performed on the predecessor task when there is no to-be-allocated task in the centralized queue, and the predecessor task is described in detail above. It should be noted that, when and only when the predecessor task meets the two determinations of belonging to the centralized queue and being in a ready state, the predecessor task is determined as the task to be run by the target processor; when the predecessor task does not meet any determination in the second preset condition, it means that there is another processor in the physical machine where the target processor is located to take away the predecessor task, at this time, it is necessary to re-detect whether there is a pre-ordered task from the centralized queue for the target processor, and if there is, the pre-ordered task is taken as the target task, and the target processor is controlled to execute the target task; if there is not, it is necessary to detect whether the run queue of the target processor is empty, and if it is, it is necessary to re-select the to-be-allocated task stored in the centralized queue according to the above step S202.
[0058] In summary, when the number of to-be-allocated tasks in the centralized queue is zero, the state of the predecessor task is determined by the second preset condition, and if the predecessor task meets the second preset condition, the process of selecting the task from the centralized queue can be skipped, and the predecessor task is directly taken as the task to be processed (i.e., the first task), which significantly reduces the scheduling delay, and makes the centralized queue better compatible with the process scheduling of the kernel scheduler, and reduces the performance overhead of task scheduling.
[0059] To reduce the performance overhead of task scheduling, optionally, the pre-ordering of the first task for the target processor to add the first task to the run queue of the target processor includes: if the first task is in the run queue of the target processor, the target processor is configured to be pre-ordered by the first task; if the first task is not in the run queue of the target processor, the spin lock of the target processor is released, and the spin lock of the run queue to which the first task belongs is acquired; the first task is dequeued from the run queue to which the first task belongs, and the spin lock of the run queue to which the first task belongs is released; the spin lock of the target processor is acquired, the first task is added to the run queue of the target processor, and the target processor is configured to be pre-ordered by the first task.
[0060] Optionally, Figure 5is a flowchart of a process for reserving a task for a target processor in a task scheduling method of a processor according to an embodiment of the present application, as shown in Figure 5 If the first task is in the run queue of the target processor, the target processor is configured to be reserved by the first task. The target processor being configured to be reserved by the first task can be that an attribute is added to the target structure variable (for example, the field in the target structure variable can be set according to the foregoing content). If the first task is not in the run queue of the target processor, the first task is first marked as a reserved task, then the spin lock of the target processor is released and the spin lock of the run queue to which the first task belongs (i.e., the run queue of another processor) is acquired, and then it is detected again whether the mark of the reserved task of the first task (i.e., the field in the target structure variable) exists. If the reserved mark still exists, the first task is dequeued from the run queue to which the first task belongs and the reserved mark of the first task is cancelled, and a preset reservation operation is performed. If the reserved mark does not exist, the preset reservation operation can be directly performed. The preset reservation operation can be that the spin lock of the run queue to which the first task belongs is released, the spin lock of the run queue of the target processor is acquired, the first task is added to the run queue of the target processor, so that the first task can be selected in the scheduling process of the kernel dispatcher, and the target processor is configured to be reserved by the first task (for example, the field in the target structure variable can be set according to the foregoing content).
[0061] For example, it is assumed that the physical machine where the target processor is located has 9 ready state tasks (the following content uses letters A-I to represent the 9 ready state tasks) at a certain moment, and the distribution of these ready state tasks is as follows: the run queue of processor 0-A, B, C; the run queue of processor 1-D, E, F; the run queue of processor 2-G, H, I; and the run queue of processor 3-empty (i.e., the run queue is empty). Among them, A, D, and G are ordinary tasks (i.e., they follow the native scheduling strategy of the kernel scheduler), and B, C, E, F, H, and I are tasks from the centralized queue (i.e., these tasks are managed by the centralized queue, but do not affect their positions in the run queue in the native scheduling strategy of the kernel scheduler). It is assumed that processor 3 is the target processor, and when its run queue (as shown in Figure 3 meets the condition that the run queue is empty in Figure 3 , the task selection will be performed according to the process shown in Figure 4 , and the highest priority task B is finally selected. However, B is currently in the run queue of processor 0 (i.e., the run queue to which the first task belongs), and B can be moved from the run queue of processor 0 to the run queue of the target processor according to the foregoing process.
[0062] In summary, by checking the predetermined state of the first task and releasing and acquiring the spin lock of different processors, the first task is scheduled for the target processor to add the first task to the running queue of the target processor, unnecessary lock competition is avoided, the replacement of task scheduling under the native scheduling strategy of the centralized queue and the kernel scheduler is compatible, and the overhead of task scheduling is reduced.
[0063] To reduce the flexibility of task scheduling, before obtaining the centralized queue, the method further includes: creating a plurality of different centralized queues, wherein the physical machine where the target processor is located includes a plurality of processors, and each centralized queue corresponds to at least one processor.
[0064] Optionally, resource isolation can be achieved by partitioning containers. For example, assuming that the physical machine where the target processor is located has 16 processors numbered 0-15 (including the target processor), all tasks for service A can use processors numbered 0-7, and all tasks for service B can use processors numbered 8-15. At the same time, centralized queue 1 is constructed for tasks for service A, and centralized queue 2 is constructed for tasks for service B, that is, centralized queue 1 corresponds to processors numbered 0-7, and centralized queue 2 corresponds to processors numbered 8-15.
[0065] In summary, by creating a plurality of centralized queues and corresponding the centralized queues to specific processors, fine-grained task management is achieved, effective resource isolation can be provided in a multi-service coexistence scenario, the quality of service for the tasks of each service is ensured, the tasks of different services can be flexibly managed, and the flexibility of task scheduling is improved.
[0066] To reduce the performance overhead of task scheduling, before obtaining the centralized queue, the method further includes: receiving system call information written by a user-mode program through memory mapping; determining a new task and a priority corresponding to the new task according to the system call information; and adding the new task to the centralized queue using the new task and the priority corresponding to the new task to update the centralized queue.
[0067] Optionally, in this embodiment, the user-mode program applies for memory of the kernel of the physical machine where the target processor is located through memory mapping, and the kernel determines the new task and the priority of the new task according to the received system call information. The task mapped by the memory belongs to the management of the centralized queue, but the task still exists in the Linux kernel scheduler framework in terms of data. The task scheduling method of this embodiment does not break the original framework. Other threads that are not mapped by the memory completely follow the framework of the Linux kernel scheduler from data to scheduling strategy.
[0068] For example, the user mode program performs a memory mapping system call on the pidfd (process ID file descriptor, a type of file descriptor introduced in the Linux system) of the specified thread to allocate a page of memory space, and writes a value representing the priority in the memory, with a smaller value indicating a higher priority. The ID of the new task is 7, and its priority is 1. Assuming that the original tasks in the centralized queue are: the priority of task 4 to be allocated is 2, the priority of task 1 to be allocated is 4, the priority of task 5 to be allocated is 5, the priority of task 2 to be allocated is 7, and the priority of task 3 to be allocated is 10. After updating the centralized queue, the updated centralized queue is: the priority of task 7 to be allocated is 1, the priority of task 4 to be allocated is 2, the priority of task 1 to be allocated is 4, the priority of task 5 to be allocated is 5, the priority of task 2 to be allocated is 7, and the priority of task 3 to be allocated is 10.
[0069] In summary, by using the memory mapping-based task and priority data interaction mechanism, the centralized queue is updated, so that the kernel can quickly obtain the priority information of the task, thereby achieving more accurate and low-latency task scheduling and reducing the performance overhead of task scheduling.
[0070] To reduce the performance overhead of task scheduling, the new task and the priority corresponding to the new task are optionally added to the centralized queue to update the centralized queue, including: determining the updated position of the new task in the centralized queue according to the priority corresponding to the new task; and updating the centralized queue by using an atomic operation linked list to add the new task to the updated position in the centralized queue.
[0071] Optionally, the centralized queue can be a lock-free priority queue, which is implemented by an atomic operation linked list without locking, further reducing the performance overhead.
[0072] For example, the priority can be determined in the form of a u64-bit length index, with a smaller index value indicating a higher priority. When the new task is ready to be queued in the centralized queue, the index values of the new task and all existing tasks in the centralized queue are first sorted to determine the serial number of the new task in the updated centralized queue, and the position corresponding to the serial number is taken as the updated position. The centralized queue can be updated by using an atomic operation linked list to obtain the updated centralized queue.
[0073] In summary, by configuring the centralized queue as a lock-free priority queue, directly updating the node pointer in the linked list, and inserting the node of the new task into the calculated position to be updated, this updating method avoids the performance bottleneck caused by the traditional lock mechanism, reduces the waiting time and the number of context switches in the task scheduling process, thereby improving the overall efficiency of task scheduling and reducing the performance overhead of task scheduling.
[0074] To reduce the performance overhead of task scheduling, optionally, after obtaining the centralized queue, the method further includes: when the run queue of the target processor is not empty, scheduling the tasks in the run queue by the kernel scheduler of the physical machine where the target processor is located to determine a second task; if the second task is not a task in the centralized queue, determining the second task as a target task to be executed by the target processor, and controlling the processor to execute the target task; if the second task is a task in the centralized queue, detecting whether the second task is a predetermined task of a second processor, and if so, dequeuing the second task from the run queue, wherein the second processor is another processor in the physical machine other than the target processor.
[0075] Optionally, as shown in Figure 3 under the premise that the target processor does not have a predetermined task from the centralized queue (i.e., the tasks stored in the centralized queue are not selected and predetermined), when there is at least one task in the run queue of the target processor (i.e., the run queue is not empty), the tasks in the run queue are scheduled according to the original framework of the kernel scheduler (for example, the kernel strategy can select the tasks according to fairness) to select a second task to be executed by the target processor. Detect whether the second task belongs to the tasks of the centralized queue, i.e., detect whether the second task is managed by the centralized queue; if the second task is not a task in the centralized queue (i.e., the second task is not managed by the centralized queue), it means that the second task follows the scheduling strategy of the kernel scheduler, and the second task is determined as the target task to be executed by the target processor; if the second task is a task in the centralized queue (i.e., the second task is managed by the centralized queue), it is detected whether the second task has been predetermined by another processor (e.g., the second processor), if the second task is predetermined by the second processor, the second task is dequeued from the run queue of the target processor to avoid the execution of the second task on the target processor; if the second task is not predetermined by the second processor, the tasks stored in the centralized queue are selected again to determine the first task of the target processor.
[0076] In summary, when the run queue of the target processor is not empty, by utilizing the effective cooperation between the centralized queue and the kernel scheduler, not only the global scheduling demand is satisfied, but also the scheduling efficiency of ordinary tasks is not affected, and the performance overhead of task scheduling is reduced.
[0077] It should be noted that, for the foregoing method embodiments, in order to simply describe, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited by the action sequence described, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily necessary for the present application.
[0078] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, and of course it can also be realized by hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solutions of the present application or the part that contributes to the related art can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a plurality of instructions to make a terminal device (which can be a mobile phone, computer, server, or network device, etc.) execute the method described in each embodiment of the present application.
[0079] Embodiment 2
[0080] According to the embodiments of the present application, a task scheduling device of a processor for implementing the task scheduling method of the processor is also provided, as shown in Figure 6 The device comprises a queue obtaining unit 601, a task selecting unit 602 and a task determining unit 603.
[0081] Specifically, the queue obtaining unit 601 is configured to obtain a centralized queue, wherein the centralized queue is configured to store a plurality of to-be-allocated tasks and priorities corresponding to the to-be-allocated tasks.
[0082] The task selecting unit 602 is configured to select a to-be-allocated task from the centralized queue when the running queue of the target processor is empty, to obtain a first task, and to reserve the first task for the target processor, so as to add the first task to the running queue of the target processor.
[0083] The task determining unit 603 is configured to determine a target task to be executed by the target processor according to the first task, so as to control the target processor to execute the target task.
[0084] The task scheduling apparatus of the processor provided in the embodiment of the present application obtains a centralized queue through the queue obtaining unit 601, wherein the centralized queue is used to store a plurality of to-be-allocated tasks and priorities corresponding to the to-be-allocated tasks; when the running queue of the target processor is empty, the task selecting unit 602 selects the to-be-allocated task stored in the centralized queue to obtain a first task, and reserves the first task for the target processor to add the first task to the running queue of the target processor; the task determining unit 603 determines a target task to be executed by the target processor according to the first task to control the target processor to execute the target task, thereby solving the problem of high performance overhead of the task scheduling of the processor in the related art and achieving the technical effect of improving the task scheduling accuracy of the processor.
[0085] Optionally, in the task scheduling apparatus of the processor provided in the embodiment of the present application, the task selecting unit 602 comprises: a first taking-out module, configured to determine a head task in the centralized queue when there is at least one to-be-allocated task in the centralized queue, wherein the head task is the to-be-allocated task with the highest priority in the centralized queue; a first predecessor determining module, configured to determine a predecessor task as the first task if the predecessor task meets a first preset condition, wherein the predecessor task is a task triggered by a previous process of the target processor, and the first preset condition comprises that the predecessor task belongs to the centralized queue, the predecessor task is in a ready state, and the priority of the predecessor task is higher than the priority of the head task; and a first head determining module, configured to determine the head task as the first task if the predecessor task does not meet the first preset condition.
[0086] Optionally, in the task scheduling apparatus of the processor provided in the embodiment of the present application, the task selecting unit 602 comprises: a second predecessor determining module, configured to determine the predecessor task as the first task in a case that the number of to-be-allocated tasks in the centralized queue is zero and the predecessor task meets a second preset condition, wherein the predecessor task is a task triggered by a previous process of the target processor, and the second preset condition comprises that the predecessor task belongs to the centralized queue and the predecessor task is in a ready state.
[0087] Optionally, in the processor task scheduling apparatus provided by the embodiment of the present application, the task selection unit 602 comprises: a first queue determination module, configured to determine that the target processor has been reserved by the first task if the first task is in the running queue of the target processor; a second queue determination module, configured to release the spin lock of the target processor and acquire the spin lock of the running queue to which the first task belongs if the first task is not in the running queue of the target processor; a release dequeuing module, configured to dequeue the first task from the running queue to which the first task belongs and release the spin lock of the running queue to which the first task belongs; and a preemptive reservation module, configured to acquire the spin lock of the target processor and add the first task into the running queue of the target processor, and determine that the target processor has been reserved by the first task.
[0088] Optionally, in the processor task scheduling apparatus provided by the embodiment of the present application, before the centralized queue is acquired, the apparatus further comprises: a queue partition unit configured to create a plurality of different centralized queues, wherein the physical machine where the target processor is located comprises a plurality of processors, and each centralized queue corresponds to at least one processor.
[0089] Optionally, in the processor task scheduling apparatus provided by the embodiment of the present application, before the centralized queue is acquired, the apparatus further comprises: a system call unit configured to receive system call information written by a user state program through memory mapping; a priority determination unit configured to determine a new task and a priority corresponding to the new task according to the system call information; and a queue updating unit configured to add the new task to the centralized queue by using the new task and the priority corresponding to the new task, so as to update the centralized queue.
[0090] Optionally, in the processor task scheduling apparatus provided by the embodiment of the present application, the queue updating unit comprises: a position determination module configured to determine a to-be-updated position of the new task in the centralized queue according to the priority corresponding to the new task; and a lock-free queue module configured to update the centralized queue by using an atomic operation linked list, so as to add the new task to the to-be-updated position in the centralized queue.
[0091] Optionally, in the processor task scheduling apparatus provided in the embodiment of the present application, the apparatus further comprises: a kernel scheduling unit, configured to schedule the task in the running queue by using the kernel scheduler of the physical machine where the target processor is located when the running queue of the target processor is not empty, and determine a second task; a first target task determining unit, configured to determine the second task as the target task to be executed by the target processor if the second task is not the task in the centralized queue, and control the processor to execute the target task; and a second target task determining unit, configured to detect whether the second task is the predetermined task of a second processor if the second task is the task in the centralized queue, and de-queue the second task from the running queue if the second task is the predetermined task of the second processor, wherein the second processor is a processor other than the target processor in the physical machine.
[0092] It should be noted that the queue obtaining unit 601, the task selecting unit 602 and the task determining unit 603 correspond to steps S201 to S203 in Embodiment 1, and the three units have the same instances and application scenarios as the corresponding steps, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules can be run in the computer terminal 10 provided in Embodiment 1 as part of the apparatus.
[0093] Embodiment 3
[0094] The embodiments of the present application can provide a computer terminal, which can be any one of the computer terminal devices in the computer terminal group. Optionally, in the present embodiment, the above computer terminal can be replaced by a mobile terminal or other terminal device.
[0095] Optionally, in the present embodiment, the above computer terminal can be located in at least one of the network devices in the computer network.
[0096] In the present embodiment, the above computer terminal can execute the program codes of the following steps in the processor task scheduling method: obtaining a centralized queue, wherein the centralized queue is used to store a plurality of to-be-assigned tasks and priorities corresponding to the to-be-assigned tasks; selecting a to-be-assigned task in the centralized queue when the running queue of the target processor is empty, obtaining a first task, and pre-assigning the first task to the target processor to add the first task to the running queue of the target processor; and determining a target task to be executed by the target processor according to the first task, and controlling the target processor to execute the target task.
[0097] Optionally, the computer terminal can execute program codes of the following steps in the task scheduling method of the processor: when there is at least one task to be allocated in the centralized queue, determining a head task in the centralized queue, wherein the head task is a task with the highest priority in the centralized queue; if the predecessor task meets a first preset condition, determining the predecessor task as the first task, wherein the predecessor task is a task triggered by a previous process of the target processor, and the first preset condition includes that the predecessor task belongs to the centralized queue, the predecessor task is in a ready state, and the priority of the predecessor task is higher than the priority of the head task; if the predecessor task does not meet the first preset condition, determining the head task as the first task.
[0098] Optionally, the computer terminal can execute program codes of the following steps in the task scheduling method of the processor: in a case where the number of tasks to be allocated in the centralized queue is zero and a predecessor task meets a second preset condition, determining the predecessor task as the first task, wherein the predecessor task is a task triggered by a previous process of the target processor, and the second preset condition includes that the predecessor task belongs to the centralized queue and the predecessor task is in a ready state.
[0099] Optionally, the computer terminal can execute program codes of the following steps in the task scheduling method of the processor: if the first task is in a running queue of the target processor, configuring that the target processor has been reserved by the first task; if the first task is not in the running queue of the target processor, releasing a spin lock of the target processor and acquiring a spin lock of a running queue to which the first task belongs; dequeuing the first task from the running queue to which the first task belongs and releasing the spin lock of the running queue to which the first task belongs; acquiring the spin lock of the target processor and adding the first task into the running queue of the target processor, and configuring that the target processor has been reserved by the first task.
[0100] Optionally, the computer terminal can execute program codes of the following steps in the task scheduling method of the processor: creating a plurality of different centralized queues, wherein a physical machine where the target processor is located includes a plurality of processors, and each centralized queue corresponds to at least one processor.
[0101] Optionally, the computer terminal can execute program codes of the following steps in the task scheduling method of the processor: receiving system call information written by a user mode program through memory mapping; determining a new task and a priority corresponding to the new task according to the system call information; and adding the new task to the centralized queue by using the new task and the priority corresponding to the new task, so as to update the centralized queue.
[0102] Optionally, the aforementioned computer terminal may execute program code for the following steps in the processor's task scheduling method: determining the position of the new task to be updated in the centralized queue based on the priority of the new task; updating the centralized queue through a linked list of atomic operations to add the new task to the position to be updated in the centralized queue.
[0103] Optionally, the aforementioned computer terminal may execute program code for the following steps in the processor's task scheduling method: when the target processor's run queue is not empty, the kernel scheduler of the physical machine where the target processor is located schedules the tasks in the run queue to determine the second task; if the second task is not a task in the centralized queue, the second task is determined as the target task to be executed by the target processor, and the processor is controlled to execute the target task; if the second task is a task in the centralized queue, it is detected whether the second task is a predetermined task of the second processor, and if so, the second task is dequeued from the run queue, wherein the second processor is a processor in the physical machine other than the target processor.
[0104] Optionally, Figure 7 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 7 As shown, the electronic device may include: one or more ( Figure 7 (Only one is shown) processor 702, memory 704, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0105] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the processor task scheduling method and apparatus in this embodiment of the invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the aforementioned processor task scheduling method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0106] The processor can access the information and application programs stored in the memory via the transmission device to perform the above steps.
[0107] The embodiment of the present application provides a processor task scheduling scheme. The centralized queue is obtained, wherein the centralized queue is used for storing a plurality of to-be-allocated tasks and priorities corresponding to the to-be-allocated tasks, the plurality of to-be-allocated tasks are arranged according to the size of the priorities, and the priority is used for representing the execution sequence of the to-be-allocated task; when the running queue of the target processor is empty, the to-be-allocated task stored in the centralized queue is selected to obtain a first task, and the first task is scheduled for the target processor to add the first task to the running queue of the target processor; the target task to be executed by the target processor is determined according to the first task, so that the target processor is controlled to execute the target task, the technical problem of high performance overhead of processor task scheduling in the related art is solved, and the technical effect of improving the task scheduling accuracy of the processor is achieved.
[0108] Those skilled in the art can understand that Figure 7 The structure shown is only schematic, and the computer terminal can also be a smart phone, a tablet computer, a palm computer, a mobile Internet device (MID), a PAD, or the like. Figure 7 It does not limit the structure of the electronic device. For example, the computer terminal can further include more or fewer components (such as a network interface, a display device, or the like) than those shown in the figure, or have a different configuration from that shown in the figure. Figure 7 Figure 7 The structure shown is only schematic, and the computer terminal can also be a smart phone, a tablet computer, a palm computer, a mobile Internet device (MID), a PAD, or the like.
[0109] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by programs instructing the related hardware of the terminal device, and the programs can be stored in a computer readable storage medium, which can include a flash disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and the like.
[0110] Embodiment 4
[0111] The embodiment of the present application further provides a computer readable storage medium. Optionally, in the embodiment, the computer readable storage medium can be used to save the program code executed by the processor task scheduling method provided in the embodiment 1.
[0112] Optionally, in the embodiment, the computer readable storage medium can be located in any one of the computer terminals in the computer terminal group in the computer network, or in any one of the mobile terminals in the mobile terminal group.
[0113] Optionally, in the embodiment, the computer readable storage medium is configured to store program code for performing the following steps: obtaining a centralized queue, wherein the centralized queue is configured to store a plurality of tasks to be allocated and priorities corresponding to the tasks to be allocated; when the running queue of the target processor is empty, selecting a task to be allocated in the centralized queue to obtain a first task, and reserving the first task for the target processor to add the first task to the running queue of the target processor; determining a target task to be executed by the target processor according to the first task, and controlling the target processor to execute the target task.
[0114] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: when there is at least one task to be allocated in the centralized queue, determining a head task in the centralized queue, wherein the head task is a task to be allocated with the highest priority in the centralized queue; if the predecessor task meets a first preset condition, determining the predecessor task as the first task, wherein the predecessor task is a task triggered by a previous process of the target processor, and the first preset condition includes that the predecessor task belongs to the centralized queue, the predecessor task is in a ready state, and the priority of the predecessor task is higher than the priority of the head task; if the predecessor task does not meet the first preset condition, determining the head task as the first task.
[0115] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: in a case where the number of tasks to be allocated in the centralized queue is zero and the predecessor task meets a second preset condition, determining the predecessor task as the first task, wherein the predecessor task is a task triggered by a previous process of the target processor, and the second preset condition includes that the predecessor task belongs to the centralized queue and the predecessor task is in a ready state.
[0116] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: if the first task is in the running queue of the target processor, configuring that the target processor has been reserved by the first task; if the first task is not in the running queue of the target processor, releasing a spin lock of the target processor, and obtaining a spin lock of a running queue to which the first task belongs; dequeuing the first task from the running queue to which the first task belongs, and releasing the spin lock of the running queue to which the first task belongs; obtaining the spin lock of the target processor, and adding the first task to the running queue of the target processor, and configuring that the target processor has been reserved by the first task.
[0117] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: creating a plurality of different centralized queues, wherein the physical machine where the target processor is located includes a plurality of processors, and each centralized queue corresponds to at least one processor.
[0118] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: receiving system call information written by the user mode program through the memory mapping; determining the new task and the priority corresponding to the new task according to the system call information; and adding the new task to the centralized queue by using the new task and the priority corresponding to the new task, so as to update the centralized queue.
[0119] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: determining the to-be-updated position of the new task in the centralized queue according to the priority corresponding to the new task; and updating the centralized queue by using the linked list of the atomic operation, so as to add the new task to the to-be-updated position in the centralized queue.
[0120] Optionally, in the embodiment, the computer readable storage medium is further configured to store program code for performing the following steps: when the running queue of the target processor is not empty, scheduling the tasks in the running queue by using the kernel scheduler of the physical machine where the target processor is located, to determine a second task; if the second task is not the task in the centralized queue, determining the second task as the target task to be executed by the target processor, and controlling the processor to execute the target task; if the second task is the task in the centralized queue, detecting whether the second task is the predetermined task of a second processor, if yes, dequeuing the second task from the running queue, wherein the second processor is a processor other than the target processor in the physical machine.
[0121] The application further provides a computer program product, which is suitable for executing the steps of the task scheduling method of the processor when executed on a data processing device.
[0122] The above-mentioned serial numbers of the embodiments of the application are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0123] In the above-mentioned embodiments of the application, the description of each embodiment has its own emphasis, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0124] In several embodiments provided in the present application, it should be understood that the disclosed technology can be implemented by other ways. Among them, the above-described device embodiments are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interfaces, units or modules, and can be electrical or other forms.
[0125] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or they can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0126] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0127] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the part that essentially contributes to the related art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes: a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various program code storage media.
[0128] The above is only the preferred embodiment of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, and these improvements and refinements should be considered as the protection scope of the present application.
Claims
1. A task scheduling method for a processor, characterized in that, include: Obtain a centralized queue, wherein the centralized queue is used to store multiple tasks to be assigned and the priorities corresponding to the tasks to be assigned; When the target processor's run queue is empty, the tasks to be assigned stored in the centralized queue are selected to obtain the first task, and the first task is reserved for the target processor so as to add the first task to the target processor's run queue. Based on the first task, a target task to be executed by the target processor is determined, so as to control the target processor to execute the target task; After obtaining the centralized queue, the method further includes: When the run queue of the target processor is not empty, the kernel scheduler of the physical machine where the target processor is located schedules the tasks in the run queue to determine the second task; If the second task is not a task in the centralized queue, then the second task is determined as the target task to be executed by the target processor, and the processor is controlled to execute the target task; If the second task is a task in the centralized queue, then it is detected whether the second task is a predetermined task of the second processor. If so, the second task is dequeued from the running queue. The second processor is a processor in the physical machine other than the target processor. Both the target processor and the second processor are central processing units.
2. The method according to claim 1, characterized in that, Selecting tasks to be assigned from the centralized queue to obtain the first task includes: When there is at least one task to be assigned in the centralized queue, the head task in the centralized queue is determined, wherein the head task is the task to be assigned with the highest priority in the centralized queue. If the predecessor task meets the first preset condition, then the predecessor task is determined as the first task, wherein the predecessor task is the task that was previously triggered by the process scheduling of the target processor, and the first preset condition includes that the predecessor task belongs to the centralized queue, the predecessor task is in a ready state, and the priority of the predecessor task is higher than the priority of the head task. If the preceding task does not meet the first preset condition, then the first task will be determined as the first task.
3. The method according to claim 1, characterized in that, Selecting tasks to be assigned from the centralized queue to obtain the first task includes: If the number of tasks to be assigned in the centralized queue is zero and the predecessor task meets the second preset condition, the predecessor task is determined as the first task. The predecessor task is the task that was previously scheduled by the target processor's triggering process. The second preset condition includes that the predecessor task belongs to the centralized queue and that the predecessor task is in a ready state.
4. The method according to claim 1, characterized in that, Reserving the first task for the target processor, and adding the first task to the target processor's run queue, includes: If the first task is in the run queue of the target processor, then the target processor is configured to be reserved by the first task; If the first task is not in the run queue of the target processor, then release the spinlock of the target processor and acquire the spinlock of the run queue to which the first task belongs; Dequeue the first task from the run queue to which the first task belongs, and release the spinlock of the run queue to which the first task belongs; Acquire the spinlock of the target processor, add the first task to the run queue of the target processor, and configure the target processor to be reserved by the first task.
5. The method according to claim 1, characterized in that, Before acquiring the centralized queue, the method further includes: Multiple different centralized queues are created, wherein the physical machine where the target processor is located includes multiple processors, and each centralized queue corresponds to at least one of the processors.
6. The method according to claim 1, characterized in that, Before acquiring the centralized queue, the method further includes: Receive system call information written by user-mode programs via memory mapping; The newly added task and its corresponding priority are determined based on the system call information. The newly added task and its corresponding priority are used to add the new task to the centralized queue, thereby updating the centralized queue.
7. The method according to claim 6, characterized in that, Updating the centralized queue by adding the new task and its corresponding priority to the centralized queue includes: The update position of the new task in the centralized queue is determined based on the priority corresponding to the new task. The centralized queue is updated using a linked list with atomic operations to add the new task to the position to be updated in the centralized queue.
8. A task scheduling device for a processor, characterized in that, include: A queue acquisition unit is used to acquire a centralized queue, wherein the centralized queue is used to store multiple tasks to be assigned and the priorities corresponding to the tasks to be assigned; The task selection unit is used to select the tasks to be assigned stored in the centralized queue when the target processor's run queue is empty, obtain the first task, and reserve the first task for the target processor so as to add the first task to the target processor's run queue. A task determination unit is configured to determine, based on the first task, a target task to be executed by the target processor, so as to control the target processor to execute the target task; A kernel scheduling unit is used to schedule tasks in the run queue through the kernel scheduler of the physical machine where the target processor is located, and determine the second task when the run queue of the target processor is not empty; a first target task determination unit is used to determine the second task as the target task to be executed by the target processor if the second task is not a task in the centralized queue, and control the processor to execute the target task; a second target task determination unit is used to detect whether the second task is a predetermined task of the second processor if the second task is a task in the centralized queue, and if so, dequeue the second task from the run queue, wherein the second processor is a processor other than the target processor in the physical machine, and both the target processor and the second processor are central processing units.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device on which the computer-readable storage medium resides to perform the task scheduling method of the processor according to any one of claims 1 to 7.
10. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, executes the task scheduling method of the processor according to any one of claims 1 to 7.
11. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the task scheduling method of the processor according to any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-core task scheduling method and device, electronic equipment and storage medium
CN114168352A
Task scheduling method and device, electronic equipment, storage medium and program product
CN118227289A