Method and device for realizing deterministic message queue supporting multi-read and multi-write, and medium
By designing a deterministic message queue that supports multiple reads and multiple writes in the Xenomai environment, using ring queues and synchronization services, many-to-many deterministic message communication between multiple tasks within the process is realized, solving the problem that existing technology cannot support many-to-many. Communication issues, achieving high real-time and low-latency message delivery.
Patent Information
- Application Number
- CN202410907931.3
- 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 support many-to-many deterministic message communication between multiple tasks within a process in a real-time environment, and the existing multi-read-multi-write lock-free queue implementation method cannot provide deterministic message communication under Xenomai and does not support the publish-subscribe mode. .
Design a deterministic message queue that supports multiple reads and multiple writes. By providing multiple independent support one-to-one deterministic message subqueues and message synchronization services in the Xenomai environment, the publish and subscribe functions of the message queue are realized, and the ring queue is used. Structure and synchronization services ensure deterministic communication of messages.
In the Xenomai environment, many-to-many deterministic message communication between multiple tasks within the same process is realized. The average delay is less than 10 microseconds and the real-time performance is good. It solves the problem that existing technology cannot support many-to-many communication.
Smart Images

Figure CN118585355A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communications, and in particular to a method, device and medium for implementing a deterministic message queue that supports multiple reads and multiple writes in the field of deterministic communications technology for real-time systems. Background Art
[0002] Xenomai is a real-time framework for the Linux platform. It enhances Linux's real-time capabilities by providing an additional real-time kernel, enabling Linux to meet the requirements of hard real-time systems. Xenomai allows real-time applications to run in parallel with the standard Linux kernel, providing deterministic real-time performance while maintaining the rich functionality and ecosystem of the Linux system. It supports the APIs of multiple real-time operating systems, such as VxWorks and QNX, making it easier to migrate applications from these systems to the Linux platform.
[0003] Deterministic message communication must complete within a specific timeframe while ensuring reliability. In real-time environments like Xenomai, this timeframe is extremely short, typically only tens or even a few microseconds, making it a very demanding requirement. Xenomai supports intra-process message communication between one task and another (referred to as one-to-one). While this is acceptable for moderate message sizes and low throughput, it cannot guarantee deterministic message communication for larger messages (e.g., megabytes or larger) or when a high number of messages are processed per second. Currently, Xenomai does not support deterministic message communication between multiple tasks within a process (referred to as many-to-many).
[0004] Patent CN111143079B provides a method for implementing a multi-reader and multi-writer lock-free queue, but this method cannot support deterministic message communication under Xenomai. In addition, the message queue functionally implemented by this method is a producer-consumer model and does not support a publish-subscribe model. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a method, device and medium for implementing a deterministic message queue that supports multiple reads and multiple writes. The method logically provides a message queue that can be used by multiple tasks within the same process in a Xenomai environment to publish messages through the message queue, and by multiple other tasks within the same process to subscribe to messages through the message queue. The message communication of the message queue is deterministic.
[0006] To solve the above technical problems, the present invention adopts a technical solution: a method for implementing a deterministic message queue that supports multiple reads and multiple writes. This method provides a message queue. In the Xenomai environment, multiple tasks within the same process publish messages through this message queue, and multiple other tasks within the same process subscribe to messages through this message queue. The message communication of this message queue is deterministic. The message queue provided by this method includes several independent one-to-one deterministic message sub-queues, message write synchronization services, and message read synchronization services that support in-process communication. The message sub-queues include write sub-queues, read sub-queues, and buffer sub-queues. The write sub-queue is used to provide message publishing services and is connected to the message write synchronization service. The read sub-queue is used to provide message subscription services and is connected to the message read synchronization service. The cache sub-queue is connected between the message write synchronization service and the message read synchronization service. The message write synchronization service reads messages from multiple write sub-queues and writes the read messages to the buffer sub-queue. The message read synchronization service reads messages from the buffer sub-queue and writes the read messages to multiple read sub-queues.
[0007] Furthermore, the message queue provided by this method is encapsulated as a class, each subqueue is encapsulated as a subclass of the class, and the message write synchronization service and the message read synchronization service are methods of the class.
[0008] Furthermore, this class also includes a publishing queue addition method, a publishing queue deletion method, a subscription queue addition method, and a subscription queue deletion method. The publishing queue addition method is to dynamically add a write subqueue to the class, and the publishing queue deletion method is to dynamically remove a write subqueue from the class. The subscription queue addition method is to dynamically add a read subqueue to the class, and the subscription queue deletion method is to dynamically remove a read subqueue from the class.
[0009] Furthermore, each subqueue in the message queue is a deterministic message queue that supports one-to-one communication in the Xenomai environment.
[0010] Furthermore, the deterministic message queue that supports one-to-one communication is a ring queue, which includes more than 3 message nodes. The more than 3 message nodes are dynamically divided into full nodes, empty nodes and buffer nodes. The buffer node is necessary and consists of one or more continuous nodes. It is used to avoid errors when the message queue reads and writes messages at the same time.
[0011] Furthermore, the data reading and writing process based on the circular queue is as follows: read the message from the message head pointer, and after reading, the message head pointer is offset by one node position in the clockwise direction. If the message head pointer points to the buffer node, 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 is an empty node. If it is not empty, it means that the message queue is full and no new message can be written. If there is an empty node, the buffer node moves forward by one node in the clockwise direction. The node that is empty after the buffer node moves forward can be used to write the message, and the message tail pointer points to the new message node position.
[0012] Furthermore, the message writing synchronization service and the message reading synchronization service run as tasks in Xenomai.
[0013] Furthermore, there are multiple write sub-queues and multiple read sub-queues.
[0014] The present invention also discloses a device for implementing a deterministic message queue that supports multiple reads and multiple writes, comprising a processor and a memory storing program instructions. The processor is configured to execute the above-mentioned method for implementing a deterministic message queue that supports multiple reads and multiple writes when running the program instructions.
[0015] The present invention also discloses a storage medium storing program instructions, which, when running, execute the above-mentioned method for implementing a deterministic message queue supporting multiple reads and multiple writes.
[0016] The beneficial effects of the present invention include a method for implementing a deterministic message queue that supports multiple reads and writes. The method logically provides a message queue composed of several independent sub-queues supporting one-to-one deterministic messaging within a process, as well as message write and read synchronization services. This message queue provides both message publishing and message subscription services, allowing multiple tasks within the same process in a Xenomai environment to publish messages through the message queue and multiple other tasks within the same process to subscribe to messages through the message queue. Message communication within the message queue is deterministic. This method solves the problem of many-to-many deterministic communication between multiple tasks within the same process in a Xenomai environment. The average latency for communication between multiple tasks is typically less than 10 microseconds, demonstrating excellent real-time performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 Schematic diagram of the message queue provided for this method; Figure 2 A schematic diagram of a circular queue; In the figure: 1. Write subqueue, 2. Buffer subqueue, 3. Read subqueue, 4. Full node, 5. Empty node, 6. Buffer node. DETAILED DESCRIPTION
[0018] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0019] Example 1 This embodiment discloses a method for implementing a deterministic message queue that supports multiple reads and multiple writes. This method logically provides a message queue ( Figure 1 As shown in the box, this message queue provides message publishing and subscription services. It can be used by multiple tasks in the same process in the Xenomai environment to publish messages through the message queue, and multiple other tasks in the same process can subscribe to messages through the message queue. The message communication of this message queue is deterministic.
[0020] like Figure 1 As shown, this message queue includes several independent subqueues that support one-to-one deterministic message processing within a process, message write synchronization services, and message read synchronization services. The message subqueues include write subqueue 1, read subqueue 3, and buffer subqueue 2. Write subqueue 1 provides message publishing services and is connected to the message write synchronization service. Read subqueue 3 provides message subscription services and is connected to the message read synchronization service. Cache subqueue 2 connects the message write synchronization service and the message read synchronization service. The buffer subqueue acts as a bridge between multiple write subqueues and multiple read subqueues. The number of write subqueues and read subqueues can be equal or different, but is generally greater than or equal to one.
[0021] The message write synchronization service contained in this message queue is responsible for reading messages from multiple write sub-queues and writing the read messages to the buffer sub-queue. This service runs as a task in Xenomai.
[0022] The message read synchronization service contained in this message queue is responsible for reading messages from the buffer subqueue and writing the read messages to multiple read subqueues. The messages read from the buffer subqueue are written once to each read subqueue. This service runs as a task in Xenomai.
[0023] The message queue is encapsulated as a class, and various message subqueues are encapsulated as subclasses of this class. Message write synchronization services and message read synchronization services are methods of this class. This class also contains methods for adding, removing, adding, and removing subscription queues. The adding method dynamically adds a writer subqueue to the class, while the removing method dynamically removes a writer subqueue from the class. The adding method dynamically adds a reader subqueue to the class, while the removing method dynamically removes a reader subqueue from the class.
[0024] Each subqueue in the message queue is a message queue that can support one-to-one deterministic message communication in the Xenomai environment.
[0025] like Figure 2 As shown, a deterministic message queue supporting one-to-one communication is structurally a ring queue containing a number of message nodes. The number of message nodes is configurable and generally not less than three. Message nodes are divided into three types: full nodes 4 with messages, empty nodes 5, and buffer nodes 6. The type of message node changes dynamically; any message node can be filled with messages at one moment and empty or function as a buffer node the next. Buffer nodes 6 are required, consisting of one or more consecutive nodes, to prevent errors when the message queue reads and writes messages simultaneously. When reading or writing information, the message is read from the message header pointer. After reading, the message header pointer is offset by one node in a clockwise direction. If the message header pointer points to the buffer node, the message queue is empty. When writing a message, the message is written clockwise from the message tail pointer. Before writing, the next node in the buffer node is checked to see if it is empty. If not, the message queue is full and no new message can be written. If there is an empty node, the buffer node is moved forward by one node in a clockwise direction. The remaining node after the buffer node is moved forward can be used to write the message, and the message tail pointer points to the new message node. The deterministic message queue structure for one-to-one communication is a clockwise circular queue, but it can also be designed to be counterclockwise.
[0026] The deterministic message queue for one-to-one communication is encapsulated as a class. As a subclass of the logical message queue, it provides message writing and message reading methods, which correspond to the message publishing and message subscription methods of the logical message queue respectively.
[0027] The deterministic message queue for one-to-one communication in this embodiment may also be replaced by other one-to-one communication deterministic message queue implementation methods.
[0028] The method for implementing a deterministic message queue supporting multiple reads and multiple writes described in this embodiment can solve the problem of many-to-many deterministic communication between multiple tasks in the same process in the Xenomai environment. The average delay of communication between multiple tasks is generally less than 10 microseconds, and the real-time performance is very good.
[0029] Example 2 This embodiment discloses a device for implementing a deterministic message queue that supports multiple reads and multiple writes, including a processor and a memory storing program instructions. The processor is configured to execute the method for implementing a deterministic message queue that supports multiple reads and multiple writes as described in Example 1 when running the program instructions.
[0030] Example 3 The present invention also discloses a storage medium storing program instructions. When the program instructions are run, the method for implementing a deterministic message queue supporting multiple reads and multiple writes as described in Example 1 is executed.
[0031] The aforementioned computer-readable storage medium may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0032] The technical solutions of the embodiments of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for causing a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in the embodiments of the present disclosure. The aforementioned storage medium may be a non-transitory storage medium, including: a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, an optical disk, and other media that can store program code, or a transient storage medium.
[0033] The above description and the accompanying drawings sufficiently illustrate the embodiments of the present disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent only possible variations. Unless expressly required, individual components and functions are optional, and the order of operations may vary. Portions and features of some embodiments may be included in or replace portions and features of other embodiments. Moreover, the terms used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and claims, the singular forms "a", "an" and "the" are intended to also include the plural forms unless the context clearly indicates otherwise. Similarly, the term "and / or" as used in this application means any and all possible combinations of one or more of the associated listings. In addition, when used in this application, the term "comprise" and its variations "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof. In the absence of further restrictions, an element defined by the sentence "comprising a..." does not exclude the presence of other identical elements in the process, method or device that includes the element. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments can be referenced to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can be referred to the description of the method part.
[0034] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. The technicians will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0035] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices and equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units may be merely a logical functional division. In actual implementation, other division methods may be used, such as combining or integrating multiple units or components into another system, or omitting or disabling some features. In addition, the coupling or direct coupling or communication connection shown or discussed between each other may be through some interface, or the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to implement the present embodiments according to actual needs. In addition, the functional units in the embodiments of the present disclosure may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit.
Claims
1. A method for implementing a deterministic message queue that supports multiple reads and multiple writes, characterized in that: This method provides a message queue. Multiple tasks in the same process in the Xenomai environment publish messages through this message queue, and multiple other tasks in the same process subscribe to messages through this message queue. The message communication of this message queue is deterministic. The message queue provided by the method includes several independent one-to-one deterministic message sub-queues, message write synchronization services, and message read synchronization services that support in-process communication. The message sub-queues include write sub-queues, read sub-queues, and buffer sub-queues. The write sub-queue is used to provide message publishing services and the write sub-queue is connected to the message write synchronization service. The read sub-queue is used to provide message subscription services and the read sub-queue is connected to the message read synchronization service. The cache sub-queue is connected between the message write synchronization service and the message read synchronization service. The message write synchronization service reads messages from multiple write sub-queues and writes the read messages to the buffer sub-queue. The message read synchronization service reads messages from the buffer sub-queue and writes the read messages to multiple read sub-queues.
2. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 1, characterized in that: The message queue provided by this method is encapsulated as a class, each subqueue is encapsulated as a subclass of the class, and the message write synchronization service and the message read synchronization service are methods of the class.
3. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 2, characterized in that: This class also includes a publishing queue addition method, a publishing queue deletion method, a subscription queue addition method, and a subscription queue deletion method. The publishing queue addition method is to dynamically add a write subqueue to the class, and the publishing queue deletion method is to dynamically remove a write subqueue from the class. The subscription queue addition method is to dynamically add a read subqueue to the class, and the subscription queue deletion method is to dynamically remove a read subqueue from the class.
4. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 1, wherein: Each subqueue in the message queue is a deterministic message queue that supports one-to-one communication in the Xenomai environment.
5. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 4, characterized in that: The deterministic message queue that supports one-to-one communication is a ring queue. The ring queue includes more than three message nodes. More than three message nodes are dynamically divided into full nodes, empty nodes, and buffer nodes. Buffer nodes are required and consist of one or more consecutive nodes. They are used to avoid errors when the message queue reads and writes messages at the same time.
6. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 5, characterized in that: The data reading and writing process based on the circular queue is as follows: read the message from the message head pointer. After reading, the message head pointer is offset by one node position in the clockwise direction. If the message head pointer points to the buffer node, 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 is an empty node. If it is not empty, it means that the message queue is full and new messages cannot be written. If there is an empty node, the buffer node is moved forward by one node in the clockwise direction. The node that is vacant after the buffer node is moved forward can be used to write messages, and the message tail pointer points to the new message node position.
7. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 1, characterized in that: The message writing synchronization service and the message reading synchronization service run as tasks in Xenomai.
8. The method for implementing a deterministic message queue supporting multiple reads and multiple writes according to claim 1, characterized in that: The number of the write sub-queue and the number of the read sub-queue are both multiple.
9. A deterministic message queue implementation device supporting multiple reads and multiple writes, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the method for implementing a deterministic message queue supporting multiple reads and multiple writes as described in any one of claims 1 to 8 when running the program instructions.
10. A storage medium storing program instructions, characterized in that: When the program instructions are run, they execute the method for implementing a deterministic message queue supporting multiple reads and multiple writes as described in any one of claims 1 to 8.
