A task scheduling method and device
By introducing AutoDL scheduler in Linux system, combining the advantages of DL and RT schedulers, dynamically allocating tasks to meet high real-time requirements, solving the problem of insufficient real-time task scheduling in existing systems, and achieving more efficient task scheduling Coordination.
Patent Information
- Application Number
- CN202411541440.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-10-31
AI Technical Summary
The task scheduler in the existing Linux system lacks real-time real-time task processing, and different schedulers cannot flexibly coordinate the task scheduling.
An AutoDL scheduler is proposed, combining the parameters of the DL scheduler and RT scheduler to generate a list of DL tasks that can be undertaken, and dynamically allocate tasks to the DL scheduler or RT scheduler according to task priority and CPU load.
The system's scheduling ability for high-real-time tasks is improved, ensuring that the real-time requirements of tasks are met, and at the same time avoiding task timeliness guarantee problems caused by CPU overload.
Smart Images

Figure CN119045977B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of operating systems, and in particular relates to a task scheduling method and device. Background Art
[0002] Most of the Linux operating systems used in modern computers and devices support multi-user and multi-tasking, which relies on the task scheduling function provided by the system. The operating system uses the task scheduling function to make users feel that they have exclusive access to all resources in most scenarios. A good scheduling algorithm can improve the user experience and improve the overall operating efficiency of the system.
[0003] The scheduler chooses which task to execute and when, and how long to execute before reselecting. Different schedulers have different selection algorithms to suit different usage scenarios and requirements.
[0004] There are five commonly used schedulers in the existing Linux system. In order of priority from high to low, they are: stop scheduler, DL scheduler, RT scheduler, CFS scheduler, idle scheduler. The scheduler with higher priority will be executed before the scheduler with lower priority.
[0005] The stop scheduler is the scheduler with the highest priority. Its characteristic is that it will preempt all other tasks and will not be preempted by other tasks.
[0006] The DL scheduler uses a completely different approach from the RT scheduler. It schedules tasks based on their deadlines, and tries to select the task that will reach its deadline the fastest each time. This means that the priority of tasks in the DL scheduler changes dynamically with the deadlines of each task. When the total load of tasks in the DL scheduler does not exceed the processing power of the CPU, this scheduling method can provide real-time performance. The DL scheduler needs to use three parameters: cycle, run time, and deadline.
[0007] The RT scheduler schedules tasks based on their priorities, and high-priority tasks are processed first each time. For tasks of the same priority, you can choose between FIFO (first-in-first-out) and RR (round robin). Therefore, this scheduling method is more friendly to high-priority tasks, while low-priority tasks will be affected by high-priority tasks.
[0008] The CFS scheduler is a widely used scheduler. Its design point is not real-time performance, but fairness. The CFS scheduler schedules tasks based on their weights, so it cannot provide real-time guarantees.
[0009] The idle scheduler is a special scheduler that is executed only when there are no other tasks to be scheduled. It is only used for statistical information, etc., and cannot actually schedule tasks.
[0010] The problems with the above scheduler are:
[0011] The idle scheduler cannot really provide task scheduling, and the CFS scheduler focuses on fairness rather than real-time performance, so it is not suitable for high-real-time tasks.
[0012] The RT scheduler schedules tasks based on priority, so it is not friendly to low-priority tasks.
[0013] The stop scheduler is suitable for scenarios where there is only one high-priority urgent task in the system and other tasks are not time-sensitive. Otherwise, when the stop scheduler occupies the CPU for a long time, other tasks will be affected.
[0014] The DL scheduler can provide timeliness guarantee for tasks very well, because this kind of scheduling is really based on the time requirements of the tasks, but this scheduling method has requirements for the system load. If there are fewer tasks in the DL scheduler and the CPU usage is not high, the timeliness of all tasks can be met. However, if there are more tasks in the DL scheduler or the CPU usage is high, the total CPU demand of the tasks exceeds the CPU capacity, which is called "CPU overload". At this time, it is obvious that timeliness cannot be provided for all tasks. In this case, the scheduler will reject the tasks that will cause CPU overload after joining. If it is not rejected, it may lead to more serious consequences. Not only the timeliness of the newly added tasks cannot be guaranteed, but the original tasks will also be affected by the chain. In the worst case, all tasks cannot be scheduled before their deadlines. That is to say, for various schedulers in the prior art, which scheduler to use for a specific task is specified by parameters, and the scheduler will not change it, so different schedulers cannot flexibly coordinate the scheduling of tasks for different situations. Summary of the invention
[0015] In view of the above technical problems, the purpose of the present invention is to provide a scheduling solution for high real-time tasks; this solution can better meet the real-time requirements of tasks. Specifically, the present invention proposes a task scheduling method and device to solve the technical problem that the real-time performance of task scheduling in the existing Linux system is not high enough.
[0016] The present invention proposes a task scheduling method, which comprises:
[0017] Step S1: constructing an AutoDL scheduler; wherein:
[0018] The parameters of the AutoDL scheduler are the union of the parameters of the DL scheduler and the parameters of the RT scheduler;
[0019] The priority of the AutoDL scheduler is lower than that of the stop scheduler, and higher than other types of schedulers in the Linux operating system except the stop scheduler;
[0020] The AutoDL scheduler is used to generate a list of DL tasks that can be undertaken, and monitor the list of DL tasks that can be undertaken in real time, and regenerate the list of DL tasks that can be undertaken when the list of DL tasks that can be undertaken is empty;
[0021] The tasks stored in the undertakeable DL task list are tasks expected to be scheduled by the DL scheduler;
[0022] Step S2: monitor the current task; wherein:
[0023] When the current task meets the triggering condition for regenerating the list of DL tasks that can be undertaken, the list of DL tasks that can be undertaken is regenerated; otherwise, the type and priority of the current task are determined, and the AutoDL scheduler determines the tasks to be assigned, and the tasks to be assigned include the current task and / or other tasks that have been added to the AutoDL scheduler;
[0024] The AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks;
[0025] The first undertakeable DL task list is the undertakeable DL task list closest to the latest undertakeable DL task list and before the latest undertakeable DL task list;
[0026] Among them, the trigger condition is one or two of the following conditions: the current task is to create or terminate the AutoDL scheduler; the priority of the current task is higher than or equal to a preset threshold, and the preset threshold is the priority of the task with the lowest priority in the latest list of DL tasks that can be undertaken.
[0027] Preferably, in step S1, the AutoDL scheduler generates the list of achievable DL tasks in the following manner:
[0028] Obtaining a task of a to-be-determined scheduler in the Linux operating system, wherein the task of the to-be-determined scheduler is: a task added to the AutoDL scheduler to be assigned to the DL scheduler or the RT scheduler by the AutoDL scheduler;
[0029] Arrange the tasks of the to-be-determined scheduler from high to low according to the priority of the tasks, obtain the operation cycle and operation time of each task of the to-be-determined scheduler, and determine the CPU load required for each task of the to-be-determined scheduler based on the operation cycle and operation time of each task of the to-be-determined scheduler;
[0030] Selecting a number of tasks of the to-be-determined scheduler from all the tasks of the to-be-determined scheduler, and storing them in the list of DL tasks that can be undertaken;
[0031] The selected tasks of the to-be-determined scheduler are selected in order of priority, and the sum of the CPU load required by the selected tasks of the to-be-determined scheduler and the current load of the CPU running the Linux operating system is less than the maximum load that the CPU can withstand.
[0032] Preferably, in step S2, the AutoDL scheduler assigns the to-be-assigned task to the DL scheduler or the RT scheduler based on the latest undertakeable DL task list and the first undertakeable DL task list, specifically including:
[0033] For each pending task in the assigned tasks, perform the following operations:
[0034] If the task to be assigned is stored in the first list of DL tasks that can be undertaken, and is not stored in the latest list of DL tasks that can be undertaken, deleting the task to be assigned from the DL scheduler, and adding the task to be assigned to the RT scheduler;
[0035] If the task to be assigned is not stored in the first list of DL tasks that can be undertaken, and is stored in the latest list of DL tasks that can be undertaken, deleting the task to be assigned from the RT scheduler, and adding the task to be assigned to the DL scheduler;
[0036] If the task to be assigned is stored in the first list of DL tasks that can be undertaken and is stored in the latest list of DL tasks that can be undertaken, then the task to be assigned is kept in the DL scheduler;
[0037] If the task to be assigned is not stored in the first list of DL tasks that can be undertaken, and is not stored in the latest list of DL tasks that can be undertaken, the task to be assigned is kept in the RT scheduler.
[0038] Preferably, the method, in which the AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks, further comprises:
[0039] The DL scheduler schedules each task stored in the DL scheduler, and schedules each task based on the running cycle, running time, and deadline of each task;
[0040] The RT scheduler schedules each task stored in the RT scheduler.
[0041] Preferably, the RT scheduler schedules each task stored in the RT scheduler, specifically including:
[0042] Sort the tasks stored in the RT scheduler by their priorities; where:
[0043] For tasks with different priorities, the task with higher priority is scheduled first;
[0044] For tasks of the same priority, one of the following modes is selected for scheduling: FIFO mode, polling mode, or DL mode.
[0045] Among them, the first-in-first-out mode is that the task that enters the running state first is scheduled first;
[0046] Among them, the polling mode is to poll the CPU for scheduling;
[0047] Among them, the DL mode is:
[0048] Initialize the expiration flags of each task of the same priority to empty;
[0049] Get the expiration mark, execution cycle, execution time, and current latest execution time of each task;
[0050] Mark the tasks that have expired as expired as priority tasks, and update the latest current execution time corresponding to the expired tasks according to the execution cycle and execution time;
[0051] Arrange the tasks in the order of priority tasks and non-priority tasks, where tasks of the same priority level are sorted in the order of the latest execution time from earliest to latest;
[0052] Schedule each task according to the sorting results;
[0053] After the task is scheduled, the expiration mark of the task is updated. If the task is a periodic task, the current latest execution time of the task is updated; otherwise, the task is deleted from the RT scheduler.
[0054] The present invention proposes a task scheduling device, which comprises:
[0055] Initialization module: configured to build the AutoDL scheduler;
[0056] The parameters of the AutoDL scheduler are the union of the parameters of the DL scheduler and the parameters of the RT scheduler;
[0057] The priority of the AutoDL scheduler is lower than that of the stop scheduler, and higher than other types of schedulers in the Linux operating system except the stop scheduler;
[0058] The AutoDL scheduler is used to generate a list of DL tasks that can be undertaken, and monitor the list of DL tasks that can be undertaken in real time, and regenerate the list of DL tasks that can be undertaken when the list of DL tasks that can be undertaken is empty;
[0059] The tasks stored in the undertakeable DL task list are tasks expected to be scheduled by the DL scheduler;
[0060] Assignment module: configured to monitor the current task; where:
[0061] When the current task meets the triggering condition for regenerating the list of DL tasks that can be undertaken, the list of DL tasks that can be undertaken is regenerated; otherwise, the type and priority of the current task are determined, and the AutoDL scheduler determines the tasks to be assigned, and the tasks to be assigned include the current task and / or other tasks that have been added to the AutoDL scheduler;
[0062] The AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks;
[0063] The first undertakeable DL task list is the undertakeable DL task list closest to the latest undertakeable DL task list and before the latest undertakeable DL task list;
[0064] Among them, the trigger condition is one or two of the following conditions: the current task is to create or terminate the AutoDL scheduler; the priority of the current task is higher than or equal to a preset threshold, and the preset threshold is the priority of the task with the lowest priority in the latest list of DL tasks that can be undertaken.
[0065] The present invention provides an electronic device, comprising:
[0066] at least one processor; and
[0067] a memory communicatively connected to the at least one processor; wherein,
[0068] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described above.
[0069] The present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute the method as described above.
[0070] The present invention adds an AutoDL scheduler, and the AutoDL scheduler accommodates as many high-priority tasks as possible using the DL scheduler based on the task priority and the required CPU load without overloading the CPU, and the remaining tasks use the RT scheduler, thereby ensuring the system's demand for scheduling high real-time tasks.
[0071] The present invention has the following technical effects:
[0072] 1. The scheduling effects of the technical solution of the present invention and the existing DL scheduler and RT scheduler on different tasks:
[0073] (1) When the number of tasks is small and all tasks are scheduled in DL mode without causing CPU overload, the technical solution of the present invention will assign all tasks to the DL scheduler. The effect is equivalent to the DL scheduler algorithm and is better than the RT scheduler algorithm.
[0074] (2) When there are a large number of tasks and all of them use the DL scheduling method, which will cause CPU overload, the technical solution of the present invention will assign some high-priority tasks to the DL scheduler and the remaining tasks to the RT scheduler. This scheduling algorithm is better than the DL scheduler algorithm (compared with the CPU overload caused by all using the DL scheduler, it ensures the timeliness requirements of as many high-priority tasks as possible) and better than the RT scheduler algorithm (all using the RT scheduler will affect the timeliness requirements of high-priority tasks).
[0075] 2. The method of reallocation of tasks when they change in the present invention realizes the automatic optimal allocation of tasks, which undoubtedly greatly improves the speed and convenience compared with manual operation.
[0076] 3. The RT scheduler of the present invention adds a DL method to the scheduling algorithm for tasks of the same priority level, schedules tasks according to their deadlines, and recalculates the deadlines after expiration, taking into account their periodic properties. This enriches the task selection method of the RT scheduler. When the system load is heavy and the DL scheduler cannot be used in full, the deadline requirements of the tasks assigned to the RT scheduler can be partially met. At the same time, since the algorithm takes into account the impact of task expiration, it provides a method for adopting a new cycle after the task times out, avoiding the "avalanche" phenomenon when the existing DL scheduler is overloaded. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] Figure 1 A flowchart of the task scheduling method provided by the present invention;
[0078] Figure 2 A schematic diagram of a task list process for determining achievable DL tasks provided by the present invention;
[0079] Figure 3 A schematic diagram of the architecture of the task scheduling device provided by the present invention. DETAILED DESCRIPTION
[0080] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0081] Figure 1 The schematic diagram of the task scheduling method is shown. The present invention is a high real-time task scheduling method. It should be understood that in other embodiments, the order of some steps can be interchanged according to actual needs, or some steps can be omitted or deleted. Figure 1-Figure 2 As shown, the method includes:
[0082] Step S1: constructing an AutoDL scheduler; wherein:
[0083] The parameters of the AutoDL scheduler are the union of the parameters of the DL scheduler and the parameters of the RT scheduler;
[0084] The priority of the AutoDL scheduler is lower than that of the stop scheduler, and higher than other types of schedulers in the Linux operating system except the stop scheduler;
[0085] The AutoDL scheduler is used to generate a list of DL tasks that can be undertaken, and monitor the list of DL tasks that can be undertaken in real time, and regenerate the list of DL tasks that can be undertaken when the list of DL tasks that can be undertaken is empty;
[0086] The tasks stored in the undertakeable DL task list are tasks expected to be scheduled by the DL scheduler;
[0087] Step S2: monitor the current task; wherein:
[0088] When the current task meets the triggering condition for regenerating the list of DL tasks that can be undertaken, the list of DL tasks that can be undertaken is regenerated; otherwise, the type and priority of the current task are determined, and the AutoDL scheduler determines the tasks to be assigned, and the tasks to be assigned include the current task and / or other tasks that have been added to the AutoDL scheduler;
[0089] The AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks;
[0090] The first undertakeable DL task list is the undertakeable DL task list closest to the latest undertakeable DL task list and before the latest undertakeable DL task list;
[0091] Among them, the trigger condition is one or two of the following conditions: the current task is to create or terminate the AutoDL scheduler; the priority of the current task is higher than or equal to a preset threshold, and the preset threshold is the priority of the task with the lowest priority in the latest list of DL tasks that can be undertaken.
[0092] In the present invention, a new scheduler is added, whose type is AutoDL. At the same time, the parameters used by the task are specified as the union of the parameters required by the DL scheduler and the RT scheduler, that is, they include parameters such as cycle, running time and deadline used by the classic DL scheduler, and the priority and scheduling algorithm used by the RT scheduler.
[0093] In the present invention, the undertakeable DL task list is used to store tasks to be added to the DL scheduler, and the tasks stored in the undertakeable DL task list are tasks that can be scheduled by the DL scheduler.
[0094] The AutoDL scheduler generates the list of DL tasks that can be undertaken in the following manner:
[0095] Obtaining a task of a to-be-determined scheduler in the Linux operating system, wherein the task of the to-be-determined scheduler is: a task added to the AutoDL scheduler to be assigned to the DL scheduler or the RT scheduler by the AutoDL scheduler;
[0096] Arrange the tasks of the to-be-determined scheduler from high to low according to the priority of the tasks, obtain the operation cycle and operation time of each task of the to-be-determined scheduler, and determine the CPU load required for each task of the to-be-determined scheduler based on the operation cycle and operation time of each task of the to-be-determined scheduler;
[0097] Selecting a number of tasks of the to-be-determined scheduler from all the tasks of the to-be-determined scheduler, and storing them in the list of DL tasks that can be undertaken;
[0098] The selected tasks of the to-be-determined scheduler are selected in order of priority, and the sum of the CPU load required by the selected tasks of the to-be-determined scheduler and the current load of the CPU running the Linux operating system is less than the maximum load that the CPU can withstand.
[0099] In the present invention, tasks are sorted from high to low according to their priorities, and the task with the highest priority is selected first. The load is calculated and accumulated according to the cycle, running time and other requirements of the task. If the CPU is overloaded, the selected work is finished. If the CPU is not overloaded, the next task is processed. The AutoDL scheduler of the present invention accommodates as many high-priority tasks as possible using the DL scheduler based on the priority of the task and the required CPU load without overloading the CPU.
[0100] The step S2, in which the AutoDL scheduler assigns the to-be-assigned task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks, includes:
[0101] For each pending task in the assigned tasks, perform the following operations:
[0102] If the task to be assigned is stored in the first list of DL tasks that can be undertaken, and is not stored in the latest list of DL tasks that can be undertaken, deleting the task to be assigned from the DL scheduler, and adding the task to be assigned to the RT scheduler;
[0103] If the task to be assigned is not stored in the first list of DL tasks that can be undertaken, and is stored in the latest list of DL tasks that can be undertaken, deleting the task to be assigned from the RT scheduler, and adding the task to be assigned to the DL scheduler;
[0104] If the task to be assigned is stored in the first list of DL tasks that can be undertaken and is stored in the latest list of DL tasks that can be undertaken, then the task to be assigned is kept in the DL scheduler;
[0105] If the task to be assigned is not stored in the first list of DL tasks that can be undertaken, and is not stored in the latest list of DL tasks that can be undertaken, the task to be assigned is kept in the RT scheduler.
[0106] In the present invention, when a task in the list of DL tasks that can be undertaken is terminated, or a high-priority AutoDL task is newly added, the list of DL tasks that can be undertaken is recalculated. If a task was originally in the list of DL tasks that can be undertaken, but is no longer in the list after recalculation, it is removed from the DL scheduler and added to the RT scheduler; if a task was not originally in the list of DL tasks that can be undertaken, but is in the list after recalculation, it is removed from the RT scheduler and added to the DL scheduler. If after recalculation, the status of whether the task is in the list of DL tasks that can be undertaken does not change, no additional processing is required.
[0107] Further, the method allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest achievable DL task list and the first achievable DL task list in the AutoDL scheduler, and further includes:
[0108] The DL scheduler schedules each task stored in the DL scheduler, and schedules each task based on the running cycle, running time, and deadline of each task;
[0109] The RT scheduler schedules each task stored in the RT scheduler.
[0110] The RT scheduler schedules each task stored in the RT scheduler, specifically including:
[0111] Sort the tasks stored in the RT scheduler by their priorities; where:
[0112] For tasks with different priorities, the task with higher priority is scheduled first;
[0113] For tasks of the same priority, one of the following modes is selected for scheduling: FIFO mode, polling mode, or DL mode.
[0114] Among them, the first-in-first-out mode is that the task that enters the running state first is scheduled first;
[0115] Among them, the polling mode is to poll the CPU for scheduling;
[0116] Among them, the DL mode is:
[0117] Initialize the expiration flags of each task of the same priority to empty;
[0118] Get the expiration mark, execution cycle, execution time, and current latest execution time of each task;
[0119] Mark the tasks that have expired as expired as priority tasks, and update the latest current execution time corresponding to the expired tasks according to the execution cycle and execution time;
[0120] Arrange the tasks in the order of priority tasks and non-priority tasks, where tasks of the same priority level are sorted in the order of the latest execution time from earliest to latest;
[0121] Schedule each task according to the sorting results;
[0122] After the task is scheduled, the expiration mark of the task is updated. If the task is a periodic task, the current latest execution time of the task is updated; otherwise, the task is deleted from the RT scheduler.
[0123] In the present invention, for tasks in the list of DL tasks that can be undertaken, their priorities and scheduling algorithm parameters are temporarily ignored, and only based on parameters such as cycle, running time and deadline, the tasks are added to the DL scheduler and scheduled using the classic DL scheduling method. For tasks in the AutoDL scheduler that are not in the total list of DL tasks that can be undertaken, the tasks are added to the RT scheduler and scheduled by the RT scheduler, using the scheduling priority and scheduling algorithm as parameters.
[0124] For RT tasks of the same priority, the present invention uses the DL algorithm in addition to the FIFO and RR scheduling algorithms. When selecting tasks, the algorithm prefers tasks that have not exceeded the deadtime and are closest to the deadtime. However, unlike the calculation method of the DL scheduler, in this scheduling algorithm, tasks that have not timed out take precedence over tasks that have timed out. Tasks that have timed out enter the next cycle for calculation. This scheduling algorithm avoids the avalanche phenomenon in which tasks are postponed in sequence due to the original RR and FIFO scheduling algorithms, resulting in all tasks timeout. The method includes:
[0125] (1) Initialization: Sort the tasks according to their deadlines, from the earliest to the latest.
[0126] (2) Check whether the task has expired (i.e., whether the current time has exceeded its required deadline). If it has expired, set an expiration mark for the task and re-sort it according to the next cycle and deadline of the task. The sorting principle is to first compare whether there is an expiration mark. Tasks without an expiration mark take precedence over tasks with an expiration mark. If the marks are the same, they are sorted according to the deadline.
[0127] (3) Select the first task to execute. After the task is completed, clear its expiration mark and re-sort it according to the next cycle and deadline of the task. Wait for the next scheduling, that is, jump to step (2).
[0128] The present invention adds an AutoDL scheduler, which allocates tasks to the DL scheduler and the RT scheduler. When creating or terminating an AutoDL scheduler task, the list of DL tasks that can be undertaken is recalculated, and tasks are reallocated to the DL scheduler and the RT scheduler according to the calculation results. The RT scheduler adds a DL method to the scheduling algorithm for tasks of the same priority, schedules according to the deadline of the task, and considers its periodic properties, and recalculates the deadline after expiration.
[0129] The allocation of DL and RT tasks can be manually specified by the user, but this requires the user to know the allocation and operation status of all tasks in the system. Because the user's reaction speed cannot match the speed of the computer system task operation, the timeliness of the manual method cannot be guaranteed. In addition, the user cannot respond to the status changes of the task in time, such as the task entering a blocked state due to waiting for certain computer resources.
[0130] The following is a description of the device used to execute the present application. The specific implementation process and technical effects are described above and will not be repeated below.
[0131] Alternatively, if Figure 3 As shown, an embodiment of the present application provides a task scheduling device, the device comprising:
[0132] Initialization module: configured to build the AutoDL scheduler;
[0133] The parameters of the AutoDL scheduler are the union of the parameters of the DL scheduler and the parameters of the RT scheduler;
[0134] The priority of the AutoDL scheduler is lower than that of the stop scheduler, and higher than other types of schedulers in the Linux operating system except the stop scheduler;
[0135] The AutoDL scheduler is used to generate a list of DL tasks that can be undertaken, and monitor the list of DL tasks that can be undertaken in real time, and regenerate the list of DL tasks that can be undertaken when the list of DL tasks that can be undertaken is empty;
[0136] The tasks stored in the undertakeable DL task list are tasks expected to be scheduled by the DL scheduler;
[0137] Assignment module: configured to monitor the current task; where:
[0138] When the current task meets the triggering condition for regenerating the list of DL tasks that can be undertaken, the list of DL tasks that can be undertaken is regenerated; otherwise, the type and priority of the current task are determined, and the AutoDL scheduler determines the tasks to be assigned, and the tasks to be assigned include the current task and / or other tasks that have been added to the AutoDL scheduler;
[0139] The AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks;
[0140] The first undertakeable DL task list is the undertakeable DL task list closest to the latest undertakeable DL task list and before the latest undertakeable DL task list;
[0141] Among them, the trigger condition is one or two of the following conditions: the current task is to create or terminate the AutoDL scheduler; the priority of the current task is higher than or equal to a preset threshold, and the preset threshold is the priority of the task with the lowest priority in the latest list of DL tasks that can be undertaken.
[0142] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0143] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital singnal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0144] The above modules can be connected or communicated with each other via a wired connection or a wireless connection. The wired connection may include a metal cable, an optical cable, a hybrid cable, etc., or any combination thereof. The wireless connection may include a connection in the form of a LAN, a WAN, Bluetooth, a ZigBee, or NFC, or any combination thereof. Two or more modules may be combined into a single module, and any one module may be divided into two or more units. Those skilled in the art will clearly understand that for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application.
[0145] It should be noted that the above modules can be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more microprocessors (DSP), or one or more field programmable gate arrays (FPGA). For example, when a module is implemented in the form of a processing element scheduling program code, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0146] The electronic device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, near field communication (NFC) or other technologies. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.
[0147] The present application also provides a program product, such as a computer-readable storage medium, including a program, which is used to execute the above method embodiment when executed by a processor.
[0148] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0149] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0150] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0151] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (English: Read-Only Memory, referred to as: ROM), random access memory (English: Random Access Memory, referred to as: RAM), disk or optical disk and other media that can store program codes.
Claims
1. A task scheduling method, characterized in that: The method comprises the following steps: Step S1: constructing an AutoDL scheduler; wherein: The parameters of the AutoDL scheduler are the union of the parameters of the DL scheduler and the parameters of the RT scheduler; The priority of the AutoDL scheduler is lower than that of the stop scheduler, and higher than other types of schedulers in the Linux operating system except the stop scheduler; The AutoDL scheduler is used to generate a list of DL tasks that can be undertaken, and monitor the list of DL tasks that can be undertaken in real time, and regenerate the list of DL tasks that can be undertaken when the list of DL tasks that can be undertaken is empty; The tasks stored in the undertakeable DL task list are tasks expected to be scheduled by the DL scheduler; Step S2: monitor the current task; wherein: When the current task meets the triggering condition for regenerating the list of DL tasks that can be undertaken, the list of DL tasks that can be undertaken is regenerated; otherwise, the type and priority of the current task are determined, and the AutoDL scheduler determines the tasks to be assigned, and the tasks to be assigned include the current task and / or other tasks that have been added to the AutoDL scheduler; The AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks; The first undertakeable DL task list is the undertakeable DL task list closest to the latest undertakeable DL task list and before the latest undertakeable DL task list; The trigger condition is one or two of the following conditions: the current task is to create or terminate an AutoDL scheduler; the priority of the current task is higher than or equal to a preset threshold, and the preset threshold is the priority of the task with the lowest priority in the latest list of DL tasks that can be undertaken; In the step S1, the AutoDL scheduler generates the list of DL tasks that can be undertaken in the following manner: Obtaining a task of a to-be-determined scheduler in the Linux operating system, wherein the task of the to-be-determined scheduler is: a task added to the AutoDL scheduler to be assigned to the DL scheduler or the RT scheduler by the AutoDL scheduler; Arrange the tasks of the to-be-determined scheduler from high to low according to the priority of the tasks, obtain the operation cycle and operation time of each task of the to-be-determined scheduler, and determine the CPU load required for each task of the to-be-determined scheduler based on the operation cycle and operation time of each task of the to-be-determined scheduler; Selecting a number of tasks of the to-be-determined scheduler from all the tasks of the to-be-determined scheduler, and storing them in the list of DL tasks that can be undertaken; The selected tasks of the to-be-determined scheduler are selected in order of priority, and the sum of the CPU load required by the selected tasks of the to-be-determined scheduler and the current load of the CPU running the Linux operating system is less than the maximum load that the CPU can withstand.
2. The method according to claim 1, characterized in that In the step S2, the AutoDL scheduler assigns the to-be-assigned task to the DL scheduler or the RT scheduler based on the latest undertakeable DL task list and the first undertakeable DL task list, specifically including: For each pending task in the assigned tasks, perform the following operations: If the task to be assigned is stored in the first list of DL tasks that can be undertaken, and is not stored in the latest list of DL tasks that can be undertaken, deleting the task to be assigned from the DL scheduler, and adding the task to be assigned to the RT scheduler; If the task to be assigned is not stored in the first list of DL tasks that can be undertaken, and is stored in the latest list of DL tasks that can be undertaken, deleting the task to be assigned from the RT scheduler, and adding the task to be assigned to the DL scheduler; If the task to be assigned is stored in the first list of DL tasks that can be undertaken and is stored in the latest list of DL tasks that can be undertaken, then the task to be assigned is kept in the DL scheduler; If the task to be assigned is not stored in the first list of DL tasks that can be undertaken, and is not stored in the latest list of DL tasks that can be undertaken, the task to be assigned is kept in the RT scheduler.
3. The method according to claim 2, characterized in that The method further includes: assigning the to-be-assigned task to the DL scheduler or the RT scheduler based on the latest undertakeable DL task list and the first undertakeable DL task list in the AutoDL scheduler: The DL scheduler schedules each task stored in the DL scheduler, and schedules each task based on the running cycle, running time, and deadline of each task; The RT scheduler schedules each task stored in the RT scheduler.
4. The method according to claim 3, characterized in that The RT scheduler schedules each task stored in the RT scheduler, specifically including: Sort the tasks stored in the RT scheduler by their priorities; where: For tasks with different priorities, the task with higher priority is scheduled first; For tasks of the same priority, one of the following modes is selected for scheduling: FIFO mode, polling mode, or DL mode. Among them, the first-in-first-out mode is that the task that enters the running state first is scheduled first; Among them, the polling mode is to poll the CPU for scheduling; Among them, the DL mode is: Initialize the expiration flags of each task of the same priority to empty; Get the expiration mark, execution cycle, execution time, and current latest execution time of each task; Mark the tasks that have expired as expired as priority tasks, and update the latest current execution time corresponding to the expired tasks according to the execution cycle and execution time; Arrange the tasks in the order of priority tasks and non-priority tasks, where tasks of the same priority level are sorted in the order of the latest execution time from earliest to latest; Schedule each task according to the sorting results; After the task is scheduled, the expiration mark of the task is updated. If the task is a periodic task, the current latest execution time of the task is updated; otherwise, the task is deleted from the RT scheduler.
5. A task scheduling device for implementing the task scheduling method according to claim 1, characterized in that: The device comprises: Initialization module: configured to build the AutoDL scheduler; The parameters of the AutoDL scheduler are the union of the parameters of the DL scheduler and the parameters of the RT scheduler; The priority of the AutoDL scheduler is lower than that of the stop scheduler, and higher than other types of schedulers in the Linux operating system except the stop scheduler; The AutoDL scheduler is used to generate a list of DL tasks that can be undertaken, and monitor the list of DL tasks that can be undertaken in real time, and regenerate the list of DL tasks that can be undertaken when the list of DL tasks that can be undertaken is empty; The tasks stored in the undertakeable DL task list are tasks expected to be scheduled by the DL scheduler; Assignment module: configured to monitor the current task; where: When the current task meets the triggering condition for regenerating the list of DL tasks that can be undertaken, the list of DL tasks that can be undertaken is regenerated; otherwise, the type and priority of the current task are determined, and the AutoDL scheduler determines the tasks to be assigned, and the tasks to be assigned include the current task and / or other tasks that have been added to the AutoDL scheduler; The AutoDL scheduler allocates the to-be-allocated task to the DL scheduler or the RT scheduler based on the latest list of achievable DL tasks and the first list of achievable DL tasks; The first undertakeable DL task list is the undertakeable DL task list closest to the latest undertakeable DL task list and before the latest undertakeable DL task list; Among them, the trigger condition is one or two of the following conditions: the current task is to create or terminate the AutoDL scheduler; the priority of the current task is higher than or equal to a preset threshold, and the preset threshold is the priority of the task with the lowest priority in the latest list of DL tasks that can be undertaken.
6. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 4.
7. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Traffic scheduling method, device and system
CN109450803A
Real-time task scheduling method and module for non-real-time operating system, terminal and storage medium
CN112579271A