CN111538607A - Message communication method and device based on boundary protection - Google Patents

Message communication method and device based on boundary protection Download PDF

Info

Publication number
CN111538607A
CN111538607A CN202010570711.8A CN202010570711A CN111538607A CN 111538607 A CN111538607 A CN 111538607A CN 202010570711 A CN202010570711 A CN 202010570711A CN 111538607 A CN111538607 A CN 111538607A
Authority
CN
China
Prior art keywords
message
data
ring buffer
read
buffer area
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010570711.8A
Other languages
Chinese (zh)
Other versions
CN111538607B (en
Inventor
韩辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Acoinfo Technology Co ltd
Original Assignee
Beijing Acoinfo Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Acoinfo Technology Co ltd filed Critical Beijing Acoinfo Technology Co ltd
Priority to CN202010570711.8A priority Critical patent/CN111538607B/en
Publication of CN111538607A publication Critical patent/CN111538607A/en
Application granted granted Critical
Publication of CN111538607B publication Critical patent/CN111538607B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • G06F21/6245Protecting personal data, e.g. for financial or medical purposes

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Databases & Information Systems (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Transfer Systems (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides a message communication method and a device based on boundary protection, wherein the method comprises the following steps: starting a boundary virtual message device, and applying for a ring buffer in a system stack through the boundary virtual message device; the first process writes first message data into the ring buffer area, and the bounded virtual message equipment releases read semaphore after the first message data is successfully written; the second process reads the first message data from the ring buffer after acquiring the read semaphore; and when the data length exceeds the range of the buffer area, the boundary virtual message equipment redirects a read pointer or a write pointer to the head address of the annular buffer area. The data leakage caused by data crossing is prevented through the ring buffer area, the message length can be obtained in advance, a multiplexing mechanism, an overtime mechanism and a permission management mechanism are also supported, and the utilization efficiency of the ring buffer area is improved.

Description

Message communication method and device based on boundary protection
Technical Field
The invention relates to the technical field of human-computer interaction, in particular to a user interaction method and user interaction equipment.
Background
With the development of computer technology, such as distributed computing and the like, inter-process communication (IPC) is becoming more and more important, and IPC refers to a technology for transferring data or signals between two or more processes. At present, common interprocess communication methods are as follows: message queues, shared memory, named semaphores, named pipes, nameless pipes, and the like.
The above common interprocess communication methods have respective technical defects, are not flexible enough to use, do not use data out-of-range protection, cannot perform authority management, and the like, and thus cannot guarantee the safety of message data. For example: the nameless pipeline can only be used for communication between parent and child processes, although the named pipeline can finish process communication without blood relationship, the named pipeline can wait all the time when the condition for reading or sending the message is not satisfied, the overtime time cannot be set, and in addition, the named pipeline exists in the system for a long time, and errors are easy to occur due to improper use. Message queues, while capable of using timeout times, require different APIs to be invoked which is relatively complex to use. The data accuracy cannot be guaranteed by using the shared memory for communication, and when a plurality of processes use the same shared memory, the data can be disordered, namely, the address during data access is out of range, and other synchronization tools are needed for solving the problem, so that the program design is more complicated.
Disclosure of Invention
The present invention addresses one or more of the above-mentioned deficiencies in the prior art and proposes the following technical solutions.
A method of message communication based on boundary protection, the method comprising:
initializing, namely starting a boundary virtual message device, and applying for a ring buffer in a system stack through the boundary virtual message device;
writing, namely writing first message data into the annular buffer area by a first process, and releasing read semaphore by the boundary virtual message equipment after the first message data is successfully written;
reading, namely reading the first message data from the annular buffer area after the second process acquires a reading semaphore;
and when the data length exceeds the range of the buffer area, the boundary virtual message equipment redirects a read pointer or a write pointer to the head address of the annular buffer area.
Further, the writing step and the reading step are synchronized by the virtual message device with the boundary, and the method includes: when the first process writes data into the ring buffer area, whether the ring buffer area is initialized successfully is judged, if so, whether the size of the ring buffer area is larger than or equal to the length of the first message data is judged continuously to obtain a first judgment result, if so, the first process writes the first message data into the ring buffer area, the bounded virtual message device releases a reading signal quantity to the second process after successful writing, and if not, the bounded virtual message device releases a blocking signal quantity to prevent the data from being written into the ring buffer area; the second process starts to read the first message data from the ring buffer after obtaining the read semaphore, after the first message data is read, whether message data still exist in the ring buffer is judged to obtain a second judgment result, if the second judgment result is negative, the bounded virtual message device releases the blocking semaphore to prevent the data from being read from the ring buffer, if the second judgment result is positive, the bounded virtual message device releases the read semaphore to enable other processes to read the message data, then whether the ring buffer has space left to obtain a third judgment result is judged, if the third judgment result is positive, the bounded virtual message device releases the write semaphore, if the third judgment result is negative, the bounded virtual message device releases the blocking semaphore, to prevent writing data to the ring buffer.
Furthermore, when the first determination result is negative, the bounded virtual message device splits the first message data into N pieces of first message sub-data and writes the first message data into the ring buffer,
Figure DEST_PATH_IMAGE001
Figure 100002_DEST_PATH_IMAGE002
indicating rounding up, M being the length of the first message data, K being the size of the ring buffer, the length of the first message data being equal to the length of the header file and the data lengthAnd (c).
Furthermore, the bounded virtual message device sets the maximum data length of one atomic operation, and when the size of the residual space of the ring buffer is judged to be smaller than the maximum data length of one atomic operation, the bounded virtual message device sends a blocking signal amount to block the write operation.
Furthermore, the ring buffer applied by the bounded virtual message device supports L processes to use simultaneously so as to realize message communication among the L processes, wherein L is more than or equal to 2.
Further, the virtual message device with the boundary has a multiplexing mechanism mode of reading and writing processes.
Furthermore, when a third process is in the multiplexing mechanism mode, the third process calls a file state monitoring process of the virtual message device with the boundary, the file state monitoring process judges whether the ring buffer is in a read blocking state to obtain a fourth judgment result, if the fourth judgment result is yes, the ring buffer is judged whether to have message data, if the fourth judgment result is yes, the read blocking is waken to block the read operation of other processes on the ring buffer, and the third process reads the message data from the ring buffer; if the fourth judgment result is negative, judging whether the ring buffer area is in a write blocking state, if so, judging whether the ring buffer area has space left, if so, awakening write blocking to block the write operation of other processes to the ring buffer area, and the third process writes message data into the ring buffer area.
Furthermore, the boundary virtual message device sets a read blocking threshold and a write blocking time threshold, and exits the process of reading the message data when the boundary virtual message device judges that the process blocking time of reading the message data reaches the read blocking threshold; and when the boundary virtual message equipment judges that the process blocking time of the written message data reaches a write blocking threshold value, exiting the process of the written message data.
Further, the bounded virtual message device sets an operation right to the ring buffer.
The invention also provides a message communication device based on boundary protection, which comprises:
the system comprises an initialization unit, a data processing unit and a data processing unit, wherein the initialization unit is used for starting a boundary virtual message device and applying for a ring buffer in a system stack through the boundary virtual message device;
a write-in unit, configured to enable a first process to write first message data into the ring buffer, and release a read semaphore by the bounded virtual message device after the first process succeeds in writing;
the reading unit is used for enabling a second process to obtain the reading semaphore and then reading the first message data from the annular buffer area;
and when the data length exceeds the range of the buffer area, the boundary virtual message equipment redirects a read pointer or a write pointer to the head address of the annular buffer area.
Furthermore, the writing unit and the reading unit perform read-write synchronization through the virtual message device with the boundary, including: when the first process writes data into the ring buffer area, whether the ring buffer area is initialized successfully is judged, if so, whether the size of the ring buffer area is larger than or equal to the length of the first message data is judged continuously to obtain a first judgment result, if so, the first process writes the first message data into the ring buffer area, the bounded virtual message device releases a reading signal quantity to the second process after successful writing, and if not, the bounded virtual message device releases a blocking signal quantity to prevent the data from being written into the ring buffer area; the second process starts to read the first message data from the ring buffer after obtaining the read semaphore, after the first message data is read, whether message data still exist in the ring buffer is judged to obtain a second judgment result, if the second judgment result is negative, the bounded virtual message device releases the blocking semaphore to prevent the data from being read from the ring buffer, if the second judgment result is positive, the bounded virtual message device releases the read semaphore to enable other processes to read the message data, then whether the ring buffer has space left to obtain a third judgment result is judged, if the third judgment result is positive, the bounded virtual message device releases the write semaphore, if the third judgment result is negative, the bounded virtual message device releases the blocking semaphore, to prevent writing data to the ring buffer.
Furthermore, when the first determination result is negative, the bounded virtual message device splits the first message data into N pieces of first message sub-data and writes the first message data into the ring buffer,
Figure 39482DEST_PATH_IMAGE001
Figure 225744DEST_PATH_IMAGE002
and representing rounding-up, wherein M is the length of the first message data, and K is the size of the ring buffer, and the length of the first message data is equal to the sum of the length of the header file and the data length.
Furthermore, the bounded virtual message device sets the maximum data length of one atomic operation, and when the size of the residual space of the ring buffer is judged to be smaller than the maximum data length of one atomic operation, the bounded virtual message device sends a blocking signal amount to block the write operation.
Furthermore, the ring buffer applied by the bounded virtual message device supports L processes to use simultaneously so as to realize message communication among the L processes, wherein L is more than or equal to 2.
Further, the virtual message device with the boundary has a multiplexing mechanism mode of reading and writing processes.
Furthermore, when a third process is in the multiplexing mechanism mode, the third process calls a file state monitoring process of the virtual message device with the boundary, the file state monitoring process judges whether the ring buffer is in a read blocking state to obtain a fourth judgment result, if the fourth judgment result is yes, the ring buffer is judged whether to have message data, if the fourth judgment result is yes, the read blocking is waken to block the read operation of other processes on the ring buffer, and the third process reads the message data from the ring buffer; if the fourth judgment result is negative, judging whether the ring buffer area is in a write blocking state, if so, judging whether the ring buffer area has space left, if so, awakening write blocking to block the write operation of other processes to the ring buffer area, and the third process writes message data into the ring buffer area.
Furthermore, the boundary virtual message device sets a read blocking threshold and a write blocking time threshold, and exits the process of reading the message data when the boundary virtual message device judges that the process blocking time of reading the message data reaches the read blocking threshold; and when the boundary virtual message equipment judges that the process blocking time of the written message data reaches a write blocking threshold value, exiting the process of the written message data.
Further, the bounded virtual message device sets an operation right to the ring buffer.
The invention has the technical effects that: the invention discloses a message communication method based on boundary protection, which comprises the following steps: initializing, namely starting a boundary virtual message device, and applying for a ring buffer in a system stack through the boundary virtual message device; writing, namely writing first message data into the annular buffer area by a first process, and releasing read semaphore by the boundary virtual message equipment after the first message data is successfully written; reading, namely reading the first message data from the annular buffer area after the second process acquires a reading semaphore; and when the data length exceeds the range of the buffer area, the boundary virtual message equipment redirects a read pointer or a write pointer to the head address of the annular buffer area. The space can be recycled through the ring operation, the message data is permanently far in the memory and can not overflow beyond the border, on one hand, the utilization rate of the buffer area is improved, the memory space is saved, on the other hand, the data leakage caused by the data crossing is effectively prevented, the high-efficiency data synchronization among the processes is realized, the message length can be obtained in advance, the situation that the complete message content cannot be stored due to the insufficient space of the buffer area for receiving the message is avoided, the error during the storage of the read message data is avoided, the maximum data length of the atomic operation is defined so as to fully utilize the ring buffer area, the process can be ensured not to be incapable of receiving the message due to the blocking of the sent message through a multiplexing mechanism, or the message cannot be sent due to the blocking of the received message and cannot be opened for use if the authority is insufficient, the safety of the data is ensured, and an overtime mechanism, the process is prevented from occupying the ring buffer all the time, and the utilization efficiency of the ring buffer is improved.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings.
Fig. 1 is a flowchart of a message communication method based on boundary protection according to one of the embodiments of the present invention.
Fig. 2 is a schematic diagram of a ring buffer according to the present invention.
Fig. 3 is a message communication apparatus based on boundary protection according to one embodiment of the present invention.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 shows a message communication method based on boundary protection according to the present invention, which includes:
initializing step S101, starting a boundary virtual message device, and applying for a ring buffer in a system stack through the boundary virtual message device; the system heap is located in memory.
A writing step S102, writing first message data into the ring buffer by a first process, and releasing read semaphore by the boundary virtual message device after the first message data is successfully written;
a reading step S103, in which the second process reads the first message data from the ring buffer after acquiring the read semaphore;
the header file of the first message data records the data length of the first message data, and when the data length exceeds the range of the buffer area, the bounded virtual message device redirects the read pointer or the write pointer to the head address of the ring buffer area, and preferably, the header file can be 2 bytes.
A bounded virtual message device (Bmsg) is a virtual device, before use, the Bmsg needs to be created in a system, and the process is as follows: firstly installing a driver, registering a driver of a bmsg device in a kernel of an operating system, then creating a bmsg device directory in the kernel, enabling a user to create a self-defined device node under the bmsg directory, and simultaneously specifying corresponding access authority, message buffer (ring buffer) size and timeout time threshold, finally writing a message to be sent into the ring buffer through ring operation, copying the message to be received from the ring buffer, wherein the ring buffer is actually a message buffer.
Fig. 2 shows a schematic diagram of the ring buffer, when the message data length exceeds the size of the ring buffer, the read/write pointer is redirected to the ring buffer head address, the first two bytes (i.e. header file) of each message are used to record the length information of the message, when the user uses Bmsg, the Bmsg will apply for a space in the system heap to be used as the ring buffer, the size of the applied space can be set by the parameter transmitted by the user, the space can be recycled by ring operation, the message data is always in the memory and will not overflow beyond the boundary, on one hand, the utilization rate of the buffer is improved, the memory space is saved, on the other hand, the data leakage caused by data boundary crossing is effectively prevented, which is an important invention point of the present invention.
In one embodiment, in order to improve the real-time performance of communication between processes, the writing step and the reading step are synchronized by reading and writing through the virtual message device with a boundary, and the method includes: when the first process writes data into the ring buffer area, whether the ring buffer area is initialized successfully is judged, if so, whether the size of the ring buffer area is larger than or equal to the length of the first message data is judged continuously to obtain a first judgment result, if so, the first process writes the first message data into the ring buffer area, the bounded virtual message device releases a reading signal quantity to the second process after successful writing, and if not, the bounded virtual message device releases a blocking signal quantity to prevent the data from being written into the ring buffer area; the second process starts to read the first message data from the ring buffer after obtaining the read semaphore, after the first message data is read, whether message data still exist in the ring buffer is judged to obtain a second judgment result, if the second judgment result is negative, the bounded virtual message device releases the blocking semaphore to prevent the data from being read from the ring buffer, if the second judgment result is positive, the bounded virtual message device releases the read semaphore to enable other processes to read the message data, then whether the ring buffer has space left to obtain a third judgment result is judged, if the third judgment result is positive, the bounded virtual message device releases the write semaphore, if the third judgment result is negative, the bounded virtual message device releases the blocking semaphore, to prevent writing data to the ring buffer.
In the invention, the Bmsg has the functions of reading and writing synchronization and reading and writing blockage, when the space of a ring buffer area is insufficient, the Bmsg device can block writing, when the message data is not prepared, the Bmsg device can block reading, the Bmsg uses a block message buffer area (ring buffer area) to store data, before reading the message data, the message length can be obtained in advance through a header file, the situation that the complete message cannot be obtained due to the insufficient space of the message receiving buffer area is avoided, and the maximum range of one atomic operation is specified by a user when the Bmsg is established, the integrity of each message can be ensured, namely the boundary virtual message device sets the maximum data length of one atomic operation, when the size of the residual space of the ring buffer area is judged to be smaller than the maximum data length of one atomic operation, the boundary virtual message device sends a blockage signal amount to block writing operation, the invention realizes the high-efficiency data synchronization among the processes through the Bmsg, can acquire the message length in advance, avoids the situation that the complete message content cannot be stored due to the insufficient space of the buffer area for receiving the message, avoids the error during the storage of the read message data, and also defines the maximum data length of the atomic operation so as to fully utilize the annular buffer area, which is another important invention point of the invention.
In order to realize the reading and writing of the message data with larger data volume, when the first judgment result is negative, the invention writes the first message data into the ring buffer after splitting the first message data into N pieces of first message subdata by the boundary virtual message equipment,
Figure 152111DEST_PATH_IMAGE001
Figure 622276DEST_PATH_IMAGE002
and representing rounding-up, wherein M is the length of the first message data, and K is the size of the ring buffer, and the length of the first message data is equal to the sum of the length of the header file and the data length. The invention is another important invention point of the invention, namely, the invention creatively splits the message data in the process into a plurality of sub-message data to realize the reading and writing of the message data with larger data volume.
In an embodiment, the ring buffer applied by the bounded virtual message device supports simultaneous use of L processes to implement message communication between the L processes, where L is greater than or equal to 2, for example, the bounded virtual message device in the present invention may support message communication between a plurality of processes such as 3, 6, and 8, and when the processes communicate with each other, the bounded virtual message device obtains an ID of a destination process to which a sending process is to send message data, and after the sending is completed, the bounded virtual message device only sends a read semaphore to a read process of the ID to allow the process to read the message data, and simultaneously blocks other processes from reading the message data, which is another important invention point of the present invention.
In one embodiment, the bounded virtual message device has a multiplexing mechanism mode of process read and write. For example, when a third process is in the multiplexing mechanism mode, the third process invokes a file state monitoring process of the virtual message device with the boundary, the file state monitoring process judges whether the ring buffer is in a read blocking state to obtain a fourth judgment result, if the fourth judgment result is yes, whether the ring buffer has message data is judged, if so, the read blocking is waken to block the read operation of other processes to the ring buffer, and the third process reads the message data from the ring buffer; if the fourth judgment result is negative, judging whether the ring buffer area is in a write blocking state, if so, judging whether the ring buffer area has space left, if so, awakening write blocking to block the write operation of other processes to the ring buffer area, and the third process writes message data into the ring buffer area. That is, the multiplexing mechanism of the Bmsg in the present invention determines whether to send a message or receive a message by detecting the status of the ring buffer in the Bmsg, and when a process uses the Bmsg to send and receive a message, the multiplexing mechanism can ensure that the process cannot receive a message due to the blocking of the sent message or cannot send a message due to the blocking of the received message, which is another important invention point of the present invention.
In one embodiment, the bordered virtual message device sets a read blocking threshold and a write blocking time threshold, and exits the process of reading the message data when the bordered virtual message device judges that the process blocking time of reading the message data reaches the read blocking threshold; and when the boundary virtual message equipment judges that the process blocking time of the written message data reaches a write blocking threshold value, exiting the process of the written message data. Preferably, the bounded virtual message device sets an operation right to the ring buffer. In the invention, the permission can be appointed when the bmsg message equipment is established, and when other processes want to use the equipment, the permission can not be opened for use if the permission is insufficient, so that the data safety is ensured, and an overtime mechanism is also arranged to prevent the processes from always occupying the ring buffer area, so that the utilization efficiency of the ring buffer area is improved, which is an important invention point of the invention.
Fig. 3 shows a message communication device based on boundary protection, the method includes:
an initialization unit 301, configured to start a bounded virtual message device, and apply for a ring buffer in a system heap through the bounded virtual message device; the system heap is located in a memory and,
a writing unit 302, configured to enable a first process to write first message data into the ring buffer, where after the first message data is successfully written, the bounded virtual message device releases a read semaphore;
a reading unit 303, configured to read the first message data from the ring buffer after the second process acquires the read semaphore;
the header file of the first message data records the data length of the first message data, and when the data length exceeds the range of the buffer area, the bounded virtual message device redirects the read pointer or the write pointer to the head address of the ring buffer area, and preferably, the header file can be 2 bytes.
A bounded virtual message device (Bmsg) is a virtual device, before use, the Bmsg needs to be created in a system, and the process is as follows: firstly installing a driver, registering a driver of a bmsg device in a kernel of an operating system, then creating a bmsg device directory in the kernel, enabling a user to create a self-defined device node under the bmsg directory, and simultaneously specifying corresponding access authority, message buffer (ring buffer) size and timeout time threshold, finally writing a message to be sent into the ring buffer through ring operation, copying the message to be received from the ring buffer, wherein the ring buffer is actually a message buffer.
Fig. 2 shows a schematic diagram of the ring buffer, when the message data length exceeds the size of the ring buffer, the read/write pointer is redirected to the ring buffer head address, the first two bytes (i.e. header file) of each message are used to record the length information of the message, when the user uses Bmsg, the Bmsg will apply for a space in the system heap to be used as the ring buffer, the size of the applied space can be set by the parameter transmitted by the user, the space can be recycled by ring operation, the message data is always in the memory and will not overflow beyond the boundary, on one hand, the utilization rate of the buffer is improved, the memory space is saved, on the other hand, the data leakage caused by data boundary crossing is effectively prevented, which is an important invention point of the present invention.
In one embodiment, in order to improve the real-time performance of communication between processes, the performing, by the writing unit and the reading unit, read and write synchronization through the bounded virtual message device includes: when the first process writes data into the ring buffer area, whether the ring buffer area is initialized successfully is judged, if so, whether the size of the ring buffer area is larger than or equal to the length of the first message data is judged continuously to obtain a first judgment result, if so, the first process writes the first message data into the ring buffer area, the bounded virtual message device releases a reading signal quantity to the second process after successful writing, and if not, the bounded virtual message device releases a blocking signal quantity to prevent the data from being written into the ring buffer area; the second process starts to read the first message data from the ring buffer after obtaining the read semaphore, after the first message data is read, whether message data still exist in the ring buffer is judged to obtain a second judgment result, if the second judgment result is negative, the bounded virtual message device releases the blocking semaphore to prevent the data from being read from the ring buffer, if the second judgment result is positive, the bounded virtual message device releases the read semaphore to enable other processes to read the message data, then whether the ring buffer has space left to obtain a third judgment result is judged, if the third judgment result is positive, the bounded virtual message device releases the write semaphore, if the third judgment result is negative, the bounded virtual message device releases the blocking semaphore, to prevent writing data to the ring buffer.
In the invention, the Bmsg has the functions of reading and writing synchronization and reading and writing blockage, when the space of a ring buffer area is insufficient, the Bmsg device can block writing, when the message data is not prepared, the Bmsg device can block reading, the Bmsg uses a block message buffer area (ring buffer area) to store data, before reading the message data, the message length can be obtained in advance through a header file, the situation that the complete message cannot be obtained due to the insufficient space of the message receiving buffer area is avoided, and the maximum range of one atomic operation is specified by a user when the Bmsg is established, the integrity of each message can be ensured, namely the boundary virtual message device sets the maximum data length of one atomic operation, when the size of the residual space of the ring buffer area is judged to be smaller than the maximum data length of one atomic operation, the boundary virtual message device sends a blockage signal amount to block writing operation, the invention realizes the high-efficiency data synchronization among the processes through the Bmsg, can acquire the message length in advance, avoids the situation that the complete message content cannot be stored due to the insufficient space of the buffer area for receiving the message, avoids the error during the storage of the read message data, and also defines the maximum data length of the atomic operation so as to fully utilize the annular buffer area, which is another important invention point of the invention.
In order to realize the reading and writing of the message data with larger data volume, when the first judgment result is negative, the boundary virtual message equipment will read the message data with larger data volumeThe first message data is divided into N pieces of first message subdata and then written into the ring buffer area,
Figure 975897DEST_PATH_IMAGE001
Figure 649455DEST_PATH_IMAGE002
and representing rounding-up, wherein M is the length of the first message data, and K is the size of the ring buffer, and the length of the first message data is equal to the sum of the length of the header file and the data length. The invention is another important invention point of the invention, namely, the invention creatively splits the message data in the process into a plurality of sub-message data to realize the reading and writing of the message data with larger data volume.
In an embodiment, the ring buffer applied by the bounded virtual message device supports simultaneous use of L processes to implement message communication between the L processes, where L is greater than or equal to 2, for example, the bounded virtual message device in the present invention may support message communication between a plurality of processes such as 3, 6, and 8, and when the processes communicate with each other, the bounded virtual message device obtains an ID of a destination process to which a sending process is to send message data, and after the sending is completed, the bounded virtual message device only sends a read semaphore to a read process of the ID to allow the process to read the message data, and simultaneously blocks other processes from reading the message data, which is another important invention point of the present invention.
In one embodiment, the bounded virtual message device has a multiplexing mechanism mode of process read and write. For example, when a third process is in the multiplexing mechanism mode, the third process invokes a file state monitoring process of the virtual message device with the boundary, the file state monitoring process judges whether the ring buffer is in a read blocking state to obtain a fourth judgment result, if the fourth judgment result is yes, whether the ring buffer has message data is judged, if so, the read blocking is waken to block the read operation of other processes to the ring buffer, and the third process reads the message data from the ring buffer; if the fourth judgment result is negative, judging whether the ring buffer area is in a write blocking state, if so, judging whether the ring buffer area has space left, if so, awakening write blocking to block the write operation of other processes to the ring buffer area, and the third process writes message data into the ring buffer area. That is, the multiplexing mechanism of the Bmsg in the present invention determines whether to send a message or receive a message by detecting the status of the ring buffer in the Bmsg, and when a process uses the Bmsg to send and receive a message, the multiplexing mechanism can ensure that the process cannot receive a message due to the blocking of the sent message or cannot send a message due to the blocking of the received message, which is another important invention point of the present invention.
In one embodiment, the bordered virtual message device sets a read blocking threshold and a write blocking time threshold, and exits the process of reading the message data when the bordered virtual message device judges that the process blocking time of reading the message data reaches the read blocking threshold; and when the boundary virtual message equipment judges that the process blocking time of the written message data reaches a write blocking threshold value, exiting the process of the written message data. Preferably, the bounded virtual message device sets an operation right to the ring buffer. In the invention, the permission can be appointed when the bmsg message equipment is established, and when other processes want to use the equipment, the permission can not be opened for use if the permission is insufficient, so that the data safety is ensured, and an overtime mechanism is also arranged to prevent the processes from always occupying the ring buffer area, so that the utilization efficiency of the ring buffer area is improved, which is an important invention point of the invention.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
From the above description of the embodiments, it is clear to those skilled in the art that the present application can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present application may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments of the present application.
Finally, it should be noted that: although the present invention has been described in detail with reference to the above embodiments, it should be understood by those skilled in the art that: modifications and equivalents may be made thereto without departing from the spirit and scope of the invention and it is intended to cover in the claims the invention as defined in the appended claims.

Claims (10)

1. A method for communicating messages based on boundary protection, the method comprising:
initializing, namely starting a boundary virtual message device, and applying for a ring buffer in a system stack through the boundary virtual message device;
writing, namely writing first message data into the annular buffer area by a first process, and releasing read semaphore by the boundary virtual message equipment after the first message data is successfully written;
reading, namely reading the first message data from the annular buffer area after the second process acquires a reading semaphore;
and when the data length exceeds the range of the buffer area, the boundary virtual message equipment redirects a read pointer or a write pointer to the head address of the annular buffer area.
2. The method of claim 1, wherein said writing step and said reading step are synchronized for reading and writing by said bounded virtual message device, comprising: when the first process writes data into the ring buffer area, whether the ring buffer area is initialized successfully is judged, if so, whether the size of the ring buffer area is larger than or equal to the length of the first message data is judged continuously to obtain a first judgment result, if so, the first process writes the first message data into the ring buffer area, the bounded virtual message device releases a reading signal quantity to the second process after successful writing, and if not, the bounded virtual message device releases a blocking signal quantity to prevent the data from being written into the ring buffer area; the second process starts to read the first message data from the ring buffer after obtaining the read semaphore, after the first message data is read, whether message data still exist in the ring buffer is judged to obtain a second judgment result, if the second judgment result is negative, the bounded virtual message device releases the blocking semaphore to prevent the data from being read from the ring buffer, if the second judgment result is positive, the bounded virtual message device releases the read semaphore to enable other processes to read the message data, then whether the ring buffer has space left to obtain a third judgment result is judged, if the third judgment result is positive, the bounded virtual message device releases the write semaphore, if the third judgment result is negative, the bounded virtual message device releases the blocking semaphore, to prevent writing data to the ring buffer.
3. The method of claim 2, wherein if the first determination result is negative, the bounded virtual message device splits the first message data into N pieces of first message sub-data and writes the N pieces of first message sub-data into the ring buffer,
Figure 457440DEST_PATH_IMAGE001
,
Figure DEST_PATH_IMAGE002
represents rounding up, M is the length of the first message data, K is the ringA size of a shape buffer, a length of the first message data being equal to a sum of a length of the header file and the data length.
4. The method of claim 3, wherein the bounded virtual message device sets a maximum data length for an atomic operation, and wherein the bounded virtual message device sends a blocking signal to block a write operation when the size of the ring buffer remaining space is determined to be less than the maximum data length for an atomic operation.
5. The method as claimed in any one of claims 1 to 4, wherein the ring buffer of the bounded virtual message device application supports simultaneous use of L processes, L ≧ 2, for message communication among the L processes.
6. The method of claim 5, wherein the bounded virtual message device has a multiplexing mechanism mode of process read and write.
7. The method according to claim 6, wherein when a third process is in the multiplexing mechanism mode, the third process invokes a file status monitoring process of the virtual message device with the boundary, the file status monitoring process determines whether the ring buffer is in a read blocking state to obtain a fourth determination result, if the fourth determination result is yes, the file status monitoring process determines whether the ring buffer has message data, if so, the file status monitoring process wakes up the read blocking to block the read operation of other processes on the ring buffer, and the third process reads the message data from the ring buffer; if the fourth judgment result is negative, judging whether the ring buffer area is in a write blocking state, if so, judging whether the ring buffer area has space left, if so, awakening write blocking to block the write operation of other processes to the ring buffer area, and the third process writes message data into the ring buffer area.
8. The method according to claim 7, wherein said bordered virtual message device sets a read blocking threshold and a write blocking time threshold, and when said bordered virtual message device determines that the process blocking time for reading message data reaches the read blocking threshold, said process for reading message data is exited; and when the boundary virtual message equipment judges that the process blocking time of the written message data reaches a write blocking threshold value, exiting the process of the written message data.
9. The method of claim 8, wherein the bounded virtual message device sets an operating privilege on the ring buffer.
10. A message communication apparatus based on boundary protection, the apparatus comprising:
the system comprises an initialization unit, a data processing unit and a data processing unit, wherein the initialization unit is used for starting a boundary virtual message device and applying for a ring buffer in a system stack through the boundary virtual message device;
a write-in unit, configured to enable a first process to write first message data into the ring buffer, and release a read semaphore by the bounded virtual message device after the first process succeeds in writing;
the reading unit is used for enabling a second process to obtain the reading semaphore and then reading the first message data from the annular buffer area;
and when the data length exceeds the range of the buffer area, the boundary virtual message equipment redirects a read pointer or a write pointer to the head address of the annular buffer area.
CN202010570711.8A 2020-06-22 2020-06-22 Message communication method and device based on boundary protection Active CN111538607B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010570711.8A CN111538607B (en) 2020-06-22 2020-06-22 Message communication method and device based on boundary protection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010570711.8A CN111538607B (en) 2020-06-22 2020-06-22 Message communication method and device based on boundary protection

Publications (2)

Publication Number Publication Date
CN111538607A true CN111538607A (en) 2020-08-14
CN111538607B CN111538607B (en) 2020-10-20

Family

ID=71978348

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010570711.8A Active CN111538607B (en) 2020-06-22 2020-06-22 Message communication method and device based on boundary protection

Country Status (1)

Country Link
CN (1) CN111538607B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102591815A (en) * 2011-12-27 2012-07-18 Tcl集团股份有限公司 Method and device for using annular data buffer to read and write batch data
CN106790599A (en) * 2016-12-29 2017-05-31 中国人民解放军国防科学技术大学 It is a kind of based on multinuclear without lock buffer circle symbiosis virtual machine communication method
CN107368374A (en) * 2017-07-26 2017-11-21 广州路派电子科技有限公司 Implementation method is buffered based on the annular data under synchronization mechanism for embedded system
US20180081625A1 (en) * 2016-09-20 2018-03-22 Advanced Micro Devices, Inc. Ring buffer design
CN108768884A (en) * 2018-04-27 2018-11-06 江苏中科芯核电子科技有限公司 A kind of wireless communication data processing method based on buffer circle

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102591815A (en) * 2011-12-27 2012-07-18 Tcl集团股份有限公司 Method and device for using annular data buffer to read and write batch data
US20180081625A1 (en) * 2016-09-20 2018-03-22 Advanced Micro Devices, Inc. Ring buffer design
CN106790599A (en) * 2016-12-29 2017-05-31 中国人民解放军国防科学技术大学 It is a kind of based on multinuclear without lock buffer circle symbiosis virtual machine communication method
CN107368374A (en) * 2017-07-26 2017-11-21 广州路派电子科技有限公司 Implementation method is buffered based on the annular data under synchronization mechanism for embedded system
CN108768884A (en) * 2018-04-27 2018-11-06 江苏中科芯核电子科技有限公司 A kind of wireless communication data processing method based on buffer circle

Also Published As

Publication number Publication date
CN111538607B (en) 2020-10-20

Similar Documents

Publication Publication Date Title
CN108829350B (en) Data migration method and device based on block chain
CN106790599B (en) A kind of symbiosis virtual machine communication method based on multicore without lock buffer circle
US7827536B2 (en) Critical path profiling of threaded programs
WO2017005010A1 (en) Audio processing method and device, and computer storage medium
US8166194B2 (en) Lock-free shared audio buffer
CN108763099A (en) Startup method, apparatus, electronic equipment and the storage medium of system
WO2023197670A1 (en) Distributed storage system control method and apparatus, and readable storage medium
WO2008067435A1 (en) Methods, systems, and apparatus for object invocation across protection domain boundaries
JP2008269288A (en) Boot system, boot program, and method therefor
JP6987340B2 (en) Database data change request processing method and equipment
CN101154202A (en) Managing system management interrupts in a multiprocessor computer system
CN111949614B (en) Bank system file conversion method and device
CN112559210A (en) Shared resource read-write mutual exclusion method based on RTX real-time system
CN111538607B (en) Message communication method and device based on boundary protection
CN116483517B (en) Virtual machine control method, device and system
CN102163164B (en) Processing method and processor for critical data in shared memory
CN114697194B (en) Blocking event notification method and device
US7254815B2 (en) Method and apparatus for implementing distributed event management in an embedded support processor computer system
CN116107774A (en) IO request processing method and device, electronic equipment and storage medium
US20100250507A1 (en) Enumeration of a concurrent data structure
CN102253940B (en) Method and device for processing data by tree view
CN114301927B (en) Main node selection method, device and medium in distributed system
CN114564154B (en) Data reading method based on distributed storage
CN113704297B (en) Processing method, module and computer readable storage medium for business processing request
CN116578446B (en) Virtual machine backup method, device and system, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant