A double-end self-initialization polling communication method based on reserved shared memory
Patent Information
- Application Number
- CN202610915701.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-24
- Publication Date
- 2026-09-08
- Estimated Expiration
- 2046-06-24
AI Technical Summary
[0004]针对现有技术中的上述不足,本发明提供的一种基于预留共享内存双端自初始化轮询通信方法,解决了共享内存通信无法落地为可重复、可测试、对启动顺序不敏感的工程方案,双端初始化公共元数据顺序难决定,如何避免读到未写完的数据,如何在Linux用户态以统一方式打开同一段物理区,以及在部分虚拟化环境下映射属性不当导致的总线异常或可见性的问题
S2014、根据控制块中独立数值字段,通过与状态标志中通用操作系统侧就绪位和实时操作系统就绪位表达相同就绪语义,设置包含通用操作系统就绪标志以及实时操作系统就绪标志的就绪标志。
Smart Images

Figure CN122450706B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer system memory communication technology, and particularly relates to a two-end self-initialization polling communication method based on reserved shared memory. Background Technology
[0002] In multi-core on-chip systems, partitioned virtualization, or collaborative architectures of "general-purpose operating systems and real-time operating systems," the two sides often need to exchange startup coordination, health status, configuration parameters, and a small amount of business data. If relying entirely on the network protocol stack (such as Transmission Control Protocol / User Datagram Protocol), the stack overhead and path latency are significant; if relying on remote procedure call middleware, the deployment and trimming costs are high. Shared memory is a common choice due to its low latency and relatively straightforward implementation.
[0003] However, for shared memory communication to be implemented as a repeatable, testable, and boot-order-insensitive engineering solution, several issues still need to be addressed: which party initializes the public metadata first, how to avoid reading incomplete data, how to open the same physical region in Linux user space in a unified manner, and bus anomalies or visibility problems caused by improper mapping attributes in some virtualization environments. This invention provides a complete technical solution to the above engineering problems. Summary of the Invention
[0004] To address the aforementioned shortcomings in existing technologies, this invention provides a dual-end self-initialization polling communication method based on reserved shared memory. This method solves the problems of shared memory communication not being able to be implemented as a repeatable, testable, and startup-insensitive engineering solution, the difficulty in determining the order of dual-end initialization of public metadata, how to avoid reading incomplete data, how to open the same physical area in Linux user space in a unified manner, and bus anomalies or visibility issues caused by improper mapping attributes in some virtualization environments.
[0005] To achieve the above objectives, the technical solution adopted by this invention is as follows: a two-end self-initialization polling communication method based on reserved shared memory, comprising the following steps: S1. Based on general-purpose operating systems and real-time operating systems, shared memory is obtained by reserving a physical contiguous region; S2. Based on the general operating system and the real-time operating system, use bitwise OR to obtain the status flag and the ready flag, set the control block, and set a bidirectional message channel based on a fixed offset. Combine the control block and the shared memory to obtain the set shared memory. S3. In response to reading from any system side, the shared memory is self-initialized according to the general operating system kernel driver, the general operating system user-space program, the real-time operating system side, and the preset handshake rules, so as to obtain the self-initialized shared memory. S4. By setting timing constraints for sending and receiving, polling communication is performed between the general-purpose operating system and the real-time operating system using self-initialized shared memory.
[0006] The beneficial effects of this invention are as follows: This invention completes the setup of the shared memory by having two operating systems share a segment of physical memory, acquiring the shared memory, setting up a control block and a bidirectional message channel, and performing dual-end self-initialization of the general operating system and the real-time operating system in conjunction with preset handshake rules, and setting timing constraints for sending and receiving to complete polling communication. This achieves independence from the startup order of both ends, reduces the dependence on doorbells and interrupts and the probability of reading incomplete data, enables the user space on the general operating system side to directly access the shared memory, and improves the visibility and compatibility of dual-end self-initialization polling communication.
[0007] Further, S1 includes the following steps: S101. Based on a general-purpose operating system containing a general-purpose operating system kernel driver and a general-purpose operating system user-mode program, and a real-time operating system containing a general-purpose operating system user-mode program, a reserved physical region is obtained by reserving a physical contiguous region between the general-purpose operating system and the real-time operating system. S102. Based on a general operating system, the reserved physical region is described using memory nodes in the board-level device tree, and the physical base address and length of the shared memory are obtained. S103. Based on the real-time operating system, the start symbol and length symbol of the shared memory are exported using the linker script, and the base address and total size of the shared memory are read using the initialization function. S104. Combining the physical base address and length of the shared memory, the start symbol and length symbol of the shared memory, and the base address and total size of the shared memory, and based on the real-time operating system, using linker script symbols, bind the same physical area shared by the real-time operating system and the general-purpose operating system to obtain the shared memory.
[0008] The beneficial effects of the above-mentioned further solutions are as follows: By reserving a physical contiguous region between the general-purpose operating system and the real-time operating system, and describing the physical base address and length by the device tree, and exporting the start and length symbols by the linker script and reading them during initialization, the present invention binds both sides to the same physical shared region, realizing a unified agreement on the shared memory address and scale at the firmware or board level, reducing communication failures and debugging costs caused by inconsistent mapping between the two sides; by separating the acquisition of the physical region from the subsequent control block and message channel layout into repeatable engineering steps, the deployability and testability of the cross-operating system shared memory solution are improved, providing a stable data plane foundation for subsequent two-end self-initialization and polling communication.
[0009] Furthermore, S2 includes the following steps: S201. Based on the general operating system and the real-time operating system, using a bitwise OR method, obtain the status flag containing the general ready bit, the general operating system ready bit, and the real-time operating system ready bit, and set the ready flag containing the general operating system ready flag and the real-time operating system ready flag according to the independent numerical fields in the control block. S202. Based on the status flag and the ready flag, the control block is set by mapping the start of the shared memory to the location of the control block, and combining the magic number, version number and total length. S203. Based on the one-way messages between the general-purpose operating system and the real-time operating system, the one-way message from the general-purpose operating system to the real-time operating system is taken as the first one-way message slot, and the one-way message from the real-time operating system to the general-purpose operating system is taken as the second one-way message slot. S204. Based on the first one-way message slot and the second one-way message slot, and with a fixed offset, set up a bidirectional message channel containing a sequence number. S205. Place the bidirectional message channel after the control block, and combine the control block and shared memory to obtain the configured shared memory.
[0010] Furthermore, step S201 includes the following steps: S2011. Based on the general operating system and the real-time operating system, using bitwise OR representation, the shared memory region that has been effectively initialized and is available for subsequent fields is recorded as the general ready bit. S2012. Mark the general operating system side as ready and ready to participate in communication as the general operating system side ready bit. S2013. Record the real-time operating system side as having completed initialization and is ready to participate in communication as the real-time operating system ready bit, and obtain the status flag by integrating the general ready bit, the general operating system side ready bit and the real-time operating system ready bit according to the bit field field in the control block. S2014. Based on the independent numerical fields in the control block, and by expressing the same ready semantics as the general operating system ready bit and the real-time operating system ready bit in the status flag, set a ready flag that includes the general operating system ready flag and the real-time operating system ready flag.
[0011] The beneficial effects of the above-mentioned further solutions are as follows: This invention sets a status flag including a general ready bit and two ready bits in a bitwise OR manner, and combines it with an independent numerical ready flag and the magic number, version number and total length at the beginning of the control block. Then, a bidirectional message channel consisting of two unidirectional message slots with sequence numbers is arranged at a fixed offset after the control block. This achieves a structured and protocol-based unified layout of the shared memory region, reducing the problem of inconsistent understanding of the communication region between the two ends. By mapping the general operating system to the real-time operating system and the real-time operating system to the general operating system as the first and second unidirectional message slots respectively, the risk of direction confusion and write conflict during bidirectional communication is improved, and a fixed and predictable message carrying position is provided for subsequent sequential number submission and polling for newness determination.
[0012] Furthermore, step S3 includes the following steps: S301, responding to reads on any system side, utilizes the kernel driver on the general operating system side to read the control block by mapping the reserved physical region of shared memory to the kernel virtual address, and obtains the magic number and version number of the control block; S302. According to the preset handshake rules, determine whether the magic number and version number of the control block meet the agreed valid values, and execute the memory barrier to obtain the initialized control block. S303. In response to the user program opening the device node, the user-space program of the general operating system is used to determine whether the device node has been successfully opened and to obtain the mapped shared memory. S304. Based on the real-time operating system, by calling the initialization interface, the system performs double-end self-initialization according to the preset handshake rules. Using shell commands, the system performs handshake and sending / receiving by symmetrically using bidirectional message channels and polling sequence numbers to determine newness. The system performs self-initialization on the configured shared memory to obtain the self-initialized shared memory.
[0013] Furthermore, S302 specifically includes: According to the preset handshake rules, it is determined whether the magic number and version number of the control block meet the agreed valid values. If not, the control block is cleared using the current system side, and the magic number, version number and total length of shared memory of the current system side are written into the control block. The current system side ready value field and the current system side ready bit and general ready bit in the status flag are set, and the memory barrier is executed to obtain the initialized control block. If so, the content already written on the other system side is not overwritten. The ready value field of the current system side and the ready bit of the current system side in the status flag are set, a memory barrier is executed, and an initialized control block is obtained.
[0014] Furthermore, S303 specifically refers to: In response to a user program opening a device node, the system uses a general-purpose operating system user-space program to determine whether the device node has been successfully opened. If so, it obtains the length of the shared memory through input / output control and performs memory mapping to obtain the mapped shared memory. If not, the default shared memory length is used, and memory mapping is performed to obtain the mapped shared memory.
[0015] The beneficial effects of the above-mentioned further solutions are as follows: When reading from either system side, the general operating system kernel drives the mapping of the reserved area and reads the magic number and version number of the control block. According to the preset handshake rules, the control block initialization or continuation bit setting is completed and the memory barrier is executed. Then, the user space opens the device node to complete the mapping, and the real-time operating system side calls the initialization interface for symmetrical handshake and transmission. This achieves self-initialization and cross-boundary visibility guarantee that is independent of the startup order of both ends, and reduces handshake failures caused by one end not being ready or writing to invisible areas. By directly accessing the shared area through the device node and memory mapping in the user space of the general operating system, the convenience of functional verification, joint debugging and bandwidth testing is improved.
[0016] Furthermore, step S4 includes the following steps: S401. By setting timing constraints for sending and receiving, in response to the message written in the sending direction, the effective length is written to the self-initialized shared memory, the payload byte is written to the self-initialized shared memory, the sequence number in the bidirectional message channel is incremented, and the sequence number update is used as the commit flag for this message, thus obtaining the writing communication process. S402. In response to the receiver receiving a message, the sequence number read last time is saved, and the sequence number of the current message slot is read in a loop. In response to the current sequence number being different from the sequence number read last time and being non-zero, the effective length and payload data are read to obtain the message receiving communication process. S403. Based on the write communication process and the message receiving communication process, polling communication is performed between the general operating system and the real-time operating system. By sleeping for several milliseconds between two polling sessions, the CPU usage is reduced, thus completing the two-end self-initialization polling communication.
[0017] The beneficial effects of the above-mentioned further solutions are as follows: By first writing the effective length and payload bytes on the sending side, then incrementing the sequence number in the bidirectional message channel and using the updated sequence number as the submission flag for this message, the present invention achieves the visible order of data submission based on the last updated sequence number, reducing the probability of the receiving side misjudging a new message or reading incomplete data when the payload is not fully written; by saving the previous sequence number on the receiving side and cyclically reading the current sequence number, and only reading the length and payload when the current sequence number is different from the previous one and is non-zero, the invention achieves a new-based polling reception that does not rely on doorbells or interrupts, reducing the dependence on dedicated interrupt notification links; by sleeping for several milliseconds between two polls, the invention improves the trade-off between CPU usage and real-time performance in polling scenarios, and completes a closed loop of bidirectional polling communication based on self-initialized shared memory. Attached Figure Description
[0018] Figure 1 This is a flowchart of the method of the present invention.
[0019] Figure 2 This is a diagram of the dual-end self-initialization polling communication structure based on reserved shared memory in this embodiment. Detailed Implementation
[0020] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.
[0021] Before describing this embodiment, the following terms will be explained: flags: bit field; Linux: A multi-user network operating system; UniProton: A lightweight real-time operating system.
[0022] Example like Figure 1 As shown, this invention provides a two-end self-initialization polling communication method based on reserved shared memory, the implementation method of which is as follows: S1. Based on general-purpose operating systems and real-time operating systems, shared memory is obtained by reserving a physically contiguous region. The specific steps are as follows: S101. Based on a general-purpose operating system containing a general-purpose operating system kernel driver and a general-purpose operating system user-mode program, and a real-time operating system containing a general-purpose operating system user-mode program, a reserved physical region is obtained by reserving a physical contiguous region between the general-purpose operating system and the real-time operating system. S102. Based on a general operating system, the reserved physical region is described using memory nodes in the board-level device tree, and the physical base address and length of the shared memory are obtained. S103. Based on the real-time operating system, the start symbol and length symbol of the shared memory are exported using the linker script, and the base address and total size of the shared memory are read using the initialization function. S104. Combining the physical base address and length of the shared memory, the start symbol and length symbol of the shared memory, and the base address and total size of the shared memory, and based on the real-time operating system, using linker script symbols, bind the same physical area shared by the real-time operating system and the general-purpose operating system to obtain the shared memory.
[0023] In this embodiment, as Figure 2 As shown, Linux and its user space and kernel drivers are used as the general operating system side; UniProton and its threads or processes, applications and commands are used as the real-time operating system side. In the diagram, the starting address of the shared memory is _shm_start; the total length of the shared memory address is _shm_size; the memory mapping is Mmap; / dev / uniproton_sh is the name of the character device under Linux; the uniproton_shm node is the name of the node in the device tree; Obtain shared memory based on both the general-purpose operating system side and the real-time operating system side; On the general operating system side, in the board-level device tree, a reserved memory node is used to describe a physically contiguous region, and a platform node matching this driver is added; the driver obtains the physical base address and length during the probing phase and maps the start point to a control block; On the real-time operating system side, the shared memory start symbol and length symbol are exported in the linker script. After startup, the initialization function reads and obtains the base address and total size. The same physical area used by the general operating system side, whose address and size must be consistent with the firmware. Align Linux and UniProton with device tree reserved memory and linker script symbols to obtain shared memory.
[0024] S2. Based on the general-purpose operating system and the real-time operating system, the status flag and ready flag are obtained using a bitwise OR method. The control block is then set up, and a bidirectional message channel is established based on a fixed offset. Combining the control block and shared memory, the configured shared memory is obtained. The specific steps are as follows: S201. Based on the general-purpose operating system and the real-time operating system, using a bitwise OR method, obtain the status flag containing the general-purpose ready bit, the general-purpose operating system ready bit, and the real-time operating system ready bit, and set the ready flag containing the general-purpose operating system ready flag and the real-time operating system ready flag according to the independent numerical fields in the control block. The specific steps are as follows: S2011. Based on the general operating system and the real-time operating system, using bitwise OR representation, the shared memory region that has been effectively initialized and is available for subsequent fields is recorded as the general ready bit. S2012. Mark the general operating system side as ready and ready to participate in communication as the general operating system side ready bit. S2013. Record the real-time operating system side as having completed initialization and is ready to participate in communication as the real-time operating system ready bit, and obtain the status flag by integrating the general ready bit, the general operating system side ready bit and the real-time operating system ready bit according to the bit field field in the control block. S2014. Based on the independent numerical fields in the control block, and by expressing the same ready semantics as the general operating system ready bit and the real-time operating system ready bit in the status flag, set a ready flag that includes the general operating system ready flag and the real-time operating system ready flag. S202. Based on the status flag and the ready flag, the control block is set by mapping the start of the shared memory to the control block location, combined with the magic number, version number and total length.
[0025] In this embodiment, a control block structure is constructed, and the control block is placed at the very beginning of the shared memory. It includes at least: magic number, version number, status flag, general operating system ready flag, real-time operating system ready flag, and total length; optionally, it includes used length, block count, and reserved fields. The specific definitions of status flags and ready flags are as follows: Status flags: These refer to the flags bit field in the control block, which uses a bitwise OR operation to represent multiple states, including at least: General ready bit: Indicates that the entire shared memory region has been effectively initialized and is available for use by subsequent fields; General operating system side ready bit: indicates that the general operating system side has completed initialization and can participate in communication; Real-time operating system ready bit: Indicates that the real-time operating system has completed initialization and is ready to participate in communication.
[0026] General operating system readiness flag and real-time operating system readiness flag: In addition to the corresponding bits in the flags bit field mentioned above, each of the embodiments also includes an independent numerical field (linuxReady and uniprotonReady, respectively, with a value of 0 or 1), which synchronously expresses the same ready semantics on the same side as the corresponding bits in the flags bit field, making it convenient for the other end to quickly judge and print diagnostics.
[0027] S203. Based on the one-way messages between the general-purpose operating system and the real-time operating system, the one-way message from the general-purpose operating system to the real-time operating system is taken as the first one-way message slot, and the one-way message from the real-time operating system to the general-purpose operating system is taken as the second one-way message slot. S204. Based on the first one-way message slot and the second one-way message slot, and with a fixed offset, set up a bidirectional message channel containing a sequence number. S205. Place the bidirectional message channel after the control block, and combine the control block and shared memory to obtain the configured shared memory.
[0028] In this embodiment, a bidirectional message channel layout is implemented. After the control block, the bidirectional message channel structure is placed with a fixed offset. The fixed offset is preset to 4096 bytes. The bidirectional message channel layout contains two unidirectional message slots: the first unidirectional message slot is from the general operating system to the real-time operating system, and the second unidirectional message slot is from the real-time operating system to the general operating system. Each message slot contains: a sequence number (volatile), an effective length, and a fixed-length payload buffer; By combining the bidirectional message channel, control block, and shared memory, the configured shared memory is obtained.
[0029] S3. In response to a read operation on any system side, the shared memory is self-initialized according to the general operating system kernel driver, the general operating system user-space program, the real-time operating system side, and the preset handshake rules, resulting in self-initialized shared memory. The specific steps are as follows: S301, responding to reads on any system side, utilizes the kernel driver on the general operating system side to read the control block by mapping the reserved physical region of shared memory to the kernel virtual address, and obtains the magic number and version number of the control block; S302. According to the preset handshake rules, determine whether the magic number and version number of the control block meet the agreed valid values, and execute the memory barrier to obtain the initialized control block, specifically: According to the preset handshake rules, it is determined whether the magic number and version number of the control block meet the agreed valid values. If not, the control block is cleared using the current system side, and the magic number, version number and total length of shared memory of the current system side are written into the control block. The current system side ready value field and the current system side ready bit and general ready bit in the status flag are set, and the memory barrier is executed to obtain the initialized control block. If so, the content already written on the other system side is not overwritten. The ready value field of the current system side and the ready bit of the current system side in the status flag are set, a memory barrier is executed, and an initialized control block is obtained.
[0030] In this embodiment, the behavior of a general operating system kernel driver is set so that, in response to the driver detecting a physical region, the reserved shared memory is mapped to the kernel virtual address; Perform a two-way self-initialization handshake and read the control block according to the handshake rules; If the magic number of the control block in the reserved shared memory is invalid, the control block is initialized; after setting the generic operating system ready flag and updating the flag, a memory barrier is executed to ensure that the real-time operating system side can subsequently see it. The driver registers miscellaneous character devices and returns the shared memory length by providing open, memory mapping, and input / output control. In the memory mapping implementation, physical pages are mapped to user processes, and the specific page attributes follow the compatibility considerations in the comments of this embodiment, such as avoiding the use of mapping types that are prone to causing exceptions under certain virtualization combinations. If the magic number and version do not meet the agreed valid values when reading from either side: that side will clear the control block and write the magic number, version, and total length, and set the ready value field of this side (linuxReady or uniprotonReady), and set the ready bit of this side and the general ready bit in flags. The general ready bit will be set at the same time as the path is initialized to indicate that the content of the control block is valid. If it is already effective: This side will not overwrite the content already written on the other side, but will only set the ready value field on this side, and set the ready bit on this side in flags, without repeatedly clearing the entire table; This allows the system to initialize the system first, with subsequent initiators taking over the process, resulting in an initialized control block.
[0031] S303. In response to the user program opening the device node, the user-space program of the general operating system is used to determine whether the device node was successfully opened, and the mapped shared memory is obtained, specifically as follows: In response to a user program opening a device node, the system uses a general-purpose operating system user-space program to determine whether the device node has been successfully opened. If so, it obtains the length of the shared memory through input / output control and performs memory mapping to obtain the mapped shared memory. If not, the default shared memory length is used, and memory mapping is performed to obtain the mapped shared memory.
[0032] In this embodiment, the behavior of a general operating system user-mode program is set. In response to the user program opening a device node, the length is obtained through input / output control. If the input / output fails, a preset default length is used, and then memory mapping is performed. Supports: printing control block information, simple read / write self-test, line-by-line sending and polling reception, and bandwidth testing; in bandwidth testing, the sender first sends a pre-defined string as the start of synchronization, and the receiver only starts timing after receiving the synchronization, reducing measurement errors.
[0033] S304. Based on the real-time operating system, by calling the initialization interface, the system performs double-end self-initialization according to the preset handshake rules. Using shell commands, the system performs handshake and sending / receiving by symmetrically using bidirectional message channels and polling sequence numbers to determine newness. The system performs self-initialization on the configured shared memory to obtain the self-initialized shared memory.
[0034] In this embodiment, the behavior on the real-time operating system side is set. In response to the call to the initialization interface, it is determined whether the control block is initialized by the peer. If so, only the local side is set to ready; otherwise, the control block is initialized. Applications or commands use slots in two directions symmetrically with the general operating system side for sending and receiving, thereby enabling self-initialization of the configured shared memory and obtaining the self-initialized shared memory; Optionally, the shared memory cache attribute configuration on this side can be aligned with the mapping strategy on the general operating system side to ensure consistency.
[0035] S4. By setting timing constraints for sending and receiving, and utilizing self-initialized shared memory, polling communication is performed between the general-purpose operating system and the real-time operating system. The specific steps are as follows: S401. By setting timing constraints for sending and receiving, in response to the message written in the sending direction, the effective length is written to the self-initialized shared memory, the payload byte is written to the self-initialized shared memory, the sequence number in the bidirectional message channel is incremented, and the sequence number update is used as the commit flag for this message, thus obtaining the writing communication process. S402. In response to the receiver receiving a message, the sequence number read last time is saved, and the sequence number of the current message slot is read in a loop. In response to the current sequence number being different from the sequence number read last time and being non-zero, the effective length and payload data are read to obtain the message receiving communication process. S403. Based on the write communication process and the message receiving communication process, polling communication is performed between the general operating system and the real-time operating system. By sleeping for several milliseconds between two polling sessions, the CPU usage is reduced, thus completing the two-end self-initialization polling communication.
[0036] Set timing constraints for sending and receiving, specifically: The sender first writes the effective length, then the payload bytes, and finally increments the sequence number by one to indicate that the message has been submitted. The receiver saves the last seen sequence number and reads the current sequence number in a loop. If it is different from the last one and is not zero, it reads the length and payload again and sleeps for a few milliseconds between two polls to reduce the CPU usage. The timing constraints for sending and receiving ensure that the receiver does not mistakenly believe there is a new message before the payload is fully written, and updates the sequence number at the end.
[0037] In this embodiment, advantages are achieved in terms of startup order, dependency surface, data integrity, testability, and quantifiable metrics. Startup sequence: Both ends can be initialized first or connected later, reducing the constraints of system integration on the power-on sequence and facilitating on-site upgrades and self-recovery after abnormal resets; Dependency: It does not force the remote processor message framework to use a full stack or a semi-virtualized queue, resulting in a shorter code path in scenarios that only require shared memory and drivers; Data integrity: Length and payload are listed first, followed by sequence number, to reduce the probability of reading incomplete packets; a monotonically increasing sequence number facilitates newness detection by the receiver. Testability: User space is directly stress tested via memory mapping, and bandwidth testing includes a synchronization start point, which facilitates repeated experiments and comparisons of CPU usage under different polling intervals; Quantifiable metrics include: handshake success rate, sequence number transition and message consistency, bandwidth (megabits per second or megabytes per second), polling cycle and utilization rate; specific values are platform-dependent and subject to actual testing.
Claims
1. A two-end self-initializing polling communication method based on reserved shared memory, characterized in that, Includes the following steps: S1. Based on general-purpose operating systems and real-time operating systems, shared memory is obtained by reserving a physical contiguous region; S2. Based on the general operating system and the real-time operating system, use bitwise OR to obtain the status flag and the ready flag, set the control block, and set a bidirectional message channel based on a fixed offset. Combine the control block and the shared memory to obtain the set shared memory. S3. In response to a read operation on any system side, based on the general operating system kernel driver, general operating system user-space program, real-time operating system side, and preset handshake rules, self-initialize the configured shared memory to obtain the self-initialized shared memory. Specifically: S301, responding to reads on any system side, utilizes the kernel driver on the general operating system side to read the control block by mapping the reserved physical region of shared memory to the kernel virtual address, and obtains the magic number and version number of the control block; S302. According to the preset handshake rules, determine whether the magic number and version number of the control block meet the agreed valid values, and execute the memory barrier to obtain the initialized control block. S303. In response to the user program opening the device node, the user-space program of the general operating system is used to determine whether the device node has been successfully opened and to obtain the mapped shared memory. S304. Based on the real-time operating system, by calling the initialization interface, the two-end self-initialization is performed according to the preset handshake rules. Using shell commands, the handshake and sending and receiving are performed by symmetrically using bidirectional message channels and polling the sequence number to determine newness. The set shared memory is then self-initialized to obtain the self-initialized shared memory. S4. By setting timing constraints for sending and receiving, and utilizing self-initialized shared memory, polling communication is performed between the general-purpose operating system and the real-time operating system. Specifically: S401. By setting timing constraints for sending and receiving, in response to the message written in the sending direction, the effective length is written to the self-initialized shared memory, the payload byte is written to the self-initialized shared memory, the sequence number in the bidirectional message channel is incremented, and the sequence number update is used as the commit flag for this message, thus obtaining the writing communication process. S402. In response to the receiver receiving a message, the sequence number read last time is saved, and the sequence number of the current message slot is read in a loop. In response to the current sequence number being different from the sequence number read last time and being non-zero, the effective length and payload data are read to obtain the message receiving communication process. S403. Based on the write communication process and the message receiving communication process, polling communication is performed between the general operating system and the real-time operating system. By sleeping for several milliseconds between two polling sessions, the CPU usage is reduced, thus completing the two-end self-initialization polling communication.
2. The dual-end self-initialization polling communication method based on reserved shared memory according to claim 1, characterized in that, S1 includes the following steps: S101. Based on a general-purpose operating system containing a general-purpose operating system kernel driver and a general-purpose operating system user-mode program, and a real-time operating system containing a general-purpose operating system user-mode program, a reserved physical region is obtained by reserving a physical contiguous region between the general-purpose operating system and the real-time operating system. S102. Based on a general operating system, the reserved physical region is described using memory nodes in the board-level device tree, and the physical base address and length of the shared memory are obtained. S103. Based on the real-time operating system, the start symbol and length symbol of the shared memory are exported using the linker script, and the base address and total size of the shared memory are read using the initialization function. S104. Combining the physical base address and length of the shared memory, the start symbol and length symbol of the shared memory, and the base address and total size of the shared memory, and based on the real-time operating system, using linker script symbols, bind the same physical area shared by the real-time operating system and the general-purpose operating system to obtain the shared memory.
3. The dual-end self-initialization polling communication method based on reserved shared memory according to claim 1, characterized in that, S2 includes the following steps: S201. Based on the general operating system and the real-time operating system, using a bitwise OR method, obtain the status flag containing the general ready bit, the general operating system ready bit, and the real-time operating system ready bit, and set the ready flag containing the general operating system ready flag and the real-time operating system ready flag according to the independent numerical fields in the control block. S202. Based on the status flag and the ready flag, the control block is set by mapping the start of the shared memory to the location of the control block, and combining the magic number, version number and total length. S203. Based on the one-way messages between the general-purpose operating system and the real-time operating system, the one-way message from the general-purpose operating system to the real-time operating system is taken as the first one-way message slot, and the one-way message from the real-time operating system to the general-purpose operating system is taken as the second one-way message slot. S204. Based on the first one-way message slot and the second one-way message slot, and with a fixed offset, set up a bidirectional message channel containing a sequence number. S205. Place the bidirectional message channel after the control block, and combine the control block and shared memory to obtain the configured shared memory.
4. The dual-end self-initialization polling communication method based on reserved shared memory according to claim 3, characterized in that, S201 includes the following steps: S2011. Based on the general operating system and the real-time operating system, using bitwise OR representation, the shared memory region that has been effectively initialized and is available for subsequent fields is recorded as the general ready bit. S2012. Mark the general operating system side as ready and ready to participate in communication as the general operating system side ready bit. S2013. Record the real-time operating system side as having completed initialization and is ready to participate in communication as the real-time operating system ready bit, and obtain the status flag by integrating the general ready bit, the general operating system side ready bit and the real-time operating system ready bit according to the bit field field in the control block. S2014. Based on the independent numerical fields in the control block, and by expressing the same ready semantics as the general operating system ready bit and the real-time operating system ready bit in the status flag, set a ready flag that includes the general operating system ready flag and the real-time operating system ready flag.
5. The dual-end self-initialization polling communication method based on reserved shared memory according to claim 4, characterized in that, Specifically, S302 is as follows: According to the preset handshake rules, it is determined whether the magic number and version number of the control block meet the agreed valid values. If not, the control block is cleared using the current system side, and the magic number, version number and total length of shared memory of the current system side are written into the control block. The current system side ready value field and the current system side ready bit and general ready bit in the status flag are set, and the memory barrier is executed to obtain the initialized control block. If so, the content already written on the other system side is not overwritten. The ready value field of the current system side and the ready bit of the current system side in the status flag are set, a memory barrier is executed, and an initialized control block is obtained.
6. The dual-end self-initialization polling communication method based on reserved shared memory according to claim 5, characterized in that, Specifically, S303 is: In response to a user program opening a device node, the system uses a general-purpose operating system user-space program to determine whether the device node has been successfully opened. If so, it obtains the length of the shared memory through input / output control and performs memory mapping to obtain the mapped shared memory. If not, the default shared memory length is used, and memory mapping is performed to obtain the mapped shared memory.
Citation Information
Patent Citations
Communication method between real-time operating system and non-real-time operating system on multi-core processor
CN103942178A
Multi-core AMP architecture inter-core communication method and system based on high-security embedded real-time operating system
CN119440869A