Inter-process one-to-one deterministic message queue implementation method and device and medium
By designing a ring queue structure in the shared memory area in the Xenomai environment to realize one-to-one deterministic message queues between processes, it solves the problem that Xenomai cannot guarantee deterministic communication under high message volume or large message size, and achieves efficient inter-process Communication and memory management improve the real-time performance and stability of the system.
Patent Information
- Application Number
- CN202410907939.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-09-03
AI Technical Summary
Xenomai cannot guarantee deterministic message communication between processes when there is a high message volume or large message size. Especially in complex or demanding real-time application scenarios, existing technology cannot support one-to-one deterministic communication between processes.
By designing two message queue classes in the Xenomai environment, the shared memory area is used to implement one-to-one deterministic message queues between processes. Message publishing and subscription are run as tasks in Xenomai through synchronization services to ensure real-time and consistency. Message addresses and content are exchanged through a ring queue structure to realize cyclic use of memory.
The average delay of inter-process communication is less than 10 microseconds, which improves the real-time performance of the system, provides predictability and deterministic communication, simplifies system design, improves memory usage efficiency and system stability, and reduces communication failures and memory System crash caused by leak.
Smart Images

Figure CN118585356A
Abstract
Description
Technical Field
[0001] The present invention relates to a method, device and medium for realizing a one-to-one deterministic message queue between processes, and belongs to the technical field of deterministic communication of real-time systems. Background Art
[0002] In modern computing systems, real-time performance is a crucial feature, especially for those application scenarios with extremely strict time requirements, such as industrial automation, aerospace control, real-time data processing, etc. Linux, as a widely used open source operating system, has rich functions and a huge ecosystem, but in its native state, its real-time performance often cannot meet the requirements of these stringent application scenarios.
[0003] Xenomai was born to solve the problem of insufficient real-time performance of Linux systems. Xenomai is a real-time framework used on the Linux platform. It greatly enhances the real-time performance of Linux by providing an additional real-time kernel. This design enables Linux to meet the needs of hard real-time systems while maintaining its original rich functions and ecology. The core advantage of Xenomai is that it allows real-time applications to run in parallel with the standard Linux kernel. This parallel processing capability not only ensures low latency and high reliability of real-time tasks, but also makes full use of the original rich resources and functions of the Linux system. In addition, Xenomai also supports the APIs of multiple real-time operating systems, such as VxWorks, QNX, etc., which provides great convenience for users who want to migrate existing real-time system applications to the Linux platform.
[0004] In real-time systems, deterministic message communication is a key feature. It requires that messages be transmitted within a specific time to ensure the overall performance and reliability of the system. In real-time environments such as Xenomai, this specific time is usually very short, which may be only tens of microseconds or even a few microseconds. Xenomai provides a one-to-one inter-task message communication mechanism, which can ensure deterministic message transmission when the message size and throughput are moderate. However, when the message is large (such as MB level and above) or the number of messages processed per second increases, Xenomai may not be able to guarantee this determinism.
[0005] Although Xenomai has achieved remarkable results in improving Linux real-time performance, there are still some limitations. For example, patent CN111143079B provides a multi-reader and multi-writer lock-free queue implementation method, but this method cannot support inter-process deterministic message communication under Xenomai. In addition, the message queue implemented by this method is a producer-consumer mode and does not support the publish-subscribe mode. This means that in some complex or high-demand real-time application scenarios, users may need to find other solutions or perform additional optimization work. Summary of the invention
[0006] The purpose of the present invention is to provide a method, device and medium for realizing a one-to-one deterministic message queue between processes, so as to solve the problem of one-to-one deterministic communication between different process tasks in a Xenomai environment.
[0007] In order to achieve the above object, the present invention is implemented through the following technical solutions: It includes two message queue classes, which together logically form an inter-process message queue. One process calls one message queue class to publish messages, and the other process calls another message queue class to subscribe to messages. The message communication of the message queue is deterministic, and data is exchanged through a shared memory area. The message publishing queue class is used for message publishing and includes a deterministic message subqueue for one-to-one communication within a process and a message writing synchronization service. The message writing synchronization service runs as a task and is responsible for creating and initializing a shared memory area, as well as reading the message address from the message subqueue within the process in real time and writing it into the shared memory area; The message subscription queue class is used for message subscription and includes a deterministic message subqueue for one-to-one communication within a process and a message reading synchronization service. The message reading synchronization service runs as a task and is responsible for obtaining the shared memory area address, and obtaining the message address from the shared memory area in real time, and writing the message address into the message subqueue within the process.
[0008] Preferably, the shared memory area is divided into two parts: one part is used as a circular queue to store message addresses, and the other part is used to store message content; when a message is published, memory is first allocated from the shared memory and the message is written. After the message is subscribed, the memory is released back to the shared memory area to achieve circular use of memory.
[0009] Preferably, the deterministic message subqueue for one-to-one communication within the process is a ring queue structure, which contains a settable number of message nodes, and the message nodes include nodes with messages, empty nodes and buffer nodes, and the type of message nodes changes dynamically; wherein, the buffer node consists of one or more consecutive nodes.
[0010] Preferably, the message is read starting from the message header pointer, and after reading, the message header pointer is offset by one node position; if the message header pointer points to a buffer node or a blank node, the message queue is empty.
[0011] Preferably, when writing a message, starting from the message tail pointer, before writing clockwise, check whether the next node of the buffer node is an empty node. If it is empty, the buffer node message tail pointer moves forward one node along the direction of movement of the message head pointer, and the original buffer node is converted to an empty node, and the message is written to the node; otherwise, it indicates that the queue is full and new messages cannot be written.
[0012] Preferably, the message head pointer and the message tail pointer move in a counterclockwise direction or a clockwise direction.
[0013] The advantage of the present invention is that, through the present method, the average delay of communication between two process tasks is generally less than 10 microseconds, which greatly improves the real-time performance of the system. This feature is particularly important in application scenarios that require high real-time response, such as industrial automation, aerospace control and other fields.
[0014] This method achieves one-to-one deterministic communication between processes, that is, the sending and receiving of messages are predictable and deterministic, which is crucial for inter-process communication that requires strict synchronization and coordination. Deterministic communication helps reduce system errors and instability caused by communication uncertainty.
[0015] This method exchanges data through a shared memory area, and the memory in the shared memory area is recycled, effectively improving the efficiency of memory use. At the same time, during the message publishing and subscription process, the read and write operations of the message address are run as tasks in Xenomai through the synchronization service, ensuring the real-time and consistency of the operation.
[0016] By providing a deterministic inter-process communication mechanism, this approach simplifies the complexity of system design. Developers can focus more on the implementation of business logic without having to pay too much attention to the details of inter-process communication and synchronization issues.
[0017] Deterministic communication and efficient memory management together improve the stability and reliability of the system, reducing system crashes and errors caused by communication failures or memory leaks. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0019] Figure 1 Schematic diagram of the method of the present invention.
[0020] Figure 2This is a schematic diagram of the one-to-one deterministic message queue structure within a process. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0022] as follows Figure 1 As shown, a method for implementing a one-to-one deterministic message queue between processes includes two message queue classes. The two message queue classes logically constitute an inter-process message queue for being called by two different processes in a Xenomai environment. One process calls one class to publish a message, and the other process calls another class to subscribe to a message. The message communication of the message queue is deterministic.
[0023] The inter-process message queue contains two message queue classes, one message queue class is responsible for message publishing (referred to as message publishing queue class), and the other message queue class is responsible for message subscription (referred to as message subscription queue class). The two message classes exchange data through a shared memory area.
[0024] The message publishing queue class contains a deterministic message subqueue for one-to-one communication within the process and a message write synchronization service. The message write synchronization service runs as a task in Xenomai. It is responsible for creating and initializing the shared memory area when it starts. After startup, it is responsible for reading the message address from the deterministic message subqueue for one-to-one communication within the process in real time and writing the read message address to the shared memory area.
[0025] The message subscription queue class contains a deterministic message subqueue for one-to-one communication within the process and a message read synchronization service. The message read synchronization service runs as a task in Xenomai. It is responsible for obtaining the shared memory area address when it starts. After startup, it is responsible for obtaining the message address from the shared memory area in real time and writing the message address to the deterministic message subqueue for one-to-one communication within the process.
[0026] The shared memory area is divided into two parts, one part is used as a circular queue to store the message address, and the other part contains the message content. When a message is published, a piece of memory is first obtained from the shared memory and the message is written to the shared memory. After the message is subscribed, the memory is released back to the shared memory area. The memory in the shared memory area is used cyclically.
[0027] Each subqueue in the message queue is a message queue that can support deterministic message communication of one-to-one communication in a Xenomai environment.
[0028] like Figure 2 As shown in the figure, the deterministic message queue supporting one-to-one communication is a circular queue in structure, which contains several message nodes. The number of message nodes can be set, and is generally not less than 3. Message nodes are divided into three types: one is a node 1 with a message, one is an empty node 3, and the other is a buffer node 2. The type of message node changes dynamically. Any message node may be a node 1 with a message at one moment, and may be an empty node 3 or a buffer node 2 at the next moment. Buffer node 2 is required, consisting of one or more consecutive nodes, and is used to avoid errors when the message queue reads and writes messages at the same time. Read the message from the message header pointer. After reading, the message header pointer is offset by one node position in the clockwise direction. If the message header pointer points to the buffer node 2, it means that the message queue is empty. When writing a message, write forward clockwise from the message tail pointer. Before writing, it is necessary to determine whether the next node of the buffer node 2 is an empty node 3. If it is not an empty node 3, it means that the message queue is full and new messages cannot be written. If there is an empty node 3, the buffer node 2 moves forward by one node in the clockwise direction. The free node after the buffer node 2 moves forward can write the message, and the message tail pointer points to the new message node position. The deterministic message queue structure of the one-to-one communication is a clockwise circular queue, which can also be designed to be counterclockwise.
[0029] The deterministic message queue for one-to-one communication within a process is encapsulated as a class. As a subclass of the logical message queue, it provides message writing and reading methods, which correspond to the message publishing and message subscription methods of the logical inter-process message queue respectively.
[0030] This patent cooperates with the multi-task many-to-many deterministic message queue method within the process, and further encapsulates it to realize one-to-many or many-to-many or even many-to-many deterministic message communication between processes.
[0031] The embodiment of the present disclosure also provides a device for implementing a one-to-one deterministic message queue between processes, including a processor and a memory. Optionally, the device may also include a communication interface and a bus. The processor, the communication interface, and the memory may communicate with each other through the bus. The communication interface may be used for information transmission. The processor may call the logic instructions in the memory to execute the one-to-one deterministic message queue implementation method between processes of the above embodiment.
[0032] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0033] The memory, as a computer-readable storage medium, can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor executes the functional application and data processing by running the program instructions / modules stored in the memory, that is, the one-to-one deterministic message queue implementation method between processes in the above embodiment is implemented.
[0034] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory may include a high-speed random access memory and may also include a non-volatile memory.
[0035] An embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the above-mentioned one-to-one deterministic message queue implementation method between processes.
[0036] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0037] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transitory storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk, and other media that can store program codes, or a transient storage medium.
[0038] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for implementing a one-to-one deterministic message queue between processes, characterized in that: It includes two message queue classes, which together logically form an inter-process message queue. One process calls one message queue class to publish messages, and the other process calls another message queue class to subscribe to messages. The message communication of the message queue is deterministic, and data is exchanged through a shared memory area. The message publishing queue class is used for message publishing and includes a deterministic message subqueue for one-to-one communication within a process and a message writing synchronization service. The message writing synchronization service runs as a task and is responsible for creating and initializing a shared memory area, as well as reading the message address from the message subqueue within the process in real time and writing it into the shared memory area; The message subscription queue class is used for message subscription and includes a deterministic message subqueue for one-to-one communication within a process and a message reading synchronization service. The message reading synchronization service runs as a task and is responsible for obtaining the shared memory area address, and obtaining the message address from the shared memory area in real time, and writing the message address into the message subqueue within the process.
2. The method for implementing a one-to-one deterministic message queue between processes according to claim 1, characterized in that: The shared memory area is divided into two parts: one part is used as a circular queue to store message addresses, and the other part is used to store message content; when a message is published, memory is first allocated from the shared memory and the message is written. After the message is subscribed, the memory is released back to the shared memory area to achieve circular use of memory.
3. The method for implementing a one-to-one deterministic message queue between processes according to claim 1, characterized in that: The deterministic message subqueue for one-to-one communication within the process is a ring queue structure, which contains a configurable number of message nodes. The message nodes include nodes with messages, empty nodes and buffer nodes, and the types of message nodes change dynamically; wherein the buffer nodes are composed of one or more consecutive nodes.
4. The method for implementing a one-to-one deterministic message queue between processes according to claim 3, characterized in that: When reading a message, start from the message header pointer. After reading, the message header pointer is offset by one node position; if the message header pointer points to a buffer node or a blank node, the message queue is empty.
5. The method for implementing a one-to-one deterministic message queue between processes according to claim 4, characterized in that: When writing a message, start from the message tail pointer and check whether the next node of the buffer node is an empty node before writing clockwise. If it is empty, the message tail pointer of the buffer node moves forward one node along the direction of the message head pointer, and the original buffer node is converted to an empty node, and the message is written to the node; Otherwise it means the queue is full and no new messages can be written.
6. The method for implementing a one-to-one deterministic message queue between processes according to any one of claims 3-4, characterized in that: The message head pointer and the message tail pointer move in a counterclockwise direction or a clockwise direction.
7. A device for implementing a one-to-one deterministic message queue between processes, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the method for implementing a one-to-one deterministic message queue between processes as described in any one of claims 1-6 when running the program instructions.
8. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the program is executed by a processor as the method for implementing a one-to-one deterministic message queue between processes as described in any one of claims 1-6.
Citation Information
Cited By
Communication method, communication system and electronic equipment
CN120743581A
