Embedded real-time operating system scheduling method based on bidirectional chain delay queue
By employing a doubly linked delay queue scheduling method in the embedded real-time operating system, the Alarm and ScheduleTable modules are abstracted into a single node, solving the problems of low scheduling efficiency and code redundancy in the prior art, and achieving efficient system scheduling and simplified interrupt handling.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUHAN KOTEI INFORMATICS
- Filing Date
- 2023-10-14
- Publication Date
- 2026-07-21
AI Technical Summary
In existing embedded real-time operating systems, the scheduling mechanisms of the Alarm and ScheduleTable modules suffer from code redundancy and low system scheduling efficiency.
A scheduling method based on a doubly linked delay queue is adopted, which abstracts the common characteristics of the Alarm module and the ScheduleTable module into a single node to form a doubly linked delay queue. The decision to execute the module is made by comparing the current counting time of the Counter module with the trigger time of the next node, thus simplifying interrupt handling.
It improves system scheduling efficiency, reduces interrupt handling time, enhances code readability and extensibility, and facilitates later maintenance.
Smart Images

Figure CN117472527B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of embedded software CP (Classical Platform AUTOSAR) RTOS (Real-Time Operating System) technology, and more specifically, to an embedded real-time operating system scheduling method based on a doubly linked delayed queue. Background Technology
[0002] In the OS (operating system) of embedded software CP (Classical Platform AUTOSAR), both the ScheduleTable module and the Alarm module are driven by the Counter module. One Counter module can drive multiple ScheduleTable modules or multiple Alarm modules. Under the current technological context, there are two common scheduling mechanisms:
[0003] ① One approach involves the Counter module driving both the Alarm and ScheduleTable modules (each Counter has its own independent linked list for both Alarm and ScheduleTable). Each time a Counter interrupt occurs, the scheduling module needs to iterate through the nodes in both the Alarm and ScheduleTable linked lists within the interrupt handler function, comparing whether the trigger time for a given node has arrived. This scheduling mechanism has simple code implementation logic and high node insertion efficiency, but many operations in Alarm and ScheduleTable are similar, resulting in significant code redundancy and making maintenance difficult.
[0004] ② Another approach is to place the Alarm module and the ScheduleTable module in a linear delay queue, distinguished by their respective identifiers (AlarmID and ScheduleTableID), and then have Counter manage this linear delay queue (in Classical Platform AUTOSAR, the number of Alarm and ScheduleTable modules can be determined by the user before the program runs, so the data structure adopts a linear array). The advantage of this scheduling mechanism is that it has high efficiency during querying, but during insertion, elements in the queue need to be moved, which affects the system scheduling efficiency.
[0005] Therefore, it is necessary to design a scheme that can improve the system scheduling efficiency. Summary of the Invention
[0006] This invention addresses the technical problems existing in the prior art by providing an embedded real-time operating system scheduling method based on a doubly linked delayed queue, thereby optimizing the embedded real-time operating system scheduling mechanism and improving system scheduling efficiency.
[0007] According to a first aspect of the present invention, an embedded real-time operating system scheduling method based on a doubly linked delay queue is provided, comprising:
[0008] S1, Multiple nodes are arranged into a doubly linked delay queue, and the multiple nodes are sorted in ascending order according to their trigger time ExpireTime. The nodes are either Alarm modules or ScheduleTable modules; the Counter module is set to be adjacent to the node with the smallest trigger time ExpireTime.
[0009] S2, When the Counter module enters an interrupt, the next node trigger time of the Counter module is assigned the trigger time of the smallest node, Expire Time, and the current counting time of the Counter module is assigned the system timer time.
[0010] S3. If the current counting time of the Counter module is consistent with the trigger time of its next node (next Expire Time), then the processing function corresponding to the next node is executed; otherwise, the Counter module exits the interrupt.
[0011] S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node;
[0012] S5, repeat steps S2 to S4. If all modules in the doubly linked delay queue have been executed, exit the interruption of the Counter module.
[0013] Based on the above technical solution, the present invention can also be improved as follows.
[0014] Optionally, the step of forming a doubly linked delay queue from multiple nodes and sorting the nodes in ascending order according to their trigger time (Expire Time), wherein the nodes are Alarm modules or ScheduleTable modules, includes:
[0015] The common features of the Alarm module and ScheduleTable module in each module are extracted as a single node. All nodes form the DrvObjectModule. The data storage structure of the DrvObjectModule is a doubly linked delayed queue. The prev of the node points to the first address of the entry member in the previous node, and the next of the node points to the first address of the entry member in the next node.
[0016] In a doubly linked delayed queue, the differences between the Alarm module and the ScheduleTable module are distinguished by registering module processing functions;
[0017] Sort the Expire Time of each module in the doubly linked delay queue from smallest to largest to obtain an ascending doubly linked delay queue.
[0018] Optionally, the differences between the Alarm module and the ScheduleTable module are distinguished using a registration module processing function, including:
[0019] Function pointers are set for the Alarm module or ScheduleTable module of each node to point to the corresponding processing function of each module; when the Alarm module or ScheduleTable module is run, the processing function of the currently executing module is called by running the function pointer of the currently executing module.
[0020] Optionally, the Counter module can be set to be adjacent to the node with the smallest trigger time (Expire Time), including:
[0021] The Counter module is set adjacent to the head node, where the head node is the node with the smallest Expire Time in the doubly linked delay queue;
[0022] The head node's `prev` pointer points to the first address of the Counter module's member list, the head node's `next` pointer points to the first address of the entry member in the next node, the Counter module's `prev` pointer points to the first address of the entry member in the tail node, the Counter module's `next` pointer points to the first address of the entry member in the head node, the tail node's `prev` pointer points to the first address of the entry member in the previous node, and the tail node's `next` pointer points to the first address of the Counter module's member list. Here, the tail node is the node with the largest trigger time (Expire Time) in the doubly linked delay queue, and `list` is the head node of the Counter module's linked list.
[0023] Optionally, S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node, including:
[0024] Delete the modules that have been executed by the current head node, set the next pointer of the Counter module to the first address of the entry member of the next node in the doubly linked delayed queue, and set the prev pointer of the next node to the first address of the list member of the Counter module, so as to update the next module to be executed to the new head node.
[0025] The next node trigger time (next Expire Time) of the Counter module is assigned the trigger time (next Expire Time) of the new head node, and the current counting time (current Time) of the Counter module is updated using the current system timer time.
[0026] Optionally, the value of next is obtained by adding the offset of member entry in the next node to the starting address of the next node, and the value of prev is obtained by adding the offset of member entry in the previous node to the starting address of the previous node.
[0027] Optionally, depending on whether the executed modules need to be periodically scheduled, the processing function can be configured to re-insert the corresponding executed modules into the doubly linked delay queue.
[0028] According to a second aspect of the present invention, an embedded real-time operating system scheduling system based on a doubly linked delayed queue is provided, comprising:
[0029] The module is used to form a doubly linked delay queue of multiple nodes and sort the multiple nodes in ascending order according to their trigger time Expire Time. The nodes are either Alarm modules or ScheduleTable modules. It is also used to set the Counter module adjacent to the node with the smallest trigger time Expire Time.
[0030] The setting module is used to assign the next Expire Time of the Counter module to the trigger time of the next node when the Counter module enters an interrupt, using the trigger time Expire Time of the smallest node, and to assign the current time of the Counter module to the current time of the system timer.
[0031] The judgment module is used to execute the processing function corresponding to the next node when the current counting time of the Counter module is consistent with the trigger time of the next node, next Expire Time; otherwise, it exits the interruption of the Counter module.
[0032] The update module is used to delete modules that have completed execution and to set the next module to be executed in the doubly linked delayed queue as the new head node;
[0033] The loop module is used to repeat the operations of the setting module, the judgment module, and the update module. If all modules in the doubly linked delay queue have been executed, the Counter module will exit the interrupt.
[0034] According to a third aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the processor is configured to implement the steps of the above-described embedded real-time operating system scheduling method based on a doubly linked delayed queue when executing a computer management program stored in the memory.
[0035] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer management class program is stored, wherein when the computer management class program is executed by a processor, the steps of the above-described embedded real-time operating system scheduling method based on a doubly linked delay queue are implemented.
[0036] This invention provides an embedded real-time operating system scheduling method, system, electronic device, and storage medium based on a doubly linked delay queue. By abstracting the common characteristics of the Alarm module and the ScheduleTable module, and sorting them in ascending order according to their trigger times (Expire Time), a doubly linked delay queue is formed. Each time the system is scheduled, it is only necessary to compare the current time of the counter module with the next node trigger time (next Expire Time) to determine whether to execute the module in the doubly linked delay queue. This not only reduces the processing time in the interrupt function and improves the system's operating efficiency, but also improves the readability and extensibility of the code, facilitating later code maintenance. Attached Figure Description
[0037] Figure 1 A flowchart of an embedded real-time operating system scheduling method based on a doubly linked delay queue provided by the present invention;
[0038] Figure 2 This is a schematic diagram of the data structure of a doubly linked delay queue containing an Alarm node according to an embodiment of the present invention;
[0039] Figure 3This is a schematic diagram of the data structure of a doubly linked delay queue containing a ScheduleTable node, as shown in an embodiment of the present invention.
[0040] Figure 4 This is a schematic diagram of the data structure of a doubly linked delay queue containing multiple Alarm and ScheduleTable nodes according to an embodiment of the present invention;
[0041] Figure 5 This is a schematic diagram of the processing flow of the new system scheduling module (DrvObjectModule) in an embodiment of the present invention;
[0042] Figure 6 This is a flowchart of the Alarm module processing function in an embodiment of the present invention;
[0043] Figure 7 This is a flowchart of the ScheduleTalbe module processing function in an embodiment of the present invention;
[0044] Figure 8 This is a schematic diagram of the delay queue registration function in an embodiment of the present invention (called by the Alarm or ScheduleTable processing function);
[0045] Figure 9 A block diagram of an embedded real-time operating system scheduling system based on a doubly linked delay queue is provided for an embodiment of the present invention.
[0046] Figure 10 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention;
[0047] Figure 11 This is a schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. Detailed Implementation
[0048] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0049] Figure 1 A flowchart of an embedded real-time operating system scheduling method based on a doubly linked delay queue provided by the present invention is shown below. Figure 1 As shown, the method includes:
[0050] S1, Multiple nodes are arranged into a doubly linked delay queue, and the multiple nodes are sorted in ascending order according to their trigger time ExpireTime. The nodes are either Alarm modules or ScheduleTable modules; the Counter module is set to be adjacent to the node with the smallest trigger time ExpireTime.
[0051] S2, When the Counter module enters an interrupt, the next node trigger time of the Counter module is assigned the trigger time of the smallest node, Expire Time, and the current counting time of the Counter module is assigned the system timer time.
[0052] S3. If the current counting time of the Counter module is consistent with the trigger time of its next node (next Expire Time), then the processing function corresponding to the next node is executed; otherwise, the Counter module exits the interrupt.
[0053] S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node;
[0054] S5, repeat steps S2 to S4. If all modules in the doubly linked delay queue have been executed, exit the interruption of the Counter module.
[0055] Understandably, traditional scheduling typically involves the Counter module managing two linked lists: Alarm and ScheduleTable. This means the Counter interrupt handler needs to compare the expiration times of the Alarm and ScheduleTable twice each time. Furthermore, some systems don't use a delayed queue approach, requiring a separate traversal of both the Alarm and ScheduleTable lists each time. To address these shortcomings, this invention proposes an embedded real-time operating system scheduling method based on a doubly linked delayed queue. By abstracting the common characteristics of the Alarm and ScheduleTable modules and sorting them by their Expire Time in ascending order, a doubly linked delayed queue is formed. During each system scheduling operation, only the current time of the Counter module needs to be compared once with the next Expire Time to determine whether to execute a module in the doubly linked delayed queue. This not only reduces processing time in the interrupt function and improves system efficiency but also enhances code readability, extensibility, and ease of maintenance.
[0056] In one possible embodiment, step S1, which involves forming a doubly linked delay queue from multiple nodes and sorting the nodes in ascending order according to their trigger times (Expire Time), wherein the nodes are Alarm modules or ScheduleTable modules, includes:
[0057] The common features of the Alarm module and ScheduleTable module in each module are extracted as a single node. All nodes form the DrvObjectModule. The data storage structure of the DrvObjectModule is a doubly linked delayed queue. The prev of the node points to the first address of the entry member in the previous node, and the next of the node points to the first address of the entry member in the next node.
[0058] In a doubly linked delayed queue, the differences between the Alarm module and the ScheduleTable module are distinguished by registering module processing functions;
[0059] Sort the Expire Time of each module in the doubly linked delay queue from smallest to largest to obtain an ascending doubly linked delay queue.
[0060] The differences between the Alarm module and the ScheduleTable module are distinguished using a registration module processing function, including:
[0061] Function pointers are set for the Alarm module or ScheduleTable module of each node to point to the corresponding processing function of each module; when the Alarm module or ScheduleTable module is run, the processing function of the currently executing module is called by running the function pointer of the currently executing module.
[0062] In one possible embodiment, step S1, setting the Counter module adjacent to the node with the smallest trigger time ExpireTime, includes:
[0063] The Counter module is set adjacent to the head node, where the head node is the node with the smallest Expire Time in the doubly linked delay queue;
[0064] The `prev` property of the head node points to the first address of the member list of the Counter module, and the `next` property of the head node points to the first address of the entry member in the next node. Similarly, the `prev` property of the Counter module points to the first address of the entry member in the tail node, and the `next` property of the Counter module points to the first address of the entry member in the head node. The `prev` property of the tail node points to the first address of the entry member in the previous node, and the `next` property of the tail node points to the first address of the member list of the Counter module. The tail node is the node with the largest Expire Time in the doubly linked delay queue, and `list` is the head node of the linked list of the Counter module. The value of `next` is obtained by adding the offset of the member entry within the next node to the first address of the next node, and the value of `prev` is obtained by adding the offset of the member entry within the previous node to the first address of the previous node.
[0065] like Figure 2 The diagram shows the data structure of a doubly linked delay queue containing only one Alarm node. Figure 3 The diagram illustrates the data structure of a doubly linked delay queue containing a ScheduleTable node. When the Counter module only needs to manage one Alarm module or ScheduleTable module, it can directly compare the current time of the Counter module with the trigger time (Expire Time) of the currently pending module (Alarm module or ScheduleTable module) to determine whether to execute the current module.
[0066] like Figure 4 The diagram shows a doubly linked delay queue containing multiple nodes, each containing both Alarm and ScheduleTable modules. Figure 4 The illustrated embodiment extracts common components from all Alarm and ScheduleTable modules to be executed, forming multiple nodes. These nodes are then arranged in ascending order of their corresponding Expire Time trigger times to form a doubly linked delay queue. A Counter module manages all nodes. During system scheduling, only the current time of the Counter module needs to be compared. Figure 4 The figure shows the trigger time Expire Time of Node1 (12). Figure 4 As shown in 20), it can be determined whether to execute the processing function of the head node Node1 or directly exit the Counter interrupt. For example... Figure 5 This is a schematic diagram of the processing flow of the Counter module.
[0067] Now combined Figure 4 and Figure 5 The Counter module enters the interrupt routine, obtains the current counting time (current Time) from the system, and determines whether the current counting time (current Time) matches the trigger time (expire Time) of the head node. If they do not match, the Counter module exits the interrupt directly. If they match, it retrieves the head node (Node1) from the doubly linked delay queue and begins executing the processing function of the head node (Node1). After execution, it continues to determine whether the trigger time (expire Time) of the next node (Node2) matches the current counting time (current Time). If they do not match, it exits the interrupt; if they match, it continues executing the processing function of the next node (Node2), and so on, until it exits the interrupt or all node processing functions have been executed.
[0068] The embodiments of the present invention avoid the Counter module traversing all nodes for comparison. Only one comparison is needed to judge all nodes of the pending modules in the doubly linked delay queue, which greatly improves the system scheduling efficiency.
[0069] In one possible embodiment, S4, the module that has completed execution is deleted, and the next module to be executed in the doubly linked delayed queue is taken as the new head node, including:
[0070] Delete the modules that have been executed by the current head node, set the next pointer of the Counter module to the first address of the entry member of the next node in the doubly linked delayed queue, and set the prev pointer of the next node to the first address of the list member of the Counter module, so as to update the next module to be executed to the new head node.
[0071] The next node trigger time (next Expire Time) of the Counter module is assigned the trigger time (next Expire Time) of the new head node, and the current counting time (current Time) of the Counter module is updated using the current system timer time.
[0072] Understandably, after each module in the doubly linked delay queue is executed, it is removed from the queue. Then, the next module to be processed is updated to the head node's position according to the sorting order, thus enabling sequential processing of modules in the doubly linked delay queue. Before processing each module, it is only necessary to compare the current time of the Counter module's update with the Expire Time of the head node's update (corresponding to the next Expire Time of the Counter module's next node) to determine whether to continue executing the processing function of the module corresponding to the new head node. This operation simplifies the system scheduling method and improves scheduling efficiency.
[0073] In one possible embodiment, depending on whether periodically scheduling of executed modules is required, the processing function is configured to either re-insert the corresponding executed module into the doubly linked delay queue. This embodiment enables the periodic execution of modules.
[0074] The present invention will now be illustrated with an example in a specific implementation scenario.
[0075] 1. The common features of the Alarm module and ScheduleTable module that need to be executed are abstracted into a scheduling module structure OS_CounterDrvObjectType. The scheduling module structure OS_CounterDrvObjectType, which is an abstraction of the common features of the Alarm module and ScheduleTable module, is implemented through the following code:
[0076] typedef void(*OS_CounterFuncType)(void*arg); / * Function pointer type alias definition * /
[0077] typedef struct __OS_List{
[0078] struct __OS_List*prev; / * Points to the previous OS_ListType structure variable * /
[0079] struct __OS_List* next; / * Points to the next OS_ListType structure variable * /
[0080] }OS_ListType;
[0081] typedef struct__OS_CounterDrvObject{
[0082] OS_ListType entry; / * Points to the entry member variables in the previous node structure and the next node structure respectively * /
[0083] OS_UINT32 expireTime; / * The time for this node to expire and be reactivated * /
[0084] OS_CounterFuncType processFunc; / * This node callback function is registered by the Alarm module or the ScheduleTable module * /
[0085] OS_VOID *pDrvModule; / * Pointer to the address of a structure variable in the Alarm module or ScheduleTable module * /
[0086] }OS_CounterDrvObjectType;
[0087] 2. The following code shows some of the structure variables in the Counter module:
[0088] typedef struct __OS_Counter
[0089] {
[0090] OS_UINT32 currentTime; / *Counter current count time* /
[0091] OS_UINT32 nextExpireTime; / * The time when the next node will expire and be activated * /
[0092] OS_ListType list; / * Delay queue head * /
[0093] ... / *Other variable members of Counter* /
[0094] }OS_CounterType;
[0095] 3. When creating a ScheduleTable module, the standard service interface "StartScheduleTableRel" or "StartScheduleTableAbs" is called, such as... Figure 8As shown, the interface will be populated with a variable of type OS_CounterDrvObjectType (the time to be triggered by the next expiration point of the ScheduleTable module will be assigned to expireTime, the address of the ScheduleTable structure variable corresponding to ScheduleTableID will be assigned to pDrvModule, and the entry address of the ScheduleTable processing function will be assigned to processFunc). Then, the node variables of type OS_CounterDrvObjectType will be inserted into the delay queue managed by Counter (doubly linked structure) in order (from small to large) according to the trigger time (expireTime), and the nextExpireTime in the Counter module will be updated at the same time.
[0096] 4. When creating an Alarm module, the standard service interface "SetRelAlarm" or "SetAbsAlarm" is called, such as... Figure 8 As shown, the interface will be populated with a variable of type OS_CounterDrvObjectType (assigning the next time the Alarm will be triggered to expireTime, assigning the address of the Alarm structure variable corresponding to AlarmID to pDrvModule, and assigning the entry address of the Alarm's processing function to processFunc). Then, the node variables of type OS_CounterDrvObjectType will be inserted into the delay queue managed by Counter (doubly linked structure) in order (from smallest to largest) according to the expiration time (expireTime), and the nextExpireTime in the Counter module will be updated at the same time.
[0097] 5. Repeat steps 3 and / or 4 according to the required number of nodes to successfully create the following: Figure 4 The doubly linked delayed queue shown contains both ScheduleTable and Alarm attribute nodes, such as... Figure 5 As shown in the flowchart, each time the Counter interrupt handler is entered, it only needs to update the current count time (currentTime) of the Counter module and compare it with the next expiration time (nextExpireTime). If they are not equal, the interrupt can be exited directly without needing to iterate through the delay queue for comparison. If they are equal, it only needs to retrieve all nodes in the delay queue that have the same current time as Counter, call the callback functions in these nodes, and pass the address of the module variable as a parameter (e.g., node->processFunc(pDrvModule)). Figures 6-7 As shown, proceed to operate the relevant functions of the Alarm module or ScheduleTable module.
[0098] 6. In the processing function of the Alarm module or ScheduleTable module, determine whether the OS_CounterDrvObjectType type variable needs to be repopulated and re-inserted into the delay queue, depending on whether periodic scheduling is required.
[0099] Figure 9 An embedded real-time operating system scheduling system architecture diagram based on a doubly linked delayed queue is provided for an embodiment of the present invention, as shown below. Figure 9 As shown, an embedded real-time operating system scheduling system based on a doubly linked delayed queue includes a construction module, a setting module, a judgment module, an update module, and a loop module, wherein:
[0100] The module is used to form a doubly linked delay queue of multiple nodes and sort the multiple nodes in ascending order according to their trigger time Expire Time. The nodes are either Alarm modules or ScheduleTable modules. It is also used to set the Counter module adjacent to the node with the smallest trigger time Expire Time.
[0101] The setting module is used to assign the next Expire Time of the Counter module to the trigger time of the next node when the Counter module enters an interrupt, using the trigger time Expire Time of the smallest node, and to assign the current time of the Counter module to the current time of the system timer.
[0102] The judgment module is used to execute the processing function corresponding to the next node when the current counting time of the Counter module is consistent with the trigger time of the next node, next Expire Time; otherwise, it exits the interruption of the Counter module.
[0103] The update module is used to delete modules that have completed execution and to set the next module to be executed in the doubly linked delayed queue as the new head node;
[0104] The loop module is used to repeat the operations of the setting module, the judgment module, and the update module. If all modules in the doubly linked delay queue have been executed, the Counter module will exit the interrupt.
[0105] It is understood that the embedded real-time operating system scheduling system based on a doubly linked delay queue provided by the present invention corresponds to the embedded real-time operating system scheduling method based on a doubly linked delay queue provided in the foregoing embodiments. The relevant technical features of the embedded real-time operating system scheduling system based on a doubly linked delay queue can be referred to the relevant technical features of the embedded real-time operating system scheduling method based on a doubly linked delay queue, and will not be repeated here.
[0106] Please see Figure 10 , Figure 10 A schematic diagram illustrating an embodiment of the electronic device provided in this invention. For example... Figure 10 As shown, an embodiment of the present invention provides an electronic device 1000, including a memory 1010, a processor 1020, and a computer program 1011 stored in the memory 1010 and executable on the processor 1020. When the processor 1020 executes the computer program 1011, it performs the following steps:
[0107] S1, Multiple nodes are arranged into a doubly linked delay queue, and the multiple nodes are sorted in ascending order according to their trigger time ExpireTime. The nodes are either Alarm modules or ScheduleTable modules; the Counter module is set to be adjacent to the node with the smallest trigger time ExpireTime.
[0108] S2, When the Counter module enters an interrupt, the next node trigger time of the Counter module is assigned the trigger time of the smallest node, Expire Time, and the current counting time of the Counter module is assigned the system timer time.
[0109] S3. If the current counting time of the Counter module is consistent with the trigger time of its next node (next Expire Time), then the processing function corresponding to the next node is executed; otherwise, the Counter module exits the interrupt.
[0110] S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node;
[0111] S5, repeat steps S2 to S4. If all modules in the doubly linked delay queue have been executed, exit the interruption of the Counter module.
[0112] Please see Figure 11 , Figure 11 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided by the present invention. (See diagram below.) Figure 11 As shown, this embodiment provides a computer-readable storage medium 1100, on which a computer program 1111 is stored. When the computer program 1111 is executed by a processor, it performs the following steps:
[0113] S1, Multiple nodes are arranged into a doubly linked delay queue, and the multiple nodes are sorted in ascending order according to their trigger time ExpireTime. The nodes are either Alarm modules or ScheduleTable modules; the Counter module is set to be adjacent to the node with the smallest trigger time ExpireTime.
[0114] S2, When the Counter module enters an interrupt, the next node trigger time of the Counter module is assigned the trigger time of the smallest node, Expire Time, and the current counting time of the Counter module is assigned the system timer time.
[0115] S3. If the current counting time of the Counter module is consistent with the trigger time of its next node (next Expire Time), then the processing function corresponding to the next node is executed; otherwise, the Counter module exits the interrupt.
[0116] S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node;
[0117] S5, repeat steps S2 to S4. If all modules in the doubly linked delay queue have been executed, exit the interruption of the Counter module.
[0118] This invention provides an embedded real-time operating system scheduling method, system, electronic device, and storage medium based on a doubly linked delay queue. It represents an optimized scheduling mechanism for embedded real-time operating systems. The main approach involves abstracting the common characteristics of the Alarm and ScheduleTable modules into a new module (DrvObjectModule). The data storage structure of this module primarily consists of a doubly linked delay queue. Within this queue, the differences between the Alarm and ScheduleTable modules are distinguished using a registered module processing function. Furthermore, the activation time of the head node in the doubly linked delay queue is stored in the Counter module. This way, when an interrupt occurs in the Counter module, the scheduler does not need to query the queue for the trigger time; it only needs to compare the current count value of the Counter with the trigger time of the nearest module node. This unifies system scheduling processing, reduces traversal of the delay queue (including the Alarm and ScheduleTable modules), effectively shortens system scheduling runtime, improves system scheduling efficiency, and enhances code readability, extensibility, and maintenance.
[0119] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0120] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0121] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0122] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0123] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0124] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0125] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A scheduling method for an embedded real-time operating system based on a doubly linked delayed queue, characterized in that, include: S1, Multiple nodes are arranged into a doubly linked delay queue, and the nodes are sorted in ascending order according to their trigger time (Expire Time). The nodes are either Alarm modules or ScheduleTable modules; including: The common features of the Alarm module and ScheduleTable module in each module are extracted as a single node. All nodes form the DrvObjectModule. The data storage structure of the DrvObjectModule is a doubly linked delayed queue. The prev of the node points to the first address of the entry member in the previous node, and the next of the node points to the first address of the entry member in the next node. In the doubly linked delay queue, the differences between the Alarm module and the ScheduleTable module are distinguished by registering module processing functions. Specifically, this includes setting function pointers for the Alarm module or ScheduleTable module on each node to point to the corresponding processing function of each module; when the Alarm module or ScheduleTable module is run, the processing function of the currently executing module is called by running the function pointer of the currently executing module. Sort the trigger times (Expire Time) of each module in the doubly linked delay queue from smallest to largest to obtain an ascending doubly linked delay queue. Set the Counter module adjacent to the node with the smallest Expire Time; S2, When the Counter module enters an interrupt, the trigger time of the smallest node, ExpireTime, is used to assign the next Expire Time of the Counter module as the trigger time of the next node, and the current counting time of the Counter module is used to assign the system timer time as the current counting time of the Counter module. S3. If the current counting time of the Counter module is consistent with the trigger time of its next node (nextExpire Time), then the processing function corresponding to the next node is executed; otherwise, the Counter module exits the interrupt. S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node; S5, repeat steps S2~S4. If all modules in the doubly linked delay queue have been executed, exit the interruption of the Counter module.
2. The embedded real-time operating system scheduling method based on a doubly linked delayed queue according to claim 1, characterized in that, Set the Counter module adjacent to the node with the smallest trigger time (Expire Time), including: The Counter module is set adjacent to the head node, where the head node is the node with the smallest Expire Time in the doubly linked delay queue; The head node's `prev` pointer points to the first address of the Counter module's member list, the head node's `next` pointer points to the first address of the entry member in the next node, the Counter module's `prev` pointer points to the first address of the entry member in the tail node, the Counter module's `next` pointer points to the first address of the entry member in the head node, the tail node's `prev` pointer points to the first address of the entry member in the previous node, and the tail node's `next` pointer points to the first address of the Counter module's member list. Here, the tail node is the node with the largest trigger time (Expire Time) in the doubly linked delay queue, and `list` is the head node of the Counter module's linked list.
3. The embedded real-time operating system scheduling method based on a doubly linked delayed queue according to claim 2, characterized in that, S4, delete the module that has completed execution, and use the next module to be executed in the doubly linked delayed queue as the new head node, including: Delete the modules that have been executed by the current head node, set the next pointer of the Counter module to the first address of the entry member of the next node in the doubly linked delayed queue, and set the prev pointer of the next node to the first address of the list member of the Counter module, so as to update the next module to be executed to the new head node. The next node trigger time (nextExpire Time) of the Counter module is assigned the trigger time (nextExpire Time) of the new head node, and the current counting time (currentTime) of the Counter module is updated using the current system timer time.
4. The embedded real-time operating system scheduling method based on a doubly linked delayed queue according to claim 3, characterized in that, The value of `next` is obtained by adding the offset of the member `entry` within the next node to the starting address of the next node, and the value of `prev` is obtained by adding the offset of the member `entry` within the previous node to the starting address of the previous node.
5. The embedded real-time operating system scheduling method based on a doubly linked delayed queue according to claim 1, characterized in that, Depending on whether periodic scheduling of executed modules is required, the processing function is configured to either re-insert the corresponding executed module into the doubly linked delay queue.
6. An embedded real-time operating system scheduling system based on a doubly linked delayed queue, characterized in that, include: A building module is used to form a doubly linked delay queue of multiple nodes and sort the nodes in ascending order according to their trigger time (Expire Time). These nodes are either Alarm modules or ScheduleTable modules; including: The common features of the Alarm module and ScheduleTable module in each module are extracted as a single node. All nodes form the DrvObjectModule. The data storage structure of the DrvObjectModule is a doubly linked delayed queue. The prev of the node points to the first address of the entry member in the previous node, and the next of the node points to the first address of the entry member in the next node. In the doubly linked delay queue, the differences between the Alarm module and the ScheduleTable module are distinguished by registering module processing functions. Specifically, this includes setting function pointers for the Alarm module or ScheduleTable module on each node to point to the corresponding processing function of each module; when the Alarm module or ScheduleTable module is run, the processing function of the currently executing module is called by running the function pointer of the currently executing module. Sort the trigger times (Expire Time) of each module in the doubly linked delay queue from smallest to largest to obtain an ascending doubly linked delay queue. The building block is also used to set the Counter module adjacent to the node with the smallest trigger time Expire Time; The setting module is used to assign the next Expire Time of the Counter module to the trigger time of the next node when the Counter module enters an interrupt, using the trigger time Expire Time of the smallest node, and to assign the current time of the Counter module to the current time of the system timer. The judgment module is used to execute the processing function corresponding to the next node when the current counting time of the Counter module is consistent with the trigger time of the next node, next Expire Time; otherwise, it exits the interruption of the Counter module. The update module is used to delete modules that have completed execution and to set the next module to be executed in the doubly linked delayed queue as the new head node; The loop module is used to repeat the operations of the setting module, the judgment module, and the update module. If all modules in the doubly linked delay queue have been executed, the Counter module will exit the interrupt.
7. An electronic device, characterized in that, The system includes a memory and a processor, wherein the processor is used to implement the steps of the embedded real-time operating system scheduling method based on a doubly linked delayed queue as described in any one of claims 1-5 when executing computer management programs stored in the memory.
8. A computer-readable storage medium, characterized in that, It stores a computer management program, which, when executed by the processor, implements the steps of the embedded real-time operating system scheduling method based on a doubly linked delay queue as described in any one of claims 1-5.