Task scheduling method and device

By employing an interrupt service cycle task scheduling method in embedded systems, tasks are arranged and executed according to their priority and attributes, thus solving the problems of uneven task execution and low resource utilization, and achieving real-time task performance and efficient resource utilization.

CN115454592BActive Publication Date: 2026-05-01TRAFFIC CONTROL TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TRAFFIC CONTROL TECH CO LTD
Filing Date
2022-08-26
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing non-preemptive scheduling methods in embedded systems result in uneven task execution, affecting real-time performance and low resource utilization, failing to meet the real-time and resource utilization requirements of embedded systems.

Method used

A task scheduling method based on interrupt service cycle is adopted. Tasks in the task pool are arranged from high to low according to task priority. The cycle execution period is determined based on task attributes. When a task reaches the cycle execution period, the target task is executed immediately and the cycle check is exited to ensure that the highest priority task is executed first.

Benefits of technology

It achieves real-time task execution and maximizes resource utilization, ensuring that tasks are executed according to the cyclical execution cycle, thus avoiding resource waste and uneven task execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115454592B_ABST
    Figure CN115454592B_ABST
Patent Text Reader

Abstract

This invention provides a task scheduling method and apparatus. The method includes: arranging all tasks in a task pool from high to low execution priority to obtain a task arrangement; determining the cyclic execution cycle of each task based on its task attributes; cyclically checking the tasks in the task arrangement based on the interrupt service cycle; when a target task in the task arrangement reaches its cyclic execution cycle, writing the target task into a task execution request and exiting the current loop; executing the target task based on the task execution request, and continuing to cyclically check the tasks in the task arrangement. The task scheduling method and apparatus provided by this invention, based on task priority, cyclically checks the tasks in the task pool to ensure the real-time execution of each task and maximize the utilization of system resources. After determining the target task to be executed, the current loop is exited, ensuring that the highest priority task is always executed sequentially.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded technology, and in particular to a task scheduling method and apparatus. Background Technology

[0002] Existing scheduling techniques for multi-tasking scenarios in the embedded field are generally based on non-preemptive methods. Non-preemptive methods employ a unified scheduling principle, dividing tasks into multiple time slices and executing them according to a fixed control cycle.

[0003] Existing non-preemptive scheduling methods impose restrictions on the tasks deployed on them; all tasks cannot exceed the total length of the current time slice. Otherwise, serious real-time issues will inevitably arise. If multiple time slices exist in the system, time statistics become even more difficult. Furthermore, due to the different task time slices, most tasks do not execute in every cycle, resulting in uneven task execution and impacting real-time performance. Summary of the Invention

[0004] This invention provides a task scheduling method and apparatus to solve the technical problem that the non-preemptive scheduling method in the prior art causes uneven task execution and affects the real-time performance of task execution.

[0005] This invention provides a task scheduling method, comprising:

[0006] Based on execution priority from high to low, all tasks in the task pool are arranged to obtain the task arrangement of all tasks.

[0007] Based on the task attributes of each task in the task arrangement, the cyclic execution cycle of each task is determined;

[0008] Based on the interrupt service cycle, the tasks in the task arrangement are checked in sequence. When the target task in the task arrangement reaches the cycle execution cycle of the target task, the target task is written into the task execution request and the current cycle is exited. The interrupt service cycle is shorter than the cycle execution cycle of each task.

[0009] Based on the task execution request, the target task is executed, and the tasks in the task arrangement are checked in a loop.

[0010] According to a task scheduling method provided by the present invention, after the step of sequentially checking the tasks in the task arrangement, the method further includes:

[0011] If none of the tasks in the task arrangement have reached their corresponding execution cycle, the task check in the task arrangement continues.

[0012] According to a task scheduling method provided by the present invention, after the step of sequentially checking the tasks in the task arrangement, the method further includes:

[0013] When a new task is added to the task arrangement, the new task is inserted into the task arrangement based on its priority.

[0014] According to a task scheduling method provided by the present invention, after inserting the new task into the task arrangement, the method further includes:

[0015] The sum of the running times of all tasks in the task arrangement containing the new task is determined to be less than the minimum cycle execution period, which is the minimum value among the cycle execution periods of all tasks in the task arrangement containing the new task.

[0016] According to a task scheduling method provided by the present invention, the step of sequentially checking the tasks in the task arrangement based on the interrupt service cycle includes:

[0017] Start the timing probes for all tasks in the task schedule;

[0018] Based on the interrupt service cycle, the tasks in the task arrangement are checked sequentially, and based on the timing probes of all tasks, it is determined whether the tasks in the task arrangement have reached the corresponding cycle execution cycle.

[0019] According to a task scheduling method provided by the present invention, after executing the target task, the method further includes:

[0020] The execution time of the target task, the execution cycle of the target task, and the CPU utilization rate of the central processing unit when the target task is executed are obtained.

[0021] The execution status of the target task is evaluated based on the execution time, the execution cycle, and the CPU utilization rate.

[0022] The present invention also provides a task scheduling device, comprising:

[0023] The task arrangement module is used to arrange all tasks in the task pool from high to low based on their execution priority, thus obtaining the task arrangement of all tasks.

[0024] The cycle execution period determination module is used to determine the cycle execution period of each task based on the task attributes of each task in the task arrangement.

[0025] The loop check module is used to check the tasks in the task arrangement in sequence based on the interrupt service loop cycle. When the target task in the task arrangement reaches the loop execution cycle of the target task, the target task is written into the task execution request and the current loop is exited. The interrupt service loop cycle is less than the loop execution cycle of each task.

[0026] The task execution module is used to execute the target task based on the task execution request, and to continue to check the tasks in the task arrangement in a loop.

[0027] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the task scheduling methods described above.

[0028] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the task scheduling method described above.

[0029] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the task scheduling method described above.

[0030] The task scheduling method and apparatus provided by this invention, based on the interrupt service cycle, cyclically checks tasks in the task pool according to task priority, and executes tasks according to their respective cycle execution times. This ensures real-time task execution while maximizing system resource utilization. After determining the target task, the current loop exits, and the system no longer checks whether lower-priority tasks have reached their execution time; instead, it continues with the next cycle check, ensuring that the highest-priority task is always executed first. Attached Figure Description

[0031] To more clearly illustrate the technical solutions in this invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly described below. Obviously, the accompanying drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0032] Figure 1 This is a flowchart illustrating the task scheduling method provided by the present invention;

[0033] Figure 2 This is a schematic diagram illustrating the task execution of the related methods provided by the present invention;

[0034] Figure 3 This is a schematic diagram of the task execution for the cyclical check of the interrupt service provided by the present invention;

[0035] Figure 4 This is a schematic diagram of a task whose total runtime is less than the minimum cycle execution period, provided by the present invention.

[0036] Figure 5 This is a schematic diagram of a task whose total runtime is greater than the minimum cycle execution period, provided by the present invention.

[0037] Figure 6 This is a schematic diagram of the device structure for applying the task scheduling method provided by the present invention;

[0038] Figure 7 This is a functional diagram of each module of the task scheduling provided by the present invention;

[0039] Figure 8 This is a schematic diagram of the external interface provided by the present invention;

[0040] Figure 9 This is a flowchart illustrating the task scheduling method provided by the present invention;

[0041] Figure 10 This is a schematic diagram of the cyclic inspection process provided by the present invention;

[0042] Figure 11 This is a schematic diagram of the task scheduling device provided by the present invention;

[0043] Figure 12 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0045] As application scenarios become increasingly complex and the demand for edge processing grows, embedded edge nodes that run simple tasks can no longer meet the needs of distributed computing. Thanks to enhanced processing capabilities, multi-task scheduling systems are gradually being applied to embedded systems.

[0046] Currently, most embedded multitasking scheduling systems are based on scheduling systems used in mature dedicated hosts, and have been modified and adapted. Their principle is to monitor and control the execution of multiple tasks through timed monitoring. When the preset task time slice expires or a higher-priority task requests a task, the stack, registers, and other resources used by the current task are saved, and the program pointer is modified to switch to another ready task. The previous task then enters a ready state to await the next scheduling. This preemptive approach can achieve multitasking scheduling and guarantee a certain level of real-time performance, but preemptive scheduling still has the following problems.

[0047] 1. Storage and computing resource consumption issues.

[0048] 2. The process of seizing control can lead to the inability to effectively control the cycle of periodic tasks.

[0049] 3. The preemption process can lead to frequent pointer switching, which may cause security issues and is not allowed in security-critical systems.

[0050] Task monitoring and switching consumes CPU computing resources and memory space resources. The shorter the task switching cycle, the better the real-time performance, but the resource consumption is also more significant.

[0051] Meeting real-time requirements involves two aspects: firstly, the task needs to sample external data at preset time points; secondly, it needs to output data at the appropriate time points. Each task deployed on an operating system typically runs in a loop. Therefore, implementing cyclical task execution requires controlling the waiting time after each run. However, a task can be interrupted and switched out at any time by a higher-priority task, resulting in inconsistent real-time performance for both data acquisition and output. Therefore, this "sometimes fast, sometimes slow" pattern is unsuitable for the real-time requirements of embedded cyclical execution.

[0052] Furthermore, the task switching process involves saving resources and switching task pointers, thus introducing uncertainty. Data errors during this process may lead to incorrect results or program crashes.

[0053] Therefore, preemptive scheduling systems are not suitable for embedded systems. Related methods employ non-preemptive approaches, which use functions as the smallest unit of scheduling. This avoids resource consumption, task cycle issues, and task security problems caused by task switching, making it more suitable for embedded scenarios where cycle control is sensitive.

[0054] Time resources are extremely valuable in computer systems, and their effective utilization determines the quality of a task scheduling system. Non-preemptive scheduling, a common approach, employs a unified scheduling principle, dividing tasks into multiple time slices and executing them according to a preset trajectory. However, this method suffers from several problems. First, the scheduling strategy imposes restrictions on the tasks deployed on it; all tasks cannot exceed the total length of the current time slice. Otherwise, serious real-time issues will inevitably arise. If multiple time slices exist in the system, time statistics become even more difficult. Furthermore, due to the different time slices of tasks, most tasks do not execute every cycle, leading to uneven task execution and impacting real-time performance. Finally, non-preemptive methods suffer from low time slice utilization, resulting in significant resource waste.

[0055] In response to the above problems, Figure 1 This is a flowchart illustrating the task scheduling method provided by the present invention. (Refer to...) Figure 1 The task scheduling method provided by this invention may include:

[0056] Step 110: Arrange all tasks in the task pool from high to low based on execution priority to obtain the task arrangement of all tasks;

[0057] Step 120: Determine the cyclic execution cycle of each task based on the task attributes of each task in the task arrangement;

[0058] Step 130: Based on the interrupt service cycle, the tasks in the task arrangement are checked in sequence. When the target task in the task arrangement reaches the cycle execution cycle of the target task, the target task is written into the task execution request and the current cycle is exited. The interrupt service cycle is less than the cycle execution cycle of each task.

[0059] Step 140: Based on the task execution request, execute the target task and continue to check the tasks in the task arrangement in a loop.

[0060] The execution subject of the task scheduling method provided by this invention can be an electronic device, a component within an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., while a non-mobile electronic device can be a server, network attached storage (NAS), or personal computer (PC), etc. This invention does not impose specific limitations.

[0061] The technical solution of this invention will be described in detail below using the example of a computer executing the task scheduling method provided by this invention.

[0062] In step 110, all tasks in the task pool are arranged in descending order of execution priority, resulting in a task arrangement of all tasks in the task pool.

[0063] This scenario involves a task pool in an embedded system where tasks are periodically scheduled. In this case, all tasks in the task pool are executed cyclically.

[0064] The priority of tasks in the task pool can be customized according to user needs or task processing requirements, or determined based on the urgency of task processing in the task pool.

[0065] In step 120, based on the task attributes of each task in the task arrangement, the cycle execution period of each task in the task pool is obtained during cyclic execution.

[0066] In embedded system scenarios, the tasks in the task pool are all executed cyclically. Therefore, each task in the task pool has its own corresponding execution cycle. When a task in the task pool is executed, it executes cyclically based on its corresponding execution cycle.

[0067] To obtain task attributes, they can be loaded into the corresponding task pool based on user-preset task attributes. These user-preset task attributes include: task name, task entry point, and task execution cycle.

[0068] In step 130, based on the interrupt service cycle of task processing, the tasks in the task pool, sorted by priority, are checked cyclically. The cyclic checking order is from highest to lowest priority in the task arrangement. When a target task is detected and its cycle execution period is reached, the target task is written into the task execution request, and the current checking cycle is exited.

[0069] The interrupt service loop is used in task scheduling to periodically check whether a task has reached its execution time. The interrupt service loop period is shorter than the individual task execution cycle.

[0070] For example, consider three tasks in the task pool: p1, p2, and p3. The execution priorities of tasks p1, p2, and p3 are as follows: p1 is the highest, p2 is the next highest, and p3 is the lowest. Task p1 has a loop execution period of 3 milliseconds, meaning it executes once every 3 milliseconds. Task p2 has a loop execution period of 2 milliseconds, meaning it executes once every 2 milliseconds. Task p3 has a loop execution period of 1 millisecond, meaning it executes once every 1 millisecond. During the execution of tasks p1, p2, and p3, the interrupt service loop period is set to 100 microseconds. The system checks each task p1, p2, and p3 every 100 microseconds to ensure that the time since their last execution has reached the corresponding loop execution period.

[0071] The loop iterates through tasks p1, p2, and p3. When it detects that p2 has been running for 2 milliseconds since its last execution, it determines that task p2 needs to be executed. Task p2 is then designated as the target task and added to the task execution request for subsequent operations. Simultaneously, the loop exits, ceasing further checks on the lower-priority task p3 and resuming the loop from the highest priority task onwards.

[0072] In step 140, after receiving the task execution request for the target task, the target task is executed. After completing the task execution, the task in the task arrangement is checked sequentially based on the interrupt service cycle.

[0073] Understandably, after writing the target task into the task execution request, the current loop exits, and the process of checking lower-priority tasks that have reached their execution time is no longer checked. Instead, the loop continues with the next check. This ensures that the highest-priority task is always executed downwards, thus guaranteeing real-time task processing.

[0074] like Figure 2The task execution diagram of the related method provided by this invention is shown. The task pool includes tasks p1, p2, and p3 for scheduling. The execution priorities of tasks p1, p2, and p3 are as follows: p1 is the highest, p2 is the second highest, and p3 is the lowest. The loop execution period for task p1 is 3 milliseconds, meaning it executes once every 3 milliseconds. The loop execution period for task p2 is 2 milliseconds, meaning it executes once every 2 milliseconds. The loop execution period for task p3 is 1 millisecond, meaning it executes once every 1 millisecond.

[0075] In the relevant methods, a non-preemptive task scheduling is employed, based on a fixed scheduling period of 1 millisecond, within which tasks are executed. Based on this fixed scheduling period, multiple 1-millisecond time slices are divided, and tasks are executed according to a preset trajectory within each time slice.

[0076] With a fixed scheduling cycle, each task can only run once within that cycle. For example, for task p3, the loop execution cycle is 1 millisecond. After running in the first scheduling cycle, it reaches its loop execution cycle in the second cycle, so it is executed first in the second cycle. This results in the execution interval between the first and second cycles being less than the 1-millisecond loop execution cycle of task p3. Similarly, in the third scheduling cycle, since both p2 and p3 have reached their loop execution cycles, and p2 has a higher priority than p3, p2 is executed first, followed by p3. This causes p3 to run in the third cycle with a time interval greater than 1 millisecond since its last execution. This prevents p3 from executing according to the set 1-millisecond loop cycle, leading to uneven task execution and severely impacting real-time performance. Meanwhile, to ensure real-time performance, all tasks in the task pool must meet the condition that they cannot exceed their scheduling cycle.

[0077] t p1 +t p2 +t p3 <1ms (1)

[0078] Among them, t p1 Let t be the execution time of task p1. p2 Let t be the execution time of task p2. p3 This refers to the execution time of task p3. Therefore, when new tasks are added later, adjustments to the scheduling cycle may be necessary.

[0079] The cyclical checking method based on interrupt services adopted in this invention, such as... Figure 3The interrupt service cycle-based cyclic checking task execution diagram provided by this invention is shown. The cyclic checking method based on the interrupt service cycle checks tasks p1, p2, and p3 in the task pool cyclically. When the target task's cycle execution period is reached, the target task is executed, ensuring the real-time execution of each task without considering the scheduling cycle in related methods. Meanwhile, the fixed scheduling cycle method in related methods results in idle states where tasks are not executed within a fixed scheduling cycle, leading to low utilization of scheduling space and resource waste. The cyclic checking method based on the interrupt service cycle, however, can determine the most suitable execution time for each task according to its cycle execution period, achieving maximum resource utilization.

[0080] The task scheduling method provided in this invention is based on an interrupt service cycle. It iteratively checks tasks in the task pool according to task priority, ensuring that tasks are executed according to their respective cycle execution times. This guarantees real-time task execution while maximizing system resource utilization. After determining the target task, the current loop exits, and the system no longer checks whether lower-priority tasks have reached their execution time. Instead, it continues with the next iteration, ensuring that the highest-priority task is always executed first.

[0081] In one embodiment, after sequentially checking the tasks in the task arrangement, the method further includes: if none of the tasks in the task arrangement have reached their corresponding execution cycle, continuing to check the tasks in the task arrangement.

[0082] During the task cycle check in the task schedule, when a target task in the task schedule reaches its corresponding execution cycle, the target task is written into the task execution request, and the current cycle is exited. However, if it is determined that none of the tasks have reached their corresponding execution cycle during the task cycle check in the task schedule, the check process for the tasks in the task schedule continues to run in a loop.

[0083] Optionally, when performing a cyclic check on tasks in the task queue, the necessary clock resources and time probes are initialized first. After the tasks in the task pool are sorted according to their priority, the time probes are started. Based on the time probes of each task, the execution time of each task and whether the cycle has been reached since the last execution are determined.

[0084] The task scheduling method provided in this embodiment of the invention is based on the interrupt service cycle and checks the tasks in the task pool in a loop according to the task priority. It can execute according to the loop execution cycle of each task, so as to maximize the utilization of system resources while ensuring that each task is executed according to the requirements of the loop execution cycle.

[0085] In one embodiment, after sequentially checking the tasks in the task arrangement, the method further includes: if a new task is added to the task arrangement, inserting the new task into the task arrangement based on the priority of the new task.

[0086] During the task cycle check, new tasks may be added to the task pool. For tasks that need to be added to the task pool, the new task is added to the original task arrangement based on its priority relative to all tasks in the original task pool.

[0087] When adding a new task to the task scheduler, there may be cases where the total runtime of all tasks in the new task scheduler is less than or greater than the minimum loop execution cycle. The minimum loop execution cycle is the shortest loop execution cycle among all tasks in the new task scheduler.

[0088] When the total task duration is less than the minimum scheduling period, the running effect is as follows: Figure 4 The present invention provides a task execution diagram where the total task runtime is less than the minimum loop execution cycle. As shown, two periodic tasks, p1 and p2, each run with a 1ms cycle and do not interfere with each other. A task p3 is temporarily inserted, occupying the time that should belong to p2. After p3 completes, task p1 is executed, resulting in a total delay of less than 1ms. After dynamically adjusting to a suitable position, executing p3 again will not cause any delay.

[0089] When the total task duration exceeds the minimum scheduling period, the execution effect is as follows: Figure 5 The task execution diagram provided by this invention, showing a total task runtime greater than the minimum loop execution cycle, is shown below. Figure 4 The situation is similar, but resources are now nearing saturation. When a task p3 is inserted, occupying time that should belong to p2, p3 is dynamically adjusted to be executed later. By this time, both p1 and p2 have already received execution requests, so the higher-priority task p1 is executed first, followed by task p2. At this point, the delay for the highest-priority task does not exceed 1ms, while the delay for lower-priority tasks is also guaranteed to be within a reasonable range. After p1 and p2 are dynamically adjusted, there will be no delays in subsequent processes.

[0090] The task scheduling method provided in this embodiment of the invention inserts a new task into the task arrangement based on its priority when a new task is added. This ensures real-time task processing regardless of whether the total duration of the new task arrangement is less than or greater than the minimum scheduling period.

[0091] In one embodiment, after inserting the new task into the task arrangement, the method further includes: determining that the sum of the running times of all tasks in the task arrangement containing the new task is less than the minimum cycle execution period, wherein the minimum cycle execution period is the minimum value among the cycle execution periods of all tasks in the task arrangement containing the new task.

[0092] It is understandable that if the execution resources are already saturated when the original task schedule is being executed after a new task is inserted, the insertion of the new task will affect the real-time performance of the task schedule.

[0093] If the sum of the running times of all tasks in the task schedule for the new task is less than the minimum loop execution cycle, the real-time performance of the task schedule can be guaranteed. If the sum of the running times of all tasks in the task schedule for the new task is greater than or equal to the minimum loop execution cycle, the system scheduling operation mode can be further adjusted to ensure both the normal operation of all tasks and real-time performance.

[0094] The task scheduling method provided in this embodiment of the invention determines that the sum of the running times of all tasks in a task arrangement containing a new task is less than the minimum cycle execution period, thus ensuring the real-time performance of the task arrangement.

[0095] In one embodiment, based on the interrupt service cycle, the tasks in the task arrangement are checked sequentially, including: starting the timing probes of all tasks in the task arrangement; checking the tasks in the task arrangement sequentially based on the interrupt service cycle; and determining, based on the timing probes of all tasks, whether the tasks in the task arrangement have reached their corresponding execution cycle.

[0096] Before performing a cyclical check on the tasks in the task queue, the necessary clock resources and time probes are initialized. Each task contains a timing probe that references the same system clock.

[0097] After tasks in the task pool are sorted by priority to obtain the task order, a timing probe is started to time each task in the task order. During the cyclical check of tasks in the task order, based on the interrupt service loop cycle, the timing probes of each task in the task order are checked sequentially to see if the corresponding loop execution cycle has been reached. That is, based on the timing probes of each task, it is determined whether the time since the last execution of each task has reached the corresponding loop execution cycle.

[0098] The task scheduling method provided in this embodiment of the invention, based on a timing probe, determines whether each task in the task arrangement has reached its corresponding cycle execution period, thereby achieving accurate determination of whether all tasks in the task arrangement have reached their corresponding cycle execution period, and providing a foundation for ensuring the real-time performance of task execution.

[0099] In one embodiment, after executing the target task, the method further includes: obtaining the execution time of the target task, the execution cycle of the target task, and the CPU utilization rate of the central processing unit when the target task is executed; and evaluating the execution status of the target task based on the execution time, the execution cycle, and the CPU utilization rate.

[0100] After executing the target task, the execution time, the execution cycle of the target task, and the CPU utilization during the execution of the target task are obtained. Among them, the execution time of the target task can be obtained by requesting a virtual probe when the target task is determined to start execution, and calculating the specific time taken to execute the target task based on the virtual probe.

[0101] The execution cycle of a target task is the interval between its actual loop executions. It measures the real-time performance of the target task. If the execution cycle of the target task is the same for each loop, then the real-time performance of the target task is considered high. The CPU utilization rate during target task execution reflects the consumption of system resources.

[0102] By analyzing the execution time, execution cycle, and CPU utilization of the target task, it is possible to evaluate the execution status of the target task during execution.

[0103] Optionally, when analyzing CPU utilization, the CPU utilization of all tasks in the task schedule can be analyzed to assess the current system resource usage. The CPU utilization t during the execution of all tasks in the task schedule is shown below. cpu It can be:

[0104]

[0105] Where i is the index of the task in the task arrangement, t pi Let represent the time taken by the i-th task in the task arrangement, and T represent the period used by the CPU utilization statistics task.

[0106] The task scheduling method provided in this embodiment of the invention can evaluate the execution status of the target task based on the analysis of the execution time, execution cycle and CPU utilization during execution, thus providing a basis for subsequent optimization of the task scheduling execution process based on the evaluation results.

[0107] The following is a schematic diagram of a device structure applying the task scheduling method provided by this invention. Figure 6 Taking an example, the technical solution provided by the present invention is illustrated. The device includes: a task loading module 610, a task monitoring module 620, a task execution module 630, and an evaluation module 640.

[0108] The task loading module 610 is used to load user-preset task attributes into the task pool. These task attributes include task name, task entry point, and task execution cycle. Based on the task attributes of each task in the task arrangement, the cyclic execution cycle of each task is determined. Simultaneously, based on execution priority from high to low, all tasks in the task pool are arranged to obtain a task arrangement for all tasks.

[0109] The task monitoring module 620 is used to periodically check whether the tasks in the task arrangement need to be executed according to priority. The standard for a task to be executed is that the task has reached its respective cycle execution period. Once the target task is found to have reached the time required for execution, the target task is immediately written into the task execution request and executed and exited immediately without checking other low-priority tasks.

[0110] The task execution module 630 is used to execute the target task based on the task execution request and continue to check the tasks in the task arrangement in a loop.

[0111] The evaluation module 640 is used to obtain the execution time of the target task, the execution cycle of the target task, and the CPU utilization rate during the execution of the target task. Based on the execution time, execution cycle, and CPU utilization rate, the execution status of the target task is evaluated, which facilitates the troubleshooting of problems in the task execution and scheduling process. Figure 7 The functional diagram of the task scheduling modules provided by this invention is shown. Besides the task loading and execution functions, it also includes an execution status evaluation function and a scheduling optimization function. Specifically, the execution status evaluation function evaluates the execution time of the target task based on its execution time; it evaluates the real-time performance of the target task based on its cyclic execution cycle; and it evaluates the CPU utilization rate of the target task during execution. After completing the execution status evaluation of the target task, the scheduling optimization function can be implemented based on the evaluation results.

[0112] Among them, the external interface of the device applying the task scheduling method provided by the present invention is as follows: Figure 8 As shown in the external interface diagram provided by the present invention, the external interface of the device applying the task scheduling method provided by the present invention includes an application layer, a platform layer, and a hardware abstraction layer.

[0113] The platform layer is responsible for scheduling tasks based on the task loading module 610, task monitoring module 620, and task execution module 630. The application layer evaluates the running status of tasks based on the evaluation module 640. The hardware abstraction layer provides hardware support such as clock sources and time probes for task scheduling.

[0114] The following is a flowchart illustrating an application of the task scheduling method provided by this invention. Figure 9 For example, the technical solution provided by this invention will be explained:

[0115] Step 910: Initialize the required clock resources and initialize the time probe, which references the system clock source.

[0116] Step 920: Import the task attributes into the corresponding task in the task pool. The tasks are arranged from high priority to low priority to obtain the task arrangement, and the start timer probe of each task is initialized.

[0117] Step 930: Based on a 100-microsecond interrupt service loop cycle, sequentially check the tasks in the task queue. The loop check process is as follows: Figure 10 The schematic diagram of the loop checking process provided by this invention is shown. When the target task in the task arrangement reaches its loop execution cycle, the target task is written into the task execution request, and the current loop is exited. If the loop execution cycle has not been reached, the remaining tasks are checked.

[0118] Step 940: Execute the target task based on the task execution request, and continue to check the tasks in the task queue in a loop.

[0119] Step 950: Obtain the execution time of the target task, the execution cycle of the target task, and the CPU utilization rate of the central processing unit during the execution of the target task. Based on the execution time, execution cycle, and CPU utilization rate, evaluate the execution status of the target task.

[0120] Figure 11 A schematic diagram of the task scheduling device provided by the present invention is shown below. Figure 11 As shown, the device includes:

[0121] The task arrangement module 1110 is used to arrange all tasks in the task pool from high to low based on execution priority, so as to obtain the task arrangement of all tasks.

[0122] The cycle execution period determination module 1120 is used to determine the cycle execution period of each task based on the task attributes of each task in the task arrangement.

[0123] The loop checking module 1130 is used to check the tasks in the task arrangement in sequence based on the interrupt service loop period. When the target task in the task arrangement reaches the loop execution period of the target task, the target task is written into the task execution request and the current loop is exited. The interrupt service loop period is less than the loop execution period of each task.

[0124] The task execution module 1140 is used to execute the target task based on the task execution request, and to continue to check the tasks in the task arrangement in a loop.

[0125] The task scheduling device provided in this embodiment of the invention, based on the interrupt service cycle, cyclically checks tasks in the task pool according to task priority, and executes tasks according to their respective cycle execution periods. This ensures real-time task execution while maximizing system resource utilization. After determining the target task, the current loop exits, and the device no longer checks whether lower-priority tasks have reached their execution time. Instead, it continues the next cycle check process, ensuring that the highest-priority task is always executed first.

[0126] In one embodiment, the loop check module 1130 is specifically used for:

[0127] After the sequential cyclical check of the tasks in the task arrangement, the method further includes:

[0128] If none of the tasks in the task arrangement have reached their corresponding execution cycle, the task check in the task arrangement continues.

[0129] In one embodiment, the loop checking module 1130 is further configured to:

[0130] After the sequential cyclical check of the tasks in the task arrangement, the method further includes:

[0131] When a new task is added to the task arrangement, the new task is inserted into the task arrangement based on its priority.

[0132] In one embodiment, the loop checking module 1130 is further configured to:

[0133] After inserting the new task into the task arrangement, the process further includes:

[0134] The sum of the running times of all tasks in the task arrangement containing the new task is determined to be less than the minimum cycle execution period, which is the minimum value among the cycle execution periods of all tasks in the task arrangement containing the new task.

[0135] In one embodiment, the loop checking module 1130 is further configured to:

[0136] Based on the interrupt service cycle, the tasks in the task arrangement are checked sequentially, including:

[0137] Start the timing probes for all tasks in the task schedule;

[0138] Based on the interrupt service cycle, the tasks in the task arrangement are checked sequentially, and based on the timing probes of all tasks, it is determined whether the tasks in the task arrangement have reached the corresponding cycle execution cycle.

[0139] In one embodiment, the task execution module 1140 is specifically used for:

[0140] After executing the target task, the process also includes:

[0141] The execution time of the target task, the execution cycle of the target task, and the CPU utilization rate of the central processing unit when the target task is executed are obtained.

[0142] The execution status of the target task is evaluated based on the execution time, the execution cycle, and the CPU utilization rate.

[0143] Figure 12 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 12 As shown, the electronic device may include: a processor 1210, a communications interface 1220, a memory 1230, and a communication bus 1240, wherein the processor 1210, the communications interface 1220, and the memory 1230 communicate with each other via the communication bus 1240. The processor 1210 can call logical instructions in the memory 1230 to execute a task scheduling method, which includes:

[0144] Based on execution priority from high to low, all tasks in the task pool are arranged to obtain the task arrangement of all tasks.

[0145] Based on the task attributes of each task in the task arrangement, the cyclic execution cycle of each task is determined;

[0146] Based on the interrupt service cycle, the tasks in the task arrangement are checked in sequence. When the target task in the task arrangement reaches the cycle execution cycle of the target task, the target task is written into the task execution request and the current cycle is exited. The interrupt service cycle is shorter than the cycle execution cycle of each task.

[0147] Based on the task execution request, the target task is executed, and the tasks in the task arrangement are checked in a loop.

[0148] Furthermore, the logical instructions in the aforementioned memory 1230 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0149] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, wherein when the program instructions are executed by a computer, the computer is able to execute the task scheduling method provided by the above methods, the method comprising:

[0150] Based on execution priority from high to low, all tasks in the task pool are arranged to obtain the task arrangement of all tasks.

[0151] Based on the task attributes of each task in the task arrangement, the cyclic execution cycle of each task is determined;

[0152] Based on the interrupt service cycle, the tasks in the task arrangement are checked in sequence. When the target task in the task arrangement reaches the cycle execution cycle of the target task, the target task is written into the task execution request and the current cycle is exited. The interrupt service cycle is shorter than the cycle execution cycle of each task.

[0153] Based on the task execution request, the target task is executed, and the tasks in the task arrangement are checked in a loop.

[0154] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the task scheduling methods provided above, the method comprising:

[0155] Based on execution priority from high to low, all tasks in the task pool are arranged to obtain the task arrangement of all tasks.

[0156] Based on the task attributes of each task in the task arrangement, the cyclic execution cycle of each task is determined;

[0157] Based on the interrupt service cycle, the tasks in the task arrangement are checked in sequence. When the target task in the task arrangement reaches the cycle execution cycle of the target task, the target task is written into the task execution request and the current cycle is exited. The interrupt service cycle is shorter than the cycle execution cycle of each task.

[0158] Based on the task execution request, the target task is executed, and the tasks in the task arrangement are checked in a loop.

[0159] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0160] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A task scheduling method, characterized in that, include: Based on execution priority from high to low, all tasks in the task pool are arranged to obtain the task arrangement of all tasks. Based on the task attributes of each task in the task arrangement, the cyclic execution cycle of each task is determined; Based on the interrupt service cycle, the tasks in the task arrangement are checked in sequence. When the target task in the task arrangement reaches the cycle execution cycle of the target task, the target task is written into the task execution request and the current cycle is exited. The interrupt service cycle is shorter than the cycle execution cycle of each task. Based on the task execution request, execute the target task, and continue to check the tasks in the task queue in a loop; After the sequential cyclical check of the tasks in the task arrangement, the method further includes: When a new task is added to the task arrangement, the new task is inserted into the task arrangement based on its priority. The sum of the running times of all tasks in the task arrangement containing the new task is determined to be less than the minimum cycle execution period, which is the minimum value among the cycle execution periods of all tasks in the task arrangement containing the new task.

2. The task scheduling method according to claim 1, characterized in that, After the sequential cyclical check of the tasks in the task arrangement, the method further includes: If none of the tasks in the task arrangement have reached their corresponding execution cycle, the task check in the task arrangement continues.

3. The task scheduling method according to claim 1, characterized in that, The sequential cyclical check of tasks in the task arrangement based on the interrupt service cycle includes: Start the timing probes for all tasks in the task schedule; Based on the interrupt service cycle, the tasks in the task arrangement are checked sequentially, and based on the timing probes of all tasks, it is determined whether the tasks in the task arrangement have reached the corresponding cycle execution cycle.

4. The task scheduling method according to claim 1, characterized in that, After executing the target task, the process also includes: The execution time of the target task, the execution cycle of the target task, and the CPU utilization rate of the central processing unit when the target task is executed are obtained. The execution status of the target task is evaluated based on the execution time, the execution cycle, and the CPU utilization rate.

5. A task scheduling device, characterized in that, include: The task arrangement module is used to arrange all tasks in the task pool from high to low based on their execution priority, thus obtaining the task arrangement of all tasks. The cycle execution period determination module is used to determine the cycle execution period of each task based on the task attributes of each task in the task arrangement. The loop check module is used to check the tasks in the task arrangement in sequence based on the interrupt service loop cycle. When the target task in the task arrangement reaches the loop execution cycle of the target task, the target task is written into the task execution request and the current loop is exited. The interrupt service loop cycle is less than the loop execution cycle of each task. The task execution module is used to execute the target task based on the task execution request, and to continue to check the tasks in the task arrangement in a loop. After the sequential cyclical check of the tasks in the task arrangement, the method further includes: When a new task is added to the task arrangement, the new task is inserted into the task arrangement based on its priority. The sum of the running times of all tasks in the task arrangement containing the new task is determined to be less than the minimum cycle execution period, which is the minimum value among the cycle execution periods of all tasks in the task arrangement containing the new task.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the task scheduling method as described in any one of claims 1 to 4.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the task scheduling method as described in any one of claims 1 to 4.

8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the task scheduling method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Airborne software task blocking processing method based on DSP

    CN114201274A