File data pre-reading and cache locking method based on real-time task priority
By configuring a file data pre-fetching and cache locking method based on real-time task priority in an embedded real-time system, the problems of uncertainty and low efficiency in file data reading in embedded real-time systems are solved, and efficient and deterministic data reading and cache management are achieved.
Patent Information
- Application Number
- CN202610143948.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-02
- Publication Date
- 2026-06-19
- Estimated Expiration
- 2046-02-02
AI Technical Summary
In existing technologies, file data reading in embedded real-time systems suffers from increased uncertainty, inaccurate prediction of response latency, lack of pre-reading mechanisms for high-frequency data access, caching strategies that do not incorporate real-time task priorities, and insufficient data locking protection mechanisms, resulting in limitations on system real-time performance and efficiency.
By configuring file data pre-reading and cache locking methods based on real-time task priorities, including priority definition strategies, cache allocation, association information maintenance, and dynamic cache management, high-priority data pre-reading and locking protection are ensured, and cache utilization is optimized.
It improves system real-time performance and read efficiency, reduces fluctuations in real-time task execution, adapts to the differentiated needs of tasks with different priorities, and improves the utilization of cache resources and the determinism of data reading.
Smart Images

Figure CN121614455B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of embedded real-time system technology, specifically relating to a method for pre-reading and locking file data based on real-time task priority. Background Technology
[0002] In the field of embedded real-time systems, file data reading is a crucial step in ensuring the implementation of core system functions. It is widely used in scenarios with extremely high requirements for task response timeliness and execution determinism, such as industrial control, automotive electronics, and smart terminals. Currently, existing technologies generally adopt the method of directly performing I / O operations on the storage medium when handling data reading and writing needs. However, I / O operations are affected by factors such as the physical characteristics of the storage medium and the data storage location. Their execution time and response latency cannot be accurately predicted, making them uncertain operations. This characteristic directly leads to uncontrollable fluctuations in the execution process of real-time tasks, thereby reducing the overall real-time performance of the system. At the same time, this method lacks a mechanism for reusing frequently accessed data, limiting data reading efficiency and making it difficult to meet the high-efficiency operation requirements of embedded real-time systems.
[0003] Relevant patent documents retrieved:
[0004] Country of origin: China, Publication number: CN109446114A, Publication date: March 8, 2019. This document discloses a spatial data caching method applied to data nodes. It determines the target data block by receiving read and write operation requests, calculates the priority by combining the access frequency of the data block, the spatial distance to the reference cache block and the corresponding weight, and then determines whether the data block should be added to the cache queue based on the priority, so as to improve the cache hit rate and read and write efficiency.
[0005] The prior art represented by the aforementioned documents has at least the following unresolved technical problems or defects:
[0006] (1) Direct I / O operations increase the uncertainty of real-time tasks. The relevant evidence is that in the prior art, I / O operations are performed directly on the storage medium. However, the execution time and response delay of I / O operations cannot be accurately predicted, resulting in uncontrollable fluctuations in the execution process of real-time tasks.
[0007] (2) The caching strategy does not take into account the priority of real-time tasks and cannot adapt to the differentiated real-time requirements. The relevant evidence is that the comparison file CN109446114A only determines the priority based on the data block's own attributes (access frequency, spatial distance) and does not associate it with the priority level of real-time tasks, which results in the data of high-priority tasks not being able to obtain the guarantee of cache priority.
[0008] (3) There is a lack of a pre-fetching mechanism for real-time task state switching. High-frequency access data cannot be cached in advance. The relevant evidence is that the existing technology and the comparison documents do not involve the pre-fetching logic when the real-time task enters the ready state from the blocked state. High-frequency access data must wait for the read request to be triggered before it is cached, which affects the read efficiency.
[0009] (4) Without a cached data locking protection mechanism, high-priority task data is easily replaced. The relevant evidence is that the existing technology and comparison documents do not have a cached data locking function. High-priority task data may be arbitrarily replaced by low-priority data, increasing the uncertainty of data reading.
[0010] (5) The cache replacement rules lack specificity and cannot accurately release space to meet the needs of high-priority tasks. The relevant evidence is that the comparison file only judges whether to replace cached data based on the priority of the data block itself, and does not establish a differentiated replacement logic based on task priority.
[0011] In view of this, the present invention is hereby proposed. Summary of the Invention
[0012] To address the aforementioned technical problems in the prior art, this invention provides a file data pre-reading and cache locking method based on real-time task priority, which solves the problems of increased uncertainty in real-time tasks, limited file data reading speed, and insufficient system real-time performance in the prior art.
[0013] To achieve the above objectives, the technical solution of the present invention is as follows:
[0014] File data prefetching and cache locking methods based on real-time task priority include:
[0015] S1. Configure priority definition strategy to classify the priority levels of real-time tasks;
[0016] S2. Allocate a cache area, which is used to store file data. The cache data is associated with task priority identifiers and lock identifiers.
[0017] S3. Maintain associated information for real-time tasks, wherein the associated information includes at least task priority and file access records;
[0018] S4. When a real-time task is detected to switch from a blocked state to a ready state, determine whether the real-time task needs to read the storage medium.
[0019] S5. If the real-time task needs to read the storage medium, determine whether the latest data corresponding to the storage medium exists in the cache; wherein, whenever the data in the storage medium is modified, the data corresponding to the cache is marked as non-latest data, and if there is no such mark, it is considered to be the latest data;
[0020] S6. If the latest data is not present in the cache, determine the priority level of the real-time task according to the priority definition strategy, and determine whether the file data is frequently accessed data.
[0021] S7. Based on the idle state of the cache area, the priority level of the real-time task, and the access frequency of the file data, perform the corresponding file data reading or pre-storage operation. The pre-storage operation includes writing the file data into the cache area and configuring the corresponding task priority identifier and lock identifier. The reading operation includes reading the file data from the cache area or storage medium.
[0022] Furthermore, the priority definition strategy includes a static priority strategy, which specifies that:
[0023] Real-time tasks with a priority value of 0-4 are high-priority tasks, real-time tasks with a priority value of 5-9 are medium-priority tasks, and real-time tasks with a priority value greater than 9 are low-priority tasks.
[0024] Furthermore, the priority definition strategy includes a dynamic priority strategy, which specifies that:
[0025] All real-time tasks currently running in the system are sorted by priority. The top 30% of real-time tasks are high-priority tasks, the middle 30% are medium-priority tasks, and the bottom 40% are low-priority tasks.
[0026] Furthermore, the associated information is maintained through a structure, with each real-time task corresponding to a unique structure, which is bound to the identification information of the real-time task.
[0027] Furthermore, in the pre-storage operation, when the real-time task is a high-priority task, the locking flag is configured to be in a locked state, and the locked state continues until a preset time expires and then switches to an unlocked state;
[0028] When the real-time task is a medium-priority task or a low-priority task, the locking flag is configured to be in an unlocked state.
[0029] Furthermore, the idle state of the cache includes having enough free space and not having enough free space. Having enough free space means that the unused space in the cache can completely accommodate the data block corresponding to the file data that needs to be read.
[0030] The phrase "insufficient free space" means that the unused space in the cache cannot fully accommodate the data block, or that the cache has no unused space left.
[0031] Furthermore, when the cache area has insufficient free space and the real-time task is a high-priority task, the cache data blocks corresponding to low-priority tasks in the cache area are released first. If there is still insufficient free space after release, the cache data blocks corresponding to medium-priority tasks are released until the free space meets the storage requirements of the data blocks.
[0032] Furthermore, when the cache area has insufficient free space and the real-time task is a medium-priority task, only the cache data blocks corresponding to low-priority tasks in the cache area are released until the free space meets the storage requirements of the data blocks or there are no cache data blocks corresponding to low-priority tasks that can be released.
[0033] Furthermore, when all cached data blocks in the cache area correspond to high-priority tasks, only the cached data blocks corresponding to the high-priority tasks that are in an unlocked state are released. If there is still not enough free space after release, the file data is read directly from the storage medium.
[0034] Furthermore, the determination of whether the file data is frequently accessed is made by querying the file access records in the associated information.
[0035] The beneficial effects of this invention are as follows:
[0036] (1) Improve system real-time performance: Reduce direct I / O operations on storage media through the buffer, lock high-priority data to prevent arbitrary replacement, reduce fluctuations in real-time task execution, and enhance task response determinism;
[0037] (2) Improve reading efficiency: When a task transitions from the blocked state to the ready state, frequently accessed data is pre-read into the cache. Cache reuse reduces repeated I / O and shortens data reading latency;
[0038] (3) Adapt to different needs: Supports both static and dynamic priority strategies to provide customized caching guarantees for tasks with different priorities, taking into account the needs of core tasks and ordinary tasks.
[0039] (4) Optimize cache utilization: Perform differentiated cache replacement according to task priority, and release low-priority, unlocked data blocks first to ensure that cache resources are tilted towards high-value data and avoid resource waste. Attached Figure Description
[0040] Figure 1 A flowchart of a file data pre-reading and cache locking method provided in an embodiment of the present invention;
[0041] Figure 2 The flowchart for file data pre-reading and cache locking is provided for embodiments of the present invention. Detailed Implementation
[0042] The technical solution of the present invention will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are not all embodiments of the present invention. All other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the present invention.
[0043] It should be noted that, unless otherwise specifically stated, the relative arrangement and numerical expressions of the components and steps described in these embodiments should not be construed as limiting the scope of the invention.
[0044] The following description of exemplary embodiments is merely illustrative and is not intended to limit the invention or its application or use in any way. Techniques, methods, and apparatus known to those skilled in the art may not be discussed in detail herein, but where applicable, such techniques, methods, and apparatus should be considered part of this specification.
[0045] Example
[0046] See Figure 1 , Figure 1 This is a flowchart of the file data pre-reading and cache locking method based on real-time task priority proposed in this invention. Specific steps may include:
[0047] S1. Configure priority definition strategy to classify the priority levels of real-time tasks; specifically including:
[0048] S11. Static Priority Strategy: Priorities are divided according to a preset fixed numerical range. The specific division rules are as follows:
[0049] Real-time tasks with a priority value of 0-4 are classified as high-priority tasks, those with a priority value of 5-9 are classified as medium-priority tasks, and those with a priority value greater than 9 are classified as low-priority tasks.
[0050] For example, the task used for emergency fault handling in the system is assigned a priority value of 3, which is a high-priority task; the routine data acquisition task is assigned a priority value of 7, which is a medium-priority task; and the log backup task is assigned a priority value of 12, which is a low-priority task.
[0051] S12. Dynamic Priority Strategy: Priorities are dynamically adjusted based on the real-time status of currently running tasks. The specific adjustment rules are as follows:
[0052] Periodically sort all real-time tasks running in the system according to their inherent priority attributes (the sorting cycle can be configured according to system requirements, such as 10ms / time). After sorting, the top 30% of real-time tasks are determined as high-priority tasks, the middle 30% as medium-priority tasks, and the bottom 40% as low-priority tasks.
[0053] For example, if the system is currently running 10 tasks, after sorting by priority, the first 3 tasks are high priority, the 4th to 6th tasks are medium priority, and the 7th to 10th tasks are low priority; if the number of tasks changes (such as adding 2 tasks), the priorities will be divided according to the same proportion after re-sorting.
[0054] S2. Allocate a cache area, which is used to store file data, and the cached data is associated with a task priority identifier and a lock identifier; specifically including:
[0055] S21. Cache Allocation: A dedicated cache area is allocated in system memory specifically for storing file data. The total capacity of the cache area can be configured based on system memory resources and actual data reading needs. Each cached data block in this cache area is associated with two sets of core identifiers:
[0056] Task priority identifier, used to record the priority level (high / medium / low) of the real-time task to which this data block belongs.
[0057] Lock flags are used to indicate whether a data block is in a locked / unlocked state.
[0058] S22. Lock flag configuration rules: When writing data blocks to the buffer, the lock flag is automatically configured according to the priority of the task to which it belongs.
[0059] If the data block belongs to a high-priority task, the locking flag will be configured to be locked. This locked state will last until a preset time (the preset time can be customized by the user, such as 5 seconds or 10 seconds, and the default setting is 60 seconds) expires, after which it will automatically switch to the unlocked state to ensure that the data of the high-priority task is not arbitrarily replaced during the critical execution cycle.
[0060] If the task to which the data block belongs is a medium-priority task or a low-priority task, the locking flag is directly configured to an unlocked state, allowing it to be replaced according to the rules when the cache space is insufficient.
[0061] S3. Maintain association information for each real-time task, wherein the association information includes at least task priority and file access records; specifically including:
[0062] S31. Create a unique structure for each real-time task. This structure is bound to the identification information of the real-time task to ensure that the information corresponds uniquely.
[0063] S32. The association information maintained in the structure is used to determine whether a file is frequently accessed data; the specific judgment rules are as follows:
[0064] The file access log contains the number of times the file data has been accessed in the last 60 seconds. If it is accessed more than 3 times, it is considered "frequently accessed data"; otherwise, it is considered infrequently accessed.
[0065] S4, see reference Figure 2 When a real-time task is detected to switch from a blocked state to a ready state, it is determined whether the real-time task needs to read the storage medium; specifically including:
[0066] S41. Monitor the running status of each real-time task in the real-time monitoring system. When a real-time task is detected to switch from the blocked state to the ready state, start the read request judgment.
[0067] S42. Determine whether the real-time task requires reading file data from the storage medium. If no reading of the storage medium is required, the task directly enters the execution process, and this method does not intervene. If reading of the storage medium is required, proceed to step S5.
[0068] S5. If a real-time task needs to read the storage medium, determine whether the latest data corresponding to the storage medium exists in the cache; confirm the timeliness of the cached data through explicit determination rules, specifically including:
[0069] S51. Based on the relevant identifiers of the target file, query whether there is corresponding cached data in the cache area;
[0070] S52. The rule for determining the latest data is as follows: Whenever the target file data in the storage medium is modified, the system automatically marks the corresponding data block in the cache as "non-latest data"; if the cached data block does not have the "non-latest data" mark, it is determined to be the latest data.
[0071] S53. If the corresponding latest data exists in the cache, read the data directly from the cache and transmit it to the task; if there is no corresponding data in the cache or the data is marked as "not the latest data", proceed to step S6.
[0072] S6. If the latest data is not present in the cache, the priority level of the real-time task is determined according to the priority definition strategy, and it is determined whether the file data is frequently accessed data; this provides a core basis for subsequent caching operations, specifically including:
[0073] S61. Call the priority definition strategy configured in step S1 to determine the priority of the current real-time task and clarify its priority level (high / medium / low).
[0074] S62. By querying the file access records maintained in step S3, determine whether the file data to be read is frequently accessed data.
[0075] S7. Based on the idle state of the cache, the priority level of the real-time task, and the access frequency of the file data, perform corresponding file data reading or pre-storage operations. The pre-storage operation includes writing file data into the cache and configuring corresponding task priority and locking flags. The reading operation includes reading file data from the cache or storage medium. Differential data processing is implemented based on the cache state and priority rules, specifically including:
[0076] S71. Determine the free status of the buffer, specifically including:
[0077] There is enough free space: the unused space in the cache can fully accommodate the data block corresponding to the file that needs to be read;
[0078] Insufficient free space: The unused space in the cache cannot fully accommodate the data block, or there is no unused space left in the cache.
[0079] S72. Based on the determination result of step S71, perform the corresponding operation:
[0080] S721, the cache has sufficient free space: regardless of the current task's priority level or whether the file is frequently accessed data, a pre-storage operation is performed: the file data in the storage medium is copied to the cache area, and the corresponding task priority identifier and locking identifier are configured for the data block; after the pre-storage is completed, the data is read from the cache area and transferred to the task;
[0081] S722, insufficient free cache space, specifically including:
[0082] S7221. If the current task is a high-priority task, prioritize releasing the cached data blocks corresponding to low-priority tasks in the cache area. After releasing, check if the free space meets the requirements. If there is still not enough space, continue to release the cached data blocks corresponding to medium-priority tasks until the free space can accommodate the current data block.
[0083] S7222: If the current task is a medium-priority task, only release the cached data blocks corresponding to low-priority tasks in the cache area until the free space meets the storage requirements of the current data block.
[0084] S7223. If all cached data blocks in the buffer belong to high-priority tasks, only release the cached data blocks that are in an unlocked state.
[0085] S7224. If, after the above release operation, there is still no free space available to accommodate the current data block, the pre-storage operation is abandoned, and the file data is read directly from the storage medium.
[0086] The above specific embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to examples, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A file data pre-reading and cache locking method based on real-time task priority, characterized in that, include: S1. Configure priority definition strategy to classify the priority levels of real-time tasks; S2. Allocate a cache area, which is used to store file data. The cache data is associated with task priority identifiers and lock identifiers. S3. Maintain association information for real-time tasks. The association information includes at least task priority and file access records. The association information is maintained through a structure. Each real-time task corresponds to a unique structure, and the structure is bound to the identification information of the real-time task. S4. When a real-time task is detected to switch from a blocked state to a ready state, determine whether the real-time task needs to read the storage medium. S5. If the real-time task needs to read the storage medium, determine whether the latest data corresponding to the storage medium exists in the cache; wherein, whenever the data in the storage medium is modified, the data corresponding to the cache is marked as non-latest data, and if there is no such mark, it is considered to be the latest data; S6. If the latest data does not exist in the cache, determine the priority level of the real-time task according to the priority definition strategy, and determine whether the file data is frequently accessed data; S7. Based on the idle state of the cache area, the priority level of the real-time task, and the access frequency of the file data, perform the corresponding file data reading or pre-storage operation. The pre-storage operation includes writing the file data into the cache area and configuring the corresponding task priority identifier and lock identifier. The reading operation includes reading the file data from the cache area or storage medium. In the pre-storage operation, when the real-time task is a high-priority task, the locking flag is configured to be in a locked state, and the locked state continues until the preset time expires and then switches to an unlocked state. When the real-time task is a medium-priority task or a low-priority task, the locking flag is configured to be in an unlocked state.
2. The method for file data pre-fetching and cache locking based on real-time task priority according to claim 1, characterized in that, The priority definition strategy includes a static priority strategy, which specifies that: Real-time tasks with a priority value of 0-4 are high-priority tasks, real-time tasks with a priority value of 5-9 are medium-priority tasks, and real-time tasks with a priority value greater than 9 are low-priority tasks.
3. The method for file data pre-fetching and cache locking based on real-time task priority according to claim 1, characterized in that, The priority definition strategy includes a dynamic priority strategy, which specifies that: All real-time tasks currently running in the system are sorted by priority. The top 30% of real-time tasks are high-priority tasks, the middle 30% are medium-priority tasks, and the bottom 40% are low-priority tasks.
4. The method for file data pre-fetching and cache locking based on real-time task priority according to claim 1, characterized in that, The idle state of the cache includes having enough free space and not having enough free space. Having enough free space means that the unused space in the cache can completely accommodate the data block corresponding to the file data that needs to be read. The phrase "insufficient free space" means that the unused space in the cache cannot fully accommodate the data block, or that the cache has no unused space left.
5. The method for file data pre-fetching and cache locking based on real-time task priority according to claim 4, characterized in that, When the cache has insufficient free space and the real-time task is a high-priority task, the cache data blocks corresponding to low-priority tasks in the cache are released first. If there is still insufficient free space after release, the cache data blocks corresponding to medium-priority tasks are released until the free space meets the storage requirements of the data blocks.
6. The file data pre-reading and cache locking method based on real-time task priority according to claim 4, characterized in that, When the cache has insufficient free space and the real-time task is a medium-priority task, only the cache data blocks corresponding to low-priority tasks in the cache are released until the free space meets the storage requirements of the data blocks or there are no cache data blocks corresponding to low-priority tasks that can be released.
7. The file data pre-read and cache locking method based on real-time task priority according to claim 5 or 6, characterized in that, When all cached data blocks in the cache area correspond to high-priority tasks, only the cached data blocks corresponding to the high-priority tasks that are in an unlocked state are released. If there is still not enough free space after release, the file data is read directly from the storage medium.
8. The method for file data pre-fetching and cache locking based on real-time task priority according to claim 1, characterized in that, Whether the file data is frequently accessed is determined by querying the file access records in the associated information.
Citation Information
Patent Citations
Spatial data caching method and device and storage medium
CN109446114A
Thread message processing method and related products
CN112579515A
Memory cache storage system oriented to big data flow
CN119917425A
Adjustable read latency for memory device in page-mode access
US20090327535A1