Data structure, control method and system for shared memory consistency based on task priority calculation and dynamic memory fence mechanism
By employing task priority calculation and a dynamic memory fence mechanism, the consistency problem between task scheduling and memory access in multi-task systems is solved, achieving efficient data consistency and system stability, and improving real-time performance and fault tolerance.
Patent Information
- Application Number
- CN202511828732.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-05
- Publication Date
- 2026-03-03
AI Technical Summary
In multitasking systems, existing technologies cannot effectively coordinate the consistency of task scheduling and memory access, leading to data inconsistency and system crashes. In particular, in real-time operating systems and embedded systems, traditional memory barrier mechanisms cannot dynamically adjust the effective time and granularity of the barrier according to the real-time requirements and priorities of the tasks.
A shared memory consistency control method based on task priority calculation and dynamic memory fence mechanism is adopted. Through the shared memory access control table SMACT, task access control table, memory fence management table MBCT and task fence priority queue TBPQ, the execution order and task priority of memory fence are dynamically adjusted to ensure that high-priority tasks access shared memory in the shortest time and avoid low-priority tasks from being blocked.
It improves the system's real-time performance and fault tolerance, reduces resource contention, ensures data consistency and system stability, ensures that high-priority tasks can update data in real time, and avoids access conflicts and data inconsistency issues between tasks.
Smart Images

Figure CN121597443A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of multi-task scheduling technology, specifically to a data structure, control method, and system for shared memory consistency based on task priority calculation and dynamic memory fence mechanism. Background Technology
[0002] In multi-tasking systems, ensuring memory consistency and avoiding race conditions when tasks share memory resources has always been a critical issue for system real-time performance and reliability. Especially in real-time operating systems and embedded systems, conflicts arising from task priorities, periodicity, and memory access can easily lead to data inconsistencies, and even system crashes or task failures. Traditional real-time task scheduling uses fixed-priority scheduling or dynamic-priority scheduling (such as EDF scheduling) to ensure task real-time performance. Existing memory consistency control mechanisms typically rely on static fence mechanisms. Memory fences are used in multi-core systems to ensure the order of memory accesses. While typical memory fence algorithms can ensure the orderliness of memory operations, they do not consider the impact of memory fences on real-time scheduling, especially in multi-tasking environments, and do not dynamically adjust the effective time and granularity of the fences based on task real-time requirements and priorities.
[0003] Traditional real-time task scheduling relies solely on a single dimension such as task periodicity or expiration time for priority calculation. This can easily lead to delays for long-running, high-priority tasks, resulting in insufficient system robustness in terms of real-time performance. Furthermore, it lacks precise control over memory consistency and fails to dynamically coordinate the consistency between task scheduling and memory access. On the other hand, traditional memory fence algorithms have several shortcomings, such as: excessively large lock granularity leading to low-priority tasks consuming too many resources; global locks and static fence mechanisms causing prolonged memory usage and latency, resulting in significant performance overhead; and a lack of coordination between task scheduling and memory access. Summary of the Invention
[0004] In view of this, the present invention provides a shared memory consistency data structure based on task priority calculation and dynamic memory fence mechanism, including: a shared memory access control table SMACT, a task access control table, a memory fence management table MBCT, and a task fence priority queue TBPQ; wherein: The shared memory access control table SMACT includes: data block ID, data status, access priority, and barrier status; among which: Data block ID, used to uniquely identify each shared data block; Data status, used to indicate whether the data block has been updated or whether the data block can be read in its current state; Access priority is used to identify the tasks that can access the data block; Fence status is used to identify whether the data block is under fence control. The task access control list includes: task priority, accessed shared memory area, access timestamp, and barrier control information; The Memory Fence Management Table (MBCT) is a dynamic fence based on data blocks and task priorities. It is used to record the granularity of the current fence, the locking time information, and to dynamically adjust the effective range of the fence in conjunction with task scheduling. The Task Fence Priority Queue (TBPQ) includes: Task ID, Task Priority, and its corresponding fence state.
[0005] This invention also provides a shared memory consistency control method based on task priority calculation and a dynamic memory fence mechanism. This method employs the data structure described above and includes: Step 21: Establish a task scheduling mechanism based on dynamic memory barriers; Step 22: Establish task priorities and shared memory access control.
[0006] Furthermore, step 21 specifically includes: Step 211: Mark the shared memory region and define the access permissions for each memory page; Step 212: Define a task access control list for each task; Step 213: When the highest priority task accesses shared memory, insert a memory barrier before its access to ensure that other priority tasks are allowed to access the relevant shared data only after the memory operation of the highest priority task is completed. Step 214: Dynamically adjust the execution order and task priority of the memory barrier so that the highest priority task can access and update the shared memory in the shortest time, avoiding blocking of other priority tasks.
[0007] Furthermore, step 22 specifically includes: Step 221: During task scheduling, dynamically adjust task priority based on the worst-case execution time (WCET), task cycle time (CycleTime), and shortest deadline (Deadline). Step 222: For the highest priority task that requires shared memory, execute the highest priority task first, and ensure memory consistency through memory barriers while the highest priority task is being executed. Step 223: For other priority tasks, the task execution order is scheduled according to the task's real-time requirements and the state of the memory barrier, so that when other priority tasks access shared data, they cannot read data that the highest priority task is modifying and has not been synchronized, thereby ensuring data consistency.
[0008] Further, in step 221, the task priority P(Task) is determined in the following manner:
[0009] Where α and β are weighting parameters.
[0010] Furthermore, the priority of each task is dynamically adjusted based on its actual execution time and cycle.
[0011] Furthermore, in step 222, memory consistency is ensured through a dynamic memory barrier when the highest priority task is executed. Specifically, when a highest priority task requests access to shared memory, the memory barrier is immediately activated, and other priority tasks are forced to wait. When the task priority changes, the locking granularity and timing of the memory barrier are also adjusted accordingly.
[0012] Furthermore, once a task completes its access, the memory barrier is immediately released, allowing other tasks to access the shared data; during the execution of a task, if the execution time of that task exceeds the predetermined maximum period, the memory barrier is forcibly released.
[0013] Furthermore, the method is applied to collaborative operations of a swarm of drones, wherein the task priorities of the drones include: First priority task: Obstacle avoidance; Second priority tasks: Flight path planning and maintaining flight formation; Third priority task: Target monitoring; The first priority is higher than the second priority, and the second priority is higher than the third priority.
[0014] This invention also provides a shared memory consistency control system based on task priority calculation and a dynamic memory fence mechanism, for implementing the method described above. The system includes a scheduler; wherein... When a task begins, the scheduler calculates the activation time and granularity of the memory fence based on the task's priority and periodicity; for the highest priority task, the memory fence granularity is set to the smallest. When executing task access control, before each task accesses shared memory, the scheduler checks the status of the corresponding memory region in the shared memory access control table SMACT. When the memory barrier is locked, the task cannot access the corresponding memory region. When the memory barrier is unlocked, the task obtains data and modifies the shared memory. When coordinating task scheduling with dynamic memory barriers, in the case of concurrent execution of multiple tasks, the scheduler dynamically adjusts the locking time of the memory barrier according to the task priority to prevent other priority tasks from blocking the memory access of the highest priority task.
[0015] The present invention has the following beneficial technical effects: 1. Improve system real-time performance: By using a priority control algorithm based on multiple time indicators, tasks with the shortest execution time and cycle expiration time are prioritized for execution, reducing task scheduling latency and ensuring that real-time tasks are completed first. In addition, high-priority tasks can access shared memory first, avoiding access conflicts and data inconsistency issues between tasks, thereby improving the real-time performance of the system.
[0016] 2. Reduce resource contention: By using a finer-grained fence mechanism and priority scheduling algorithm, resource contention between tasks is reduced, avoiding unnecessary task blocking.
[0017] 3. Ensure data consistency: Through granular memory fencing control, high-priority tasks can update data in real time, while low-priority tasks cannot access data if there is inconsistency, thus ensuring memory integrity.
[0018] 4. Improve system fault tolerance: If high-priority tasks are delayed in execution, the barrier mechanism will be forcibly removed to avoid occupying resources for a long time and ensure the normal operation of the system.
[0019] In summary, most existing memory barrier mechanisms are static and coarse-grained locking mechanisms, unable to dynamically adjust the granularity and locking time of the lock according to task priority. In contrast, the priority- and periodic-based barrier control mechanism proposed in this invention can significantly reduce memory access conflicts and improve real-time response capabilities in systems with high real-time requirements (such as unmanned clusters). Attached Figure Description
[0020] Figure 1 This is a shared memory consistency control method based on task priority calculation and dynamic memory fence mechanism, according to an embodiment of the present invention. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] This invention proposes a multi-task shared memory consistency control method based on task priority using a precision monotonic scheduler and a dynamic memory barrier mechanism. By designing a dynamic scheduling mechanism based on task priority and a memory access control table, and utilizing a memory barrier mechanism, the method ensures the consistency of high-priority tasks' access to shared memory, preventing low-priority tasks from reading inconsistent data, thus ensuring the stability and real-time performance of the system.
[0023] 1.1 Memory Fence Mechanism This invention proposes a task scheduling mechanism based on dynamic memory barriers, which specifically includes the following steps: The shared memory region is marked, and the access permissions for each memory page are defined.
[0024] Define a task access control table for each task, which contains the task's priority, the shared memory area to be accessed, the access timestamp, and barrier control information.
[0025] When a high-priority task accesses shared memory, a memory barrier is inserted before its access to ensure that other tasks are allowed to access the relevant shared data only after the task's memory operation is completed.
[0026] The execution order and task priority of memory barriers are dynamically adjusted to ensure that high-priority tasks can access and update shared memory in the shortest possible time, avoiding blocking of low-priority tasks.
[0027] 1.2 Task Priority and Shared Memory Access Control 1) During task scheduling, the task priority will be dynamically adjusted based on and by combining multiple indicators such as the worst-case execution time (WCET), task cycle, and shortest due time.
[0028] 2) For high-priority tasks that require shared memory (such as flight control tasks and obstacle avoidance tasks), the system prioritizes the execution of these tasks and ensures memory consistency through barriers during task execution.
[0029] 3) For low-priority tasks (such as status monitoring tasks), the system will reasonably schedule the task execution order according to the real-time requirements of the task and the state of the memory barrier, so as to ensure that when low-priority tasks access shared data, they will not read data that high-priority tasks are modifying and that has not been synchronized, thereby ensuring data consistency.
[0030] 1.3 Data Structure Design This invention designs the following data structures to manage task priorities and memory access control. The Shared Memory Access Control Table (SMACT) contains metadata and access control flags for each shared data block. This table includes: 1. Block ID – uniquely identifies each shared data block; 2. Data Status – indicates whether the data block has been updated or is currently readable; 3. Access Priority – identifies which tasks can access the data block; 4. Fence Status – indicates whether the data block is under fence control (i.e., other tasks must wait while one task is modifying the data block).
[0031] The innovation of this data structure design lies in: 1. Fine-grained control - each shared memory data block has independent access control, which can ensure that when a high-priority task modifies the data, a low-priority task cannot access the data at the same time; 2. Dynamic fence mechanism - based on task priority, the fence mechanism can be dynamically adjusted to ensure that high-priority tasks can modify data in real time without being blocked by low-priority tasks.
[0032] Each task needs to query the SMACT table when accessing shared memory. For example, the flight control task needs to access flight path data, and the obstacle avoidance task needs to access obstacle information. The SMACT table records each task's access to the memory region based on task priority and access timestamp. For instance, the flight control and obstacle avoidance tasks are high-priority tasks and therefore have higher access permissions to the memory region.
[0033] The Memory Barrier Control Table (MBCT) is a dynamic barrier based on data blocks and task priorities. This table records the current barrier granularity, locking time information, and dynamically adjusts the effective range of the barrier in conjunction with task scheduling.
[0034] In traditional memory fence mechanisms, the granularity of the fence is usually quite coarse, potentially locking the entire data structure (i.e., the entire flight path data, obstacle information, etc., need to be locked). In this invention, however, the granularity of the memory fence is designed to be at the data block level. This includes: 1. Data block-level memory fence – When a high-priority task needs to modify a data block in shared memory (such as flight data or obstacle information), the memory fence will lock this data block, ensuring that other tasks cannot access it until the task completes the modification. Therefore, this is a dynamic fence based on task and data block priorities; 2. Fence lifecycle control – The fence is activated at the start of the task and deactivated upon completion of the task. This mechanism ensures that the fence does not continue to occupy resources after the task ends, improving system throughput.
[0035] The MBCT table manages the state of memory barriers. For example, when a flight control task is accessing flight path data, it sets a fine-grained barrier to ensure that low-priority tasks (such as target monitoring tasks) cannot access the same memory region during this period, thus avoiding data conflicts. After the task is completed, the MBCT dynamically adjusts the granularity of the memory barriers. For instance, after the flight control task is completed, the MBCT is set to an unbarriered state by the task, allowing other tasks to access memory.
[0036] The Task Barrier Priority Queue (TBPQ) contains the priorities of multiple tasks and their corresponding barrier states: 1. Task ID – a unique task identifier; 2. Task Priority – the task's priority, determining its access rights to shared memory; 3. Barrier Control State – indicating whether the task is currently under barrier control. This data structure can automatically adjust the barrier control strength based on task priority. For example, high-priority tasks are processed first, and the barrier mechanism releases quickly; low-priority tasks enter the waiting queue until the high-priority task completes its operation on the shared data.
[0037] During task scheduling, each task calculates its priority based on a priority control algorithm that considers multiple time metrics, and adds it to the TBPQ queue according to the calculated priority. At the same time, the fence control status of the task item in the TBPQ queue is updated.
[0038] In summary, the Task Priority Queue (TBPQ) dynamically adjusts the execution order of tasks, ensuring that high-priority tasks are executed first. The Shared Memory Access Control Table (SMACT) ensures access control of shared memory, avoiding data conflicts between tasks. The Memory Fence Management Table (MBCT) dynamically adjusts the fence granularity to ensure memory consistency and prevent low-priority tasks from affecting high-priority memory access.
[0039] 1.4 Algorithm Innovation and Implementation like Figure 1 As shown, the shared memory consistency control method of the present invention based on task priority calculation and dynamic memory fence mechanism includes: establishing a task scheduling mechanism based on dynamic memory fence, and establishing task priority and shared memory access control. These will be described in detail below.
[0040] 1.4.1 Priority Control Algorithm Based on Multiple Time Indicators for Real-Time Systems In real-time systems, the real-time performance of task scheduling is crucial. When designing a priority algorithm based on actual deployment, the following key time metrics should be considered: 1-- Worst-Case Execution Time (WCET): This is the maximum execution time of a task, i.e., the execution time required in the worst-case scenario. A shorter WCET means the task can complete faster, reducing the consumption of system resources and thus having a higher priority; 2-- Cycle Time: This is the period during which the task is repeatedly executed. Tasks with shorter cycles usually have stronger real-time requirements and should be given higher priority; 3-- Shortest Deadline: This is the time before which a task must be completed. Failure to complete a task on time may lead to serious consequences, therefore tasks with shorter deadlines usually have higher priority. This invention designs a unique priority calculation formula that integrates the above key time metrics:
[0041] WCET / CycleTime prioritizes tasks with shorter execution times to prevent them from consuming system resources for extended periods. This measure assesses the maximum resource consumption a task requires within a given cycle. 1 / Deadline prioritizes tasks with the shortest due dates to avoid missing deadlines. Parameters α and β are weighting parameters that determine the relative impact of different time metrics on priority calculation. Parameter α can be large to emphasize the impact of task execution time and periodicity on priority, but the weighting system can be adjusted based on the specific needs of each task. For example, if the task has very high real-time requirements, the weighting parameter β can be increased to amplify the impact of the task's due date on priority.
[0042] 1.4.2 Priority-based dynamic fence control algorithm In existing memory fence mechanisms, the granularity of the fences is often too coarse, or the priority adjustment of the fence mechanism is too simple. To improve real-time performance and avoid data access conflicts, we designed a dynamic fence control algorithm based on task priority and task cycle time, which includes: Task priority adjustment algorithm: The priority of tasks is dynamically adjusted based on the actual execution time and cycle of each task. Higher priority tasks are scheduled for execution immediately, ensuring that critical tasks can access shared memory first and guaranteeing real-time performance.
[0043] Task priority and fence adjustment algorithm: When a high-priority task requests access to shared memory, the fence is activated immediately, forcing other tasks to wait. Fence control is dynamically adjusted based on task priority; when task priorities change, the granularity and timing of the fence's locking are adjusted accordingly.
[0044] The fence release algorithm releases the fence immediately after a task completes its access, allowing other tasks to access the shared data. If a task's execution time exceeds a predetermined maximum period, the fence will be forcibly released to prevent prolonged resource occupation.
[0045] 1.4.3 Ensure multi-task collaboration and memory consistency control Combining memory fence mechanisms with multi-task scheduling algorithms (such as scheduling based on worst-case execution time (WCET) and longest cycle time): Real-time memory consistency: When multiple drone missions need to access the same memory region, memory consistency is guaranteed in real time. For example, if a flight control mission and an obstacle detection mission need to read obstacle data simultaneously, and one mission modifies the data, a fence mechanism will prevent other missions from accessing that data until the mission completes the data modification.
[0046] Priority-based access control: The memory fence mechanism allocates memory access permissions to each task according to its priority. High-priority tasks can access data in real time when it is updated, while low-priority tasks need to wait.
[0047] 1.4.4 Implementation Case It is especially suitable for multi-task systems with high real-time requirements, such as drone swarm collaboration and IoT devices.
[0048] In a drone swarm cooperative flight system, multiple drone missions share data such as flight paths and obstacle information. In this environment, the flight control mission has the highest priority and must acquire and update the shared flight path data in real time, while the obstacle avoidance mission also needs to read the shared obstacle information in real time and make obstacle avoidance decisions. At this point, through the memory fence mechanism of this invention, high-priority flight control missions can access and update the flight path data in shared memory first, while low-priority status monitoring missions must wait until the flight control missions have completed before they can safely read the shared data, avoiding erroneous updates to the drone flight paths due to data conflicts. For example: Flight control task (WCET: 5ms, cycle: 10ms, expiration time: 10ms) Obstacle avoidance task (WCET: 8ms, period: 20ms, due date: 10ms) Target monitoring task (WCET: 6ms, period: 50ms, due date: 15ms) Status monitoring task (WCET: 100ms, period: 100ms, due date: 90ms) When both parameters α and β are set to 1, the priority of the flight control task is 0.6, the obstacle avoidance task is 0.4667, the target monitoring task is 0.145, and the status monitoring task is 0.1111. According to the priority-based dynamic fence control algorithm, high-priority tasks (flight control and obstacle avoidance) have smaller fence granularities to ensure efficient and timely memory access; low-priority tasks (target monitoring and status monitoring) have larger fence granularities to prevent them from blocking the execution of high-priority tasks. Therefore, during the execution of high-priority tasks such as flight control and obstacle avoidance, the fence mechanism locks the shared memory areas of the relevant flight paths and obstacles, preventing data inconsistencies caused by other tasks accessing this critical data. Memory access for target monitoring and status monitoring tasks can be performed after the high-priority tasks have finished executing, avoiding resource contention.
[0049] 1.4.5 Case Study of Dynamically Adjusting Fence Granularity High-priority tasks (such as obstacle avoidance): These tasks have the highest requirements for shared memory access because any data inconsistency could cause the drone to collide or deviate from its planned path. Therefore, the fence granularity is set to the smallest to ensure data consistency. This task will have exclusive access to obstacle information and flight path data; the fence will only be removed after this task is completed, allowing other tasks to access this data.
[0050] Medium-priority tasks (flight path planning, formation keeping): These tasks require frequent access to shared memory, but can tolerate slightly less latency compared to obstacle avoidance tasks with high safety requirements. The fence granularity can be appropriately increased to balance resource access between high-priority and low-priority tasks. In path planning and formation keeping tasks, the fence mechanism will ensure that multiple UAVs do not conflict in accessing flight path and formation data.
[0051] Low-priority tasks (target monitoring): Target monitoring tasks have relatively low real-time requirements, but they still rely on unknown target data in shared memory. The fence granularity can be set larger to ensure that it does not affect the execution of high-priority tasks.
[0052] 1.4.6 Overall System Operation 1) Memory fencing combined with task priority: At the start of a task, the scheduler calculates the activation time and granularity of the fencing based on the task's priority and periodicity. For high-priority tasks, the fencing granularity is set to the smallest to ensure memory consistency.
[0053] Task access control: Before accessing shared memory, each task first checks the status of the corresponding memory region in the SMACT table. If the barrier is locked, the task must wait for the barrier to be released before accessing it. Only after the barrier is released will the task acquire data and modify the shared memory.
[0054] Task scheduling and memory fence coordination: When multiple tasks are executed concurrently, the scheduler dynamically adjusts the locking time of the memory fence according to the task priority to prevent low-priority tasks from blocking the memory access of high-priority tasks.
[0055] As can be seen from the above introduction: The Shared Memory Access Control Table (SMACT) of this invention is a novel data structure capable of dynamically controlling access permissions for each shared data block and recording task priorities and barrier states. This represents a fundamental innovation over traditional memory mechanisms. The SMACT data structure of this invention does not simply mark the access status of memory blocks; rather, based on SMACT, it can dynamically adjust the access status of memory blocks according to task priorities, access types, access time windows, and barrier states. Furthermore, SMACT can automatically select the granularity and effective scope of the barrier based on different task types (real-time requirements and priorities), thereby avoiding excessive memory access locking.
[0056] The Task Priority Queue (TBPQ) of this invention optimizes memory access control by finely managing the fence control state of tasks through a queue structure based on task priority and cycle. This patented TBPQ queue is not merely a priority queue; it also dynamically adjusts the fence release time based on the task's real-time cycle and priority changes, and automatically triggers the activation or deactivation of the memory fence according to the actual progress of task execution.
[0057] The priority control algorithm based on multiple time indicators proposed in this invention calculates priorities by combining WCET, periodicity, and expiration time with weighted calculations using weight parameters. This takes into account execution complexity and periodicity requirements, making task scheduling more flexible and precise, and placing greater emphasis on the real-time requirements of the system. Furthermore, the algorithm incorporates a memory fence mechanism, dynamically adjusting the fence mechanism according to priority, thus avoiding the inability of traditional static priority and memory fence strategies to effectively balance task scheduling and memory consistency issues.
[0058] The task priority and fence dynamic adjustment algorithm of this invention combines task priority and periodicity to design a dynamic fence control mechanism, enabling high-priority tasks to access shared memory in real time, while low-priority tasks can access memory without affecting high-priority tasks. This invention solves the problem of consistency between task execution and shared memory by designing a close link between a dynamic fence mechanism and a task scheduling mechanism. This combination of real-time scheduling and memory access is uniquely innovative.
[0059] This invention can also implement a hardware-accelerated memory fence mechanism. When drone swarms are interconnected via wireless or wired networks, they can combine the hardware-accelerated fence mechanism to synchronize memory data through hardware acceleration, thereby reducing the latency caused by software fences.
[0060] The task fence control mechanism (fence granularity control, dynamic fence loading and releasing) of this invention is not typically found in other systems. Existing technologies rarely consider memory access control in task scheduling, usually only offering separate scheduling strategies and separate memory consistency control; this patent, however, deeply integrates these two areas.
[0061] This invention solves the problem of consistency between task execution and shared memory by designing a dynamic fence mechanism and a close connection and interaction between the task mechanism. Other existing scheduling systems generally do not adjust task scheduling based on actual memory access conditions (such as whether memory fences are released), so this invention's interaction between real-time scheduling and memory access is uniquely innovative.
[0062] This invention introduces a unique computational model that dynamically adjusts the granularity of the fence based on the actual real-time requirements of the task (Worst-Case Execution Time (WCET) and task cycle time, etc.). While most existing technologies rely on fixed static priority algorithms to schedule tasks and control the fence, this invention's innovative computational method continuously and dynamically adjusts the fence during execution, further enhancing the interaction and feedback between real-time performance and memory consistency.
[0063] This invention dynamically adjusts the activation and release time of memory fences based on task priority and real-time requirements. It can calculate the granularity and scope of the fence in real time according to task priority. Furthermore, this dynamic activation and release mechanism is unique, avoiding unnecessary locking and scheduling, thereby improving system efficiency and stability. Existing technologies do not integrate these dynamic control functions with task scheduling.
[0064] Please note that the technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments have been described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification. The above embodiments only illustrate several implementation methods of this application, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the invention patent. It should be pointed out that those skilled in the art can make several modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A shared memory consistency data structure based on task priority calculation and dynamic memory fence mechanism, characterized in that, This data structure includes: the Shared Memory Access Control Table (SMACT), the Task Access Control Table (MBCT), and the Task Fence Priority Queue (TBPQ); among which: The shared memory access control table SMACT includes: data block ID, data status, access priority, and barrier status; among which: Data block ID, used to uniquely identify each shared data block; Data status, used to indicate whether the data block has been updated or whether the data block can be read in its current state; Access priority is used to identify the tasks that can access the data block; Fence status is used to identify whether the data block is under fence control. The task access control list includes: task priority, accessed shared memory area, access timestamp, and barrier control information; The Memory Fence Management Table (MBCT) is a dynamic fence based on data blocks and task priorities. It is used to record the granularity of the current fence, the locking time information, and to dynamically adjust the effective range of the fence in conjunction with task scheduling. The Task Fence Priority Queue (TBPQ) includes: Task ID, Task Priority, and its corresponding fence state.
2. A shared memory consistency control method based on task priority calculation and dynamic memory fence mechanism, characterized in that, This method employs the data structure described in claim 1, and the method includes: Step 21: Establish a task scheduling mechanism based on dynamic memory barriers; Step 22: Establish task priorities and shared memory access control.
3. The method as described in claim 2, characterized in that, Step 21 specifically includes: Step 211: Mark the shared memory region and define the access permissions for each memory page; Step 212: Define a task access control list for each task; Step 213: When the highest priority task accesses shared memory, insert a memory barrier before its access to ensure that other priority tasks are allowed to access the relevant shared data only after the memory operation of the highest priority task is completed. Step 214: Dynamically adjust the execution order and task priority of the memory barrier so that the highest priority task can access and update the shared memory in the shortest time, avoiding blocking of other priority tasks.
4. The method as described in claim 2, characterized in that, Step 22 specifically includes: Step 221: During task scheduling, dynamically adjust task priority based on the worst-case execution time (WCET), task cycle time (CycleTime), and shortest due date (Deadline). Step 222: For the highest priority task that requires shared memory, execute the highest priority task first, and ensure memory consistency through memory barriers during the execution of the highest priority task. Step 223: For other priority tasks, the task execution order is scheduled according to the task's real-time requirements and the state of the memory barrier, so that when other priority tasks access shared data, they cannot read data that the highest priority task is modifying and has not been synchronized, thereby ensuring data consistency.
5. The method as described in claim 4, characterized in that, In step 221, the task priority P(Task) is determined as follows: , Where α and β are weighting parameters.
6. The method as described in claim 4, characterized in that, The priority of each task is dynamically adjusted based on its actual execution time and cycle.
7. The method as described in claim 4, characterized in that, In step 222, memory consistency is ensured through a dynamic memory barrier when the highest priority task is executed. Specifically, when a highest priority task requests access to shared memory, the memory barrier is activated immediately, and other priority tasks are forced to wait. When the task priority changes, the locking granularity and timing of the memory barrier are also adjusted accordingly.
8. The method as described in claim 7, characterized in that, Once a task completes its access, the memory barrier is immediately released, allowing other tasks to access the shared data; if the execution time of a task exceeds the predetermined maximum period during the execution of the task, the memory barrier is forcibly released.
9. The method according to any one of claims 2-8, characterized in that, The method is applied to collaborative operations of drone swarms, wherein the task priorities of the drones include: First priority task: Obstacle avoidance; Second priority tasks: Flight path planning and maintaining flight formation; Third priority task: Target monitoring; The first priority is higher than the second priority, and the second priority is higher than the third priority.
10. A shared memory consistency control system based on task priority calculation and dynamic memory fence mechanism, used to implement the method as described in any one of claims 2-9, characterized in that, The system includes a scheduler; wherein, When a task begins, the scheduler calculates the activation time and granularity of the memory fence based on the task's priority and periodicity; for the highest priority task, the memory fence granularity is set to the smallest. When executing task access control, before each task accesses shared memory, the scheduler checks the status of the corresponding memory region in the shared memory access control table SMACT. When the memory barrier is locked, the task cannot access the corresponding memory region. When the memory barrier is unlocked, the task obtains data and modifies the shared memory. When coordinating task scheduling with dynamic memory barriers, in the case of concurrent execution of multiple tasks, the scheduler dynamically adjusts the locking time of the memory barrier according to the task priority to prevent other priority tasks from blocking the memory access of the highest priority task.