Search

CN-121996367-A - Task scheduling method, device, electronic equipment, storage medium and program product

CN121996367ACN 121996367 ACN121996367 ACN 121996367ACN-121996367-A

Abstract

The application provides a task scheduling method, a task scheduling device, electronic equipment, a storage medium and a program product, and relates to the technical field of computers. The method comprises the steps of determining a task scheduling table of a plurality of periodic tasks, wherein the task scheduling table comprises task scheduling moments of each periodic task, determining time intervals between two task scheduling moments after the current task scheduling moment according to the task scheduling moments in the task scheduling table, preloading the time intervals to a task timer, and scheduling the plurality of periodic tasks based on the task timer, so that the periodic tasks can be independently maintained through the task scheduling table, and the task scheduling can be carried out by triggering interrupt according to the task scheduling moments in the task scheduling table, namely the task timer can trigger interrupt according to the time intervals, interrupt processing is not required according to a minimum time slice, and CPU load can be effectively reduced.

Inventors

  • CHEN DU
  • ZHANG BIN

Assignees

  • 宁德时代未来能源(上海)研究院有限公司
  • 宁德时代新能源科技股份有限公司

Dates

Publication Date
20260508
Application Date
20241107

Claims (12)

  1. 1. A method of task scheduling, the method comprising: Determining a task schedule of a plurality of periodic tasks, wherein the task schedule comprises task scheduling moments of each periodic task; Determining the time interval between two task scheduling moments after the current task scheduling moment according to the task scheduling moment in the task scheduling table; And preloading the time interval to a task timer, and scheduling the plurality of periodic tasks based on the task timer.
  2. 2. The method of claim 1, wherein the task schedule is a linked list structure, wherein the linked list structure is formed by linking each periodic task sequentially according to its task scheduling time, the last task scheduling time is the least common multiple of the periods of the plurality of periodic tasks, and the remaining task scheduling times are arranged in order according to integer multiples of the periods of each periodic task.
  3. 3. A method as claimed in claim 2, wherein, in the event that there are a plurality of task scheduling instants which are the same, the plurality of task scheduling instants are ordered in the task schedule according to the priority of the respective periodic tasks.
  4. 4. The method of claim 1, wherein determining a time interval between two task scheduling moments after a current task scheduling moment according to task scheduling moments in the task schedule comprises: When periodic tasks corresponding to the ith task scheduling moment are scheduled, calculating a time interval between the (i+1) th task scheduling moment and the (i+2) th task scheduling moment, wherein i is an integer greater than or equal to 2; The preloading the time interval to a task timer and scheduling the plurality of periodic tasks based on the task timer includes: Preloading the time interval to a register of a task timer; When the periodic task corresponding to the (i+1) th task scheduling moment is scheduled, assigning the time interval to a register of the task timer; And when the task timer reaches the value of the register, scheduling the periodic task corresponding to the (i+2) th task scheduling moment.
  5. 5. The method of claim 1, wherein the scheduling the plurality of periodic tasks based on the task timer comprises: and under the condition that the task timer has at least two periodic tasks to be scheduled at the same time, scheduling according to the priorities of the at least two periodic tasks.
  6. 6. The method of claim 5, wherein, in the case that the task timer has at least two periodic tasks to be scheduled at the same time, scheduling according to the priorities of the at least two periodic tasks comprises: under the condition that the task timer has at least two periodic tasks to be scheduled at the same time, adding the at least two periodic tasks into a task ready list; and scheduling periodic tasks in the task ready list according to the priority level.
  7. 7. The method of claim 6, wherein said scheduling periodic tasks in said task ready list according to priority levels is followed by: and deleting the periodic task from the task ready list after the periodic task is executed.
  8. 8. The method of claim 6, wherein the method further comprises: And under the condition that no periodic task exists in the task ready list, entering a task idle state, wherein the execution state of each periodic task is monitored by a task state machine.
  9. 9. A task scheduling device, the device comprising: The scheduling table determining module is used for determining task scheduling tables of a plurality of periodic tasks, wherein the task scheduling tables comprise task scheduling moments of the periodic tasks; The time interval determining module is used for determining the time interval between two task scheduling moments after the current task scheduling moment according to the task scheduling moment in the task scheduling table; And the task scheduling module is used for preloading the time interval to a task timer and scheduling the periodic tasks based on the task timer.
  10. 10. An electronic device comprising a processor and a memory storing computer readable instructions that, when executed by the processor, perform the method of any of claims 1-8.
  11. 11. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, performs the method according to any of claims 1-8.
  12. 12. A computer program product comprising computer program instructions which, when read and executed by a processor, perform the method of any of claims 1-8.

Description

Task scheduling method, device, electronic equipment, storage medium and program product Technical Field The present application relates to the field of computer technologies, and in particular, to a task scheduling method, apparatus, electronic device, storage medium, and program product. Background With the development of computer technology, application of a multitasking operating system, such as Windows, linux, QNX (Quick UNIX), freeRTOS, etc., is becoming more and more popular. In a multi-task scheduling algorithm, interrupts are typically generated every minimum time slice, typically determined based on the greatest common divisor of a plurality of periodic tasks, by defining a minimum time slice, by a system interrupt or hardware timer. When the interrupt is processed each time, the currently executed task needs to be paused to transfer to the interrupt service related to processing, and the execution of the task is returned to continue after the interrupt is completed. Since the minimum time slices are typically short in duration, interrupts are frequent, often interrupting current task execution, thereby increasing CPU load. Disclosure of Invention An objective of the embodiments of the present application is to provide a task scheduling method, apparatus, electronic device, storage medium and program product, so as to solve the problem that the load of a CPU increases due to frequent interruption in the existing manner. In a first aspect, an embodiment of the present application provides a task scheduling method, where the method includes: Determining a task schedule of a plurality of periodic tasks, wherein the task schedule comprises task scheduling moments of each periodic task; Determining the time interval between two task scheduling moments after the current task scheduling moment according to the task scheduling moment in the task scheduling table; And preloading the time interval to a task timer, and scheduling the plurality of periodic tasks based on the task timer. In the implementation process, the task scheduling table of the plurality of periodic tasks is determined, the task scheduling table comprises task scheduling moments of the periodic tasks, then the time interval between two task scheduling moments after the current task scheduling moment is determined according to the task scheduling moments in the task scheduling table, the time interval is preloaded to the task timer, and the plurality of periodic tasks are scheduled based on the task timer, so that the periodic tasks can be independently maintained through the task scheduling table, the task scheduling is carried out by triggering interruption according to the task scheduling moments in the task scheduling table, namely the task timer can trigger interruption according to the time interval, interruption processing is not required according to a minimum time slice, and the CPU load can be effectively reduced. Optionally, the task schedule is a linked list structure, wherein the linked list structure is formed by linking each periodic task in turn according to the task scheduling time, the last task scheduling time is the least common multiple of the periods of the periodic tasks, and the rest task scheduling times are arranged in sequence according to the integer multiple of the periods of each periodic task. In the implementation process, the periodic tasks are maintained through the task scheduling table with the linked list structure, so that the scheduling flow can be simplified, the scheduling is only performed according to the task scheduling time in the task scheduling table, the time required for searching the next task is reduced, and the scheduling efficiency is higher. Optionally, in the case that there are multiple task scheduling moments that are the same, the multiple task scheduling moments are ordered in the task schedule according to priorities of corresponding periodic tasks. In the implementation process, the priorities of the tasks are directly reflected in the task scheduling table, so that the tasks are directly scheduled according to the task scheduling table, the time for judging the priorities can be saved, and the scheduling efficiency is improved. Optionally, the determining, according to the task scheduling time in the task scheduling table, a time interval between two task scheduling times after the current task scheduling time includes: When periodic tasks corresponding to the ith task scheduling moment are scheduled, calculating a time interval between the (i+1) th task scheduling moment and the (i+2) th task scheduling moment, wherein i is an integer greater than or equal to 2; The preloading the time interval to a task timer and scheduling the plurality of periodic tasks based on the task timer includes: Preloading the time interval to a register of a task timer; When the periodic task corresponding to the (i+1) th task scheduling moment is scheduled, assigning the time interval to a registe