Method and system for dynamically distributing priority of embedded operating system
By initializing the core data structure and integrating dynamic priority factors in the embedded operating system, and using a multi-layer scheduling mechanism for task registration and priority calculation, the problems of low-priority task starvation and priority flipping caused by static scheduling are solved, and the system structure is simplified and the hardware adaptability is improved.
Patent Information
- Application Number
- CN202510902588.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-01
- Publication Date
- 2025-09-26
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing embedded operating systems have problems such as static scheduling leading to starvation of low-priority tasks, frequent priority flipping, complex structure, high development threshold, and poor hardware adaptability.
By initializing the core data structure, integrating dynamic priority factors, and utilizing a multi-layer scheduling mechanism for task registration and priority calculation, the priority is dynamically adjusted to prevent priority flipping and starvation of low-priority tasks, adapting to different hardware resource constraints.
It realizes the dynamic allocation of priorities of the embedded operating system, simplifies the system structure, reduces the development difficulty, and improves the hardware adaptability and real-time performance.
Smart Images

Figure CN120704843A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded operating systems, and in particular to a method and system for dynamically allocating priorities of embedded operating systems. Background Art
[0002] Embedded terminal devices are currently widely used in various fields, including industrial automation, healthcare, transportation, smart homes, consumer electronics, energy management, and the Internet of Things. The various embedded terminal devices used in these fields will eventually be implemented as a variety of products on the market. Users have a common understanding of their needs for these products: low price or high cost-performance; rich, simultaneous functionality and smooth operation; high reliability; and diverse needs that are met promptly. Therefore, embedded systems require an operating system designed specifically for the software architecture to facilitate comprehensive system management, precise management, and efficient operation. Unlike PC operating systems, embedded operating systems currently have a diverse range of applications, with no single dominant player. Some are commercial, some are non-profit, and each has its own advantages and disadvantages.
[0003] In the existing technology, most embedded operating systems are commercial closed-source systems with black box modules, difficult debugging, redundant embedded Linux code, complex system structure, and high development threshold; high memory usage, difficult to deploy on low-end hardware, and high resource consumption; static scheduling causes low-priority tasks to starve, and lacks real-time performance; there is no dynamic adjustment mechanism, and priority flips occur frequently, resulting in priority management defects; the fixed architecture cannot adapt to devices with different resource constraints, and has poor hardware adaptability. Summary of the Invention
[0004] The purpose of the present invention is to provide a method and system for dynamically allocating priorities of an embedded operating system, so as to solve the technical problems in the prior art of embedded operating systems, such as static scheduling leading to starvation of low-priority tasks, lack of dynamic adjustment mechanism, frequent priority flipping, complex structure, high development threshold, and poor hardware adaptability.
[0005] In order to achieve the above-mentioned purpose, the present invention provides a method for dynamically allocating priorities of an embedded operating system, the method comprising: initializing a core data structure of the embedded operating system and starting a time base manager; performing task registration and static parameter setting based on the core data structure, integrating a dynamic priority factor, and utilizing a dynamic priority algorithm to calculate the effective priority of the task to dynamically configure task parameters; performing multi-level task scheduling based on the task parameters and utilizing the time base manager to drive a multi-layer scheduling mechanism; dynamically adjusting the effective priority during the multi-level task scheduling process to achieve dynamic priority allocation of the embedded operating system; monitoring the operating status of the embedded operating system and dynamically tailoring it according to the operating status to optimize the operation of the embedded operating system.
[0006] Optionally, the initializing the core data structure of the embedded operating system includes: initializing a priority mapping table; creating a task enable flag table; establishing a cycle counter table; extending a task control block to add dynamic parameters; and creating an interrupt mapping table.
[0007] Optionally, the task registration and static parameter setting includes: allocating a task ID to each task, setting a basic priority of the task, setting an execution cycle of the task, and updating the task status.
[0008] Optionally, updating the task status includes: if the task is activated, setting the position of the corresponding task ID of the activated task in the enable flag table to the enabled state, and setting the position of the corresponding task ID in the priority mapping table to the basic priority value of the task; if the task is disabled, setting the position of the corresponding task ID of the disabled task in the enable flag table to the disabled state, and resetting the position of the corresponding task ID in the priority mapping table to 0.
[0009] Optionally, the time base manager is used to drive a multi-layer scheduling mechanism to perform multi-level task scheduling, including: using M milliseconds as the hard real-time layer scheduling period of the time base manager to drive hard real-time layer scheduling to handle urgent tasks; using N milliseconds as the dynamic adjustment layer scheduling period of the time base manager to drive dynamic adjustment layer scheduling to optimize the sorting of ordinary task queues, where N is greater than M; using M milliseconds as the periodic execution control layer scheduling period of the time base manager to drive periodic execution control to ensure that tasks are executed on time.
[0010] Optionally, the hard real-time layer scheduling includes: scanning the priority mapping table to detect whether there is a task with an effective priority value greater than a preset value; if a task with an effective priority value greater than the preset value is found, preempting the currently executing task and executing the high-priority task instead.
[0011] Optionally, the dynamic adjustment layer scheduling includes: traversing all tasks and increasing the waiting time of each task; recalculating the effective priority of each task using a dynamic priority algorithm based on a dynamic priority factor; and reordering the ready task queue using a minimum heap sorting algorithm to ensure that the task with the highest priority is at the top of the heap.
[0012] Optionally, the periodic execution control includes: traversing all tasks, and if the task enable flag is in the enabled state, performing a decrement operation on the cycle counter of the enabled task; if the cycle counter of the task returns to zero after decrementing, the task is added to the ready task queue, and the cycle counter of the task is reset to a preset execution cycle value to periodically trigger task execution.
[0013] Optionally, during the multi-level task scheduling process, the effective priority is dynamically adjusted, including: if the multi-level task scheduling is hard real-time layer scheduling, then responding to the event priority linkage task status to make the effective priority jump; if the multi-level task scheduling is dynamic adjustment layer scheduling, then responding to the anti-priority flip mechanism to make the effective priority rise to the highest priority; if the multi-level task scheduling is periodic execution control, then responding to the anti-starvation strategy.
[0014] On the other hand, the present invention provides a priority dynamic allocation system, which includes a control module, the control module includes a memory, a processor and a computer program stored in the memory and runnable on the processor, and the processor executes the computer program to implement any one of the above-mentioned priority dynamic allocation methods.
[0015] Through the above technical solution, the present invention uses a multi-layer scheduling mechanism to implement 1 millisecond-level task scheduling using the SysTick timer to perform multi-level task scheduling, realize interrupt-task linkage, and directly trigger the priority transition of dependent tasks by peripheral interrupts; through the synchronous initialization of task priority and enable flag and the dynamic priority algorithm, the priority can be dynamically adjusted to prevent priority flipping and prevent low-priority tasks from starving; by dynamically tailoring the embedded operating system, the functional modules can be automatically downgraded according to hardware resources, thereby achieving the purpose of simplified structure and good hardware adaptability.
[0016] Other features and advantages of the present invention will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following detailed description, they are used to explain the embodiments of the present invention, but do not constitute a limitation of the embodiments of the present invention. In the accompanying drawings: Figure 1 This is a schematic diagram of the process of the priority dynamic allocation method of the embedded operating system of the present invention Figure 1 ; Figure 2 It is a schematic diagram of the process of driving hard real-time layer scheduling in the present invention; Figure 3 It is a schematic diagram of the process of driving the dynamic adjustment layer scheduling in the present invention; Figure 4 It is a schematic flow chart of the drive cycle execution control in the present invention; Figure 5 It is a software architecture diagram of the priority dynamic allocation method of the embedded operating system of the present invention; Figure 6 This is a schematic diagram of the process of the priority dynamic allocation method of the embedded operating system of the present invention Figure 2 . DETAILED DESCRIPTION
[0018] The following describes the specific implementation of the embodiment of the present invention in detail with reference to the accompanying drawings. It should be understood that the specific implementation described herein is only used to illustrate and explain the embodiment of the present invention and is not used to limit the embodiment of the present invention.
[0019] It should be noted that the acquisition, transmission, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations. In the embodiments of this application, certain software, components, models, and other existing solutions in the industry may be mentioned. These should be considered as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of this application, but it does not mean that the applicant has or will necessarily use such solutions.
[0020] Please refer to Figure 1 An embodiment of the present invention provides a method for dynamically allocating priorities of an embedded operating system. The method may include: Step S110: Initialize the core data structure of the embedded operating system and start the time base manager.
[0021] Combine Figure 1 、 Figure 5 and Figure 6 In an embodiment of the present invention, initializing the core data structure of the embedded operating system may include: initializing a priority mapping table, with the array length equal to the maximum number of tasks (e.g., 64), with all elements initialized to 0, where 0 indicates no active task; creating a task enable flag table, with all elements initially in the enabled state, activated by default; establishing a cycle counter table to store the execution cycle of each task in milliseconds; extending the task control block to add dynamic parameters, which may include waiting time, historical timeout counts, and event dependency flags; creating an interrupt mapping table to associate peripheral interrupt numbers with dependent tasks (e.g., emergency stop button interrupts). Mapped to security monitoring tasks).
[0022] The priority mapping table is used to establish a table that corresponds to different things or tasks and their priorities. The preconfigured priority mapping table includes elements such as projects, events, and tasks. At the same time, each element is assigned a corresponding priority level. Priority can be represented by numbers (for example, 1, 2, 3, with lower numbers indicating higher priorities), letters (for example, A, B, C, with A being the highest priority), or other specific symbols. The priority mapping table can clearly define the importance of each element and the order in which it should be processed. Work can be arranged and resources allocated based on priority, ensuring that important matters are processed first. For example, in an operating system, a priority mapping table is used to determine the scheduling order of different processes.
[0023] In a preferred embodiment of the present invention, the time base manager can be a SysTick timer, which is configured to have a 1 millisecond interrupt period and initializes three levels of scheduling clocks: 1 millisecond triggers the hard real-time layer; 10 milliseconds triggers the dynamic adjustment layer; and events (for example, starting when the memory is greater than 90%) trigger the resource recovery layer.
[0024] Step S120: Based on the core data structure, perform task registration and static parameter setting, integrate dynamic priority factors, and use dynamic priority algorithms to calculate the effective priority of the task to dynamically configure task parameters.
[0025] In an embodiment of the present invention, task registration and static parameter setting may include: assigning a task ID to each task; setting the basic priority of the task, for example, the numerical range can be 1 to 255, the larger the numerical value, the higher the priority, and when the task is disabled, the basic priority is set to 0; setting the execution period of the task (in milliseconds, such as 5 milliseconds, 10 milliseconds or 50 milliseconds, etc.); and updating the task status.
[0026] The static parameters may include a task ID as an identification of the task in the system, a basic priority as a preset importance level, an execution period as a preset time trigger interval, and the like.
[0027] In a preferred embodiment of the present invention, updating the task status may include: if the task is activated, setting the position of the corresponding task ID of the activated task in the enable flag table to the enabled state, and setting the position of the corresponding task ID in the priority mapping table to the basic priority value of the task; if the task is disabled, setting the position of the corresponding task ID of the disabled task in the enable flag table to the disabled state, and resetting the position of the corresponding task ID in the priority mapping table to 0.
[0028] In a preferred embodiment of the present invention, the effective priority of a task can be expressed by the following formula:
[0029] in, Both represent adjustable coefficients. Waiting time represents the cumulative time a task waits for execution after becoming ready. Event dependency tag represents the external event triggering status related to the task. Historical timeout count represents the cumulative number of task execution timeouts.
[0030] Further, Follow the coefficient adaptive adjustment rule, that is, when the system detects that the number of ready tasks is greater than 10 (high load state), increase The weights (e.g., ), to reduce the risk of low-priority tasks starving, when the system detects that the number of ready tasks is less than or equal to 3 (low load state), increase The weights (e.g., ) to enhance incident response capabilities, As an error penalty factor, it is usually set to a fixed value (e.g. ).
[0031] Step S130: Based on the task parameters, a time base manager is used to drive a multi-layer scheduling mechanism to perform multi-level task scheduling to achieve interrupt-task linkage and enable peripheral interrupts to directly trigger priority transitions of dependent tasks.
[0032] Please refer to Figure 2 In a preferred embodiment of the present invention, M milliseconds (e.g., 1 millisecond) is used as the hard real-time layer scheduling period of a time base manager (e.g., SysTick timer) to drive hard real-time layer scheduling to handle urgent tasks. The process may include steps S1301 and S1302: Step S1301: Scan the priority mapping table to detect whether there is a task with an effective priority value greater than a preset value (eg, 80).
[0033] Step S1302: If it is found that there is a task with an effective priority value greater than the preset value, the currently executed task is preempted and the high-priority task is executed instead.
[0034] Please refer to Figure 3 In a preferred embodiment of the present invention, N milliseconds (e.g., 10 milliseconds) is used as the dynamic adjustment layer scheduling period of the time base manager to drive the dynamic adjustment layer scheduling to optimize the order of the ordinary task queue, where N is greater than M. The process may include steps S1311 and S1312: Step S1311: traverse all tasks and increase the waiting time of each task.
[0035] Step S1312: Recalculate the effective priority of each task using a dynamic priority algorithm based on the dynamic priority factor.
[0036] Step S1313: Use the minimum heap sorting algorithm to reorder the ready task queue to ensure that the task with the highest priority is at the top of the heap, so as to dynamically respond to changes in task status (for example, automatically increase priority when waiting time is extended) and adapt to load (for example, increase priority when load is high). weight, to prevent low-priority tasks from starving).
[0037] The min heap sort algorithm is a sorting algorithm based on the min heap data structure. It uses the properties of the min heap to sort a set of data, ultimately obtaining a sequence in ascending order. First, a min heap is created from an unordered array. Starting from the last non-leaf node, each node is gradually adjusted upward to ensure that the subtree rooted at that node satisfies the min heap property. The top element of the heap (the current minimum value) is then swapped with the last element of the heap. The heap size is reduced by 1, and the new top element is adjusted to satisfy the min heap property again. This swapping and adjustment process is repeated until the heap size reaches 1, at which point the array is in ascending order.
[0038] Please refer to Figure 4 In a preferred embodiment of the present invention, M milliseconds (e.g., 1 millisecond) is used as the periodic execution control layer scheduling period of the time base manager to drive periodic execution control to ensure that tasks are executed on time. The process may include steps S1321 and S1322: Step S1321: traverse all tasks, and if the task enable flag is in the enabled state, perform a decrement operation on the cycle counter of the enabled task.
[0039] Step S1322: If the cycle counter of the task returns to zero after decrementing, the task is added to the ready task queue and the cycle counter of the task is reset to the preset execution cycle value (for example, the temperature sampling task cycle = 10 milliseconds) to ensure that the periodic task (for example, sensor data acquisition) is strictly executed according to the preset frequency to avoid the task cycle drift due to scheduling delays.
[0040] Step S140: In the multi-level task scheduling process, the effective priority is dynamically adjusted to achieve dynamic priority allocation of the embedded operating system, thereby preventing priority flipping and starvation of low-priority tasks.
[0041] In a preferred embodiment of the present invention, if the multi-level task scheduling is hard real-time layer scheduling, the response event priority is linked to the task status to make the effective priority jump. For example, when a peripheral interrupt (for example, an emergency stop button) is triggered, the dependent task (for example, a safety monitoring task) is first found through the interrupt mapping table, and then its event dependency flag is set to the maximum value (for example, plus 30) to make the priority jump. Finally, the attenuation mechanism is used to decay the event dependency flag by 50% per cycle after the task is executed.
[0042] In a preferred embodiment of the present invention, if the multi-level task scheduling is a dynamic adjustment layer scheduling, the anti-priority flipping mechanism is responded to so that the effective priority is raised to the highest priority. For example, a lightweight priority ceiling protocol is adopted to first preset the highest priority for the shared resource (for example, the SPI bus) (for example, the highest task priority that depends on the resource plus 5), and then when the task holds the resource, temporarily raise its own priority to the highest priority.
[0043] In a preferred embodiment of the present invention, if the multi-level task scheduling is a periodic execution control, it responds to the anti-starvation strategy. For example, every time a task waits for 10 milliseconds, the effective priority increases by 1 (the upper limit is 255). The increased effective priority participates in subsequent scheduling decisions. In this way, the starvation problem of low-priority tasks caused by resource competition can be solved by dynamically improving the priority of long-waiting tasks (i.e., indefinitely delayed execution).
[0044] Step S150: monitor the running status of the embedded operating system and dynamically tailor it according to the running status to optimize the running of the embedded operating system, so as to achieve the purpose of automatically downgrading functional modules according to hardware resources, simplifying the structure and improving hardware adaptability.
[0045] In a preferred embodiment of the present invention, when the embedded operating system detects memory sensitivity—for example, when the system detects that available memory falls below the 8KB threshold—a downgrade strategy is automatically triggered. This demotion disables the dynamic priority calculation module and reverts the scheduling mode to a static priority mechanism, where task priorities are determined solely by a preset base priority value. This downgrade is not a simple functional loss; rather, it maintains core scheduling functionality through intelligent switching. Specifically, the 1ms hard real-time layer and periodic execution control are retained, while only dynamic priority factor calculation and min-heap sorting are disabled, ensuring that the system maintains basic functionality even when resources are exhausted.
[0046] In a preferred embodiment of the present invention, an enhanced strategy can be implemented when the embedded operating system is in a high-reliability scenario. For example, in key areas such as industrial control and medical equipment, the system identifies the high-reliability demand mode through configuration registers, forcibly activates the lightweight anti-flip protocol in this mode, and additionally increases the resource priority ceiling. Specifically, a safety margin of 10 units is automatically added to the priority ceiling of all shared resources, significantly enhancing the defense against priority flips and ensuring that critical tasks are not blocked by low-priority tasks in scenarios such as motor stalls and safety emergency stops.
[0047] In a preferred embodiment of the present invention, intelligent downgrade is implemented when the embedded operating system is in energy-sensitive mode. For example, when the system enters an energy-sensitive scenario such as battery power, a deep power-saving strategy is initiated. This strategy automatically identifies and shuts down non-core tasks such as logging and debugging services. These tasks have their base priority set to zero and are removed from the ready queue. The dynamic adjustment layer also skips related computational processes. This strategy not only reduces CPU computational load but also reduces overall power consumption by hibernating peripheral modules, thereby extending device battery life.
[0048] Accordingly, an embodiment of the present invention provides a method for dynamically allocating priorities for an embedded operating system. The method comprises: initializing a core data structure of the embedded operating system and starting a timebase manager; performing task registration and static parameter settings based on the core data structure, integrating a dynamic priority factor, and calculating the effective priority of the task to dynamically configure task parameters; driving a multi-level scheduling mechanism based on the task parameters and utilizing the timebase manager to perform multi-level task scheduling; dynamically adjusting the effective priority during the multi-level task scheduling process to achieve dynamic priority allocation for the embedded operating system; monitoring the operating status of the embedded operating system and dynamically tailoring tasks based on the operating status to optimize the operation of the embedded operating system. The present invention utilizes a multi-level scheduling mechanism and a SysTick timer to implement 1 millisecond-level task scheduling, thereby performing multi-level task scheduling and realizing interrupt-task linkage, with peripheral interrupts directly triggering priority transitions of dependent tasks; dynamically adjusting priorities through synchronous initialization of task priorities and enable flags and a dynamic priority algorithm to prevent priority rollover and starvation of low-priority tasks; and dynamically tailoring the embedded operating system to automatically downgrade functional modules based on hardware resources, thereby achieving a simplified structure and good hardware adaptability.
[0049] An embodiment of the present invention also provides a priority dynamic allocation system, which includes a control module, the control module includes a memory, a processor, and a computer program stored in the memory and runnable on the processor, and the processor executes the computer program to implement any one of the above-mentioned priority dynamic allocation methods.
[0050] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0051] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0052] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0053] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0054] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0055] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0056] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can be implemented using any method or technology for information storage. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change RAM (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
[0057] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0058] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for dynamically allocating priorities of an embedded operating system, characterized in that: The priority dynamic allocation method includes: Initialize the core data structure of the embedded operating system and start the time base manager; Based on the core data structure, task registration and static parameter setting are performed, and dynamic priority factors are integrated. The dynamic priority algorithm is used to calculate the effective priority of the task to dynamically configure the task parameters. Based on the task parameters, the time base manager is used to drive a multi-layer scheduling mechanism to perform multi-level task scheduling; In the multi-level task scheduling process, the effective priority is dynamically adjusted to achieve dynamic priority allocation of the embedded operating system; Monitor the running status of the embedded operating system and dynamically tailor it according to the running status to optimize the operation of the embedded operating system.
2. The priority dynamic allocation method according to claim 1, characterized in that: The core data structure of the initialization embedded operating system includes: Initialize the priority mapping table; Create a task enable flag table; Create a cycle counter table; Extend the task control block to add dynamic parameters; And create an interrupt mapping table.
3. The priority dynamic allocation method according to claim 2, characterized in that: The task registration and static parameter setting include: Assign a task ID to each task, set the basic priority of the task, set the execution period of the task, and update the task status.
4. The priority dynamic allocation method according to claim 3, characterized in that: The update task status includes: If a task is activated, the position of the corresponding task ID in the enable flag table is set to the enabled state, and the position of the corresponding task ID in the priority mapping table is set to the basic priority value of the task; If the task is disabled, the position of the disabled task corresponding to the task ID in the enable flag table is set to a disabled state, and the position of the corresponding task ID in the priority mapping table is reset to 0.
5. The priority dynamic allocation method according to claim 1, characterized in that: The time base manager is used to drive a multi-layer scheduling mechanism to perform multi-level task scheduling, including: The hard real-time layer scheduling cycle of the time-base manager is M milliseconds, which drives the hard real-time layer scheduling to handle urgent tasks; The dynamic adjustment layer scheduling cycle of the time base manager is N milliseconds, which drives the dynamic adjustment layer scheduling to optimize the order of the common task queue, where N is greater than M; The periodic execution control layer of the time-base manager schedules the periodic execution control in M milliseconds to drive the periodic execution control to ensure that tasks are executed on time.
6. The priority dynamic allocation method according to claim 5, characterized in that: The hard real-time layer scheduling includes: Scan the priority mapping table to detect whether there is a task with an effective priority value greater than the preset value; If a task with an effective priority value greater than the preset value is found, the currently executing task will be preempted and the high-priority task will be executed instead.
7. The priority dynamic allocation method according to claim 5, characterized in that: The dynamic adjustment layer scheduling includes: Traverse all tasks and increase the waiting time of each task; According to the dynamic priority factor, the effective priority of each task is recalculated using the dynamic priority algorithm; Use the minimum heap sort algorithm to reorder the ready task queue to ensure that the task with the highest priority is at the top of the heap.
8. The priority dynamic allocation method according to claim 5, characterized in that: The cycle execution control includes: Traverse all tasks, if the task enable flag is enabled, decrement the cycle counter of the enabled task; If the task's cycle counter returns to zero after decrementing, the task is added to the ready task queue and the task's cycle counter is reset to the preset execution cycle value to periodically trigger task execution.
9. The priority dynamic allocation method according to claim 5, characterized in that: The dynamically adjusting the effective priority in the multi-level task scheduling process includes: If the multi-level task scheduling is hard real-time scheduling, the response event priority is linked to the task status to make the effective priority jump; If the multi-level task scheduling is a dynamic adjustment layer scheduling, the anti-priority flip mechanism is responded to so that the effective priority is raised to the highest priority; If the multi-level task scheduling is periodic execution control, the anti-starvation strategy is responded.
10. A priority dynamic allocation system, characterized in that: The priority dynamic allocation system includes a control module, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the priority dynamic allocation method according to any one of claims 1 to 9.
Citation Information
Cited By
An embedded task scheduling optimization method based on dynamic priority adjustment
CN122547471A