CN112114982B - Management method for shared memory among multiple tasks based on VxWorks system - Google Patents
Management method for shared memory among multiple tasks based on VxWorks system Download PDFInfo
- Publication number
- CN112114982B CN112114982B CN202010941157.XA CN202010941157A CN112114982B CN 112114982 B CN112114982 B CN 112114982B CN 202010941157 A CN202010941157 A CN 202010941157A CN 112114982 B CN112114982 B CN 112114982B
- Authority
- CN
- China
- Prior art keywords
- data
- task
- message
- shared memory
- tasks
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/544—Buffers; Shared memory; Pipes
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Storage Device Security (AREA)
- Multi Processors (AREA)
Abstract
The invention relates to a management method for shared memory among multiple tasks based on a VxWorks system, and belongs to the technical field of VxWorks shared memory. The invention firstly dynamically applies for a global memory according to actual needs, equally divides a memory block into N data blocks, establishes M +1 global message queues with the member number of N, fills the message queue 1 with the number 1-N labels, the labels correspond to the data blocks of the global shared memory one by one, a plurality of tasks obtain the labels according to the message queue 1 to operate the shared memory, and informs the receiving tasks 1-M through the message queues 2-M +1, thereby efficiently realizing the management and data communication of the shared memory among the plurality of tasks. The invention solves the requirement of frequent mass data exchange among multiple tasks through a universal design, improves the reliability of the program and is suitable for all software using the VxWorks system.
Description
Technical Field
The invention belongs to the technical field of VxWorks shared memories, and particularly relates to a management method of a shared memory among multiple tasks based on a VxWorks system.
Background
VxWorks is a high-performance, tailorable, embedded real-time operating system launched by the american wind river company that runs on a target machine. VxWorks is widely applied to the high-precision technology such as communication, military, aviation, aerospace and the like and the field with high real-time requirement due to the excellent real-time performance and good reliability of VxWorks.
In order to ensure the real-time performance of the whole machine, at present, multi-task design is mostly adopted for slightly complex program development, a task with the highest real-time performance requirement is assigned with the highest priority, other tasks can be delayed to be executed while meeting the functional performance index, the multi-tasks often need to be interacted, and at present, the following communication modes mainly exist.
1. The semaphore is the fastest communication mechanism among tasks, and the VxWorks system provides three semaphores, namely binary, mutual exclusion and counting, and is used for solving the mutual exclusion and synchronization among the tasks. The binary semaphore is mainly used for task synchronization, the mutual exclusion semaphore can solve the problem of mutual exclusion, and is mainly used for priority inheritance, safe deletion and the like, the counting semaphore is added with a counting function on the basis of the binary semaphore, and the problem that a plurality of members of one resource need to be protected can be solved. The semaphore mechanism has high communication speed, low system overhead and simple processing method, but cannot be accompanied by more information and cannot be used for data exchange.
2. In VxWorks, a message queue is a relatively high-level inter-task communication mechanism, and the message queue is flexible to use and slightly more complex to implement than a semaphore. The advantage is that it can deliver more information and can be used for data communication between tasks, but due to its higher overhead, when messages are transmitted frequently or the amount of data is large, the communication efficiency is reduced, which may cause communication timeout problems for high real-time system environments.
3. The shared memory is a commonly used method for data communication between tasks, the memory in the same block address space is shared during communication between multiple tasks, and in order to prevent access conflict, the common practice at present is to lock the shared memory by using a mutual exclusion semaphore to ensure the correctness of data. The method does not allow a plurality of tasks to access the area at the same time, is safe in operation, but has low efficiency for the condition that a large amount of data is needed to be exchanged, and can cause the low-priority tasks to be incapable of working normally due to the fact that the tasks with high priorities are excessively preempted.
In order to make up for the defects of the existing method for processing data communication among multiple tasks, meet the requirement of large data volume and frequent communication among the tasks, and improve the response real-time performance and the operation reliability of a program, a better solution is urgently needed.
Disclosure of Invention
Technical problem to be solved
The technical problem to be solved by the invention is as follows: how to realize a management method for sharing memory among multiple tasks based on a VxWorks system solves the problem of the existing data communication processing method among multiple tasks, meets the requirement of large data quantity and frequent communication among the tasks, and improves the response real-time performance and the operation reliability of a program.
(II) technical scheme
In order to solve the technical problem, the invention provides a management method for sharing a memory among multiple tasks based on a VxWorks system, which comprises the following steps:
step 1, determining total execution tasks including a data receiving task, a data recording task, a power-off protection task and a periodic self-checking task, and setting the priority sequence of the tasks as follows: the method comprises the following steps that (1) a data receiving task > a power-off protection task > a data recording task > a periodic self-checking task, wherein the number of the data recording tasks is 1;
step 2, dynamically applying a global memory g _ pool with enough capacity through a malloc function according to the estimated actual communication capacity and frequency, and dividing the memory block g _ pool into N data blocks with equal length, wherein the size of each data block is 1024 bytes according to the received data volume, and the number of the data blocks is 10000;
step 3, establishing 1 global message queue with the member number of 10000 through an msgQCreate function, namely MsgQ1, setting the attribute of the MSG queue to be first-in first-out MSG _ Q _ FIFO, enabling the data length to be 2 bytes, meeting the requirement of the member number of 10000, sending the number of 1-10000 to a queue MsgQ1, filling the MsgQ1, and establishing a one-to-one corresponding relation between the member number of the MsgQ1 and each data block in a shared memory g _ pool in the mode; then 1 global message queue with the member number of 10000 is established, named as MsgQ2, the attribute of the MSG _ Q _ PRIORITY is set to be queued according to the PRIORITY, the data length is 6 bytes, and the MSG _ Q _ PRIORITY comprises three information of a message label, a message type and a message length;
step 4, after the system is started, the data receiving task operates the shared memory g _ pool by receiving the application label of the MsgQ1, and after the data of the shared memory g _ pool is filled, the data receiving task completes the notification of the data recording task by sending a message to the MsgQ 2;
step 5, the data recording task receives the information in the MsgQ2 in real time, obtains the data content in the shared memory g _ pool according to the message label and the data length, analyzes and processes the data content in real time according to the message type, and sends the received label back to the MsgQ 1;
and 6, repeating the steps 4 and 5, sending data to the data recording task after the data receiving task, the power-off protection task and the periodic self-checking task apply for the labels in real time, executing corresponding operation by the data recording task according to the received message, and finishing the release of the label resources.
Preferably, in step 4, the data receiving task sending message types are set to be 1-4, and the data receiving task sending message types are respectively used as the identifications of the receiving channels.
Preferably, in step 4, the message type sent by the power-off protection task is set to 5.
Preferably, in step 4, the message type of the periodic self-test task is set to 6.
Preferably, in step 4, the data length is the actual transmission data length, and the range is 1-1024 bytes.
Preferably, in step 4, when the data receiving task and the periodic self-test task send MsgQ2, the parameter selects MSG _ PRI _ NORMAL for sending, and when the power-off protection task sends MsgQ2, the parameter selects MSG _ PRI _ URGENT for sending.
Preferably, in step 5, the data recording task performs data storage recording on the data content with the message type of 1-4 by channels.
Preferably, in step 5, if the received message type is 5, which represents that the power-off signal is detected, the operation of writing the data file is stopped.
Preferably, in step 5, for the type 6 message, it is stored separately or combined with one of the channels.
The invention also provides application of the method in the technical field of VxWorks shared memory.
(III) advantageous effects
The invention firstly dynamically applies for a global memory according to actual needs, equally divides a memory block into N data blocks, establishes M +1 global message queues with the member number of N, fills the message queue 1 with the number 1-N labels, the labels correspond to the data blocks of the global shared memory one by one, a plurality of tasks obtain the labels according to the message queue 1 to operate the shared memory, and informs the receiving tasks 1-M through the message queues 2-M +1, thereby efficiently realizing the management and data communication of the shared memory among the plurality of tasks. The invention solves the requirement of frequent mass data exchange among multiple tasks through a universal design, improves the reliability of the program and is suitable for all software using the VxWorks system.
Drawings
FIG. 1 is a communication schematic diagram in a management method of shared memory among multiple tasks based on a VxWorks system.
Detailed Description
In order to make the objects, contents, and advantages of the present invention clearer, the following detailed description of the embodiments of the present invention will be made in conjunction with the accompanying drawings and examples.
The invention provides a general solution for the requirement of frequent mass data exchange among multiple tasks of the VxWorks system, and the solution can support the simultaneous operation of multiple tasks on a shared memory, complete mass data exchange among any tasks, and improve the reliability of the system while ensuring the real-time performance of data processing among the tasks. The invention adopts the universal design, has clear logic mechanism, flexible and simple realization and high program portability, and is suitable for all software using VxWorks systems.
The invention relates to a management method of shared memory among multiple tasks based on a VxWorks system, which has the technical principle that the message queue 1 and the shared memory block in M +1 message queues from the message queue 1 to the message queue M +1 are bound, the number of the message queue 1 and the shared memory block is in one-to-one correspondence, the VxWorks system is used for maintaining the message queues, the shared memory block can be applied and utilized by receiving the message queue 1 at the same time among the multiple tasks, and shared data can be transmitted to other tasks through the message queues 2-M + 1. Taking the simplest pitch-catch task model as an example, the data flow principle is shown in fig. 1.
Furthermore, the function of the message queue 1 is equivalent to a group of semaphores, each member in the message queue 1 is equivalent to one semaphore, and the member stores the label of the shared memory block, and can access the corresponding shared memory block only by obtaining the label, thereby preventing access conflict of multiple tasks to the shared memory on a system level and improving the reliability of program operation.
Further, the message queue 2 corresponds to data reception of the task 1, other tasks can send messages to the task 1 through the message queue 2, the content stored in the message queue 2 is the label of the shared memory block, the data type and the length of the actual effective content, information transmission between the tasks of sending and receiving can be performed only by occupying a few bytes, the actual corresponding shared memory block may contain several KB of actual content, and the efficiency of data transmission between the tasks can be greatly improved through a manner similar to pointer processing.
Further, the mapping relation between the message queue 2 and the tasks is multiple pairs 1, and the number of the message queues for communication between the tasks is equal to the number of the tasks needing to receive data, so that any communication between the tasks can be realized.
The above scheme is decomposed in detail by combining with a specific embodiment, and a task data recorder completes the functions of equipment state reporting and data recording while ensuring the real-time performance and integrity of received data. The specific implementation steps are as follows:
step 1, firstly, determining a total execution task according to system requirements, wherein the total execution task comprises a data receiving task, a data recording task, a power-off protection task and a periodic self-checking task, and the priority sequence of the tasks is set as follows: the data receiving task, the power-off protection task and the data recording task are periodic self-checking tasks, wherein the data receiving task, the power-off protection task and the periodic self-checking tasks correspond to a task 1 in a graph 1, the data recording tasks correspond to tasks 2 in the graph 1, and the number of the data recording tasks is 1;
and 2, dynamically applying a global memory g _ pool with enough capacity through a malloc function according to the estimated actual communication capacity and frequency, and equally dividing the memory block g _ pool into N data blocks. Here, the size of each data block is 1024 bytes according to the amount of data received, and the number of data blocks is 10000;
step 3, establishing 1 global message queue with the member number of 10000 through an msgQCreate function, namely MsgQ1, setting the attribute of the MSG queue to be first-in first-out MSG _ Q _ FIFO, enabling the data length to be 2 bytes, meeting the requirement of the member number of 10000, sending the number of 1-10000 to a queue MsgQ1, filling the MsgQ1, and establishing a one-to-one corresponding relation between the member number of the MsgQ1 and each data block in a shared memory g _ pool in the mode; then 1 global message queue with the member number of 10000 is established, named as MsgQ2, the attribute of the MSG _ Q _ PRIORITY is set to be queued according to the PRIORITY, the data length is 6 bytes, and the MSG _ Q _ PRIORITY comprises three information of a message label, a message type and a message length;
and 4, after the system is started, the data receiving task operates the shared memory g _ pool by receiving the application label of the MsgQ1, and after the data of the shared memory g _ pool is filled, the data receiving task completes the notification of the data recording task by sending a message to the MsgQ 2.
The data receiving task sending message types are 1-4 and are respectively used as the identification of a receiving channel; the message type sent by the power-off protection task is 5, and the message type of the periodic self-checking task is 6; the data length is the actual transmission data length and ranges from 1 byte to 1024 bytes.
When the data receiving task and the periodic self-checking task send the MsgQ2, the parameter selects the MSG _ PRI _ NORMAL with the NORMAL priority to send, and when the power-off protection task sends the MsgQ2, the parameter selects the MSG _ PRI _ URGENT to send, so that the first-in first-out characteristic of normally receiving data is ensured, and the real-time performance of the power-off protection operation is ensured.
And step 5, the data recording task receives the information in the MsgQ2 in real time, acquires the data content in the shared memory g _ pool according to the message label and the data length, analyzes and processes the data content in real time according to the message type, and sends the received label back to the MsgQ1, so that other tasks (the data receiving task, the power-off protection task and the periodic self-checking task) can apply for the label in the follow-up process, and the recovery of the memory block is completed.
The data recording task carries out data storage recording on data contents with message types of 1-4 in channels; if the type of the received message is 5, the data writing operation is stopped when the power-off signal is detected, and the file is prevented from being damaged accidentally; for type 6 messages, storage alone or in combination with one of the channels may be considered.
And 6, repeating the steps 4 and 5, sending data to the data recording task after the three tasks (the data receiving task, the power-off protection task and the periodic self-checking task) apply for the label in real time, executing corresponding operation by the data recording task according to the received message, and finishing the release of the label resource.
Through the steps, management and data communication of the shared memory among multiple tasks of the VxWorks system are stably and efficiently realized. And aiming at different system requirements, the size of the shared memory, the number of memory blocks and the format of message transmission can be flexibly changed only by adjusting a plurality of parameters according to the size of the content to be cached, so that the universality and the portability of the program are improved while the reliability and the efficiency of the program are ensured.
The above description is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, several modifications and variations can be made without departing from the technical principle of the present invention, and these modifications and variations should also be regarded as the protection scope of the present invention.
Claims (9)
1. A management method for sharing memory among multiple tasks based on a VxWorks system is characterized by comprising the following steps:
step 1, determining total execution tasks including a data receiving task, a data recording task, a power-off protection task and a periodic self-checking task, and setting the priority sequence of the tasks as follows: the method comprises the following steps that (1) a data receiving task > a power-off protection task > a data recording task > a periodic self-checking task, wherein the number of the data recording tasks is 1;
step 2, dynamically applying a global memory g _ pool with enough capacity through a malloc function according to the estimated actual communication capacity and frequency, and dividing the memory block g _ pool into N data blocks with equal length, wherein the size of each data block is 1024 bytes according to the received data volume, and the number of the data blocks is 10000;
step 3, establishing 1 global message queue with the member number of 10000 through an msgQCreate function, namely MsgQ1, setting the attribute of the MSG queue to be first-in first-out MSG _ Q _ FIFO, enabling the data length to be 2 bytes, meeting the requirement of the member number of 10000, sending the number of 1-10000 to a queue MsgQ1, filling the MsgQ1, and establishing a one-to-one corresponding relation between the member number of the MsgQ1 and each data block in a shared memory g _ pool in the mode; then 1 global message queue with the member number of 10000 is established, named as MsgQ2, the attribute of the MSG _ Q _ PRIORITY is set to be queued according to the PRIORITY, the data length is 6 bytes, and the MSG _ Q _ PRIORITY comprises three information of a message label, a message type and a message length;
step 4, after the system is started, the data receiving task operates the shared memory g _ pool by receiving the application label of the MsgQ1, and after the data of the shared memory g _ pool is filled, the data receiving task completes the notification of the data recording task by sending a message to the MsgQ 2;
step 5, the data recording task receives the information in the MsgQ2 in real time, obtains the data content in the shared memory g _ pool according to the message label and the data length, analyzes and processes the data content in real time according to the message type, and sends the received label back to the MsgQ 1;
and 6, repeating the steps 4 and 5, sending data to the data recording task after the data receiving task, the power-off protection task and the periodic self-checking task apply for the labels in real time, executing corresponding operation by the data recording task according to the received message, and finishing the release of the label resources.
2. The method according to claim 1, wherein in step 4, the data receiving task sends message types of 1-4, which are respectively used as the identifiers of the receiving channels.
3. The method of claim 2, wherein in step 4, the message type sent by the power down protection task is set to 5.
4. A method as claimed in claim 3, wherein in step 4, the message type of the periodic self-test task is set to 6.
5. The method of claim 4, wherein in step 4, the data length is the actual transmission data length, and is in the range of 1-1024 bytes.
6. The method as claimed in claim 5, wherein in step 4, when the data receiving task and the periodic self-test task send MsgQ2, the parameter selects the NORMAL priority MSG _ PRI _ NORMAL to send, and when the power-off protection task sends MsgQ2, the parameter selects MSG _ PRI _ URGENT to send.
7. The method according to claim 6, wherein in step 5, the data recording task performs data storage recording by channels for the data content with the message type of 1-4.
8. The method of claim 7, wherein in step 5, if the received message type is 5, which represents that a power-off signal is detected, the operation of writing the data file is stopped.
9. The method of claim 8, wherein in step 5, messages of type 6 are stored separately or in combination with one of the channels.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010941157.XA CN112114982B (en) | 2020-09-09 | 2020-09-09 | Management method for shared memory among multiple tasks based on VxWorks system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010941157.XA CN112114982B (en) | 2020-09-09 | 2020-09-09 | Management method for shared memory among multiple tasks based on VxWorks system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112114982A CN112114982A (en) | 2020-12-22 |
CN112114982B true CN112114982B (en) | 2022-03-08 |
Family
ID=73802417
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010941157.XA Active CN112114982B (en) | 2020-09-09 | 2020-09-09 | Management method for shared memory among multiple tasks based on VxWorks system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112114982B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113608883B (en) * | 2021-06-21 | 2024-02-13 | 天津津航计算技术研究所 | Encapsulation method based on VxWorks real-time operating system |
CN115396387B (en) * | 2022-08-30 | 2024-04-12 | 上海航天电子通讯设备研究所 | Data recording method, device, equipment and storage medium based on VxWorks message queue |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1504892A (en) * | 2002-12-05 | 2004-06-16 | 华为技术有限公司 | Realization method for communication between tasks |
CN103019823A (en) * | 2012-12-12 | 2013-04-03 | 上海航天测控通信研究所 | Message queue method for realizing communication between VxWorks and Qt |
CN107992370A (en) * | 2017-11-28 | 2018-05-04 | 上海机电工程研究所 | VxWorks platform multi-tasks Software framework implementation method |
CN110018914A (en) * | 2019-03-26 | 2019-07-16 | 中国人民银行清算总中心 | Message collection method and device based on shared drive |
CN110764935A (en) * | 2019-10-28 | 2020-02-07 | 天津津航计算技术研究所 | Method for efficiently transferring messages among tasks based on real-time operating system |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8990821B2 (en) * | 2009-09-29 | 2015-03-24 | International Business Machines Corporation | Task dispatching based on composite queue size and upper and lower compare values |
-
2020
- 2020-09-09 CN CN202010941157.XA patent/CN112114982B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1504892A (en) * | 2002-12-05 | 2004-06-16 | 华为技术有限公司 | Realization method for communication between tasks |
CN103019823A (en) * | 2012-12-12 | 2013-04-03 | 上海航天测控通信研究所 | Message queue method for realizing communication between VxWorks and Qt |
CN107992370A (en) * | 2017-11-28 | 2018-05-04 | 上海机电工程研究所 | VxWorks platform multi-tasks Software framework implementation method |
CN110018914A (en) * | 2019-03-26 | 2019-07-16 | 中国人民银行清算总中心 | Message collection method and device based on shared drive |
CN110764935A (en) * | 2019-10-28 | 2020-02-07 | 天津津航计算技术研究所 | Method for efficiently transferring messages among tasks based on real-time operating system |
Also Published As
Publication number | Publication date |
---|---|
CN112114982A (en) | 2020-12-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109729024B (en) | Data packet processing system and method | |
CN101127685B (en) | An inter-process communication device and inter-process communication method | |
CN102035732B (en) | Service scheduling method and device | |
CN107241281B (en) | Data processing method and device | |
CN112114982B (en) | Management method for shared memory among multiple tasks based on VxWorks system | |
CN112698959A (en) | Multi-core communication method and device | |
CN101707565A (en) | Method and device for transmitting and receiving zero-copy network message | |
CN110800328A (en) | Buffer status reporting method, terminal and computer storage medium | |
CN114205183A (en) | Communication method and system of AT instruction protocol stack based on real-time operating system | |
CN103986585A (en) | Message preprocessing method and device | |
CN112559476A (en) | Log storage method for improving performance of target system and related equipment thereof | |
CN110457251A (en) | Data communications method and device between a kind of multiprocessor | |
CN102170401B (en) | Method and device of data processing | |
WO2019109902A1 (en) | Queue scheduling method and apparatus, communication device, and storage medium | |
Golchin et al. | Tuned pipes: end-to-end throughput and delay guarantees for USB devices | |
US6105071A (en) | Source and destination initiated interrupt system for message arrival notification | |
CN114500036A (en) | Method, device and medium for transmitting data | |
CN114500403A (en) | Data processing method and device and computer readable storage medium | |
CN107911317B (en) | Message scheduling method and device | |
CN108153597B (en) | LINUX equipment management device and method | |
US9338219B2 (en) | Direct push operations and gather operations | |
CN108121580B (en) | Method and device for realizing application program notification service | |
CN115801814A (en) | Data transmission method and system based on serial port double FIFO buffer area structure and storage medium | |
JP5262418B2 (en) | Task scheduling apparatus and task scheduling method | |
CN109558107B (en) | FC message receiving management method for shared buffer area |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |