Inter-process communication method, apparatus, device, and storage medium
By mapping the virtual address of the data to be sent to the kernel virtual address in the kernel space in parallel in the QNX Neutrino real-time operating system before the client process and the server process establish a communication connection, the problem of low efficiency in inter-process communication is solved, communication efficiency is improved and the load on the server process is reduced.
Patent Information
- Application Number
- CN202211145860.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-20
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-09-20
AI Technical Summary
In the QNX Neutrino real-time operating system, inter-process communication is inefficient, especially when the data is larger than 256 bytes. Existing technologies require multiple virtual address mappings and data copies, resulting in low communication efficiency and excessive load on the server process.
By mapping the virtual address of the data to be sent to the kernel virtual address in the kernel space in parallel before the client process and the server process establish a communication connection, the virtual address mapping steps of the server process are reduced, and the communication efficiency is improved by adopting a parallel mapping method.
It effectively reduces virtual address mapping time, improves communication efficiency between multiple client processes and server processes, and reduces the load on server processes.
Smart Images

Figure CN115437811B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an inter-process communication method, apparatus, device, and storage medium. Background Technology
[0002] When an operating system is running, the processor can execute programs through multi-process cooperation. Process isolation exists between processes; that is, one process cannot directly access the resources of another. However, different processes need to exchange information and pass status information to achieve multi-process cooperation. Therefore, inter-process communication (IPC) is currently used to enable information exchange and status transfer between processes, thereby achieving multi-process cooperation.
[0003] In existing technologies, for data larger than 256 bytes, the operating system of a terminal device running the QNX Neutrino Real-Time Operating System (RTOS) completes data synchronization IPC through one virtual address mapping and one data copy. During the synchronization IPC process, the client process needs to wait for the server process to complete its data reception preparation before performing virtual address mapping and data copying. This results in low efficiency when multiple client processes are performing synchronization IPC with at least one server process. Summary of the Invention
[0004] This application provides an inter-process communication method, apparatus, device, and storage medium to solve the problem of low efficiency in inter-process communication in the prior art.
[0005] In a first aspect, this application provides an inter-process communication method applied to a processor, comprising:
[0006] Obtain the virtual addresses of the data to be sent from N client processes, where N is an integer greater than or equal to 1.
[0007] The virtual addresses of the data to be sent by the N client processes are mapped in parallel to kernel virtual addresses in the kernel space.
[0008] Based on the communication order of the N client processes and the communication order of the M server processes, communication is performed between the N client processes and the M server processes to synchronize the data to be sent by the client processes to the server processes; where M is an integer greater than or equal to 1.
[0009] Optionally, the step of mapping the virtual addresses of the data to be sent by the N client processes to kernel virtual addresses in the kernel space in parallel includes:
[0010] For each of the aforementioned client processes, the following operations are performed in parallel:
[0011] Obtain the virtual address of the data to be sent by the client process.
[0012] Based on the virtual address of the data to be sent by the client process, obtain the physical address of the data to be sent by the client process.
[0013] The physical address of the data to be sent by the client process is mapped to the kernel virtual address in the kernel space.
[0014] Optionally, obtaining the physical address of the data to be sent by the client process based on the virtual address of the data to be sent by the client process includes:
[0015] Obtain the page table of the client process, which includes the mapping relationship between the virtual address of the client process and the physical address of the client process.
[0016] Based on the page table of the client process and the virtual address of the data to be sent by the client process, the physical address of the data to be sent by the client process is obtained.
[0017] Optionally, after mapping the physical address of the data to be sent by the client process to the kernel virtual address in the kernel space, the method further includes:
[0018] By merging consecutive kernel virtual addresses, at least one kernel virtual address segment is obtained.
[0019] Optionally, the communication order of the N client processes is determined based on the synchronization completion time of the N client processes; the step of performing communication between the N client processes and the M server processes based on the communication order of the N client processes and the communication order of the M server processes includes:
[0020] For any client process and its corresponding server process, perform the following operations:
[0021] Establish a communication connection between the client process and the server process.
[0022] The server process sends a receive message to the client process; the receive message instructs the client process to send communication information; the communication information includes a pointer to the kernel virtual address.
[0023] Based on the received message, the client process sends the communication information to the server process.
[0024] The server process copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function.
[0025] Optionally, sending the communication information from the client process to the server process according to the received message includes:
[0026] Based on the received message, the sending state of the client process is activated, and the sending state is used to indicate that the client process is capable of sending the communication information.
[0027] After the client process completes the transmission of the communication information, it sends a message to the server process. The message indicates that the client process has completed the transmission of all the communication information.
[0028] Based on the sent message, the receiving state of the server process is activated, and the receiving state is used to indicate that the server process is able to receive the communication information.
[0029] Optionally, after the server process copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function, the method further includes:
[0030] After the server process completes the copying of the data to be sent, it sends a feedback message to the client process. The feedback message indicates that the server process has completed this inter-process communication.
[0031] After receiving the feedback message, the client process disconnects the communication connection between the client process and the server process.
[0032] Secondly, this application provides an inter-process communication device, comprising:
[0033] The acquisition module acquires the virtual addresses of data to be sent from N client processes, where N is an integer greater than or equal to 1.
[0034] The mapping module maps the virtual addresses of the data to be sent by the N client processes to kernel virtual addresses in the kernel space in parallel.
[0035] The synchronization module performs communication between the N client processes and the M server processes according to the communication order of the N client processes and the communication order of the M server processes, so as to synchronize the data to be sent by the client processes to the server processes; where M is an integer greater than or equal to 1.
[0036] Thirdly, this application provides an inter-process communication device, including: a processor, and a memory communicatively connected to the processor.
[0037] The memory stores computer-executed instructions.
[0038] The processor executes computer execution instructions stored in the memory to implement the method as described in any one of the first aspects.
[0039] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the inter-process communication method as described in any one of the first aspects.
[0040] Fifthly, this application provides a computer program product, comprising: a computer program that, when executed by a processor, implements the method as described in any of the first aspects.
[0041] The inter-process communication method, apparatus, device, and storage medium provided in this application transfer the virtual address mapping process of the data to be sent to before the client process and the server process establish a communication connection. This allows the virtual address of the data to be sent to be mapped from the client process to the kernel space, enabling multiple client processes to map the virtual address of the data to be sent to the kernel virtual address in the kernel space in parallel. Then, the aforementioned kernel virtual address is used for inter-process communication between multiple client processes and the server process. By using parallel mapping, the time consumed by the virtual address mapping process is effectively reduced, and the efficiency of communication between multiple client processes and the server process is improved. By changing the virtual address mapping process from being executed sequentially between the server process and each client process to being directly mapped to the kernel space by each client process, the step of the server process executing the virtual address mapping process is eliminated, thereby reducing the load on the server process. Attached Figure Description
[0042] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0043] Figure 1 A schematic diagram of an operating system architecture provided for an embodiment of this application;
[0044] Figure 2 A flowchart illustrating an inter-process communication method provided in an embodiment of this application;
[0045] Figure 3 A flowchart illustrating a mapping method provided in an embodiment of this application;
[0046] Figure 4 This application provides an example diagram illustrating a virtual address to physical address mapping.
[0047] Figure 5 A schematic diagram illustrating another inter-process communication process provided in an embodiment of this application;
[0048] Figure 6 A communication connection construction diagram between a client process and a server process is provided in an embodiment of this application;
[0049] Figure 7 A schematic diagram illustrating a virtual address mapping method provided in an embodiment of this application;
[0050] Figure 8 A flowchart illustrating an example of an inter-process communication method provided in an embodiment of this application;
[0051] Figure 9 This is a schematic diagram of the structure of an inter-process communication device provided in an embodiment of this application;
[0052] Figure 10 This is a schematic diagram of the structure of an inter-process communication device provided in an embodiment of this application.
[0053] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0054] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0055] First, let me explain the terms used in this application:
[0056] Microkernel architecture: In a microkernel architecture, the processor running the operating system is divided into kernel mode (sometimes simply called the kernel) and user mode. Kernel mode handles only some critical business functions, while most operating system functions reside in user mode. This ensures the "miniaturization" of the kernel and separates different functional modules, allowing them to run as different processes. A problem in one module will not affect other modules, resulting in better security and reliability. Typical microkernel operating systems include SeL4, QNX, MINIX, and Fuchsia.
[0057] Process: A process is a running program that occupies a corresponding memory area and is executed and computed by the operating system. A process is an independent entity within the system, possessing its own independent resources and its own private address space. Without the process's permission, one process cannot directly access the address space of another process. Multiple processes can execute concurrently on a single central processing unit (CPU, operating system) without interfering with each other.
[0058] Inter-process communication (IPC) refers to the communication between multiple processes in a system, where they typically need to transfer data and exchange information to complete system or user tasks. However, since different processes are independent of each other, a process cannot directly access the address space of other processes without the process's permission. Therefore, IPC is needed to enable multiple processes to transfer data and exchange information.
[0059] Virtual address: In order to protect a process from being affected by other processes, it is necessary to achieve process isolation between processes. Therefore, virtual addresses are used to ensure that no matter how the virtual address in a process is offset, it can only be in the virtual address space of that process. This ensures that the physical address mapped by the virtual address cannot affect the physical address mapped by the virtual address of other processes.
[0060] Physical memory address: When the operating system accesses memory, it provides the address of a memory unit (memory address). Each memory unit has a unique address, called the physical address. Each thread can use the mapping relationship between virtual addresses in its virtual address space and physical memory addresses to locate the corresponding physical memory address and read data from that physical memory address.
[0061] Address mapping refers to the process of converting virtual addresses in user programs into physical addresses that are directly addressed by the machine at runtime in order to ensure that the operating system can correctly access memory units when executing instructions.
[0062] Page tables are stored in physical memory and can be used to represent the virtual address space of a process. They store the mapping relationship between the virtual address of the process and the physical address in memory, and are used to convert virtual addresses into physical addresses in memory.
[0063] Figure 1 This is a schematic diagram of an operating system architecture provided in an embodiment of this application. Figure 1 As shown, the architecture includes:
[0064] User mode: refers to the user mode of the operating system, a working state in which programs are not allowed to perform operations requiring privileged mode in the processor to avoid operating system crashes. Each process runs in its own virtual address space and is not allowed to access the virtual address spaces of other processes. Multiple processes, including process 1 and process 2, can exist in user mode. Subsequent embodiments will illustrate the communication process between these processes.
[0065] Kernel mode: The kernel is the core program inside the operating system, providing external access to the computer's devices through core management calls. Kernel mode refers to the privileged mode of the operating system, a working state that affects the execution results of different instructions. The operating system, in conjunction with other systems, sets up privileged and user modes to prevent applications from performing unauthorized operations. The address space where the kernel resides is called kernel space. Both the kernel and kernel space mentioned above are included in kernel mode. Different processes can access addresses and data in kernel space.
[0066] Since each process has its own distinct virtual address space in user space and cannot access the virtual address spaces of other processes, while all processes can access addresses and data in kernel space, processes must exchange data through kernel space. A buffer is allocated in kernel space; process 1 copies data from user space to the kernel space buffer, and process 2 then reads the data from the kernel buffer. This mechanism provided by the kernel is called inter-process communication (IPC).
[0067] Currently, in QNX Neutrino RTOS, the way the operating system of a terminal device running this operating system performs inter-process communication can be divided into the following two types based on the size of the data to be sent:
[0068] The first scenario: The data to be sent is greater than 256 bytes. In this case, the operating system completes synchronous inter-process communication by performing a virtual address mapping and a data copy.
[0069] The second scenario: The data to be sent is less than 256 bytes. In this case, the operating system does not need to perform a virtual address mapping process; synchronous inter-process communication is completed by copying data twice.
[0070] The specific application scenario of this application only applies to the case where the aforementioned operating system completes synchronous inter-process communication through a single virtual address mapping and a single data copy. When there are multiple client processes (i.e., processes sending data to be sent) and at least one server process (i.e., processes receiving data to be sent), the specific process of inter-process communication executed by the operating system in the QNXNeutrino RTOS operating system when the data to be sent is greater than 256 bytes is as follows:
[0071] S101. Obtain the communication order between multiple client processes and the first server process. Based on this communication order, each client process must wait for the previous client process to complete inter-process communication with the first server process before it can communicate with the first server process.
[0072] The communication order described above refers to the order in which multiple client processes wait on the channel (i.e., pipe) of the first server process. This channel is used for inter-process communication; client processes can use the channel to transmit information to the server process. Multiple client processes wait on the channel in a queue, transmitting information to the server process in a first-in, first-out (FIFO) manner. This communication order can be stored in memory as a linked list, and the operating system can schedule the communication order of multiple client processes by reading this linked list.
[0073] S102. Establish a communication connection between the first client process and the first server process according to the communication order.
[0074] The operating system establishes a channel on the server process that needs inter-process communication (IPC), and multiple server processes can share the same channel. The operating system then connects the client processes that need IPC to the aforementioned channel as needed, and temporarily prohibits communication between all client processes and all server processes. When it's the first client process's turn to communicate with the first server process, the operating system controls that client process to be allowed to communicate with that server process.
[0075] S103. Map the list of physical memory addresses corresponding to the list of virtual addresses of the data to be sent in the first client process to the list of physical memory addresses in the first server process.
[0076] Specifically, the first server process obtains the virtual address list of data to be sent from the first client process. The operating system uses a page table to map the virtual address list of the first client process's data to be sent to a kernel virtual address list. This page table includes the mapping relationship between the virtual address corresponding to each piece of data from the first client process and its physical memory address. The first server process can directly read the kernel virtual address list of the data to be sent and obtain the kernel virtual addresses from that list.
[0077] S104. Based on the above mapping relationship, copy the data to be sent from the first client process to the first server process.
[0078] The first server process retrieves the data stored in the memory space corresponding to the physical memory address of the kernel virtual address based on the kernel virtual address mentioned above, and copies this data to the memory space prepared in advance by the first server process.
[0079] S105. Disconnect the communication connection between the first client process and the first server process, and end the communication between the first client process and the first server process.
[0080] Therefore, in existing technologies, for data synchronization exceeding 256 bytes in the QNX Neutrino RTOS operating system, the inter-process communication (IPC) method requires each client process to perform a virtual address mapping process and a data copy operation, one for each server process. For example, if there are 10 client processes and 1 server process, completing the IPC task requires the time required for 10 virtual address mappings and 10 data copy operations. This method of performing IPC tasks suffers from long processing times and low communication efficiency. Furthermore, since both the virtual address mapping and data copy operations occur on the server process side, the server process experiences heavy load when there are many processes requiring IPC.
[0081] In view of this, this application provides an inter-process communication method. By shifting the virtual address mapping process of the data to be sent to before the client process and the server process establish a communication connection, the virtual address of the data to be sent is mapped from the client process to the kernel space. This allows multiple client processes to map the virtual address of the data to be sent to the kernel virtual address in the kernel space in parallel. Then, the aforementioned kernel virtual address is used for inter-process communication between multiple client processes and the server process. By using parallel mapping, the time consumed by the virtual address mapping process is effectively reduced, and the efficiency of communication between multiple client processes and the server process is improved. By changing the virtual address mapping process from being executed sequentially between the server process and each client process to each client process directly mapping to the kernel space, the step of the server process executing the virtual address mapping process is removed, thereby reducing the load on the server process.
[0082] The executing entity of this application can be the operating system running on the processing chip of a terminal device that runs microkernel architecture operating systems such as SeL4, QNX, MINIX, and Fuchsia. Such terminal devices may include, for example, wearable devices, smart home devices, in-vehicle terminals, and aerospace terminals.
[0083] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0084] Figure 2 This is a flowchart illustrating an inter-process communication method provided in an embodiment of this application. Figure 2 As shown, the method includes:
[0085] S201. Obtain the virtual addresses of the data to be sent by N client processes, where N is an integer greater than or equal to 1.
[0086] In this context, the client process is the process that sends data to be transmitted. This data is data to be synchronized from the client process to the server process. The virtual address of the data to be transmitted is a virtual address composed of the virtual addresses corresponding to this data in the client process. The operating system can obtain this virtual address, for example, by using the buffer register of the client process. Then, it can use the page table to obtain the physical memory address of the data to be transmitted in the client process based on the virtual address. For example, the page table of the client process can be shown in Table 1 below:
[0087] Table 1
[0088] Data to be sent Virtual address physical memory address Data 1 Virtual address 1 Physical address 1 Data 2 Virtual address 2 Physical address 2 Data 3 Virtual address 3 Physical address 3 Data 4 Virtual address 4 Physical address 4
[0089] Taking data 1 as an example, data 1 is data stored in physical address 1 in memory. The virtual address corresponding to data 1 in the aforementioned client process is virtual address 1 in the virtual address space of the client process. The operating system can address physical address 1 and retrieve data 1 from physical address 1 by obtaining the virtual address of data 1 and the mapping relationship between the virtual address in the aforementioned virtual address space and the physical address in memory.
[0090] S202. Map the virtual addresses of the data to be sent by the above N client processes to kernel virtual addresses in the kernel space in parallel.
[0091] Since the communication order between the N client processes and the M server processes is not yet determined, it is not possible to directly map the virtual addresses of the data to be sent by the client processes into the page tables of the server processes. The operating system needs to control the N client processes to first map the virtual addresses of the data to be sent to kernel virtual addresses in kernel space, so that after the communication order is determined, the server processes can directly copy the data to be sent by accessing the virtual addresses in kernel space.
[0092] This method can simultaneously map the virtual addresses of data to be sent from N client processes, mapping each client process's virtual address to a different kernel virtual address in kernel space. The greater the number of client processes N compared to the number of server processes M, the better this method improves communication efficiency.
[0093] One possible implementation involves obtaining the physical memory address corresponding to the virtual address of the data to be sent by the client process. This can be achieved, for example, through a mapping relationship in the client process's page table, as shown in Table 1 above, and will not be elaborated further here. Then, based on the physical memory address corresponding to the virtual address of the data to be sent, the data is mapped to a kernel virtual address segment in the kernel space.
[0094] Another possible implementation involves establishing a mapping relationship between the virtual address segment of the data to be sent by the client process and the kernel virtual address segment in the kernel space. This mapping relationship maps the virtual address segment of the data to be sent by the client process to the corresponding kernel virtual address segment in the kernel space.
[0095] S203. Based on the communication order of the N client processes and the communication order of the M server processes, perform communication between the N client processes and the M server processes to synchronize the data to be sent by the client processes to the server processes, where M is an integer greater than or equal to 1.
[0096] The communication order of the N client processes can be, for example, the order in which their mapping tasks are completed; or it can be the actual communication order scheduled according to requirements. For instance, if communication is performed according to a preset communication order, even if a client process with a higher communication order has completed its mapping task, it cannot immediately communicate with the server process until the client process with the higher communication order has completed its mapping task and then the inter-process communication can proceed. This application does not impose any restrictions on the specific settings of the communication order of the N client processes and the communication order of the M server processes.
[0097] The communication between the aforementioned N client processes and the aforementioned M server processes can be achieved by having the N client processes communicate with the corresponding server processes in sequence, according to their communication order. Once the server process corresponding to each client process has completed its communication, the communication connection between that client process and that server process is closed.
[0098] The synchronization of data to be sent from the client process to the server process can be achieved, for example, through the mapping relationship between the virtual address of the data to be sent in step S202 and the kernel virtual address in the kernel space. The server process obtains the kernel virtual address in the kernel space, looks up the corresponding physical address according to the page table, thereby obtaining the physical address and virtual address of the data to be sent. It then reads the data to be sent from the physical address and copies the data to be sent to the physical address corresponding to the server process.
[0099] To synchronize data to be sent from the client process to the server process, it can be achieved, for example, in the following ways:
[0100] The server process calls a data copy function to obtain the kernel virtual address segment in the kernel space corresponding to the data to be sent. Based on the obtained kernel virtual address segment, it copies the data to be sent. Then, it defines a virtual address segment in the server process to receive the data and copies the data to be sent to that virtual address segment defined in the server process. Defining the virtual address segment for receiving the data to be sent in the server process can, for example, be done by selecting a virtual address segment within the server process's virtual address space to store the data to be sent.
[0101] The inter-process communication method provided in this application maps the virtual address segments of data to be sent by N client processes in parallel to a kernel virtual address segment in the kernel space. Based on this kernel virtual address segment, the server process can copy the data to be sent to the virtual address segment used to receive the data in the server process. By performing the mapping process in parallel with N client processes, the mapping process, which previously required sequential execution, can be performed simultaneously. This reduces the mapping time required for communication between N client processes and M server processes, thereby improving the efficiency of inter-process communication.
[0102] The following section will describe in detail how to map the virtual address segments of the data to be sent by the N client processes to the kernel virtual address segments in the kernel space in parallel.
[0103] Figure 3 This is a flowchart illustrating a mapping method provided in an embodiment of this application. Figure 3 As shown, step S202 above may further include:
[0104] For each of the above client processes, perform the following operations in parallel:
[0105] S301. Obtain the virtual address of the data to be sent by the client process.
[0106] The operating system obtains the virtual address of the data to be sent by the client process in the same way as in step S201 above, and will not be repeated here.
[0107] Figure 4 This application provides an example diagram illustrating a virtual address to physical address mapping, as shown in the embodiments. Figure 4 As shown, it includes:
[0108] Virtual Address: This virtual address consists of four contiguous virtual addresses, each with a corresponding storage space of 4KB. The 16KB virtual address segment comprised of these four virtual addresses constitutes the virtual address segment corresponding to the data to be sent. This virtual address segment can be allocated by the client process using the dynamic memory allocation function malloc.
[0109] Physical address: This refers to the physical memory address corresponding to the virtual address mentioned above. The data to be sent is actually stored in the physical memory address. After receiving the virtual address, the operating system can use the virtual address and the mapping relationship between the virtual address and the physical memory address to locate the physical memory address corresponding to the virtual address, thereby obtaining the data to be sent from the physical memory address.
[0110] The four virtual addresses mentioned above can be either consecutive or non-consecutive physical addresses. The mapping relationship between the virtual addresses and their corresponding physical memory addresses is stored in the page table of the client process. The operating system can obtain the physical address with a storage space of 4KB corresponding to each virtual address by querying the page table through software.
[0111] For example, in the following embodiments, the virtual address of the data to be sent is a 16k virtual address segment siov (sender I / O vector) allocated by the client process through the dynamic memory allocation function malloc. Assuming that the maximum size of each virtual address is 4k, the virtual address segment siov includes 4 consecutive virtual addresses.
[0112] S302. Obtain the physical address of the data to be sent by the client process based on the virtual address of the data to be sent by the client process.
[0113] One possible implementation involves obtaining the page table of the client process, which includes a mapping between the virtual address and the physical address of the client process. The page table and the mapping between the virtual address and the physical address of the client process within it are shown in Table 1 above. The operating system retrieves the page table from memory, reads the data in the page table, and thus obtains the mapping between the virtual address and the physical address of the client process.
[0114] Based on the client process's page table and the virtual address of the data to be sent, obtain the physical address of the data to be sent by the client process.
[0115] For example, the physical addresses of the client processes corresponding to the four consecutive virtual addresses included in the virtual address segment siov can be consecutive or non-consecutive. The client process obtains the corresponding 4KB physical address for each of the four virtual addresses included in the virtual address segment siov by querying the page table, thus obtaining the physical addresses of the four client processes.
[0116] It should be understood that any other feasible method can be used to obtain the corresponding physical address based on the virtual address of the data to be sent by the client process. This application does not restrict how to obtain the corresponding physical address based on the virtual address of the data to be sent.
[0117] S303. Map the physical address of the data to be sent by the client process to the kernel virtual address in the kernel space.
[0118] Specifically, the physical address of the client process's data to be sent can be mapped to the kernel virtual address in the kernel space using the offset relationship between the address segment containing the physical address of the client process and the address segment containing the kernel virtual address in the kernel space. This offset relationship can be determined, for example, by a fixed offset between the kernel virtual address and the physical address, which is determined during kernel initialization; this application does not impose any restrictions on this. Based on this offset relationship, the physical address, or physical address segment, corresponding to the virtual address of each piece of data to be sent by the client process is mapped to the corresponding kernel virtual address, or kernel virtual address segment, in the kernel space.
[0119] For example, by using the offset relationship described above to obtain the physical addresses of the four client processes, each 4KB in size, four kernel virtual addresses of size 4KB in kernel space are obtained. These four kernel virtual addresses are then four kernel virtual address segments, which can be represented by miov (map I / O vector). These four kernel virtual addresses can be contiguous or non-contiguous.
[0120] Optionally, after mapping the physical address of the data to be sent by the client process to the kernel virtual address in the kernel space, consecutive kernel virtual addresses are merged to obtain at least one kernel virtual address segment.
[0121] The kernel virtual addresses in the kernel space described above are used to indicate the location where the server process copies the data to be sent, as well as the size of the data to be sent. Continuing with the example of each kernel virtual address being 4KB in size, each kernel virtual address can store 4KB of data to be sent. When consecutive kernel virtual addresses are merged to obtain kernel virtual address segments, each segment is composed of multiple 4KB kernel virtual addresses, allowing for the storage of a larger amount of data to be sent. Therefore, a larger amount of data can be transmitted using fewer kernel virtual address segments, thus avoiding the problem of low communication efficiency caused by the system's limitation on the number of simultaneous transmissions per address segment. Therefore, when there are at least two consecutive kernel virtual addresses, they can be merged into a single kernel virtual address segment. This segment can be represented using its base address and address length. That is, the address segment starting from the base address and ending at the address obtained by adding the address length to the base address can represent the kernel virtual address segment. This transforms at least two consecutive kernel virtual addresses into a single kernel virtual address segment, reducing the number of kernel virtual address segments corresponding to the data to be sent. In this way, the efficiency of inter-process communication can be further improved.
[0122] For example, if the first and second kernel virtual address segments (miov) in the four kernel virtual address segments are contiguous, they are merged into a new kernel virtual address segment, resulting in only three kernel virtual address segments (miov). The server process can then copy the data to be sent corresponding to these three kernel virtual address segments (miov) to complete inter-process communication with the client process.
[0123] The method provided in this application obtains the virtual address of the data to be sent by the client process, obtains the corresponding physical memory address in the client process based on the virtual address, and further obtains the corresponding kernel virtual address in the kernel space to obtain the kernel virtual address corresponding to the data to be sent by the client process. This enables the server process to directly copy the data to be sent by accessing the kernel virtual address in the kernel space, thereby improving the efficiency of inter-process communication.
[0124] The communication between the N client processes and the M server processes is performed according to the communication order of the N client processes and the communication order of the M server processes. Figure 5 This is a schematic diagram of another inter-process communication process provided in an embodiment of this application, such as... Figure 5 As shown, step S203 above also includes:
[0125] For any client process and its corresponding server process, perform the following operations:
[0126] S501. Establish a communication connection between the client process and the server process.
[0127] Figure 6 This is a diagram illustrating the communication connection between the client process and the server process provided in an embodiment of this application. For example... Figure 6 As shown, the structure includes three client processes and two server processes. Each client process can establish a communication connection interface (connection) to communicate with the two server processes through a shared pipe (channel).
[0128] After completing the mapping process described above, the client process can wait on the server process's channel and exchange messages with the server process through the client process communication connection interface. These messages can be, for example, receive messages, send messages, or feedback messages. These messages can be, for example, semaphores. The specific type and content of the message are only required to achieve the effect of the message in this application; this application does not limit the specific form of the message.
[0129] S502, Send the server process's receive message to the client process; the receive message is used to instruct the client process to send communication information; the communication information includes the pointer to the aforementioned kernel virtual address.
[0130] Accordingly, the client process receives the receive message sent by the server process.
[0131] When the server process is ready to begin synchronizing the client process's pending data, it sends the aforementioned receive message to the client process to indicate that the server process is in a pending state, i.e., waiting for the client process to send communication information. This communication information may include a pointer to the kernel virtual address corresponding to the pending data, or it may directly include the kernel virtual address itself, used to synchronize the kernel virtual address corresponding to the pending data to the server process.
[0132] Optionally, if the kernel virtual address has been merged and at least one merged kernel virtual address segment exists, the communication information may further include the segment number of the kernel virtual address corresponding to the data to be sent. This is used by the server process to determine whether communication with the client process has been completed when copying the data to be sent. For example, the completion of inter-process communication can be determined by comparing the number of kernel virtual address segments that have been copied with the number of kernel virtual address segments corresponding to the data to be sent.
[0133] S503. Based on the received message, the client process sends the aforementioned communication information to the server process.
[0134] Accordingly, the server process receives communication information sent by the client process.
[0135] Once the client process receives the receive message, it indicates that the server process is ready to receive communication information sent by the client process. Therefore, the client process can begin sending the aforementioned communication information.
[0136] In one possible implementation, based on the received message, the client process's sending state is activated. This sending state indicates that the client process is capable of sending the aforementioned communication information. After the client process completes sending the communication information, it sends a message to the server process. Based on the sending message, the server process's receiving state is activated. This receiving state indicates that the server process is capable of receiving the communication information. That is, in this implementation, after each step is completed, both the client process and the server process need to enter a pending state and send a corresponding completion message to indicate to the other party that they can proceed to the next step. The pending state could be, for example, a "pending send" state when the client process is ready to send communication information, a "completed send" state after all communication information has been sent, or a "pending receive" state when the client process is ready to receive communication information.
[0137] S504. The server process copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function.
[0138] The data copy function can be, for example, `msg_copy(riov, rparts, miov, mmets)`. Here, `riov` (receive I / O vector) can be a virtual address or virtual address segment defined by the server process for receiving data to be sent; `rparts` is the number of segments corresponding to the virtual address or virtual address segment in the server process; `miov` is the kernel virtual address or kernel virtual address segment corresponding to the data to be sent; and `mparts` is the number of segments corresponding to the kernel virtual address or virtual address segment corresponding to the data to be sent. The server process copies the data to be sent from the kernel virtual address or kernel virtual address segment corresponding to each segment of data to be sent to the virtual address or virtual address segment in the server process. The copying of the data to be sent is then confirmed by checking whether the data length stored in `rparts` and `mparts` has been copied completely.
[0139] Optionally, after the server process copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function, it sends a feedback message to the client process. This feedback message indicates that the server process has completed the inter-process communication. After receiving the feedback message, the client process disconnects the communication connection between the client process and the server process.
[0140] That is, after the server process completes the data copying task described above, it enters a pending state where the copying is completed, and instructs the client process, as in the above embodiment, that the inter-process communication has been completed, and further instructs the client process to disconnect the communication connection with the server process.
[0141] The following example illustrates the method provided in this application using inter-process communication between a client process and a server process.
[0142] Figure 7 This is a schematic diagram illustrating a virtual address mapping method provided in an embodiment of this application. Figure 7 As shown, the method includes:
[0143] In this scenario, the data to be sent from the client process to the server process is stored in three siov virtual address segments. Through steps S302-S304, the three siov virtual address segments corresponding to the data to be sent are mapped to three miov virtual address segments in the kernel space. After the client process and the server process establish a communication connection, the server process accesses the three miov virtual address segments in the kernel space through the data copy function. Based on the mapping relationship between miov and siov, it addresses the memory space storing the physical memory address corresponding to the siov for the data to be sent, and reads the data to be sent from this memory space, copying it to the memory space corresponding to the riov virtual address in the server process.
[0144] Figure 8 This is a flowchart illustrating an example of an inter-process communication method provided in an embodiment of this application. Figure 8 As shown, the method includes:
[0145] S801: The client process maps the multiple siov virtual addresses corresponding to the data to be sent to the kernel virtual address miov, and records the segment number mparts of the kernel virtual address segment in miov. The client process enters a pending state, waiting for the server process to send and receive messages.
[0146] S802. The server process obtains the communication order of the client process and sends a receive message to the client process to instruct the client process to perform the send task.
[0147] S803: After receiving the message, the client process sends the kernel virtual address miov and the corresponding kernel virtual address segment number mparts to the server process.
[0148] S804. After the client process completes the sending task, it sends a completion message to the server process, prompting the server process to perform the receiving operation. The client process then enters a pending state, waiting for a feedback message from the server process.
[0149] S805. After the server process acquires the send semaphore, it changes from the pending state to the running state, calls the data copy function, and copies the data corresponding to miov to riov.
[0150] S806. After the server process completes the data copy, it sends a feedback message to the client process to notify the client process that the inter-process communication has ended.
[0151] S807. After receiving the feedback message, the client process changes from the pending state to the running state and disconnects the communication connection with the server process.
[0152] The method provided in this application establishes a communication connection between a client process and a server process, and uses this communication connection to transmit messages, thereby ensuring that the client process and the server process establish a communication connection according to preset steps, reducing the possibility of incomplete synchronization of data to be sent, and thus ensuring the stability of inter-process communication.
[0153] Figure 9 This is a schematic diagram of an inter-process communication device provided in an embodiment of this application. Figure 9 As shown, the inter-process communication device includes: an acquisition module 11, a mapping module 12, and a synchronization module 13. In one possible implementation, it further includes: a merging module 14 and a feedback module 15.
[0154] The acquisition module 11 is used to acquire the virtual addresses of the data to be sent by N client processes, where N is an integer greater than or equal to 1.
[0155] The mapping module 12 is used to map the virtual addresses of the data to be sent by the N client processes to kernel virtual addresses in the kernel space in parallel.
[0156] Synchronization module 13 is used to perform communication between the N client processes and the M server processes according to the communication order of the N client processes and the communication order of the M server processes, so as to synchronize the data to be sent by the client processes to the server processes, where M is an integer greater than or equal to 1.
[0157] In one possible implementation, the mapping module 12 is specifically configured to perform the following operations in parallel for each client process: obtain the virtual address of the data to be sent by the client process; obtain the physical address of the data to be sent by the client process based on the virtual address of the data to be sent; and map the physical address of the data to be sent by the client process to a kernel virtual address in the kernel space.
[0158] In this implementation, the mapping module 12 is specifically used to obtain the page table of the client process, which includes the mapping relationship between the virtual address and the physical address of the client process. Based on the page table of the client process and the virtual address of the data to be sent by the client process, the physical address of the data to be sent by the client process is obtained.
[0159] In one possible implementation, after the mapping module 12 maps the physical address of the data to be sent by the client process to the kernel virtual address in the kernel space, the merging module 14 is used to merge consecutive kernel virtual addresses to obtain at least one kernel virtual address segment.
[0160] In one possible implementation, the communication order of the N client processes is determined based on the synchronization completion time of the N client processes. The synchronization module 13 is specifically configured to perform the following operations for any client process and its corresponding server process: establish a communication connection between the client process and the server process; send a receive message from the server process to the client process; the receive message instructs the client process to send communication information; the communication information includes a pointer to the kernel virtual address; based on the receive message, send the communication information to the server process through the client process; and through the server process, based on the communication information and a data copy function, copy the data to be sent to the storage space corresponding to the preset virtual address of the server process.
[0161] In one possible implementation, the synchronization module 13 is specifically configured to activate the sending state of the client process based on the received message. This sending state indicates that the client process is capable of sending the communication information. After the client process completes sending the communication information, it sends a message to the server process; this sending message indicates that the client process has completed sending all the communication information. Based on this sending message, the receiving state of the server process is activated, indicating that the server process is capable of receiving the communication information.
[0162] In one possible implementation, after the synchronization module 13 copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function, the feedback module 15 sends a feedback message to the client process after the server process has completed copying the data to be sent. Upon receiving the feedback message, the client process disconnects the communication connection with the server process. This feedback message indicates that the server process has completed this inter-process communication.
[0163] The inter-process communication device provided in this application embodiment can execute the inter-process communication method in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.
[0164] Figure 10 This is a schematic diagram of an inter-process communication device provided in an embodiment of this application. The inter-process communication device is used to execute the aforementioned inter-process communication method, and may be, for example, a terminal device running a microkernel architecture operating system as described above. Figure 10 As shown, the inter-process communication device 1000 may include at least one processor 1001 and a memory 1002.
[0165] The memory 1002 is used to store programs. Specifically, the program may include program code, which includes computer operation instructions.
[0166] The memory 1002 may be, for example, a high-speed RAM memory.
[0167] The processor 1001 is used to execute computer execution instructions stored in the memory 1002 to implement the methods described in the foregoing method embodiments. The processor 1001 may be an operating system, an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0168] In practical implementation, if the memory 1002 and the processor 1001 are implemented independently, they can be interconnected via a bus to communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc., but this does not imply that there is only one bus or one type of bus.
[0169] Optionally, in a specific implementation, if the memory 1002 and the processor 1001 are integrated on a single chip, the memory 1002 and the processor 1001 can communicate through an internal interface.
[0170] This application also provides a computer-readable storage medium, which may include various media capable of storing program code, such as random access memory (RAM) and high-speed RAM. Specifically, the computer-readable storage medium stores program instructions, which are used in the methods described in the above embodiments.
[0171] This application also provides a program product including executable instructions stored in a readable storage medium. At least one processor of an inter-process communication device can read the executable instructions from the readable storage medium, and the at least one processor executes the executable instructions to cause the inter-process communication device to implement the inter-process communication methods provided in the various embodiments described above.
[0172] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. An inter-process communication method, characterized in that, Applied to a microkernel operating system, the method includes: Obtain the virtual addresses of data to be sent from N client processes, where N is an integer greater than or equal to 1; The virtual addresses of the data to be sent by the N client processes are mapped in parallel to kernel virtual addresses in the kernel space; Based on the communication order of the N client processes and the communication order of the M server processes, communication is performed between the N client processes and the M server processes to synchronize the data to be sent by the client processes to the server processes; where M is an integer greater than or equal to 1. The step of mapping the virtual addresses of the data to be sent by the N client processes to kernel virtual addresses in the kernel space in parallel includes: For each of the aforementioned client processes, the following operations are performed in parallel: Obtain the virtual address of the data to be sent by the client process; Based on the virtual address of the data to be sent by the client process, obtain the physical address of the data to be sent by the client process; By using the offset relationship between the physical address of the data to be sent by the client process and the address segment where the kernel virtual address in the kernel space is located, the physical address is mapped to the kernel virtual address in the kernel space through address offset; consecutive kernel virtual addresses are merged to obtain at least one kernel virtual address segment.
2. The method according to claim 1, characterized in that, The step of obtaining the physical address of the data to be sent by the client process based on the virtual address of the data to be sent by the client process includes: Obtain the page table of the client process, which includes the mapping relationship between the virtual address of the client process and the physical address of the client process; Based on the page table of the client process and the virtual address of the data to be sent by the client process, the physical address of the data to be sent by the client process is obtained.
3. The method according to claim 1 or 2, characterized in that, The communication order of the N client processes is determined based on the synchronization completion time of the N client processes; the communication between the N client processes and the M server processes based on the communication order of the N client processes and the communication order of the M server processes includes: For any client process and its corresponding server process, perform the following operations: Establish a communication connection between the client process and the server process; The server process sends a receive message to the client process; the receive message instructs the client process to send communication information; the communication information includes a pointer to the kernel virtual address. Based on the received message, the client process sends the communication information to the server process; The server process copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function.
4. The method according to claim 3, characterized in that, The step of sending the communication information from the client process to the server process according to the received message includes: Based on the received message, the sending state of the client process is activated, and the sending state is used to indicate that the client process is able to send the communication information; After the client process completes the transmission of the communication information, it sends a message to the server process; the message indicates that the client process has completed the transmission of all the communication information. Based on the sent message, the receiving state of the server process is activated, and the receiving state is used to indicate that the server process is able to receive the communication information.
5. The method according to claim 4, characterized in that, After the server process copies the data to be sent to the storage space corresponding to the preset virtual address of the server process according to the communication information and the data copy function, the method further includes: After the server process completes the copying of the data to be sent, it sends a feedback message to the client process. The feedback message indicates that the server process has completed this inter-process communication. After receiving the feedback message, the client process disconnects the communication connection between the client process and the server process.
6. An inter-process communication device, characterized in that, The communication device runs a microkernel operating system, and the device includes: The acquisition module acquires the virtual addresses of data to be sent from N client processes, where N is an integer greater than or equal to 1; The mapping module maps the virtual addresses of the data to be sent by the N client processes to kernel virtual addresses in the kernel space in parallel. The synchronization module, based on the communication order of the N client processes and the communication order of the M server processes, performs communication between the N client processes and the M server processes to synchronize the data to be sent by the client processes to the server processes; where M is an integer greater than or equal to 1. The mapping module is specifically used to perform the following operations in parallel for each client process: obtain the virtual address of the data to be sent by the client process; obtain the physical address of the data to be sent by the client process based on the virtual address of the data to be sent by the client process; map the physical address to the kernel virtual address in the kernel space through the offset relationship between the physical address of the data to be sent by the client process and the address segment where the kernel virtual address in the kernel space is located, using the address offset method; and merge consecutive kernel virtual addresses to obtain at least one kernel virtual address segment.
7. An inter-process communication device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the inter-process communication method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Method, device and system for directly accessing physical address of memory and storage medium
CN114356802A
Method and system for inter-process communication
WO2021217529A1