CN117421106A - Task scheduling method, system and equipment for embedded software - Google Patents
Task scheduling method, system and equipment for embedded software Download PDFInfo
- Publication number
- CN117421106A CN117421106A CN202311686449.3A CN202311686449A CN117421106A CN 117421106 A CN117421106 A CN 117421106A CN 202311686449 A CN202311686449 A CN 202311686449A CN 117421106 A CN117421106 A CN 117421106A
- Authority
- CN
- China
- Prior art keywords
- task
- variable
- scheduling
- executing
- embedded software
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 57
- 230000009191 jumping Effects 0.000 claims abstract description 8
- 230000006870 function Effects 0.000 claims description 49
- 230000000737 periodic effect Effects 0.000 claims description 15
- 238000004590 computer program Methods 0.000 claims description 3
- 230000008878 coupling Effects 0.000 abstract description 5
- 238000010168 coupling process Methods 0.000 abstract description 5
- 238000005859 coupling reaction Methods 0.000 abstract description 5
- 230000008569 process Effects 0.000 description 11
- 238000004891 communication Methods 0.000 description 9
- 238000010586 diagram Methods 0.000 description 5
- 238000012545 processing Methods 0.000 description 3
- 238000003491 array Methods 0.000 description 2
- 230000007547 defect Effects 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 239000000463 material Substances 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000012163 sequencing technique Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000012217 deletion Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005538 encapsulation Methods 0.000 description 1
- 230000007613 environmental effect Effects 0.000 description 1
- 239000004744 fabric Substances 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000011084 recovery Methods 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 230000004043 responsiveness Effects 0.000 description 1
- 239000000725 suspension Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/485—Task life-cycle, e.g. stopping, restarting, resuming execution
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/5038—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The invention relates to the technical field of embedded software development, and particularly discloses a task scheduling method, a system and equipment of embedded software, wherein the method comprises the following steps: s10: creating and initializing a task management structure for storing and managing tasks; s20: registering a new task and adding the new task into a task management structure; s30: judging whether all registered tasks are executed, if yes, ending task scheduling, and if not, executing S40; s40: traversing the tasks in the task management structure body and calculating the difference value between the current time variable and the last task scheduling time variable; s50: and judging whether the difference value is greater than or equal to a preset task period variable, if so, executing the task, updating the task scheduling time variable of the last time, and then jumping to execute the S30, and if not, directly jumping to execute the S30. The invention can make the structure layering of task scheduling clear, and reduce the code coupling degree and resource consumption, thereby meeting the requirement of millisecond-level scheduling time.
Description
Technical Field
The invention relates to the technical field of embedded software development, in particular to a task scheduling method, a task scheduling system and task scheduling equipment for embedded software.
Background
Embedded software refers to software running in an embedded device (e.g., an embedded multitasking vehicle controller device) that typically needs to perform a variety of functions and tasks such as data acquisition, signal processing, communication protocols, user interfaces, etc. In order to efficiently manage and execute these tasks, the tasks need to be scheduled to ensure real-time, reliability and performance of the tasks.
The existing time-sharing scheduling method for embedded software tasks is characterized in that a task management queue is set by initializing execution basic information of each task, and the tasks to be executed are added into the task management queue; and then, a task scheduling function is called in a time sharing manner, the task execution period is divided into a plurality of time slices, each time slice inquires about task management queue members, whether the task management queue members need to execute the corresponding tasks is judged, if the task management queue members need to execute the corresponding tasks, the task execution function is called according to the execution frequency until the task execution is completed or the execution time is exceeded, and finally, the task is deleted from the queue according to whether the self-deletion mark is allowed or not.
However, although the task scheduling can be realized by the method, the method still has the defects of unclear structure layering, high code coupling degree, high resource consumption and incapability of meeting the requirement of millisecond-level scheduling time.
Disclosure of Invention
The invention provides the following technical scheme for overcoming the defects of high code coupling degree, large resource consumption and incapability of meeting millisecond-level scheduling time requirements of the existing embedded software task scheduling method:
in a first aspect, the present invention provides a task scheduling method for embedded software, including:
s10: a task management structure for storing and managing registered tasks is created and initialized.
S20: registering a new task and adding the new task to the task management structure.
S30: and judging whether all the registered tasks are executed, if so, ending task scheduling, and if not, executing S40.
S40: traversing the tasks in the task management structure body, and calculating the difference value between the current time variable and the last task scheduling time variable.
S50: and judging whether the difference value is larger than or equal to a preset task period variable, if so, executing the task currently traversed, updating the task scheduling time variable last time, and then jumping to execute the S30, and if not, directly jumping to execute the S30 without executing the task currently traversed.
As a preferable technical scheme, the task management structure body comprises a task array, a task registration number variable and a current time variable.
The task array is used for distributing idle array positions for the newly registered tasks.
The task registration number variable is used for recording the number of the tasks currently registered.
The current time variable is used for storing a time stamp of the current system.
As a preferable technical scheme, the structural members in the task array comprise a task callback function, a task period variable, a last task scheduling time variable and a task ID variable.
In S20, the step of registering a new task and adding the new task to the task management structure includes:
and acquiring the idle position in the task array according to the current task registration number variable.
And respectively assigning the current task callback function, the current task period variable, the current time variable and the current array index assignment to the task callback function, the task period variable, the last task scheduling time variable and the task ID variable in the task structure body pointer.
And adding the task registration number variable by 1.
As a preferred embodiment, in S20, the method further includes: after registering the new task, the new task is set as a dynamic adjustment task or a periodic task.
As a preferred embodiment, in S50, the method further includes:
when executing the currently traversed task, if the actual execution time of the executed task is greater than the preset task period variable and the executed task is set to be a dynamic adjustment task, the preset task period variable is automatically increased to be greater than the actual execution time of the executed task.
As a preferred embodiment, in S50, the method further includes: when executing the task currently traversed, if the task is set as a periodic task, adding the task period variable of the task to the last task scheduling time variable of the task after the task is executed, obtaining the next task scheduling time variable of the task, and reinserting the task into a task management structure body according to the size of the next task scheduling time variable.
As a preferred technical solution, the executing the task currently traversed includes:
and taking out the task structure body of the currently traversed task from the task management structure body.
And obtaining the address of the task callback function from the task structure body, and calling the task callback function of the task through the address.
And executing the logic corresponding to the task by using the task callback function.
When executing logic corresponding to a currently traversed task by using the task callback function, if a condition or event needing to be waited is met, setting a task state variable of the task as a block, removing the task from a task management structure body, and adding the current task into the task management structure body again until the condition or event is met, and continuing executing logic corresponding to the currently traversed task by using the task callback function.
In a second aspect, the present invention further provides a task scheduling method for embedded software, including:
and the task management module is used for creating and initializing a task management structure body for storing and managing the registered tasks.
And the task registration module is used for registering a new task and adding the new task into the task management structure body. And judging whether all the registered tasks are executed, if so, ending task scheduling, and if not, calling a task scheduling module to perform task scheduling.
And the task scheduling module is used for traversing the task in the task management module, calculating the difference value between the current time variable and the last task scheduling time variable, executing the currently traversed task when the difference value is larger than or equal to a preset task period variable, updating the last task scheduling time variable, and not executing the currently traversed task when the difference value is smaller than the preset task period variable.
In a third aspect, the present invention also proposes an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the operations performed by the task scheduling method of embedded software as described in the first aspect when the program is executed.
The beneficial effects of the invention at least comprise:
(1) The invention separates the task storage and management from the task registration, realizes the dynamic registration and scheduling of the task, and compared with the traditional embedded software task scheduling method, the method generally needs to predefine all tasks in codes and sequentially execute the tasks in a fixed cycle, thereby reducing the code coupling degree.
(2) According to the invention, whether the task traversed currently is needed to be executed is judged according to the difference value of the current time variable and the time variable of the task scheduling last time, so that unnecessary task execution is avoided, different task scheduling periods can be set according to the real-time requirements of different tasks, and compared with the traditional embedded software task scheduling method, the method has the advantages that a fixed scheduling period or preemptive scheduling based on priority is generally needed, the resource consumption is reduced, and the requirement of millisecond scheduling time is met.
Drawings
Fig. 1 is a flow chart of an embedded software task scheduling method according to an embodiment of the present application.
Fig. 2 is a schematic diagram of an embedded software task scheduling system according to an embodiment of the present application.
Fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Further advantages and effects of the present invention will be readily apparent to those skilled in the art from the disclosure herein, by referring to the accompanying drawings and the preferred embodiments. The invention may be practiced or carried out in other embodiments that depart from the specific details, and the details of the present description may be modified or varied from the spirit and scope of the present invention. It should be understood that the preferred technical scheme is only for illustrating the present invention and is not intended to limit the protection scope of the present invention.
It should be noted that the illustrations provided in the following embodiments merely illustrate the basic concept of the present invention by way of illustration, and only the components related to the present invention are shown in the drawings and are not drawn according to the number, shape and size of the components in actual implementation, and the form, number and proportion of the components in actual implementation may be arbitrarily changed, and the layout of the components may be more complicated.
In the following description, numerous details are set forth in order to provide a more thorough explanation of embodiments of the present invention, it will be apparent, however, to one skilled in the art that embodiments of the present invention may be practiced without these specific details, in other embodiments, well-known structures and devices are shown in block diagram form, rather than in detail, in order to avoid obscuring the embodiments of the present invention.
Specifically, fig. 1 is a flow chart of a task scheduling method of embedded software provided in an embodiment of the present application.
As shown in fig. 1, the task scheduling method of the embedded software includes the following steps:
s10: a task management structure for storing and managing registered tasks is created and initialized.
Optionally, in one embodiment of the present application, the task management structure includes a task array, a task registration number variable, and a current time variable.
The task array is used for distributing idle array positions for the newly registered tasks.
The task registration number variable is used for recording the number of the tasks currently registered.
The current time variable is used for storing a time stamp of the current system.
By way of example, the task array is an array storing a plurality of strTask types, strTask being a structure for managing a single task, the structure including a task callback function pFUN, a task Period variable u32Period, a last scheduling time variable u32ms0, and a task ID variable u8ID. The task callback function pFun points to the specific execution logic of each task. The task Period variable u32Period represents the execution interval of each task in milliseconds. The last scheduled time variable u32ms0 represents the last scheduled time stamp of each task in milliseconds. The task ID variable u8ID represents the index position of each task in the array. The task registration number variable regTaskIdx is used for recording the number of the tasks registered currently and distributing idle array positions for the tasks registered newly. The current time variable u32ms1 is used for storing a time stamp of the current system.
S20: registering a new task and adding the new task to the task management structure.
Optionally, in an embodiment of the present application, the structural member in the task array includes a task callback function, a task period variable, a last task scheduling time variable, and a task ID variable. The registering and adding the new task to the task management structure includes:
and acquiring the idle position in the task array according to the current task registration number variable.
And respectively assigning the current task callback function, the current task period variable, the current time variable and the current array index assignment to the task callback function, the task period variable, the last task scheduling time variable and the task ID variable in the task structure body pointer.
And adding the task registration number variable by 1.
In this embodiment, the task registration function is used to receive the current task callback function and the current task period variable as parameters and assign the parameters to the task structure body pointer.
As an exemplary illustration, the step of the task registration function receiving a task callback function pFun and a task Period variable u32Period as parameters assigned to the task fabric pointer comprises: and finding a task structure body pointer pstrTask to be registered according to the task registration number variable regTaskIdx. The task callback function pFun is assigned to the task structure pointer pstrTask- > task callback function pFun. The task Period variable u32Period is assigned to the task structure pointer pstrTask- > task Period variable u32Period. The current time variable u32ms1 is assigned to the task structure pointer pstrTask- > last scheduled time variable u32ms0. And assigning the task registration number variable regTaskIdx to a task structure body pointer pstrTask- > task ID variable u8ID. And (5) automatically increasing the task registration number variable regTaskIdx by 1. The TASK registration function classifies TASKs according to their period and the number of TASKs is modified according to the macro definition SIGNAL MAX TASK.
Optionally, in one embodiment of the present application, after registering the new task, the new task is set as a dynamic adjustment task or a periodic task.
In the specific implementation process, when a new task needs to be registered, a task structure body is firstly allocated to the task, and then the task structure body is set as a dynamic adjustment task or a periodic task according to the characteristics and the requirements of the task.
It is understood that dynamically adjusting tasks refers to those tasks whose execution time is uncertain and may change with input or environmental changes. Periodic tasks are tasks which are repeatedly executed according to a certain period, wherein the execution time of the periodic tasks is fixed. The method for setting the task type is to add a flag bit in the task structure body to indicate whether the task is a dynamic adjustment task or a periodic task. For example, a dynamic adjustment task may be represented by 0 and a periodic task may be represented by 1. After the task type is set, the task is inserted into a task management structure body to wait for scheduling. By setting the task or the periodic task to be dynamically adjusted, the task of different types can be distinguished and managed, the flexibility and the adaptability of task scheduling are improved, and scheduling failure or efficiency reduction caused by mismatching of task types is avoided.
Optionally, in one embodiment of the present application, when executing the currently traversed task, if the actual execution time of the executed task is greater than the preset task period variable and the executed task is set to be a dynamic adjustment task, the preset task period variable is self-increased to be greater than the actual execution time of the executed task.
In the implementation process, when a task is taken out from the task management structure body to be executed, the task type of the task is checked first, if the task is dynamically adjusted, the starting execution time of the task is recorded, then a task callback function of the task is called, and corresponding logic of the task is executed. After the execution is finished, the ending execution time of the task is recorded, the actual execution time of the task is calculated, and the actual execution time is compared with a preset task period variable of the task. If the actual execution time is greater than the preset task period variable, the preset task period variable is self-increased to a value greater than the actual execution time, for example, may be self-increased to twice the actual execution time. And then setting the next task scheduling time variable of the task as the current time plus a preset task period variable, reinserting the task into a task management structure body, and sequencing according to the size of the next task scheduling time variable.
It can be understood that the execution time of the dynamically adjusted task is dynamically adjusted, so that the situation that the task misses the scheduling due to overlong execution time can be avoided, and the instantaneity and the correctness of the task are ensured.
Optionally, in an embodiment of the present application, when executing the task currently traversed, if the task is set as a periodic task, after the task is executed, a task period variable of the task is added to a last task scheduling time variable of the task to obtain a next task scheduling time variable of the task, and the task is reinserted into the task management structure body according to the size of the next task scheduling time variable.
In the implementation process, when a task is taken out from the task management structure body to be executed, the task type of the task is checked first, if the task is a periodic task, a task callback function of the task is directly called, and corresponding logic of the task is executed. After the execution is finished, adding the task period variable of the task to the task scheduling time variable of the last time of the task to obtain the task scheduling time variable of the next time of the task, reinserting the task into a task management structure body, and sequencing according to the size of the task scheduling time variable of the next time.
It will be appreciated that periodic scheduling of periodic tasks may ensure stability and predictability of tasks.
S30: and judging whether all the registered tasks are executed, if so, ending task scheduling, and if not, executing S40.
S40: traversing the tasks in the task management structure body, and calculating the difference value between the current time variable and the last task scheduling time variable.
S50: and judging whether the difference value is larger than or equal to a preset task period variable, if so, executing the task currently traversed, updating the task scheduling time variable last time, and then jumping to execute the S30, and if not, directly jumping to execute the S30 without executing the task currently traversed.
Optionally, in an embodiment of the present application, the performing the task currently traversed includes: taking out a task structure body of a task currently traversed from the task management structure body; acquiring an address of a task callback function from the task structure body, and calling the task callback function of the task through the address; and executing the logic corresponding to the task by using the task callback function.
In the specific implementation process, when executing the task which is currently traversed, firstly, a task structure body of the task is taken out from a task management structure body, then, the address of a task callback function of the task is obtained from the task structure body, the task callback function of the task is called through the address, and the corresponding logic of the task which is currently traversed is executed by utilizing the task callback function.
It is understood that the task callback function refers to a function that encapsulates task logic, and is generally written by a developer of a task, and can perform different operations according to different requirements of the task, for example, reading or writing data, processing or sending signals, controlling or responding to devices, and the like.
Through abstraction and encapsulation of the task, the reusability and maintainability of the task are improved, and the development and debugging processes of the task are simplified.
As an exemplary illustration, the steps of task scheduling include: the current time variable u32ms1 is updated to be the timestamp of the current system. All registered task structures are traversed starting from 0 using one loop variable i until the task registration number variable regTaskIdx is reached. For each traversed task structure pointer pstrTask, the difference between the current time variable u32ms1 and the task structure pointer pstrTask- > the last scheduled time variable u32ms0 is calculated. If the difference is greater than or equal to the task structure pointer pstrTask- > task Period variable u32Period, it indicates that the task has reached the time to be executed. The update task structure pointer pstrTask- > last scheduled time variable u32ms0 is the current time variable u32ms1. The task structure pointer pstrTask- > the task callback function pFUN is called to execute the corresponding task logic. And obtaining the timestamp of the current system again, and subtracting the variable u32ms0 of the last scheduling time of the task structural body pointer pstrTask-, so as to obtain the execution time of the task. The ID and execution time of the task are output. When all registered tasks have been executed, then task scheduling is ended.
Optionally, in an embodiment of the present application, when executing logic corresponding to a task currently traversed by using the task callback function, if a condition or event needing to wait is encountered, a task state variable of the task is set to be blocked, the task is removed from the task management structure body, until the condition or event is met, then the current task is added to the task management structure body again, and executing logic corresponding to the task currently traversed by using the task callback function is continued.
In the implementation process, when logic corresponding to the currently traversed task is executed by utilizing the task callback function, if certain conditions or events are found to be unsatisfied, and the task cannot be continuously executed, a task state variable of the task is set to be blocked, so that the task cannot be run temporarily. And then removing the task from the task management structure body, releasing the occupied resources thereof, and yielding the CPU to other tasks. And when the condition or the event is met, the task is re-added into the task management structure body, and the task state variable is recovered to be ready, so that the task can be continuously executed. And then, continuing to execute the logic corresponding to the currently traversed task by utilizing the task callback function until the task is completed or a condition or event needing to be waited is met again.
It can be understood that the embodiment can realize the suspension and the recovery of the task to be waited, improve the concurrency and the responsiveness of the system and avoid the idle CPU or the task blockage caused by waiting.
As an exemplary illustration, there are a number of tasks in the embodiments of the present application, including: task5ms_1, task10ms_1, task10ms_2, task50ms_1, task50ms_2, task100ms_, task100ms_2, task100ms_3, task1000ms_1, task5000ms_1. Each task is developed independently and executed in a given cycle. The process of registration and scheduling of tasks is as follows:
the specific process of task registration comprises the following steps:
drvtaskregister_taskfunc (Task 5ms_1, 5); registration/registration for a period of 5ms
DrvTaskRegister_TaskFunc (Task 10ms_1, 10); registration/registration for a 10ms period task
DrvTaskRegister_TaskFunc (Task 10ms_2, 10); another task with a period of 10 milliseconds is registered
DrvTaskRegister_TaskFunc (Task50ms_1, 50); one cycle of 50 milliseconds of task/registration
Drvtaskregister_taskfunc (Task 50ms_2, 50); one other cycle of 50 milliseconds of task is/register
DrvTaskRegister_TaskFunc (Task100 ms_1, 100); one cycle of 100ms task is/register
Drvtaskregister_taskfunc (Task 100ms_2, 100); another task with a period of 100 milliseconds is registered
DrvTaskRegister_TaskFunc (Task100 ms_3, 100); task with third cycle of 100 ms/registration
Drvtaskregister_taskfunc (Task 1000ms_1,1000); one cycle of 1000 milliseconds of task is/register
Drvtaskregister_taskfunc (Task 5000ms_1,5000); registration/registration for a task with a period of 5000 milliseconds
The specific process of task scheduling comprises the following steps:
if at a certain moment the system time tsys is 10005 ms, the last execution time of the system time tsys minus the Task5ms_1 is 5ms or more, and the last execution time of the system time tsys minus other tasks is smaller than the execution period of the other tasks, then at this moment the system only executes the Task5ms_1, the other tasks are not executed. If at another time, the system time tsys is 100010 ms, the last execution time of the system time tsys minus the Task5ms_1 is equal to or greater than 5ms, the last execution time of the system time tsys minus the Task10ms_1 is equal to or greater than 10ms, the last execution time of the system time tsys minus the Task10ms_2 is equal to or greater than 10ms, and the last execution time of the system time tsys minus the other tasks is less than the execution period of the other tasks, then at this time, the system sequentially executes three tasks of Task5ms_1, task10ms_2, and the other tasks are not executed.
It can be understood that, by separating the task storage and management from the task registration, the task scheduling method of the embedded software provided by the embodiment realizes the dynamic registration and scheduling of the task, and the software interface can be called through the simulink model at the application layer to realize independent development of the bottom layer and the application layer. According to the difference value of the current time variable and the last task scheduling time variable, whether the current traversed task needs to be executed is judged, so that unnecessary task execution is avoided, different task scheduling periods can be set according to the real-time requirements of different tasks, and compared with a traditional embedded software task scheduling method, a fixed scheduling period or preemptive scheduling based on priority is generally needed, resource consumption is reduced, and therefore millisecond scheduling time requirements are met.
Next, a task scheduling system of embedded software according to an embodiment of the present application will be described with reference to the accompanying drawings.
Specifically, fig. 2 is a schematic diagram of a task scheduling system of embedded software according to an embodiment of the present application.
As shown in fig. 2, the task scheduling system of the embedded software includes: a task management module 100, a task registration module 200, and a task scheduling module 300.
Wherein the task management module 100 is used for creating and initializing a task management structure for storing and managing registered tasks; the task registration module 200 is configured to register a new task and add the new task to the task management structure; judging whether all registered tasks are executed, if yes, ending task scheduling, and if not, calling a task scheduling module to perform task scheduling; the task scheduling module 300 is configured to traverse the task in the task management module, calculate a difference between a current time variable and a last task scheduling time variable, execute the currently traversed task when the difference is greater than or equal to a preset task period variable, update the last task scheduling time variable, and not execute the currently traversed task when the difference is less than the preset task period variable.
It should be noted that the foregoing explanation of the task scheduling method embodiment of the embedded software is also applicable to the task scheduling system of the embedded software of this embodiment, and will not be repeated here.
It can be understood that, in the task scheduling system of the embedded software provided by the embodiment, by separating the task storage and management from the task registration, the task dynamic registration and scheduling are realized, and compared with the traditional task scheduling method of the embedded software, all tasks are usually required to be predefined in codes and sequentially executed in a fixed cycle, so that the code coupling degree is reduced. According to the difference value of the current time variable and the last task scheduling time variable, whether the current traversed task needs to be executed is judged, so that unnecessary task execution is avoided, different task scheduling periods can be set according to the real-time requirements of different tasks, and compared with a traditional embedded software task scheduling method, a fixed scheduling period or preemptive scheduling based on priority is generally needed, resource consumption is reduced, and therefore millisecond scheduling time requirements are met.
Fig. 3 is a schematic structural diagram of an electronic device 400 according to an embodiment of the present application. The electronic device 400 includes: memory 401, processor 402, and a computer program stored on memory 401 and executable on processor 402.
The processor 402 implements the task scheduling method of the embedded software provided in the above embodiment when executing a program.
Further, the electronic device 400 further includes: a communication interface 403 for communication between the memory 401 and the processor 402.
The memory 401 may include a Random Access Memory (RAM) memory, and may further include a nonvolatile memory, such as at least one magnetic disk memory.
If the memory 401, the processor 402, and the communication interface 403 are implemented independently, the communication interface 403, the memory 401, and the processor 402 may be connected to each other by a bus and perform communication with each other. The bus may be an ISA (Industry Standard Architecture ) bus, a PCI (Peripheral Component, external device interconnect) bus, or EISA (Extended Industry Standard Architecture ) bus, among others. The buses may be divided into address buses, data buses, control buses, etc. For ease of illustration, only one thick line is shown in fig. 3, but not only one bus or one type of bus.
Alternatively, in a specific implementation, if the memory 401, the processor 402, and the communication interface 403 are integrated on a chip, the memory 401, the processor 402, and the communication interface 403 may perform communication with each other through internal interfaces.
The processor 402 may be a CPU (central processing unit), or an ASIC (application specific integrated circuit), or one or more integrated circuits configured to implement embodiments of the present application.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. In this specification, schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or N embodiments or examples. Furthermore, the different embodiments or examples described in this specification and the features of the different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In the description of the present application, the meaning of "N" is at least two, such as two, three, etc., unless explicitly defined otherwise.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more N executable instructions for implementing specific logical functions or steps of the process, and further implementations are included within the scope of the preferred embodiment of the present application in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the embodiments of the present application.
It is to be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above-described embodiments, the N steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. As with the other embodiments, if implemented in hardware, may be implemented using any one or combination of the following techniques, as is well known in the art: discrete logic circuits having logic gates for implementing logic functions on data signals, application specific integrated circuits having suitable combinational logic gates, programmable gate arrays, field programmable gate arrays, and the like.
Those of ordinary skill in the art will appreciate that all or part of the steps carried out in the method of the above-described embodiments may be implemented by a program to instruct related hardware, and the program may be stored in a computer readable storage medium, where the program when executed includes one or a combination of the steps of the method embodiments.
It is to be understood that the above examples of the present invention are provided by way of illustration only and not by way of limitation of the embodiments of the present invention. Other variations or modifications of the above teachings will be apparent to those of ordinary skill in the art. It is not necessary here nor is it exhaustive of all embodiments. Any modification, equivalent replacement, improvement, etc. which come within the spirit and principles of the invention are desired to be protected by the following claims.
Claims (10)
1. The task scheduling method of the embedded software is characterized by comprising the following steps of:
s10: creating and initializing a task management structure for storing and managing registered tasks;
s20: registering a new task and adding the new task to the task management structure;
s30: judging whether all registered tasks are executed, if so, ending task scheduling, and if not, executing S40;
s40: traversing the tasks in the task management structure body, and calculating the difference value between the current time variable and the last task scheduling time variable;
s50: and judging whether the difference value is larger than or equal to a preset task period variable, if so, executing the task currently traversed, updating the task scheduling time variable last time, and then jumping to execute the S30, and if not, directly jumping to execute the S30 without executing the task currently traversed.
2. The task scheduling method of embedded software according to claim 1, wherein the task management structure includes a task array, a task registration number variable, and a current time variable;
the task array is used for distributing idle array positions for the newly registered task;
the task registration number variable is used for recording the number of the currently registered tasks;
the current time variable is used for storing a time stamp of the current system.
3. The method for task scheduling of embedded software according to claim 2, wherein the structural members in the task array include a task callback function, a task period variable, a last task scheduling time variable and a task ID variable;
in S20, the step of registering a new task and adding the new task to the task management structure includes:
acquiring an idle position in a task array according to the current task registration number variable;
respectively assigning the current task callback function, the current task period variable, the current time variable and the current array index assignment to the task callback function, the task period variable, the last task scheduling time variable and the task ID variable in the task structure body pointer;
and adding the task registration number variable by 1.
4. The task scheduling method of embedded software according to claim 1, wherein in S20, the method further comprises: after registering the new task, the new task is set as a dynamic adjustment task or a periodic task.
5. The task scheduling method of embedded software according to claim 4, wherein in S50, the method further comprises:
when executing the currently traversed task, if the actual execution time of the executed task is greater than the preset task period variable and the executed task is set to be a dynamic adjustment task, the preset task period variable is automatically increased to be greater than the actual execution time of the executed task.
6. The task scheduling method of embedded software according to claim 4, wherein in S50, the method further comprises: when executing the task currently traversed, if the task is set as a periodic task, adding the task period variable of the task to the last task scheduling time variable of the task after the task is executed, obtaining the next task scheduling time variable of the task, and reinserting the task into a task management structure body according to the size of the next task scheduling time variable.
7. A method of task scheduling embedded software according to any one of claims 1 to 6, wherein the executing the task currently traversed comprises:
taking out a task structure body of a task currently traversed from the task management structure body;
acquiring an address of a task callback function from the task structure body, and calling the task callback function of the task through the address;
and executing the logic corresponding to the task by using the task callback function.
8. The method for task scheduling of embedded software according to claim 7, wherein when executing logic corresponding to a task currently traversed by using the task callback function, if a condition or event requiring waiting is encountered, setting a task state variable of the task to be blocked, removing the task from the task management structure, and adding the current task to the task management structure again until the condition or event is satisfied, and continuing executing logic corresponding to the task currently traversed by using the task callback function.
9. A task scheduling system for embedded software, comprising:
a task management module for creating and initializing a task management structure for storing and managing registered tasks;
the task registration module is used for registering a new task and adding the new task into the task management structure body; judging whether all registered tasks are executed, if yes, ending task scheduling, and if not, calling a task scheduling module to perform task scheduling;
and the task scheduling module is used for traversing the task in the task management module, calculating the difference value between the current time variable and the last task scheduling time variable, executing the currently traversed task when the difference value is larger than or equal to a preset task period variable, updating the last task scheduling time variable, and not executing the currently traversed task when the difference value is smaller than the preset task period variable.
10. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements operations performed by the task scheduling method of embedded software of any one of claims 1 to 8 when the program is executed by the processor.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311686449.3A CN117421106B (en) | 2023-12-11 | 2023-12-11 | Task scheduling method, system and equipment for embedded software |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311686449.3A CN117421106B (en) | 2023-12-11 | 2023-12-11 | Task scheduling method, system and equipment for embedded software |
Publications (2)
Publication Number | Publication Date |
---|---|
CN117421106A true CN117421106A (en) | 2024-01-19 |
CN117421106B CN117421106B (en) | 2024-03-08 |
Family
ID=89531088
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311686449.3A Active CN117421106B (en) | 2023-12-11 | 2023-12-11 | Task scheduling method, system and equipment for embedded software |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117421106B (en) |
Citations (17)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103257864A (en) * | 2013-05-09 | 2013-08-21 | 南京航空航天大学 | Task scheduling method of embedded software |
CN103365708A (en) * | 2012-04-06 | 2013-10-23 | 阿里巴巴集团控股有限公司 | Method and device for scheduling tasks |
CN104834564A (en) * | 2015-05-20 | 2015-08-12 | 百度在线网络技术(北京)有限公司 | Task scheduling method and device |
CN109445939A (en) * | 2018-10-19 | 2019-03-08 | 积成电子股份有限公司 | A kind of dispatching method based on the soft real-time scheduling kernel for actively selling mechanism |
CN111008072A (en) * | 2019-12-25 | 2020-04-14 | 青梧桐有限责任公司 | Task scheduling method and device, storage medium and electronic equipment |
WO2021093248A1 (en) * | 2019-11-13 | 2021-05-20 | 上海商汤智能科技有限公司 | Scheduling method and apparatus, electronic device, and storage medium |
CN112925631A (en) * | 2021-04-08 | 2021-06-08 | 上海科世达-华阳汽车电器有限公司 | Task scheduling method and device, electronic equipment and storage medium |
CN114281504A (en) * | 2021-12-23 | 2022-04-05 | 建信金融科技有限责任公司 | Task scheduling method and device, electronic equipment and computer readable medium |
CN114942833A (en) * | 2022-03-30 | 2022-08-26 | 中国人寿保险股份有限公司 | Method and related device for dynamically scheduling timing task resources |
CN115061799A (en) * | 2022-06-30 | 2022-09-16 | 天津津航计算技术研究所 | Task scheduling method without operating system |
CN115292039A (en) * | 2022-07-29 | 2022-11-04 | 北京神舟航天软件技术股份有限公司 | Multitask distributed scheduling load balancing method for heterogeneous computing platform |
WO2022252026A1 (en) * | 2021-05-31 | 2022-12-08 | Boe Technology Group Co., Ltd. | Computer-implemented method in system comprising one or more processors for executing periodic tasks, system comprising one or more processors for executing periodic tasks, and computer-program product |
US20230048833A1 (en) * | 2020-05-29 | 2023-02-16 | Alibaba Group Holding Limited | Method, apparatus, and storage medium for scheduling tasks |
CN116126491A (en) * | 2022-12-19 | 2023-05-16 | 北京航天控制仪器研究所 | Time-sharing scheduling method for embedded software tasks |
CN116501465A (en) * | 2023-04-06 | 2023-07-28 | 嬴彻星创智能科技(上海)有限公司 | Automatic driving task execution method and device, electronic equipment and storage medium |
CN116820697A (en) * | 2022-03-21 | 2023-09-29 | 腾讯科技(深圳)有限公司 | Timing task scheduling method, device, equipment and storage medium |
CN116974728A (en) * | 2023-09-20 | 2023-10-31 | 深圳市德兰明海新能源股份有限公司 | Singlechip task scheduling method, singlechip product and storage medium |
-
2023
- 2023-12-11 CN CN202311686449.3A patent/CN117421106B/en active Active
Patent Citations (17)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103365708A (en) * | 2012-04-06 | 2013-10-23 | 阿里巴巴集团控股有限公司 | Method and device for scheduling tasks |
CN103257864A (en) * | 2013-05-09 | 2013-08-21 | 南京航空航天大学 | Task scheduling method of embedded software |
CN104834564A (en) * | 2015-05-20 | 2015-08-12 | 百度在线网络技术(北京)有限公司 | Task scheduling method and device |
CN109445939A (en) * | 2018-10-19 | 2019-03-08 | 积成电子股份有限公司 | A kind of dispatching method based on the soft real-time scheduling kernel for actively selling mechanism |
WO2021093248A1 (en) * | 2019-11-13 | 2021-05-20 | 上海商汤智能科技有限公司 | Scheduling method and apparatus, electronic device, and storage medium |
CN111008072A (en) * | 2019-12-25 | 2020-04-14 | 青梧桐有限责任公司 | Task scheduling method and device, storage medium and electronic equipment |
US20230048833A1 (en) * | 2020-05-29 | 2023-02-16 | Alibaba Group Holding Limited | Method, apparatus, and storage medium for scheduling tasks |
CN112925631A (en) * | 2021-04-08 | 2021-06-08 | 上海科世达-华阳汽车电器有限公司 | Task scheduling method and device, electronic equipment and storage medium |
WO2022252026A1 (en) * | 2021-05-31 | 2022-12-08 | Boe Technology Group Co., Ltd. | Computer-implemented method in system comprising one or more processors for executing periodic tasks, system comprising one or more processors for executing periodic tasks, and computer-program product |
CN114281504A (en) * | 2021-12-23 | 2022-04-05 | 建信金融科技有限责任公司 | Task scheduling method and device, electronic equipment and computer readable medium |
CN116820697A (en) * | 2022-03-21 | 2023-09-29 | 腾讯科技(深圳)有限公司 | Timing task scheduling method, device, equipment and storage medium |
CN114942833A (en) * | 2022-03-30 | 2022-08-26 | 中国人寿保险股份有限公司 | Method and related device for dynamically scheduling timing task resources |
CN115061799A (en) * | 2022-06-30 | 2022-09-16 | 天津津航计算技术研究所 | Task scheduling method without operating system |
CN115292039A (en) * | 2022-07-29 | 2022-11-04 | 北京神舟航天软件技术股份有限公司 | Multitask distributed scheduling load balancing method for heterogeneous computing platform |
CN116126491A (en) * | 2022-12-19 | 2023-05-16 | 北京航天控制仪器研究所 | Time-sharing scheduling method for embedded software tasks |
CN116501465A (en) * | 2023-04-06 | 2023-07-28 | 嬴彻星创智能科技(上海)有限公司 | Automatic driving task execution method and device, electronic equipment and storage medium |
CN116974728A (en) * | 2023-09-20 | 2023-10-31 | 深圳市德兰明海新能源股份有限公司 | Singlechip task scheduling method, singlechip product and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN117421106B (en) | 2024-03-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112513814B (en) | Task scheduling method and device | |
US20110072434A1 (en) | System, method and computer program product for scheduling a processing entity task | |
JP2008506187A (en) | Method and system for parallel execution of multiple kernels | |
CN109960589B (en) | Method and device for realizing system software layer of embedded system and readable medium | |
CN103329102A (en) | Multiprocessor system | |
CN114090498B (en) | Method for realizing multi-core starting and service mutual decoupling of embedded SOC (system on chip) system | |
CN111666210A (en) | Chip verification method and device | |
EP3327573B1 (en) | Multi-processor and multi-processor system | |
CN114780248A (en) | Resource access method, device, computer equipment and storage medium | |
EP4167080A1 (en) | Memory initialisation apparatus and method, and computer system | |
CN117421106B (en) | Task scheduling method, system and equipment for embedded software | |
CN118295778A (en) | Task scheduling method and device, electronic equipment and storage medium | |
US9612863B2 (en) | Hardware device for accelerating the execution of a systemC simulation in a dynamic manner during the simulation | |
CN116107728B (en) | Task execution method and device, storage medium and electronic equipment | |
WO2024119930A1 (en) | Scheduling method and apparatus, and computer device and storage medium | |
JP7425685B2 (en) | electronic control unit | |
CN109388505B (en) | A kind of asynchronous multitask sequence loading method based on Android | |
CN116126937A (en) | Job scheduling method, job scheduling device, electronic equipment and storage medium | |
US12071149B2 (en) | Vehicle control device including asynchronous driver | |
CN112148228A (en) | Storage space release method, terminal and storage medium | |
CN111416780A (en) | Real-time priority ceiling optimization method, system, medium and terminal | |
CN117093345B (en) | Task linked list execution method and device, terminal equipment and storage medium | |
CN113886123B (en) | Watchdog feeding method and device, electronic equipment and storage medium | |
CN109213575B (en) | Method for running program by single processor | |
CN102567034B (en) | Driver management system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |