Interface calling method and device, equipment and storage medium
By using shared memory in cross-process interface calls, data copying operations are reduced, which solves the problem of inconsistent cross-process interface call duration and improves efficiency, especially the efficiency of batch interface calls in multi-interface call scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-30
- Publication Date
- 2026-04-07
AI Technical Summary
The existing cross-process interface call method requires two memory copies, resulting in variable transmission time and affecting efficiency.
By pre-creating shared memory, the first process reads the target data from the shared memory and processes it after receiving the interface call request, and then writes the result back to the shared memory. The second process directly reads the interface call result from the shared memory, reducing data copying operations.
The time consumption of cross-process interface calls has been optimized, improving efficiency, especially significantly improving the efficiency of batch interface calls in scenarios with multiple interface calls.
Smart Images

Figure CN121807591A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an interface calling method, apparatus, device and storage medium. Background Technology
[0002] The current socket cross-process interface call process typically adopts a client / server (C / S) model. For example, when client process A and server process B make an interface call, the interface call process is as follows: process B listens on a port, process A establishes a connection with process B through a socket, then process A packages the name of the interface to be called and the interface parameter information into a string, copies the string to the send buffer of process A's socket, and then copies it to the receive buffer of process B through the socket. Process B then parses the name of the interface to be called and the interface parameter information from the receive buffer, thereby performing the actual interface call.
[0003] However, the above cross-process interface call method requires two memory copies. The first copy is of the send buffer of process A, and the second copy is of the send buffer of process A to the receive buffer of process B. Since the length of the parameter information of the called interface is variable, coupled with the two copy operations, the time for process A to transmit the parameter information of the called interface to process B is not fixed (that is, the cross-process interface call has dynamic changes in duration), which affects the time spent by process A calling the interface, making the efficiency of cross-process interface calls low. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide an interface invocation method, apparatus, device, and storage medium that can store large amounts of data generated during real-time interface invocation, such as interface invocation results, in pre-created shared memory, thereby optimizing the time consumption of cross-process interface invocation and improving the efficiency of cross-process interface invocation. The specific solution is as follows:
[0005] Firstly, this application discloses an interface invocation method applied to a first process, comprising:
[0006] Obtain the interface call request sent by the second process; the interface call request carries the first information;
[0007] Based on the first information, the corresponding target data is read from the shared memory, and the corresponding data processing method is determined;
[0008] The target data is processed according to the data processing method, and the interface call result obtained after processing is written into the shared memory;
[0009] The second information corresponding to the interface call result is sent to the second process so that the second process can read the interface call result from the shared memory based on the second information.
[0010] Optionally, the first information includes the command opcode of the interface to be called and the first write length;
[0011] Accordingly, the step of reading the corresponding target data from the shared memory based on the first information and determining the corresponding data processing method includes:
[0012] Based on the first write length, the command opcode and the interface parameter information of the interface to be called are read from the shared memory, and the interface execution function corresponding to the command opcode is determined.
[0013] Optionally, processing the target data according to the data processing method includes:
[0014] The interface parameter information is processed using the interface execution function to obtain the interface call result.
[0015] Optionally, the first information may also include a descriptor array;
[0016] Correspondingly, the interface call method also includes:
[0017] The index corresponding to the region file descriptor in the descriptor array is found in the shared memory, and the corresponding data block is read from the DMA-BUF memory region according to the index.
[0018] Optionally, sending the second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory based on the second information, includes:
[0019] The command opcode and the second write length are sent to the second process so that the second process can read the interface call result of the corresponding length from the shared memory according to the second write length.
[0020] Optionally, the interface invocation method further includes:
[0021] Obtain the input queue structure data sent by the second process;
[0022] A command input queue is created in the first process based on the input queue structure data, and the command input queue is bound to the shared memory.
[0023] Accordingly, after reading the corresponding target data from the shared memory based on the first information, the process further includes:
[0024] The read target data is saved to the command input queue.
[0025] Optionally, writing the processed interface call result into the shared memory includes:
[0026] In the first process, a command output queue is created and bound to the shared memory;
[0027] The processed interface call results are written to the shared memory through the command output queue.
[0028] Secondly, this application discloses an interface calling device, applied to a first process, comprising:
[0029] The acquisition module is used to acquire the interface call request sent by the second process; the interface call request carries first information.
[0030] The reading module is used to read the corresponding target data from the shared memory based on the first information;
[0031] The determination module is used to determine the corresponding data processing method;
[0032] The processing module is used to process the target data according to the data processing method.
[0033] The writing module is used to write the processed interface call results into the shared memory;
[0034] The sending module is used to send the second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory according to the second information.
[0035] Thirdly, this application discloses an interface invocation method applied to a second process, including:
[0036] An interface call request carrying first information is sent to the first process, so that the first process can read the corresponding target data from the shared memory and determine the corresponding data processing method according to the first information, process the target data according to the data processing method, and write the processed interface call result into the shared memory.
[0037] Obtain the second information corresponding to the interface call result sent by the first process;
[0038] The interface call result is read from the shared memory based on the second information.
[0039] Optionally, the interface invocation method further includes:
[0040] The command input queue in the second process is bound to the shared memory, and the target data is written to the shared memory through the command input queue; the target data includes the command opcode and interface parameter information of the interface to be called.
[0041] Optionally, after writing the target data to shared memory through the command input queue, the method further includes:
[0042] The region file descriptors of the DMA-BUF memory region are stored in the descriptor array located in the command input queue;
[0043] Write the index of the region file descriptor in the descriptor array into the shared memory so that the first process can read the corresponding data block from the DMA-BUF memory region according to the index;
[0044] Accordingly, the first information includes the command opcode of the interface to be called, the first write length, and the descriptor array; the first write length is the data length of the target data.
[0045] Optionally, the interface invocation method further includes:
[0046] Obtain the output queue structure data sent by the first process;
[0047] A command output queue is created in the second process based on the output queue structure data, and the command output queue is bound to the shared memory.
[0048] Accordingly, after reading the interface call result from the shared memory based on the second information, the method further includes:
[0049] The read interface call results are saved to the command output queue.
[0050] Fourthly, this application discloses an interface calling device applied to a second process, comprising:
[0051] The write module is used to write the target data related to the interface to be called into shared memory;
[0052] The sending module is used to send an interface call request carrying first information to a first process, so that the first process can read the target data from the shared memory according to the first information, process the target data according to the corresponding data processing method, and write the processed interface call result into the shared memory.
[0053] The acquisition module is used to acquire the second information corresponding to the interface call result sent by the first process;
[0054] The reading module is used to read the interface call result from the shared memory based on the second information.
[0055] Fifthly, this application discloses an electronic device, including a processor and a memory; wherein, when the processor executes a computer program stored in the memory, it implements the aforementioned interface calling method.
[0056] Sixthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned interface calling method.
[0057] As can be seen, this application is applied to a first process, including: obtaining an interface call request sent by a second process; the interface call request carrying first information; reading corresponding target data from shared memory according to the first information, and determining a corresponding data processing method; processing the target data according to the data processing method, and writing the processed interface call result into the shared memory; sending second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory according to the second information.
[0058] Before communication between the two processes, this application pre-creates a shared memory. Through this shared memory, after receiving an interface call request from the second process, the first process can directly read the corresponding target data from the shared memory based on the first information carried in the request, process the target data according to the corresponding data processing method, and then write the processed interface call result into the shared memory. In this way, the second process can directly read the interface call result from the shared memory. It can be seen that the second process and the first process do not directly send interface parameter information and interface call results with a large amount of data, but send interface call requests with a small amount of data. In this way, the time consumption of cross-process interface calls can be optimized, thereby improving the efficiency of cross-process interface calls. Attached Figure Description
[0059] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0060] Figure 1 This is a flowchart of an interface calling method disclosed in this application;
[0061] Figure 2This is a flowchart of a specific interface call process disclosed in this application;
[0062] Figure 3 This is a flowchart of a specific interface calling method disclosed in this application;
[0063] Figure 4 This is a schematic diagram of an interface calling device disclosed in this application;
[0064] Figure 5 This is a schematic diagram of an interface calling device disclosed in this application;
[0065] Figure 6 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0066] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0067] This application discloses an interface invocation method applied to a first process. See [link to relevant documentation]. Figure 1 As shown, the method includes:
[0068] Step S11: Obtain the interface call request sent by the second process; the interface call request carries the first information.
[0069] It should be noted that the interface call scheme proposed in this application is specifically applied to the first process (such as server process A, which is responsible for the specific execution of the interface). Through this process (i.e., server process A), the interface call request carrying the first information is sent by another process (i.e., the second process, such as client process B, which is used for interface call) via socket.
[0070] The API call request can be for a single API or for multiple APIs. If it's for multiple APIs, a single socket transmission can complete the execution of multiple APIs, thus enabling batch API calls. This reduces the number of socket calls, optimizes the time consumption of batch API calls, and significantly improves the efficiency of multi-API calls.
[0071] Specifically, the interfaces to be called include, but are not limited to, addition function call interfaces (such as add(a :int, b :int):int), subtraction function call interfaces (such as subtract(a :int, b : int) :int), and multiplication function call interfaces (such as multiply(a : int, b : int) :int), etc.
[0072] In practical applications, the server has only one process, while the client can have multiple processes. Furthermore, the first process (i.e., server process A) automatically creates a socket to listen for data after startup, parses the listened data, processes the parsed data, and then continues listening for data after processing, repeating this process repeatedly.
[0073] The first information includes, but is not limited to, the command opcode (i.e., OPCODE, such as OPCODE = 0x300) of the interface to be called and the first write length (i.e., LEN1, such as LEN1 = 0x3). The first write length refers to the length of data written to the shared memory by the second process (i.e., client process B) during the current cross-process interface call.
[0074] It is understandable that different opcodes correspond to different operations, so different command operations correspond to different opcodes, such as CMD ADD = 0x200, CMD SUB = 0x201, and CMD MUL = 0x202. Among them, the command operation corresponding to CMD ADD is to pop the two values at the top of the stack, calculate their sum, and push the result onto the stack; the command operation corresponding to CMD SUB is to pop the two values at the top of the stack, calculate the result of subtracting the second value from the first value, and push the difference onto the stack; the command operation corresponding to CMD MUL is to pop the two values at the top of the stack, calculate their product, and push the result onto the stack.
[0075] Furthermore, the length of interface call requests transmitted via socket can be set to a fixed length, meaning the length of data communicated directly between two processes is a preset length. For example, the length of data transmitted via socket (i.e., the length of the interface call request) is 4 bytes, where the first two bytes are the command opcode and the last two bytes are the length of data written to shared memory. This optimizes socket transmission time.
[0076] As can be seen, the length of the data directly transmitted between the two processes is fixed, and all of them are small amounts of data (i.e., command opcodes and the first write length, not involving large amounts of data, such as interface parameter information, image data, video data, etc.). In this way, not only can the duration of a single communication / interaction between the first process (such as server process A) and the second process (such as client process B) be controlled, but the efficiency of a single communication / interaction is also improved, thereby improving the overall efficiency of cross-process interface calls.
[0077] Step S12: Based on the first information, read the corresponding target data from the shared memory and determine the corresponding data processing method.
[0078] It should be noted that this application pre-creates a shared memory in the Linux kernel for multiple different processes (such as server process A and client process B) to access. Using shared memory can reduce one data copy, thereby optimizing the interface call time.
[0079] In this embodiment, when server process A receives an interface call request sent by client process B, it can read the target data corresponding to the first write length (such as LEN1=0x3) from the pre-created shared memory, such as the command opcode and the interface parameter information of the interface to be called, according to the first write length carried in the interface call request. The first write length is the sum of the lengths of the command opcode and the interface parameter information written to the shared memory.
[0080] After obtaining the target data (i.e., command opcode and interface parameter information) with the same length as the first write, determine the interface execution function corresponding to the command opcode. For example, when the command opcode is CMD ADD = 0x200, the corresponding interface execution function is the addition function (i.e., add); when the command opcode is CMD SUB = 0x201, the corresponding interface execution function is the subtraction function (i.e., subtract); when the command opcode is CMD MUL = 0x202, the corresponding interface execution function is the multiplication function (i.e., multiply), and so on.
[0081] In one specific implementation, the shared memory can be further partitioned according to actual application requirements. For example, see... Figure 2As shown, the shared memory includes two shared memory regions: shared memory region in and shared memory region out. Shared memory region in is used to receive data written by client process B, and shared memory region out is used to receive data written by server process A. By partitioning the shared memory, in scenarios with multiple API calls, each API can be called sequentially (for example, server process A sequentially sends its generated data to shared memory region out, and client process B sequentially sends its generated data to shared memory region in), thereby improving the efficiency of API calls in multi-API scenarios.
[0082] Additionally, see Figure 2 As shown, the server process A and the client process B have the same structure. The server process A includes a command input queue, a command output queue, a command control module, a command processing engine, and an interface implementation module.
[0083] The server process A has a command input queue for storing data read from the shared memory area in (such as target data including command opcodes and interface parameter information), a command output queue for storing the final interface call results, a command control module for receiving commands / requests sent by the client process B, a command processing engine for processing interface call requests and requests for creating command input / output queues, and an interface implementation module for processing the target data according to a determined data processing method.
[0084] It should be noted that, see Figure 2 As shown, before server process A reads the corresponding target data from shared memory, it needs to determine whether a command input queue exists in its own process. If it exists, the target data is directly stored in the command input queue. If it does not exist, a request to create the command input queue is sent to client process B via a socket. When the command control module receives the structure data (i.e., input queue structure data) returned by client process B, the command processing engine creates a queue in its own process with the same structure as the command input queue in client process B, and binds the created command input queue to shared memory. In this way, server process A can receive the target data read from shared memory for subsequent command processing and interface implementation.
[0085] Specifically, the command output queue can read and write to shared memory by binding file descriptors of shared memory to the command output queue. It's understandable that the values of different file descriptors change after cross-process transfers, resulting in differences between file descriptors of different processes. However, by binding file descriptors of different processes to the same shared memory, mutual access between the two processes can be achieved.
[0086] It is understandable that cross-process interface calls may involve the transfer of large blocks of data (such as images, videos, etc.). In order to solve the problem of time-consuming memory copying, cross-process access to large blocks of data can be achieved through the DMA-BUF (Direct Memory Access Buffer, which is an independent subsystem in the Linux kernel, usually used for data transfer between devices such as graphics processors, video processors, and displays) memory area.
[0087] Specifically, the received interface call request can include first information including a descriptor array. This descriptor array stores file descriptors for the DMA-BUF memory region (i.e., region file descriptors), and the index *i* of that region file descriptor in the descriptor array is written into shared memory. In this way, server process A can find the index *i* corresponding to the region file descriptor in the descriptor array from shared memory, and then retrieve the corresponding data block (such as a large block of image data or a large block of video data) from the DMA-BUF memory region based on that index *i*. By combining shared memory with the DMA-BUF memory region, the time-consuming memory copying problem during large data transfers is solved, thus enabling fast transfer of large data blocks during cross-process interface calls.
[0088] Step S13: Process the target data according to the data processing method, and write the processed interface call result into the shared memory.
[0089] In this embodiment, it can be achieved by... Figure 2 The interface implementation module processes the interface parameter information (a = 3, b = 4) using the determined interface execution function (such as add(a : int, b : int)) to obtain the interface call result, i.e. a + b = 3 + 4 = 7; or, using the determined interface execution function (such as multiply(a : int, b : int)) to process the interface parameter information (a = 3, b = 4) to obtain the interface call result, i.e. a * b = 3 * 4 = 12; then, the processed interface call result (i.e. 7 or 12) is written into shared memory.
[0090] It should be noted that, see Figure 2 As shown, before writing the interface call result (e.g., 7 or 12) to shared memory, it is necessary to first determine whether a command output queue exists in the current server process A. If it exists, the interface call result (i.e., 7 or 12) is directly written to the command output queue, and then the interface call result stored in the command output queue is written to shared memory. If it does not exist, the command processing engine creates a command output queue in server process A, and then binds the created command output queue to the file descriptor of shared memory. In this way, server process A can write the interface call result to the command output queue, and then write the interface call result (i.e., 7 or 12) in the command output queue to shared memory. By creating a command output queue, interface call results can be stored and forwarded in an orderly manner in multi-interface call scenarios, thereby reducing the error rate and improving the efficiency of multi-interface calls.
[0091] Step S14: Send the second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory according to the second information.
[0092] In this embodiment, after the first process (server process A) writes the interface call result to shared memory (e.g., shared memory region out), it further sends the second information of fixed length (e.g., 4 bytes) corresponding to the interface call result, such as the command opcode (OPCODE = 0x300) and the second write length (i.e., LEN2, such as LEN2 = 0x4), to the second process (client process B).
[0093] When the second process (client process B) receives the second information containing 0x300 and 0x4 sent by the first process (server process A), it can directly read the corresponding interface call result (such as 7 or 12) from the shared memory according to the second write length 0x4 in the second information, and then assign the interface call result (such as 7 or 12) to the corresponding interface to be called by means of assignment.
[0094] As can be seen, in this embodiment, a shared memory is pre-created before the two processes communicate. Through this shared memory, after receiving an interface call request sent by the second process, the first process can directly read the corresponding target data from the shared memory according to the first information carried in the request, process the target data according to the corresponding data processing method, and then write the processed interface call result into the shared memory. In this way, the second process can directly read the interface call result from the shared memory. It is evident that the second process and the first process do not directly send interface parameter information and interface call results with a large amount of data, but rather send interface call requests with a small amount of data. This optimizes the time consumption of cross-process interface calls and improves the efficiency of cross-process interface calls.
[0095] This application discloses a specific interface calling method applied to a second process. See [link to relevant documentation]. Figure 3 As shown, the method includes:
[0096] Step S21: Send the interface call request carrying the first information to the first process, so that the first process can read the corresponding target data from the shared memory and determine the corresponding data processing method according to the first information, process the target data according to the data processing method, and write the processed interface call result into the shared memory.
[0097] It should be noted that the interface calling scheme proposed in this application is specifically applied to the second process (such as client process B, used for interface calling). Through this process (i.e., client process B), a call request for any interface (such as addition function call interface, subtraction function call interface, multiplication function call interface, etc.) can be generated. This request can carry first information including the command opcode of the interface to be called (such as OPCODE = 0x300) and the first write length (such as LEN1 = 0x3), where the first write length is the length of the target data written by the second process to the shared memory. Then, the generated interface calling request is sent to another process (i.e., the first process, server process A) via a socket.
[0098] While generating the interface call request, the second process (such as client process B) also saves the target data related to the current interface call in the shared memory, such as the command opcode (such as OPCODE = 0x300) and the interface parameter information (a = 3, b = 4) of the interface to be called (such as add(a : int, b : int)).
[0099] It should be noted that, see Figure 2As shown, this application pre-creates a memory space in the Linux kernel that can be accessed by both the second process (i.e., client process B) and the first process (server process A). The command execution engine in client process B creates a command input queue in its own process, and then binds the command input queue in client process B to the file descriptor of the shared memory, thereby enabling the two processes to access the same memory space.
[0100] The target data can be stored through the command input queue in client process B, and then written to shared memory through the command input queue.
[0101] When the first process (i.e., server process A) receives an interface call request from the second process (e.g., client process B), it can directly read the target data (i.e., command opcode and interface parameter information) with the same length as the first write from the shared memory based on the first information (e.g., command opcode) carried in the interface call request. Then, it determines the corresponding data processing method (e.g., the interface execution function add), and processes the target data (e.g., interface parameter information (a = 3, b = 4)) according to the interface execution function add to obtain the interface call result, i.e., a + b = 3 + 4 = 7. Finally, it writes the interface call result (i.e., 7) into the shared memory and sends the second information (e.g., command opcode (OPCODE = 0x300) and the second write length (i.e., LEN2, e.g., LEN2 = 0x4)) corresponding to the interface call result to the client process B via a socket. The second write length is the data length of the interface call result (i.e., 7).
[0102] In this embodiment, if large blocks of data, such as image or video data, need to be transmitted during the interface call process, the region file descriptor of the DMA-BUF memory region (used to store large blocks of data) can be stored in the descriptor array of the command input queue of the second process (such as client process B). Simultaneously, the index i of the region file descriptor in the descriptor array is written to shared memory so that the first process (i.e., server process A) can read the corresponding data block (such as image data used for model training) from the DMA-BUF memory region based on this index i. Furthermore, for scenarios involving large data transmission, the descriptor array also needs to be recorded in the interface call request to inform the first process (i.e., server process A) that a large block of data is currently being transmitted, and the first write length will also include the length of the descriptor array. By combining shared memory with the DMA-BUF memory region, fast transmission of large blocks of data can be achieved during cross-process interface calls.
[0103] Step S22: Obtain the second information corresponding to the interface call result sent by the first process.
[0104] In this embodiment, when the second process (such as client process B) detects the second information regarding the interface call result sent by the first process (server process A) via socket, it will receive it.
[0105] Step S23: Read the interface call result from the shared memory according to the second information.
[0106] In this embodiment, the second process (such as client process B) reads the corresponding interface call result (such as 7) from the shared memory according to the second write length (such as 0x4) carried in the second information, and assigns the interface call result (such as 7) to the corresponding interface to be called, thereby completing the call to the interface to be called.
[0107] For more detailed processing procedures regarding the above steps, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0108] As can be seen, in this embodiment of the application, a shared memory is pre-created before the two processes communicate. Through this shared memory, the second process can write information related to the interface to be called into the shared memory. So that after the first process receives the interface call request sent by the second process, it can read the corresponding target data from the shared memory according to the information carried in the request, process the target data according to the corresponding data processing method, and then write the processed interface call result into the shared memory. In this way, the second process can directly read the interface call result from the shared memory, thereby optimizing the time consumption of cross-process interface calls and improving the efficiency of cross-process interface calls.
[0109] In one specific implementation, see Figure 2 As shown, when client process B needs to make a cross-process interface call to any interface, it first checks whether a command input queue exists in its own process. If it does not exist, it creates a shared memory 'a' (corresponding to the shared memory region 'in') in the Linux kernel and obtains the file descriptor 'a' allocated to client process B by the shared memory 'a'. Then, through the command execution engine in client process B, it creates a command input queue in its own process and binds the command input queue to the file descriptor 'a' of the shared memory region 'in', thereby enabling the command input queue to read and write to the shared memory region 'in' in the shared memory. Next, it obtains the structure data of the command input queue and transmits the obtained input queue structure data (which can be serialized data) to the server process A via a socket.
[0110] When server process A receives the input queue structure data sent by client process B, it parses it to recreate the same command input queue structure in its own process. Then, it obtains the file descriptor a′ allocated to server process A by shared memory a and binds file descriptor a′ to shared memory a. In this way, server process A and client process B can access the same shared memory (i.e., shared memory region in). Next, server process A serializes the command opcode and interface parameter information of the interface through the command input queue and writes the serialized target data into the bound shared memory a, while recording the length L0 of the target data written into shared memory a. It should be noted that the value of the file descriptor changes after cross-process transmission. File descriptor a′ and file descriptor a belong to different processes but point to the same shared memory.
[0111] If there is a large amount of data (such as image data, video data, etc.) that needs to be transmitted, the file descriptors of the DMA-BUF memory region (i.e., the region file descriptors) are stored in a file descriptor array, and the index i of the region file descriptor in the array is written into the shared memory. For batch interface call scenarios, the above steps need to be repeated (that is, from the step of checking whether there is a command input queue in the process itself to the step of writing the index of the region file descriptor in the array into the shared memory) until all interfaces have completed the above steps.
[0112] Furthermore, the interface execution operation is performed, specifically by transmitting the command opcode of the interface to be called, the length L0 of the target data written in the aforementioned shared memory, and the existing file descriptor array to the server process A via a socket, and waiting for the server process A to return the corresponding interface execution result.
[0113] Specifically, server process A can read data of the length L0 from shared memory a and parse it according to the length of the received target data. Then, it can find the corresponding execution function from the list of implemented functions for the command opcode in the parsed target data. At the same time, it can parse the interface parameter information in the target data. If there is a region file descriptor at index i in the array, it can obtain the corresponding region file descriptor from the file descriptor array and then execute the specific interface call operation. That is, it can use the execution function to process the interface parameter information accordingly to obtain the corresponding interface execution result.
[0114] Next, the interface execution result is returned to the client process B. The specific steps are as follows: First, check if a command output queue exists in the server process A. If it does not exist, create a shared memory b (corresponding to the shared memory region out) in the Linux kernel, and obtain the file descriptor b allocated to the server process A for this shared memory. Then, create a command output queue in its own process through the command processing engine in the server process A, and bind the created command output queue to the file descriptor b of the shared memory b. In this way, the command output queue can perform read and write operations on the shared memory b. Next, write the interface execution result to the bound shared memory through the command output queue. If it is a batch interface call scenario, the above steps need to be repeated (that is, from parsing the target data to writing the interface execution result to the bound shared memory) until all interfaces have completed the above steps.
[0115] Furthermore, the command opcode of the interface to be called and the length L1 of the interface execution result written in shared memory are transmitted to the client process B via socket. When the client process B receives the command opcode and length L1, it first checks whether a command output queue exists in its own process. If it does not exist, it sends a request to the server process A to create a command output queue. After obtaining the output queue structure data (serialized data) sent by the server process A via socket, it parses (i.e., deserializes) it, and then uses the parsed output queue structure data to create a command output queue with the same structure in its own process (i.e., client process B). The command output queue is then bound to the file descriptor b′ allocated to the client process B by the shared memory, thereby enabling the client process B and the server process A to access the same shared memory.
[0116] After creating a command output queue and binding it to shared memory, client process B reads the interface execution result of length L1 from the shared memory through the command output queue and assigns the interface execution result to the corresponding interface to be called. For batch interface call scenarios, it is necessary to repeatedly assign the execution result from the command output queue to the corresponding interface to complete the cross-process call process of all interfaces.
[0117] Accordingly, this application also discloses an interface calling device applied to the first process, see [link to relevant documentation]. Figure 4 As shown, the device includes:
[0118] The acquisition module 101 is used to acquire the interface call request sent by the second process; the interface call request carries first information.
[0119] The reading module 102 is used to read the corresponding target data from the shared memory according to the first information;
[0120] Module 103 is used to determine the corresponding data processing method;
[0121] Processing module 104 is used to process the target data according to the data processing method;
[0122] The writing module 105 is used to write the processed interface call result into the shared memory;
[0123] The sending module 106 is used to send the second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory according to the second information.
[0124] The specific workflow of each of the above modules can be found in the relevant content disclosed in the foregoing embodiments, and will not be repeated here.
[0125] Accordingly, this application also discloses an interface calling device applied to a second process, see [link to relevant documentation]. Figure 5 As shown, the device includes:
[0126] The writing module 201 is used to write the target data related to the interface to be called into the shared memory.
[0127] The sending module 202 is used to send an interface call request carrying first information to a first process, so that the first process can read the target data from the shared memory according to the first information, process the target data according to the corresponding data processing method, and write the processed interface call result into the shared memory.
[0128] The acquisition module 203 is used to acquire the second information corresponding to the interface call result sent by the first process;
[0129] The reading module 204 is used to read the interface call result from the shared memory based on the second information.
[0130] The specific workflow of each of the above modules can be found in the relevant content disclosed in the foregoing embodiments, and will not be repeated here.
[0131] Furthermore, embodiments of this application also disclose an electronic device, Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0132] Figure 6This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the interface calling method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0133] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0134] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0135] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs capable of performing the interface call methods executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0136] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed interface invocation method. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0137] Furthermore, embodiments of this application also disclose a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the interface calling method disclosed above.
[0138] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0139] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0140] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0141] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0142] The above provides a detailed description of an interface calling method, apparatus, device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. An interface invocation method, characterized in that, Applied to the first process, including: Obtain the interface call request sent by the second process; the interface call request carries the first information; Based on the first information, the corresponding target data is read from the shared memory, and the corresponding data processing method is determined; The target data is processed according to the data processing method, and the interface call result obtained after processing is written into the shared memory; The second information corresponding to the interface call result is sent to the second process so that the second process can read the interface call result from the shared memory based on the second information.
2. The interface calling method according to claim 1, characterized in that, The first information includes the command opcode of the interface to be called and the first write length; Accordingly, the step of reading the corresponding target data from the shared memory based on the first information and determining the corresponding data processing method includes: Based on the first write length, the command opcode and the interface parameter information of the interface to be called are read from the shared memory, and the interface execution function corresponding to the command opcode is determined.
3. The interface calling method according to claim 2, characterized in that, The step of processing the target data according to the data processing method includes: The interface parameter information is processed using the interface execution function to obtain the interface call result.
4. The interface calling method according to claim 3, characterized in that, The first information also includes a descriptor array; Correspondingly, the interface call method also includes: The index corresponding to the region file descriptor in the descriptor array is found in the shared memory, and the corresponding data block is read from the DMA-BUF memory region according to the index.
5. The interface calling method according to claim 3, characterized in that, Sending the second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory based on the second information, includes: The command opcode and the second write length are sent to the second process so that the second process can read the interface call result of the corresponding length from the shared memory according to the second write length.
6. The interface calling method according to claim 1, characterized in that, Also includes: Obtain the input queue structure data sent by the second process; A command input queue is created in the first process based on the input queue structure data, and the command input queue is bound to the shared memory. Accordingly, after reading the corresponding target data from the shared memory based on the first information, the process further includes: The read target data is saved to the command input queue.
7. The interface invocation method according to any one of claims 1 to 6, characterized in that, The step of writing the processed interface call result into the shared memory includes: In the first process, a command output queue is created and bound to the shared memory; The processed interface call results are written to the shared memory through the command output queue.
8. A cross-process interface calling device, characterized in that, Applied to the first process, including: The acquisition module is used to acquire the interface call request sent by the second process; the interface call request carries first information. The reading module is used to read the corresponding target data from the shared memory based on the first information; The determination module is used to determine the corresponding data processing method; The processing module is used to process the target data according to the data processing method. The writing module is used to write the processed interface call results into the shared memory; The sending module is used to send the second information corresponding to the interface call result to the second process, so that the second process can read the interface call result from the shared memory according to the second information.
9. An interface invocation method, characterized in that, Applied to the second process, including: An interface call request carrying first information is sent to the first process, so that the first process can read the corresponding target data from the shared memory and determine the corresponding data processing method according to the first information, process the target data according to the data processing method, and write the processed interface call result into the shared memory. Obtain the second information corresponding to the interface call result sent by the first process; The interface call result is read from the shared memory based on the second information.
10. The interface calling method according to claim 9, characterized in that, Also includes: The command input queue in the second process is bound to the shared memory, and the target data is written to the shared memory through the command input queue; the target data includes the command opcode and interface parameter information of the interface to be called.
11. The interface invocation method according to claim 10, characterized in that, After writing the target data into shared memory via the command input queue, the process further includes: The region file descriptors of the DMA-BUF memory region are stored in the descriptor array located in the command input queue; Write the index of the region file descriptor in the descriptor array into the shared memory so that the first process can read the corresponding data block from the DMA-BUF memory region according to the index; Accordingly, the first information includes the command opcode of the interface to be called, the first write length, and the descriptor array; the first write length is the data length of the target data.
12. The interface invocation method according to any one of claims 9 to 11, characterized in that, Also includes: Obtain the output queue structure data sent by the first process; A command output queue is created in the second process based on the output queue structure data, and the command output queue is bound to the shared memory. Accordingly, after reading the interface call result from the shared memory based on the second information, the method further includes: The read interface call results are saved to the command output queue.
13. An interface calling device, characterized in that, Applied to the second process, including: The write module is used to write the target data related to the interface to be called into shared memory; The sending module is used to send an interface call request carrying first information to a first process, so that the first process can read the target data from the shared memory according to the first information, process the target data according to the corresponding data processing method, and write the processed interface call result into the shared memory. The acquisition module is used to acquire the second information corresponding to the interface call result sent by the first process; The reading module is used to read the interface call result from the shared memory based on the second information.
14. An electronic device, characterized in that, It includes a processor and a memory; wherein, when the processor executes a computer program stored in the memory, it implements the interface invocation method as described in any one of claims 1 to 7, or any one of claims 9 to 12.
15. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the interface calling method as described in any one of claims 1 to 7, or any one of claims 9 to 12.