Process communication method, device, electronic device and readable storage medium

By sharing memory space between the kernel state and the user state, two-way data transmission between the kernel state and the user state is realized, the problem of low communication efficiency in the existing technology is solved, and communication efficiency and reliability are improved.

CN117215803BActive Publication Date: 2025-05-16CHINA MOBILE M2M +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210625529.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-02
Publication Date
2025-05-16
Estimated Expiration
2042-06-02

AI Technical Summary

Technical Problem

In the prior art, the data interaction and communication between the kernel state and the user state is relatively low. It is mainly because ioctl is one-way. When the user state needs to obtain the message transmission actively initiated by the kernel state, it can only be queried through polling.

Method used

By sharing memory space between the kernel state and the user state, two-way data transmission is achieved. Specifically, the first process writes data into the first memory space, and the second process reads data in the memory space; conversely, the second process writes data into the second memory space, and the first process reads data in the memory space.

Benefits of technology

The communication efficiency between the kernel state and the user state is improved, and parallel data transmission between the kernel state and the user state to the kernel state is realized, without the need for atomic protection operations such as locks or semaphores, avoiding the impact of communication efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117215803B_ABST
    Figure CN117215803B_ABST
Patent Text Reader

Abstract

The present application provides a process communication method, device, electronic device and readable storage medium, the method comprising: a first process writes first data into a first memory space, and a second process reads the first data in the first memory space; and / or, a second process writes second data into a second memory space, and the first process reads the second data in the second memory space; wherein, the first process is in kernel mode, the second process is in user mode, and the first memory space and the second memory space are memory spaces shared by the first process and the second process. The present application can improve communication efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a process communication method, device, electronic device and readable storage medium. Background Art

[0002] In the operating system, due to the limitation of the permissions of the Central Processing Unit (CPU), the data communication between the kernel state and the user state is mainly realized through the device control interface function (input / output control, ioctl) in the device driver. However, ioctl is mainly used to transmit information from the user state to the kernel state, which is one-way and can only be initiated by the user state. When the user state needs to obtain the message transmission initiated by the kernel state, it can only query by polling, resulting in low communication efficiency. Summary of the invention

[0003] The present application provides a process communication method, device, electronic device and readable storage medium to solve the problem.

[0004] In a first aspect, an embodiment of the present application provides a process communication method, characterized by comprising:

[0005] The first process writes the first data into the first memory space, and the second process reads the first data in the first memory space; and / or,

[0006] The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space;

[0007] The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process.

[0008] In a second aspect, an embodiment of the present application further provides a process communication device, characterized in that it includes:

[0009] A first communication module is used for a first process to write first data into a first memory space, and a second process to read the first data in the first memory space; and / or,

[0010] A second communication module, used for the second process to write the second data into the second memory space, and the first process to read the second data in the second memory space;

[0011] The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process.

[0012] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a transceiver, a memory, a processor, and a program stored in the memory and executable on the processor; the processor is used to read the program in the memory to implement the steps in the method described in the first aspect of the embodiment of the present application.

[0013] In a fourth aspect, an embodiment of the present application further provides a readable storage medium, on which a program is stored, and when the program is executed by a processor, the steps in the method described in the first aspect of the embodiment of the present application are implemented.

[0014] In the embodiment of the present application, the first process writes the first data into the first memory space, and the second process reads the first data in the first memory space; and / or the second process writes the second data into the second memory space, and the first process reads the second data in the second memory space. That is, the kernel state can send data to the user state through the first memory space, and the user state can send data to the kernel state through the second memory space, thereby improving communication efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0016] Figure 1 It is a schematic diagram of a process communication process provided by an embodiment of the present application;

[0017] Figure 2 This is a schematic diagram of kernel state initialization provided by an embodiment of the present application;

[0018] Figure 3 is a schematic diagram of a shared memory space provided in an embodiment of the present application;

[0019] Figure 4 It is a schematic diagram of user mode initialization provided by an embodiment of the present application;

[0020] Figure 5 This is a schematic diagram of sending data from kernel state to user state provided by an embodiment of the present application;

[0021] Figure 6It is a schematic diagram of a user state receiving data sent by a kernel state provided by an embodiment of the present application;

[0022] Figure 7 This is a schematic diagram of sending data from a user state to a kernel state provided by an embodiment of the present application;

[0023] Figure 8 It is a schematic diagram of a kernel state receiving data sent by a user state provided by an embodiment of the present application;

[0024] Fig. 9 It is a structural diagram of a process communication device provided in an embodiment of the present application;

[0025] Fig.10 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0027] The terms "first", "second" etc. in the embodiments of the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. In addition, the terms "include" and "have" and any variation thereof are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment. In addition, "and / or" is used in the present application to represent at least one of connected objects, such as A and / or B and / or C, representing the inclusion of separate A, separate B, separate C, and A and B all exist, B and C all exist, A and C all exist, and 7 situations that A, B and C all exist.

[0028] See also Figure 1 , Figure 1 is a flowchart of a process communication method provided by an embodiment of the present application, such as Figure 1 As shown, the following steps are included:

[0029] Step 101: A first process writes first data into a first memory space, and a second process reads the first data in the first memory space; and / or,

[0030] The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space;

[0031] The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process.

[0032] It can be understood that the first memory space and the second memory space are two independent memory spaces. The first memory space is used for writing data in kernel mode and reading data in user mode, and the second memory space is used for writing data in user mode and reading data in kernel mode.

[0033] Among them, the process in which the first data is written into the first memory space by the first process and read by the second process is the process of transmitting data from the kernel state to the user state; the process in which the second data is written into the second memory space by the second process and read by the first process is the process of transmitting data from the user state to the kernel state. The above two processes can be executed in parallel, that is, while the first process writes the first data into the first memory space, the second process can write the second data into the second memory space, or the first process can also read data from the second memory space; while the second process reads the first data from the first memory space, the second process can write the second data into the second memory space, or the first process can also read data from the second memory space. That is, when the kernel state and the user state communicate, the sending or receiving of data can be executed in parallel through the first memory space and the second memory space respectively.

[0034] In this way, by assigning data write permissions to the first memory space to the first process in kernel state and assigning data write permissions to the second memory space to the second process in user state, the first process and the second process will not write data to the same memory space, thereby ensuring the reliability of communication data between kernel state and user state.

[0035] In the embodiment of the present application, the first process writes the first data into the first memory space, and the second process reads the first data in the first memory space; and / or the second process writes the second data into the second memory space, and the first process reads the second data in the second memory space. That is, the kernel state can send data to the user state through the first memory space, and the user state can send data to the kernel state through the second memory space, thereby improving communication efficiency.

[0036] Furthermore, the transmission of data from kernel state to user state is implemented based on the first memory space, and the transmission of data from user state to kernel state is implemented based on the second memory space, that is, the process of sending data from kernel state to user state and the process of sending data from user state to kernel state can be executed in parallel without affecting each other, and the reliability is high. In this way, the communication process between kernel state and user state does not require atomic protection operations such as locks or semaphores to prevent data from being tampered with, and the influence of atomic protection operations on communication efficiency can be avoided.

[0037] Optionally, the method further comprises:

[0038] The first process creates the first memory space and the second memory space;

[0039] The first process maps the first memory space and the second memory space to the second process, so that the first process and the second process share the first memory space and the second memory space.

[0040] Before the kernel state communicates with the user state, a first storage space and a second memory space can be created by a first process, and the first memory space and the second memory space can be mapped to the second process so that the first process and the second process share the first memory space and the second memory space.

[0041] Specifically, in a Linux system, the above mapping can be implemented by creating and initializing a first virtual device ( / dev / mem device), and the / dev / mem device is used for mapping the first memory space and the second memory space created in the kernel state in the user state.

[0042] In this implementation, through the first memory space and the second memory space shared by the first process and the second process, the first process and the second process can achieve parallel communication, thereby improving the communication efficiency between the kernel state and the user state.

[0043] Optionally, the first memory space includes M storage units, where M is a positive integer;

[0044] The first process writes the first data into a first memory space, and the second process reads the first data in the first memory space, including:

[0045] The first process obtains the first data;

[0046] When there is an idle first storage unit among the M storage units, the first process writes the first data into the first storage unit;

[0047] The first process updates the status information of the first storage unit;

[0048] The second process reads the first data in the first storage unit when monitoring a change in the state information of the first storage unit.

[0049] For the first memory space, the capacity of the first memory space and the capacity of each storage unit can be determined according to system resources and actual business needs, and the data structure of each storage unit may include multiple fields, for example, a field for indicating the current usage status of the storage unit, a field for indicating the effective data length that can be used to transmit data in the storage unit, a field for storing data, etc.

[0050] It should be noted that the usage status of a storage unit can be divided into idle and full. An idle storage unit means that data can be written to the storage unit, and a full storage unit means that data cannot be written to the storage unit.

[0051] The first storage unit is any storage unit in the M storage units that is idle, and data can be written into the first storage unit. If the M storage units are all full, data can be rewritten when there is an idle storage unit.

[0052] The state information of the first storage unit can be used to inform the second process that there is newly written data in the first storage unit. The state information of the first storage unit can include the usage state of the first storage unit and the length of the data in the first storage unit. Specifically, it can be represented by the information of different fields in the above storage unit. For example, the length of the field used to represent the usage state of the storage unit can be 1 bit: when the value is "0", it indicates that the usage state of the storage unit is idle, and when the value is "1", it indicates that the usage state of the storage unit is full; or when the value is "0", it indicates that the usage state of the storage unit is full, and when the value is "1", it indicates that the usage state of the storage unit is idle. The length of the field used to represent the length of the data in the storage unit can be set according to the length of the data that can be stored in the storage unit, and this application does not impose any restrictions on this.

[0053] Specifically, in the Linux system, the second process monitors the status information of the first storage unit through a monitoring function (such as an epoll function, a select function), etc. When the status information of the first storage unit is monitored to change, the second process is notified to read the first data written in the first storage unit.

[0054] In this implementation, the first process obtains the first data; when there is an idle first storage unit among the M storage units, the first process writes the first data into the first storage unit; the first process updates the status information of the first storage unit; and the second process reads the first data in the first storage unit when it monitors the change of the status information of the first storage unit. That is, the first process writes the first data into the idle first storage unit and updates the status information of the first storage unit, and the second process can read the first data written in the first storage unit by monitoring the status information result of the first storage unit, thereby realizing the sending of the first data from the kernel state to the user state, and improving the real-time performance of the communication between the kernel state and the user state.

[0055] In addition, through the first memory space, if the kernel state needs to send data to multiple user states, it can be achieved by expanding the M storage units. The process of the kernel state sending data to each user state is as described above.

[0056] Optionally, the first process updates the state information of the first storage unit, including:

[0057] After the first data is written into the first storage unit, the first process updates the state information of the first storage unit when at least one of the following conditions is met:

[0058] The data length of the first storage unit is greater than or equal to a first preset threshold;

[0059] The first timer expires.

[0060] Among them, the above-mentioned first preset threshold and the above-mentioned first timer can be pre-set according to actual needs or experience values. For example, for data with high timeliness, a smaller first preset threshold or a smaller first timer timeout period can be set to send the data from kernel state to user state as soon as possible. For another example, in order to save transmission resources, a larger first preset threshold or a larger first timer timeout period can be set to avoid frequent updates of the status information of the first storage unit, thereby avoiding the second process from frequently reading data in the first storage unit. In addition, in the process of communication between kernel state and user state, the status update frequency of the first storage unit can be considered from the data length through the above-mentioned first preset threshold, and the status update frequency of the first storage unit can be considered from the time through the above-mentioned first timer.

[0061] It can be understood that the first preset threshold value needs to be smaller than the length of data that can be stored in the first storage unit.

[0062] It should be noted that, in the embodiment of the present application, the update of the status information of the first storage unit can be performed according to the length of the newly written data or at a certain time interval. Specifically, the status information of the first storage unit can be updated after the data length of the data written to the first storage unit by the first process is greater than or equal to the first preset threshold. For example, the status information of the first storage unit can be updated when the data length of the first data is greater than or equal to the first preset threshold; when the data length of the first data is less than the first preset threshold, if the data length of all data written by the first process after the last update of the status information of the first storage unit is greater than or equal to the first preset threshold, the status information of the first storage unit can also be updated; when the data length of all data written by the first process after the last update of the status information of the first storage unit is still less than the first preset threshold, it is necessary to wait for the first process to continue writing data to the first storage unit until the data length written in the first storage unit is greater than or equal to the first preset threshold.

[0063] In this implementation, after the first data is written into the first storage unit, the first process updates the state information of the first storage unit when at least one of the following conditions is met: the data length of the first storage unit is greater than or equal to the first preset threshold value; the first timer times out. That is, the update frequency of the state information of the first storage unit can be controlled from the data length and time, and the frequent update of the state information of the first storage unit can be avoided while ensuring the real-time performance of data transmission, thereby reducing the resources required for data transmission.

[0064] Optionally, the first memory space includes N storage units, where N is a positive integer;

[0065] The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space, including:

[0066] The second process obtains the second data;

[0067] When there is an idle second storage unit among the N storage units, the second process writes the second data into the second storage unit;

[0068] The second process updates the status information of the second storage unit;

[0069] The first process reads the second data in the second storage unit when monitoring a change in the status information of the second storage unit.

[0070] It should be noted that the process of the second process writing the second data into the second memory space and the first process reading the second data in the second memory space can refer to the process of the first process writing the first data into the first memory space and the second process reading the first data in the first memory space, which will not be repeated here.

[0071] Among them, the data writing permission of the above-mentioned second memory space is obtained by the second process, and the data writing permission of the above-mentioned first memory space is obtained by the first process, and the above-mentioned first process and the above-mentioned second process both have the data reading permission of the above-mentioned first memory space and the above-mentioned second memory space.

[0072] Specifically, in a Linux system, the first process can monitor the status information of the second storage unit by creating a second virtual device (notification device), and the notification device can be used to notify the kernel state whether the status information of the second storage unit has changed. The first process can read the second data in the second storage unit by creating a workqueue, and the work item content of the workqueue is to read the data sent by the user state from the second storage unit. For example, after writing data in the second storage unit, the notification device can monitor the increase of data stored in the second storage unit, so that the first process can read the newly written data in the second storage unit through the workqueue according to the monitoring result.

[0073] In this implementation, the second process obtains the second data; when there is an idle second storage unit among the N storage units, the second process writes the second data into the second storage unit; the second process updates the status information of the second storage unit; and the first process reads the second data in the second storage unit when it monitors the change of the status information of the second storage unit. That is, the second process writes the second data into the idle second storage unit and updates the status information of the second storage unit, and the first process can read the second data written in the second storage unit by monitoring the status information result of the second storage unit, thereby realizing the sending of the second data from the user state to the kernel state, and improving the real-time performance of the communication between the kernel state and the user state.

[0074] Optionally, the second process updates the status information of the second storage unit, including:

[0075] After the second data is written into the second storage unit, the second process updates the status information of the second storage unit when at least one of the following conditions is met:

[0076] The data length of the second storage unit is greater than or equal to a second preset threshold;

[0077] The second timer times out.

[0078] It should be noted that the process of updating the status information of the second storage unit by the second process may refer to the process of updating the status information of the first storage unit by the first process, which will not be described in detail here.

[0079] In this implementation, after the second data is written into the second storage unit, the second process updates the state information of the second storage unit when at least one of the following conditions is met: the data length of the second storage unit is greater than or equal to the second preset threshold value; the second timer times out. That is, the update frequency of the state information of the second storage unit can be controlled from the data length and time, and the frequent update of the state information of the second storage unit can be avoided while ensuring the real-time performance of data transmission, thereby reducing the resources required for data transmission.

[0080] Optionally, after the first process writes the first data into the first memory space and the second process reads the first data in the first memory space, the method further includes:

[0081] The second process updates the state information and the first pointer of the first memory space, where the first pointer points to a first address, and the first address is the address of the data most recently read by the second process in the first memory space;

[0082] and / or,

[0083] After the second process writes the second data into the second memory space and the first process reads the second data in the second memory space, the method further includes:

[0084] The first process updates the state information and the second pointer of the second memory space, the second pointer points to a second address, and the second address is the data address most recently read by the first process in the second memory space.

[0085] In the process of the second process reading the data in the first memory space, the state information of the first memory space can be obtained.

[0086] The state information of the first memory space may also be used to inform the first process that the data written in the first memory space has been read by the second process.

[0087] The state information of the second memory space may be used to inform the first process that there is newly written data in the second memory space waiting to be read, or to inform the second process that the data written in the second memory space has been read by the first process.

[0088] In this implementation, through the status information of the first memory space and the first pointer, the second process can determine whether it is necessary to read the data in the first memory space and the address of the data most recently read in the first memory space, so that the second process can completely read the data written to the first memory space by the first process; through the status information of the second memory space and the second pointer, the first process can determine whether it is necessary to read the data in the second memory space and the address of the data most recently read in the second memory space, so that the first process can completely read the data written to the second memory space by the second process, thereby improving the reliability and real-time performance of communication between the kernel state and the user state.

[0089] For better understanding, the specific implementation of the present application is further described in detail below with reference to the accompanying drawings:

[0090] Step S1, initialize kernel state and user state respectively;

[0091] Among them, the kernel state initialization process, such as Figure 2 As shown, the specific process includes the following:

[0092] During the Linux system kernel driver loading phase, two memory spaces are applied for, of which the memory space used for kernel state sending and user state receiving is denoted as M K The memory space used for user-mode transmission and kernel-mode reception is denoted as M U ;

[0093] Among them, the memory space M K and memory space M U The same space layout and data structure can be used. The capacity of each shared memory space and storage unit can be flexibly adjusted according to system resources and actual business needs. The space layout of the memory space is as follows: Figure 3 As shown, each memory space can be divided into multiple storage units.

[0094] According to the storage unit data structure shown in Table 1, the memory space M K and memory space M U Initialize, where the capacity of each shared memory space and storage unit can be flexibly adjusted according to system resources and actual business needs;

[0095] To set the memory space M K (or memory space M U ) as an example, the space capacity is 4MB and the storage unit capacity is 4KB, and the fields in the storage unit are set as follows:

[0096] Table 1

[0097]

[0098] Create a workqueue, the work item content is from the memory space M U Read the data sent by the user state. It should be noted that the content of this work item can add corresponding operations based on the actual business;

[0099] Create and initialize the first virtual device ( / dev / mem device), which is used to map the memory space M created in the user state memory state K 、M U ;

[0100] Create a second virtual device (notification device), which is used to notify the kernel state and user state that the current / dev / mem device has changed and can receive data;

[0101] This completes the kernel initialization process.

[0102] Among them, the user state initialization process, such as Figure 4 As shown, the specific process includes the following:

[0103] After the system kernel is initialized, the user-mode application is run. At this time, the kernel mode has completed the relevant initialization process;

[0104] Open the / dev / mem device and map the memory space M K 、M U ;

[0105] Create a monitoring function (epoll function or select function) to monitor the status change of the / dev / mem device. The execution entity corresponding to the monitoring status change is used to read the status change from the memory space M K Read the data sent from the kernel state; similarly, this part can add corresponding operations based on actual business.

[0106] This completes the user mode initialization process.

[0107] Step S2: The kernel state sends data to the user state, such as Figure 5 As shown, the specific process includes the following:

[0108] The kernel state obtains the data information D that needs to be sent to the user state K ;

[0109] Determine the memory space M K Whether there are any free storage units available;

[0110] At this time, if the memory space M K There is no free storage unit in the process, so the error information is recorded, and the process waits and tries to retransmit.

[0111] At this time, if the memory space M K There is an idle storage unit in the K Fill in memory space M K At the same time, the usage status and data length of the storage unit are updated;

[0112] Determine whether the data length in the storage unit reaches the storage threshold;

[0113] If the data length corresponding to the storage unit currently filled with data does not reach the preset threshold, determine whether a sending timer has been created;

[0114] If the send timer is not created currently, create a send timer. The timeout period is defined according to the actual scenario. The timeout task is to refresh the notification device to notify the user state / dev / mem device status change;

[0115] When the sending timer has been created, determine whether the sending timer has timed out;

[0116] If the sending timer has not timed out, return to the previous step to continue judging;

[0117] If the sending timer times out, the timeout task is executed, and the refresh notification device notifies the user state / dev / mem device status change;

[0118] If the data length corresponding to the storage unit currently filled with data has reached a preset threshold, the existing sending timer is deleted;

[0119] The refresh notification device notifies the user state / dev / mem device status change;

[0120] This completes the process of sending data from kernel mode to user mode.

[0121] Step S3: User state receives data sent by kernel state, such as Figure 6 As shown, the specific process includes the following:

[0122] User mode monitors / dev / mem device status changes through epoll or select;

[0123] Execute the task entity when listening to the / dev / mem device change notification;

[0124] From memory space M K Read the filled data D K Until the reading is completed;

[0125] Update the read data D K The corresponding storage unit state is idle, and the user state unit pointer is refreshed at the same time;

[0126] This completes the process of user mode receiving data and kernel mode sending data.

[0127] Step S4: User state sends data to kernel state, such as Figure 7 As shown, the specific process includes the following:

[0128] The user state obtains the data information that needs to be sent to the kernel state. U ;

[0129] Determine the memory space M U Whether there are any free storage units available;

[0130] At this time, if the memory space M U There is no free storage unit in the process, so the error information is recorded, and the process waits and tries to retransmit.

[0131] At this time, if the memory space M U There is an idle storage unit in the U Fill in memory space M U At the same time, the usage status and data length of the storage unit are updated;

[0132] Determine whether the data length in the storage unit reaches the storage threshold;

[0133] If the data length corresponding to the storage unit currently filled with data does not reach the preset threshold, determine whether a sending timer has been created;

[0134] If the send timer is not created currently, create a send timer. The timeout period is defined according to the actual scenario. The timeout task is to refresh the notification device to notify the user state / dev / mem device status change;

[0135] When the sending timer has been created, determine whether the sending timer has timed out;

[0136] If the sending timer has not timed out, return to the previous step to continue judging;

[0137] If the sending timer times out, the timeout task is executed, and the refresh notification device notifies the user state / dev / mem device status change;

[0138] If the data length corresponding to the storage unit currently filled with data has reached a preset threshold, the existing sending timer is deleted;

[0139] The refresh notification device notifies the kernel state of the / dev / mem device status change;

[0140] This completes the process of sending data from user mode to kernel mode.

[0141] Step S5: The kernel state receives the data sent by the user state, such as Figure 8As shown, the specific process includes the following:

[0142] When the / dev / mem device changes, the device status update function is called;

[0143] Update the workqueue created in the initialization phase and execute the workqueue entity;

[0144] From memory space M U Read the filled data D U Until the reading is completed;

[0145] Update the read data D U The corresponding storage unit state is idle, and the kernel state unit pointer is refreshed at the same time;

[0146] This completes the process of kernel mode receiving data sent by user mode.

[0147] It should be noted that the above step S1 can be executed when the kernel state and the user state communicate for the first time, and may not be executed in the subsequent communication process. In addition, since the implementation method of the present application respectively executes different functions through two memory spaces, the above steps S2 to S3 and steps S4 to S5 can be executed in parallel without affecting each other.

[0148] In the embodiment of the present application, the user state and the kernel state use two independent memory spaces to interact with each other, which do not affect each other and have high reliability. Since the two memories have different functions and there is no interaction, there is no need for atomic protection in the form of locks or semaphores between the user state and the kernel state, and only one copy is required to complete the communication, which greatly improves the communication efficiency.

[0149] In addition, in the case of multiple sending and receiving, that is, the kernel state needs to interact with multiple user states, or the user state needs to interact with multiple kernel states, the memory can be directly expanded, the interaction method remains unchanged, and the scalability is strong.

[0150] See also Fig. 9 , Fig. 9 Schematic diagram of a process communication device provided in an embodiment of the present application. Fig. 9 As shown, the process communication device 900 includes:

[0151] The first communication module 901 is used for a first process to write first data into a first memory space, and a second process to read the first data in the first memory space; and / or,

[0152] A second communication module 902, configured for the second process to write second data into a second memory space, and the first process to read the second data in the second memory space;

[0153] The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process.

[0154] Optionally, the first memory space includes M storage units, where M is a positive integer;

[0155] The first communication module 901 includes:

[0156] A first acquisition unit, used for the first process to acquire the first data;

[0157] a first writing unit, configured to, when there is an idle first storage unit among the M storage units, write the first data into the first storage unit by the first process;

[0158] A first updating unit, used for the first process to update the state information of the first storage unit;

[0159] The first reading unit is used for the second process to read the first data in the first storage unit when monitoring the change of the state information of the first storage unit.

[0160] Optionally, the first updating unit includes:

[0161] A first updating subunit is configured to update the state information of the first storage unit by the first process after the first data is written into the first storage unit when at least one of the following conditions is met:

[0162] The data length of the first storage unit is greater than or equal to a first preset threshold;

[0163] The first timer expires.

[0164] Optionally, the process communication device 900 further includes:

[0165] A first updating module, used for the second process to update the state information and a first pointer of the first memory space, where the first pointer points to a first address, and the first address is the address of the data most recently read by the second process in the first memory space;

[0166] and / or,

[0167] The second update module is used for the first process to update the state information and the second pointer of the second memory space, where the second pointer points to a second address, and the second address is the data address most recently read by the first process in the second memory space.

[0168] Optionally, the first memory space includes N storage units, where N is a positive integer;

[0169] The second communication module 902 includes:

[0170] A second acquisition module, used for the second process to acquire the second data;

[0171] a second writing unit, configured to, when there is an idle second storage unit among the N storage units, write the second data into the second storage unit by the second process;

[0172] a second updating unit, used for the second process to update the status information of the second storage unit;

[0173] The second reading unit is used for the first process to read the second data in the second storage unit when monitoring the change of the state information of the second storage unit.

[0174] Optionally, the second updating unit includes:

[0175] The second sub-update unit is configured to, after the second data is written into the second storage unit, update the state information of the second storage unit by the second process when at least one of the following conditions is met:

[0176] The data length of the second storage unit is greater than or equal to a second preset threshold;

[0177] The second timer times out.

[0178] Optionally, the process communication device 900 further includes:

[0179] A creation module, used by the first process to create the first memory space and the second memory space;

[0180] A mapping module is used for the first process to map the first memory space and the second memory space to the second process, so that the first process and the second process share the first memory space and the second memory space.

[0181] The process communication device 900 can implement the embodiment of the present application Figure 1 The various processes of the method embodiment and the same beneficial effects are achieved, and will not be described again here to avoid repetition.

[0182] The present application also provides an electronic device. Figure 1 The process communication method shown is similar, so the implementation of the electronic device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0183] like Fig.10As shown, the electronic device of the embodiment of the present application includes a memory 1020, a transceiver 1010, and a processor 1000;

[0184] The memory 1020 is used to store computer programs; the transceiver 1010 is used to send and receive data under the control of the processor 1000; the processor 1000 is used to read the computer program in the memory 1020 and perform the following operations:

[0185] The first process writes the first data into the first memory space, and the second process reads the first data in the first memory space; and / or,

[0186] The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space;

[0187] The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process.

[0188] Among them, Fig.10 In the embodiment, the bus architecture may include any number of interconnected buses and bridges, specifically linking together various circuits of one or more processors represented by processor 1000 and memory represented by memory 1020. The bus architecture may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface. The transceiver 1010 may be a plurality of components, namely, a transmitter and a transceiver, providing a unit for communicating with various other devices on a transmission medium. The processor 1000 is responsible for managing the bus architecture and general processing, and the memory 1020 may store data used by the processor 1000 when performing operations.

[0189] The processor 1000 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or a complex programmable logic device (CPLD). The processor may also adopt a multi-core architecture.

[0190] Optionally, the first memory space includes M storage units, where M is a positive integer;

[0191] The first process writes the first data into a first memory space, and the second process reads the first data in the first memory space, including:

[0192] The first process obtains the first data;

[0193] When there is an idle first storage unit among the M storage units, the first process writes the first data into the first storage unit;

[0194] The first process updates the status information of the first storage unit;

[0195] The second process reads the first data in the first storage unit when monitoring a change in the state information of the first storage unit.

[0196] Optionally, the first process updates the state information of the first storage unit, including:

[0197] After the first data is written into the first storage unit, the first process updates the state information of the first storage unit when at least one of the following conditions is met:

[0198] The data length of the first storage unit is greater than or equal to a first preset threshold;

[0199] The first timer expires.

[0200] Optionally, the processor 1000 is further configured to read the computer program in the memory 1020 and perform the following operations:

[0201] The second process updates the state information and the first pointer of the first memory space, where the first pointer points to a first address, and the first address is the address of the data most recently read by the second process in the first memory space;

[0202] and / or,

[0203] The first process updates the state information and the second pointer of the second memory space, the second pointer points to a second address, and the second address is the data address most recently read by the first process in the second memory space.

[0204] Optionally, the first memory space includes N storage units, where N is a positive integer;

[0205] The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space, including:

[0206] The second process obtains the second data;

[0207] When there is an idle second storage unit among the N storage units, the second process writes the second data into the second storage unit;

[0208] The second process updates the status information of the second storage unit;

[0209] The first process reads the second data in the second storage unit when monitoring a change in the status information of the second storage unit.

[0210] Optionally, the second process updates the status information of the second storage unit, including:

[0211] After the second data is written into the second storage unit, the second process updates the status information of the second storage unit when at least one of the following conditions is met:

[0212] The data length of the second storage unit is greater than or equal to a second preset threshold;

[0213] The second timer times out.

[0214] Optionally, the processor 1000 is further configured to read the computer program in the memory 1020 and perform the following operations:

[0215] The first process creates the first memory space and the second memory space;

[0216] The first process maps the first memory space and the second memory space to the second process, so that the first process and the second process share the first memory space and the second memory space.

[0217] The electronic device provided in the embodiment of the present application can perform the above Figure 1 The implementation principle and technical effect of the method embodiment shown are similar, and this embodiment will not be repeated here.

[0218] The embodiment of the present application also provides a readable storage medium on which a program or instruction is stored. When the program or instruction is executed by a processor, the above Figure 1 The various processes of the method embodiment can achieve the same technical effect, and to avoid repetition, they will not be described again here.

[0219] The processor is a processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0220] The present application also provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the above Figure 1 The various processes of the method embodiment can achieve the same technical effect, and to avoid repetition, they will not be described again here.

[0221] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0222] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0223] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0224] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A process communication method, characterized in that: include: The first process writes the first data into the first memory space, and the second process reads the first data in the first memory space; and / or, The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space; The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process; The first memory space includes M storage units, and the data structure of each storage unit includes a domain segment for indicating the current use status of the storage unit, a domain segment for indicating the effective data length of the storage unit that can be used to transmit data, and a domain segment for storing data, wherein the domain segment includes a reserved segment, and the reserved segment is used for subsequent expansion, and M is a positive integer; The first process writes the first data into a first memory space, and the second process reads the first data in the first memory space, including: The first process obtains the first data; When there is an idle first storage unit among the M storage units, the first process writes the first data into the first storage unit; The first process updates the status information of the first storage unit, wherein the status information includes the usage status of the first storage unit and the length of data in the first storage unit; The second process reads the first data in the first storage unit when monitoring a change in the state information of the first storage unit; After the first process writes the first data into the first memory space and the second process reads the first data in the first memory space, the method further includes: The second process updates the state information and the first pointer of the first memory space, where the first pointer points to a first address, and the first address is the address of the data most recently read by the second process in the first memory space; and / or, After the second process writes the second data into the second memory space and the first process reads the second data in the second memory space, the method further includes: The first process updates the state information and the second pointer of the second memory space, the second pointer points to a second address, and the second address is the data address most recently read by the first process in the second memory space.

2. The method according to claim 1, characterized in that The first process updates the status information of the first storage unit, including: After the first data is written into the first storage unit, the first process updates the state information of the first storage unit when at least one of the following conditions is met: The data length of the first storage unit is greater than or equal to a first preset threshold; The first timer expires.

3. The method according to claim 1, characterized in that The first memory space includes N storage units, where N is a positive integer; The second process writes the second data into the second memory space, and the first process reads the second data in the second memory space, including: The second process obtains the second data; When there is an idle second storage unit among the N storage units, the second process writes the second data into the second storage unit; The second process updates the status information of the second storage unit; The first process reads the second data in the second storage unit when monitoring a change in the status information of the second storage unit.

4. The method according to claim 3, characterized in that The second process updates the status information of the second storage unit, including: After the second data is written into the second storage unit, the second process updates the status information of the second storage unit when at least one of the following conditions is met: The data length of the second storage unit is greater than or equal to a second preset threshold; The second timer times out.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: The first process creates the first memory space and the second memory space; The first process maps the first memory space and the second memory space to the second process, so that the first process and the second process share the first memory space and the second memory space.

6. A process communication device, characterized in that: include: A first communication module, configured for a first process to write first data into a first memory space, and a second process to read the first data in the first memory space; and / or, A second communication module, used for the second process to write the second data into the second memory space, and the first process to read the second data in the second memory space; The first process is in kernel state, the second process is in user state, and the first memory space and the second memory space are memory spaces shared by the first process and the second process; The first memory space includes M storage units, the data structure of each storage unit includes a field segment for indicating the current use status of the storage unit, a field segment for indicating the effective data length of the storage unit that can be used to transmit data, and a field segment for storing data, wherein the field segment includes a reserved segment, and the reserved segment is used for subsequent expansion, and M is a positive integer; The first communication module comprises: A first acquisition unit, used for the first process to acquire the first data; a first writing unit, configured to, when there is an idle first storage unit among the M storage units, write the first data into the first storage unit by the first process; a first updating unit, used by the first process to update state information of the first storage unit, wherein the state information includes a usage state of the first storage unit and a length of data in the first storage unit; A first reading unit, configured for the second process to read the first data in the first storage unit when monitoring a change in the state information of the first storage unit; The process communication device also includes: A first updating module, used for the second process to update the state information and a first pointer of the first memory space, where the first pointer points to a first address, and the first address is the address of the data most recently read by the second process in the first memory space; and / or, The second update module is used for the first process to update the state information and the second pointer of the second memory space, where the second pointer points to a second address, and the second address is the data address most recently read by the first process in the second memory space.

7. An electronic device, characterized in that: include: A transceiver, a memory, a processor, and a computer program stored in the memory and executable on the processor; characterized in that: The processor is used to read the program in the memory to implement the steps in any one of the methods according to claims 1 to 5.

8. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by the processor, the steps of the process communication method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Communicating method and system between user mode and kernel

    CN105677493A