Socket-based data transmission method, electronic equipment and storage medium

By adding a data cache module and Socket kernel driver to the kernel space, the mapping relationship between the data cache module and the user space is established, and the problem of multiple data copying in Socket processes is solved, data transmission efficiency is improved and data modification is supported.

CN119248530AActive Publication Date: 2025-01-03HONOR DEVICE CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410174195.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-02-07
Publication Date
2025-01-03
Estimated Expiration
2044-02-07

AI Technical Summary

Technical Problem

During the Socket process communication, data transmission efficiency is low, resulting in multiple data copies, affecting performance.

Method used

By adding a data cache module and Socket kernel driver to the kernel space, a mapping relationship between the data cache module and the data forwarding service module in the user space is established, and the number of data copies is reduced, so that only two data copies are required in local inter-process communication.

Benefits of technology

It improves data transmission efficiency, reduces the number of data copies, and supports access and modification of data in the data cache module in the kernel space in user space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248530A_ABST
    Figure CN119248530A_ABST
Patent Text Reader

Abstract

The invention provides a Socket-based data transmission method, electronic equipment and a storage medium, and relates to the technical field of communication. A data cache module and a Socket kernel driver are newly added in a kernel space, and the Socket kernel driver can control a cache region of the data cache module to cache data from a first application and transmit a cache index value corresponding to the cache region to a data forwarding service module of a user space. And then the Socket kernel driver can read the cache index value from the data forwarding service module, copy the data from the cache region based on the cache index value, and forward the data to the second application. According to the application, the data caching module and the data forwarding service module have the mapping relationship, so that the kernel space and the user space can share data through the data caching module, and therefore, only two times of data copying are needed in the local inter-process communication process, the data copying times are reduced, and the data transmission efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a data transmission method, electronic device and storage medium based on Socket. Background Art

[0002] Currently, in the process of Socket inter-process communication, such as Figure 1A and Figure 1B As shown, the sender packs the data to be sent into msg structure data, calls the Socket interface, and copies (the first copy) the msg structure data to the Socket buffer; then, the data forwarding service module calls the Socket interface to copy (the second copy) the msg structure data from the Socket send buffer, and then calls the Socket interface to copy (the third copy) the msg structure data to the Socket receive buffer; then, the receiver calls the Socket interface to copy (the fourth copy) the msg structure data from the Socket receive buffer.

[0003] When electronic devices use the above-mentioned traditional Socket communication method to forward data, four data copies will occur during a single data transmission process, which seriously affects the data transmission efficiency. Summary of the invention

[0004] The present application provides a data transmission method and electronic device based on Socket, which can reduce the number of data copies, improve data transmission efficiency, and enhance user experience.

[0005] In a first aspect, the present application provides a data transmission method based on Socket, wherein the electronic device includes a Socket interface, a Socket kernel driver, a data cache module and a data forwarding service module, and the method includes:

[0006] The Socket kernel driver receives first data from a first application; the Socket kernel driver copies the first data to a first cache area of ​​the data cache module; the Socket kernel driver writes a first cache index value corresponding to the first cache area into a receiving queue of the data forwarding service module; the Socket kernel driver receives second data sent by the data forwarding service module, the second data being obtained based on the first cache index value; the Socket kernel driver parses the first cache index value from the second data, and writes the first cache index value into a receiving queue of a second application; the Socket kernel driver copies the first data from the first cache area based on the first cache index value, and transmits the first data to the second application.

[0007] Through the Socket-based data transmission method provided by the embodiment of the present application, a data cache module and a Socket kernel driver are added to the kernel space. The Socket kernel driver can control the cache area of ​​the data cache module to cache the data from the first application, and transmit the cache index value corresponding to the cache area to the data forwarding service module of the user space. Then the Socket kernel driver can read the cache index value from the data forwarding service module, and copy the data from the cache area based on the cache index value, and then forward it to the second application. Through the present application, since there is a mapping relationship between the data cache module of the kernel space and the data forwarding service module of the user space, the kernel space and the user space can share data through the data cache module. Therefore, in the process of local inter-process communication, only two data copies are needed. Compared with the four data copies required by the related technology, the present application scheme can reduce the number of data copies and improve data transmission efficiency.

[0008] The first application may be a third-party application installed on the electronic device by the user, or a system application in the electronic device. Applications such as photo album or camera.

[0009] The second application may be a service application such as managing power consumption, managing policies, monitoring performance status, and / or collecting user habit data, and the application B may be used to monitor and manage various event data of the application A. For example, the second application may be a power consumption management service program, a policy management service program, a performance status monitoring service program, or a user habit data collection service program.

[0010] When application A generates user input and response data, application B will obtain the user input and response data. The data on application A needs to be forwarded by the data forwarding service module before reaching application B.

[0011] In the related art, the data forwarding function between local processes is implemented based on Socket, and 4 data copies will occur in a single message transmission. In the present application, the data forwarding function between local processes is implemented based on Socket, and 2 data copies will occur in a single message transmission, reducing the number of data copies.

[0012] In some possible implementations, the receiving queue of the data forwarding service module includes cache index values ​​corresponding to each cache area of ​​the data cache module. The data cache module includes multiple cache areas, each of which corresponds to a cache index value. When the data cache module receives a cache application from the socket kernel driver, the data cache module allocates a cache area and notifies the socket kernel driver of the cache index value corresponding to the cache area.

[0013] In some possible implementations, after the Socket kernel driver receives the first data from the first application and before the Socket kernel driver copies the first data to the first cache area of ​​the data cache module, the method further includes: the Socket kernel driver determines that the type of the first data is a first business type; the Socket kernel driver sends an application message to the data cache module, the application message is used to apply for a cache area to store data of the first business type; the Socket kernel driver receives a response message from the data cache module, the response message is used to indicate that the first cache area is allocated for the data of the first business type, and the response message also includes the first cache index value corresponding to the first cache area.

[0014] Through the above scheme, when the data cache module receives the cache application of the Socket kernel driver, the data cache module will allocate a cache area and notify the Socket kernel driver of the cache index value corresponding to the cache area, so that the Socket kernel driver writes the cache index value into the receiving queue of the data forwarding service module, and facilitates the data forwarding service module to access the cache area based on the cache index value and modify the data in the cache area; and also facilitates the Socket kernel driver to access the cache area based on the cache index value, copy the data in the cache area and send it to the second application. Through this application scheme, not only can the number of data copies be reduced and the data transmission efficiency be improved, but also it supports the access and modification of the forwarding data cached in the data cache module of the kernel space in the user space.

[0015] In some possible implementations, there is a mapping relationship between the first service type, the first cache area, and the first cache index value. The data of the first service type belongs to the service data collected by the second application request.

[0016] In some possible implementations, before the Socket kernel driver receives the first data from the first application, the method further includes: in response to a user operation, the first application executes a first service and generates first data; the first application calls the Socket interface and transmits the first data to the Socket kernel driver.

[0017] In some possible implementations, the first application calls the Socket interface to transmit the first data to the Socket kernel driver, including: the first application calls the Socket interface, encapsulates the first data into a first message structure according to a preset specification, and transmits the first message structure to the Socket kernel driver.

[0018] The first message structure may also be referred to as the first msg structure. The msg structure is used for inter-process Socket communication within an electronic device. In the present application, the electronic device may use the msg structure to transmit messages between different processes, thereby improving the compatibility of inter-process Socket communication.

[0019] In some possible implementations, after the Socket kernel driver writes the first cache index value corresponding to the first cache area into the receiving queue of the data forwarding service module, the method further includes: the Socket kernel driver sequentially reads the cache index values ​​from the receiving queue of the data forwarding service module, encapsulates the read cache index values ​​into a second message structure, and transmits the first message structure to the data forwarding service module.

[0020] Through the solution of this application, the problem of multiple copies in the data forwarding and filtering link using Socket is solved. This application designs a unique shared cache management mechanism and solves the compatibility problem with the existing data interface of Socket, thereby improving the efficiency of data transmission between local processes based on Socket.

[0021] In some possible implementations, the method also includes: the data forwarding service module receives a data modification instruction; in response to the data modification instruction, the data forwarding service module accesses a first cache area in the data cache module based on the first cache index value, and modifies the data in the first cache area based on the data modification instruction.

[0022] Through the present application scheme, compared with the related art that does not support modification or deletion of forwarding data in user space, the present application scheme supports accessing and modifying the forwarding data cached in the data cache module of the kernel space in user space, which can achieve the purpose of modifying or deleting the forwarding data in user space and improve the convenience of data transmission.

[0023] In some possible implementations, before the Socket kernel driver receives the second data sent by the data forwarding service module, the method also includes: the data forwarding service module calls the Socket interface, encapsulates the first cache index value into a third message structure according to a preset specification, and transmits the third message structure as the second data to the Socket kernel driver.

[0024] In some possible implementations, the method further includes: when the Socket kernel driver writes the first cache index value into the receiving queue of the second application, the Socket kernel driver sends a new data notification to the second application; and the Socket kernel driver receives a fourth message structure sent by the second application for receiving new data.

[0025] In some possible implementations, the Socket kernel driver copies the first data from the first cache area based on the first cache index value, and transmits the first data to the second application, including: the Socket kernel driver accesses the first cache area based on the first cache index value, and copies the first data in the first cache area to the fourth message structure; the Socket kernel driver calls the Socket interface to transmit the fourth message structure to the second application.

[0026] In some possible implementations, the data cache module includes a control area and a data area, the control area includes N control blocks, the data area includes N data blocks, the N control blocks correspond to the N data blocks one by one, and some of the N control blocks have an associated relationship. The control block can be called a node.

[0027] Among them, the characteristic structure of the control block includes node status, data block allocation size, used size, current node number, next node number, number of occupied services, and real address of the data block.

[0028] The first cache area corresponds to a cache set, the cache set includes a control block and a corresponding data block, and the first cache index value corresponds to the serial number of the data block.

[0029] In some possible implementations, the state of the data cache module is one of the following states: idle state, kernel space read-write state, waiting state, user space read-write state.

[0030] In some possible implementations, the method further includes: the Socket kernel driver controls the data cache module to switch states between the various states.

[0031] In some possible implementations, the Socket kernel driver controls the data cache module to switch between the various states, including:

[0032] The data cache module is in the idle state after initialization, waiting for allocation;

[0033] After the Socket kernel driver copies the data to the data cache module, the Socket kernel driver updates the state of the data cache module to the waiting state;

[0034] When the data forwarding service module reads and writes the data cache module, the Socket kernel driver updates the state of the data cache module to the user space read and write state;

[0035] After the data forwarding service module completes reading and writing to the data cache module, the Socket kernel driver updates the state of the data cache module to a waiting or idle state again.

[0036] When the Socket kernel driver copies data from the data cache module, the state of the data cache module is updated to the kernel space read-write state again.

[0037] After the Socket kernel driver finishes copying the data from the data cache module, the occupied cache area in the data cache module is released, and the state of the data cache module is updated to an idle state.

[0038] The Socket-based data transmission method provided by the embodiment of the present application only requires two data copies, which is less than the four data copies required by the related art. In addition, compared with the related art that does not support modification or deletion of forwarded data in user space, the present application adds a data cache module in the kernel space to cache forwarded data, and establishes a mapping relationship between the data cache module and the data forwarding service module in the user space, so that the kernel space and the user space can share data through the data cache module, and support access and modification of the forwarded data cached in the data cache module in the kernel space in the user space, thereby achieving the purpose of modifying or deleting the forwarded data in the user space.

[0039] In a second aspect, the present application provides a data transmission device based on Socket, the device comprising a unit for executing the method in the first aspect. The device may correspond to executing the method described in the first aspect, and the relevant description of the unit in the device can refer to the description of the first aspect, which will not be repeated here for the sake of brevity.

[0040] The method described in the first aspect above can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above functions. For example, a processing module or unit, a display module or unit, etc.

[0041] In a third aspect, the present application provides an electronic device, comprising a processor, a computer program or instructions stored in the processor and a memory, wherein the processor is configured to execute the computer program or instructions so that the method in the first aspect is executed.

[0042] In a fourth aspect, the present application provides a computer-readable storage medium on which a computer program (also referred to as instructions or codes) for implementing the method in the first aspect is stored. For example, when the computer program is executed by a computer, the computer can perform the method in the first aspect.

[0043] In a fifth aspect, the present application provides a chip, including a processor. The processor is used to read and execute a computer program stored in a memory to perform the method in the first aspect and any possible implementation thereof. Optionally, the chip also includes a memory, and the memory is connected to the processor via a circuit or wire.

[0044] In a sixth aspect, the present application provides a chip system, including a processor. The processor is used to read and execute a computer program stored in a memory to perform the method in the first aspect and any possible implementation thereof. Optionally, the chip system also includes a memory, and the memory is connected to the processor via a circuit or wire.

[0045] In a seventh aspect, the present application provides a computer program product, which includes a computer program (also referred to as instructions or codes). When the computer program is executed by an electronic device, the electronic device implements the method in the first aspect.

[0046] It can be understood that the beneficial effects of the second to seventh aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1A Schematic diagram 1 of a flow chart of data transmission between internal processes of an electronic device in the related art;

[0048] Figure 1B Schematic diagram of the process of transmitting data between processes in electronic devices in the related art Figure 2 ;

[0049] Figure 2 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0050] Figure 3 A schematic diagram of the software architecture of an electronic device provided in an embodiment of the present application;

[0051] Figure 4A A schematic diagram of an improved Socket-based data transmission method provided in an embodiment of the present application relative to the related art;

[0052] Figure 4B Schematic diagram 1 of the flow chart of the data transmission method based on Socket provided in the embodiment of the present application;

[0053] Figure 5 A timing diagram of a data transmission method based on Socket provided in an embodiment of the present application;

[0054] Figure 6 Schematic diagram of the data transmission method based on Socket provided in the embodiment of the present application Figure 2 ;

[0055] Figure 7 Schematic diagram of the data transmission method based on Socket provided in the embodiment of the present application Figure 3 ;

[0056] Figure 8 A schematic diagram of the structure of a data cache module used in a Socket-based data transmission method provided in an embodiment of the present application;

[0057] Fig. 9 A schematic diagram of nodes and data blocks of a data cache module applied in a Socket-based data transmission method provided in an embodiment of the present application;

[0058] Fig.10 A schematic diagram of state switching of a data cache module applied in a Socket-based data transmission method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the embodiments of the present application are further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0060] To facilitate understanding of the embodiments of the present application, some terms used in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.

[0061] 1. Socket: refers to the network socket. Socket is the inter-process communication mechanism provided by the operating system. Based on this mechanism, different processes can communicate with each other. Specifically, the communication process can be completed using the relevant functions in the socket.

[0062] 2. Socket interface: refers to the socket interface (Socket API). The socket interface is an application programming interface, which is a set of application programming interfaces (APIs) provided by the operating system for applications. Applications can use network sockets to exchange data through the socket interface. Two communicating processes can use a socket interface to describe the two ends of the communication link to achieve socket communication.

[0063] 3.msg structure: It is a commonly used data structure used to pass messages between applications.

[0064] Specifically, the msg structure usually consists of multiple fields, each of which has a specific name and data type. These fields can store different types of data, such as integers, strings, Boolean values, etc. By defining the msg structure, related information can be packaged together and passed between applications.

[0065] In practical applications, the msg structure is often used in inter-process communication, network communication, and event-driven programming models. By packaging the data to be transmitted into a msg structure, data can be easily exchanged between different applications. This method can improve the flexibility and scalability of the application, allowing different modules to be developed and debugged independently.

[0066] In network communication, the msg structure can be used to pass messages between the client and the server. For example, in a chat application, the client and the server need to pass user messages. By defining a msg structure containing fields such as sender, receiver, and message content, it is convenient to pass messages between the client and the server and realize the function of real-time communication.

[0067] Specifically in the present application, the msg structure is used for inter-process Socket communication within an electronic device. Among them, the electronic device can use the msg structure to pass messages between different processes. For example, in a distributed transaction, different service processes need to exchange data and coordinate work. By defining a unified msg structure, data that needs to be shared can be easily passed between these processes to achieve system collaboration.

[0068] Figure 1A Schematic diagram of system architecture involved in various exemplary embodiments of the present application is shown. Figure 1AAs shown in the figure, the system architecture includes application A, data forwarding service module / program, and application B. When application A sends data to application B, it needs to call the Socket interface to complete the inter-process communication, and the data forwarding needs to be completed through the data forwarding service module. On the sending side, the data is stored in the Socket sending buffer; on the receiving side, the data is stored in the Socket receiving buffer. Application A acts as the sender of the data, application B acts as the receiver of the data, and the data forwarding service module acts as the forwarder of the data.

[0069] For example, application A can be a third-party application installed on an electronic device triggered by a user, or a system application in the electronic device. Application B can be a service application such as managing power consumption, managing policies, monitoring performance status, and / or collecting user habit data. Application B can be used to monitor and manage various event data of application A. When user input and response data are generated on the application A side, application B will obtain the user input and response data.

[0070] For example, the electronic device receives an operation of the user on application A, which may be an operation in which the user triggers the opening of application A. Accordingly, the electronic device responds to the user operation and opens application A. In this process, application A sends the opening event data to application B, and accordingly, application B obtains the opening event data of application A. It should be noted that the user triggering the opening of application A is used as an example for illustrative explanation here. In actual implementation, the user operation may also be an operation in which the user triggers the installation, closing or uninstallation of application A, and application B may also obtain various event data such as the installation event, closing event or uninstallation event of application A, which is not limited in the embodiments of the present application.

[0071] Figure 1B FIG. 1 shows a schematic diagram of inter-process communication in an electronic device in the related art. Figure 1B As shown, the sending side includes multiple senders, for example, these senders are The receiving side includes multiple receivers, such as the photo album, camera and other applications, such as the power management service program, policy management service program, performance status monitoring service program, and user habit data collection service program. The sender, data forwarding service module and receiver are all located in the user space of the electronic device (i.e., the application layer), and the socket buffer is located in the kernel space of the electronic device (i.e., the kernel layer).

[0072] In the process of inter-process communication, such as Figure 1BIn the direction indicated by the arrow, the sender packs the data to be sent into msg structure data, calls the Socket interface, and copies (the first copy) the msg structure data to the Socket buffer; then, the data forwarding service module calls the Socket interface to copy (the second copy) the msg structure data from the Socket send buffer, and then calls the Socket interface to copy (the third copy) the msg structure data to the Socket receive buffer; then, the receiver calls the Socket interface to copy (the fourth copy) the msg structure data from the Socket receive buffer.

[0073] It can be seen that in electronic equipment using Figure 1B In the case of forwarding data using the traditional Socket communication method shown in the figure, four data copies will occur during a single data transmission process. The large number of data copies seriously affects the data transmission efficiency. In addition, during the data forwarding process, data modification and deletion in the user space are not supported.

[0074] Based on this, the embodiment of the present application provides a data transmission method and electronic device based on Socket, which reduces the number of data copies, improves data transmission efficiency, and improves user experience by making improvements at the bottom layer of the electronic device system. In addition, through the solution of the present application, during the data forwarding process, the data forwarding service module can modify and delete the forwarded data in the user space.

[0075] In order to better understand the embodiments of the present application, the embodiments of the present application are briefly described below:

[0076] The data transmission method based on Socket provided in the embodiment of the present application is applied to an electronic device, which includes a Socket interface, a Socket kernel driver, a data cache module and a data forwarding service module. The data transmission method based on Socket includes: the Socket kernel driver receives the first data from the first application; the Socket kernel driver copies the first data to the first cache area of ​​the data cache module; the Socket kernel driver writes the first cache index value corresponding to the first cache area into the receiving queue of the data forwarding service module; the Socket kernel driver receives the second data sent by the data forwarding service module, and the second data is obtained based on the first cache index value; the Socket kernel driver parses the first cache index value from the second data, and writes the first cache index value into the receiving queue of the second application; the Socket kernel driver copies the first data from the first cache area based on the first cache index value, and transmits the first data to the second application.

[0077] Through the Socket-based data transmission method provided by the embodiment of the present application, a data cache module and a Socket kernel driver are added to the kernel space. The Socket kernel driver can control the cache area of ​​the data cache module to cache the data from the first application, and transmit the cache index value corresponding to the cache area to the data forwarding service module of the user space. Then the Socket kernel driver can read the cache index value from the data forwarding service module, and copy the data from the cache area based on the cache index value, and then forward it to the second application. Through the present application, since there is a mapping relationship between the data cache module of the kernel space and the data forwarding service module of the user space, the kernel space and the user space can share data through the data cache module. Therefore, in the process of local inter-process communication, only two data copies are needed. Compared with the four data copies required by the related technology, the present application scheme can reduce the number of data copies and improve data transmission efficiency.

[0078] Hereinafter, an electronic device to which the Socket-based data transmission method provided in an embodiment of the present application is applied will be described with reference to the accompanying drawings.

[0079] Exemplarily, the electronic device in the embodiments of the present application may be a mobile phone, a tablet computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), a wearable device (such as a smart watch, a smart bracelet), and the like. The embodiments of the present application do not impose any special restrictions on the specific form of the electronic device.

[0080] Figure 2 FIG. 1 is a schematic diagram showing the structure of an electronic device provided by an embodiment of the present application. For example, taking a mobile phone as an example, Figure 2 As shown, the mobile phone may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver (i.e., an earpiece) 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0081] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural-network processing unit (neural-network processing unit, NPU), etc. Among them, different processing units can be independent devices or integrated in one or more processors. The controller can be the nerve center and command center of the mobile phone. The controller can generate an operation control signal according to the instruction opcode and the timing signal to complete the control of fetching and executing instructions.

[0082] In an embodiment of the present application, the processor 110 can be used to: receive first data from a first application through a Socket kernel driver; copy the first data to a first cache area of ​​the data cache module through the Socket kernel driver; write a first cache index value corresponding to the first cache area into a receive queue of the data forwarding service module through the Socket kernel driver; receive second data sent by the data forwarding service module through the Socket kernel driver, the second data being obtained based on the first cache index value; parse the first cache index value from the second data through the Socket kernel driver, and write the first cache index value into a receive queue of a second application; copy the first data from the first cache area based on the first cache index value through the Socket kernel driver, and transmit the first data to the second application.

[0083] This application adds a data cache module and a Socket kernel driver in the kernel space. The Socket kernel driver can control the cache area of ​​the data cache module to cache the data from the first application, and transmit the cache index value corresponding to the cache area to the data forwarding service module in the user space. Then the Socket kernel driver can read the cache index value from the data forwarding service module, and copy the data from the cache area based on the cache index value, and then forward it to the second application. Through this application, since there is a mapping relationship between the data cache module in the kernel space and the data forwarding service module in the user space, the kernel space and the user space can share data through the data cache module. Therefore, in the process of local inter-process communication, only two data copies are needed. Compared with the four data copies required by the related technology, the solution of this application can reduce the number of data copies and improve data transmission efficiency.

[0084] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0085] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0086] It is understandable that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation on the mobile phone. In other embodiments, the mobile phone may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0087] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the mobile phone. The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the mobile phone by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 can execute instructions stored in the internal memory 121, and the internal memory 121 may include a program storage area and a data storage area.

[0088] The wireless communication function of the mobile phone can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor.

[0089] The mobile phone can realize audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver (ie, the handset) 170B, the microphone 170C, the earphone interface 170D, and the application processor.

[0090] The mobile phone can realize the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information. The display screen 194 is used to display images, videos, etc.

[0091] The mobile phone can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, and the application processor. The ISP is used to process the data fed back by the camera 193. In some embodiments, the ISP can be set in the camera 193. The camera 193 is used to capture a static image or a video. In some embodiments, the mobile phone can include 1 or N cameras 193, where N is a positive integer greater than 1.

[0092] The above is a specific description of the embodiment of the present application using the electronic device 100 as an example. It should be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. The electronic device 100 may have more or fewer components than those shown in the figure, may combine two or more components, or may have different component configurations. The various components shown in the figure may be implemented in hardware, software, or a combination of hardware and software including one or more signal processing and / or application specific integrated circuits.

[0093] In addition, an operating system is running on the above hardware. The operating system of the operating system layer can be any one or more computer operating systems that implement business processing through processes, such as Linux operating system, Unix operating system, Android operating system, iOS operating system or Windows operating system, etc. Applications can be installed and run on the operating system.

[0094] The operating system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.

[0095] Figure 31 is a software structure diagram of the electronic device 100 of the embodiment of the present application. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer (applications), the application framework layer (applicationframework), the system library layer (native) and the kernel layer (kernel).

[0096] Specific to the present application scheme, each layer including kernel layer, system library layer, application framework layer, application layer, etc. can call the Socket interface. The present application implements the data forwarding function between local application processes based on the Socket mechanism. The specific process will be described in detail below.

[0097] The application layer may include a series of application packages. For example, the application layer may include camera applications (application, APP), gallery APP, calendar APP, map APP, navigation APP, music APP, video APP and other applications, and also includes data forwarding service program / module, and also includes power consumption management program, policy management program, etc., and the embodiments of the present application do not impose any restrictions on this.

[0098] The application framework layer provides an application programming interface (API) and a programming framework for the application programs in the application layer. The application framework layer includes some predefined functions. In the embodiment of the present application, the application framework layer may include a subscription unit and a collection unit set for application data. As the operating system becomes more and more complex, a unified data bus needs to be implemented to meet the collection and subscription of system messages by various units.

[0099] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0100] The system library may include multiple functional modules. For example: surface manager, media library, 3D graphics processing library (for example: OpenGL ES), 2D graphics engine (for example: SGL), etc. The system library layer may also be referred to as the native layer, which is a native code platform library that can provide native services for hardware operations for the upper layer. In an embodiment of the present application, the system library includes a data bus and an adapter library, and the data bus includes a collector, a distributor, a cache management, a pipeline control, a socket interface, etc.

[0101] The kernel layer is the layer between hardware and software. The kernel layer at least includes display driver, camera driver, audio driver, and sensor driver. In an embodiment of the present application, the kernel layer includes a data cache module (data cache, DC), a Socket kernel driver, a CPU data acquisition module, an I / O data acquisition module, a memory data acquisition module, etc. Among them, the data cache module and the cache driver are newly added modules in the existing software architecture of the present application. The present application is based on the Socket mechanism, adopts the data cache module and the cache driver, realizes the data forwarding service between local processes, reduces the number of data copies, and supports the modification operation of the content of the forwarded data. The specific inter-process communication process will be described in detail below.

[0102] It should be noted that although the embodiments of the present application are described using the Android system as an example, its basic principles are also applicable to electronic devices based on operating systems such as iOS or Windows.

[0103] The execution subject of the data transmission method based on Socket provided in the embodiment of the present application can be the above-mentioned electronic device, or it can be a functional module and / or functional entity in the electronic device that can implement the data transmission method based on Socket, and the present application scheme can be implemented by hardware and / or software, which can be determined according to actual use requirements, and the embodiment of the present application is not limited. Below, taking an electronic device as an example, the data transmission method based on Socket provided in the embodiment of the present application is exemplarily described in combination with the accompanying drawings.

[0104] The following will be combined with the accompanying drawings to illustrate the embodiments of the present application through the following multiple exemplary embodiments. The methods in the following embodiments can be implemented in an electronic device with the above hardware structure and software architecture. The hardware structure diagram of the electronic device can be as follows: Figure 2 As shown, the software structure diagram of the electronic device can be as follows Figure 3 For the sake of convenience, the embodiments of the present application are all based on electronic devices as shown in FIG. Figure 2 Take the mobile phone shown as an example.

[0105] Figure 4A A schematic diagram showing the improvement of the present application relative to the related art is shown.

[0106] In the Socket communication architecture of the related technology, the user space includes application A (or the first application), data forwarding service, and application B (or the second application); the kernel space includes the Socket send buffer and the Socket receive buffer; the user space interacts with the kernel space by calling the Socket interface. When an electronic device uses this traditional Socket communication architecture to forward data, four data copies will occur in a single data transmission process. For details, please refer to the above combined Figure 1B Description. The large number of data copies seriously affects the data transmission efficiency. In addition, during the data forwarding process, data modification and deletion in user space are not supported.

[0107] In the Socket communication architecture of the present application, the user space includes application A, data forwarding service, and application B; the kernel space includes the Socket kernel driver and the data cache module; the user space interacts with the kernel space by calling the Socket interface. When the electronic device adopts the Socket communication architecture provided by the present application to forward data, a single data transmission process only requires 2 data copies, which can be specifically referred to in conjunction with the above Figure 1B Therefore, the application scheme can reduce the number of data copies, improve data transmission efficiency, and enhance user experience. In addition, through the application scheme, during the data forwarding process, the data forwarding service module can modify and delete the forwarded data in the user space. The details will be described in detail below.

[0108] Figure 4B Schematic diagram of inter-application process communication within an electronic device provided by an embodiment of the present application. Figure 4B As shown, the present application solution adds a data cache module in the kernel space and establishes a custom protocol; based on the custom protocol, the data cache module is shared to the user space through memory mapping (Mmap), and the data forwarding service module in the user space is allowed to modify the content of the forwarded data. In addition, the present application solution also adds a Socket kernel driver that meets the custom protocol in the kernel space, and triggers the data cache module to cache data through the Socket kernel driver.

[0109] Reference below Figure 4B The flow shown by the arrows is described below. The sender (application A), data forwarding service module, and receiver (application B) are all located in the user space, and the socket kernel driver and data cache module are located in the kernel space.

[0110] 1. The sender (application A) calls the Socket interface to encapsulate the data to be sent and then transfers it to the kernel space. The data is encapsulated as the first msg structure.

[0111] The Socket kernel driver in the kernel space receives the encapsulated data, namely the first msg structure.

[0112] 2-1. The Socket kernel driver parses the first msg structure to obtain the service data, then applies for a buffer area from the data buffer module and copies the parsed service data to the buffer area.

[0113] 2-2. The Socket kernel driver first encapsulates the cache index value corresponding to the cache area and then writes it into the receiving queue of the data forwarding service module. The cache index value is encapsulated as the second msg structure.

[0114] 3. The data forwarding service module reads the cache index value from the receiving queue of the data forwarding service module, and then can access the cache area of ​​the data cache module according to the cache index value. When the data forwarding service module receives a modification instruction, the data forwarding service module can respond to the modification instruction and modify the data in the cache area.

[0115] 4-1. The data forwarding service module calls the Socket interface to encapsulate the cache index value and then transfer it to the kernel space. The cache index value is encapsulated as the third msg structure.

[0116] The Socket kernel driver in the kernel space receives the encapsulated data, that is, the third msg structure.

[0117] 4-2. The Socket kernel driver parses the third msg structure and writes the parsed cache index value into the receiving queue of the receiver (application B).

[0118] 5. The receiver (application B) sends the fourth msg structure to the Socket kernel driver to receive data. The Socket kernel driver reads the cache index value from the receiver's (application B) receiving queue, and accesses the cache area corresponding to the cache index value in the data cache module based on the cache index value, and copies the data stored in the cache area to the fourth msg structure. Then, the Socket kernel driver calls the Socket interface to send the fourth msg structure to the receiver (application B).

[0119] Thus, inter-process communication of application programs within electronic devices is realized based on Socket.

[0120] It should be noted that the msg structure is a nested structure pointer. According to the BSD specification, data is encapsulated into the msg structure, and its function is to implement communication between local application processes according to the BSD Socket specification.

[0121] For example, calling the msgget function will create a new message queue or get an existing message queue.

[0122] For example, when the msgsnd function is called to send a message of a specified size on a specified message queue, a msg_msg structure is created.

[0123] For example, call the alloc_msg function to allocate space and copy the user data to the kernel msg_msg structure.

[0124] Among them, the message queue is a communication mechanism of Linux. The data transmitted by this communication mechanism has a certain structure, rather than a simple byte stream. The essence of the message queue is actually a linked list provided by the kernel. The kernel implements a data structure based on this linked list. Inter-process communication can be achieved through the message queue.

[0125] This application scheme implements data forwarding services between local processes based on the Socket mechanism. Figure 4B When forwarding data using the Socket communication method shown, a single data transmission process requires only two data copies, so the present application reduces the number of data copies and supports modification and deletion of the content of the data to be forwarded during the forwarding process.

[0126] The following describes a Socket-based data transmission method provided in an embodiment of the present application in conjunction with a specific embodiment.

[0127] Figure 5 Schematic diagram of the interactive process of the data transmission method based on Socket provided in the embodiment of the present application. Figure 5 As shown, the method includes the following steps S201-S223. The modules involved in the interactive process include application A, Socket sending interface, Socket kernel driver, data cache module, data forwarding service module, Socket receiving interface, and application B. For the sake of convenience, the embodiment of the present application takes application A as a video APP and application B as a power consumption management program as an example for exemplary description.

[0128] S201 . Application A (first application) detects a first operation of a user. In response to the operation, application A executes a first service.

[0129] In some embodiments, the first operation is an installation operation of the video APP by the user, and the electronic device installs the video APP in response to the installation operation. In this case, the first service is installation of the video APP.

[0130] In some embodiments, the first operation is a user clicking an application icon of the video APP, and the electronic device opens the video APP in response to the clicking operation. In this case, the first service is opening the video APP.

[0131] In some embodiments, the first operation is a user's closing operation on the video APP, and the electronic device closes the video APP in response to the closing operation. In this case, the first service is closing the video APP.

[0132] In some embodiments, the first operation is an uninstallation operation of the video APP by the user, and the electronic device uninstalls the video APP in response to the uninstallation operation. In this case, the first service is uninstalling the video APP.

[0133] S202, application A sends the first data to the Socket sending interface.

[0134] The first data refers to data related to the first business.

[0135] S203. The Socket sending interface encapsulates the first data into a first msg structure according to the BSD specification.

[0136] Among them, the BSD specification refers to the Berkeley sockets specification, which is also called the BSD Socket specification. The application programming interface (API) of the BSD Socket specification is a library for inter-process communication using the C language, and is often used for communication between computer networks. The application programming interface of the BSD Socket specification has become an abstract standard for network sockets.

[0137] The first msg structure includes first data and complies with the BSD Socket specification.

[0138] S204. The Socket sending interface sends the first msg structure to the Socket kernel driver.

[0139] The Socket kernel driver parses the first msg structure to obtain the first data.

[0140] S205. The socket kernel driver sends a message 1 to the data cache module. The message 1 is used to apply for a cache area.

[0141] S206 . The data cache module creates a first cache area in response to the message 1 , and returns a message 2 indicating a successful application to the Socket kernel driver. The message 2 carries index information of the first cache area.

[0142] The index information may be represented by a preset value. For ease of explanation, the index information of the cache area is referred to as a cache index value below.

[0143] In some embodiments, the socket kernel driver determines that the type of the first data is the first business type, and then the socket kernel driver sends an application message to the data cache module, the application message is used to apply for a cache area to store the data of the first business type. Then, the socket kernel driver receives a response message from the data cache module, the response message is used to indicate that the first cache area is allocated for the data of the first business type, and the response message also includes a cache index value corresponding to the first cache area.

[0144] Among them, there is a mapping relationship between the first service type, the first cache area, and the cache index value.

[0145] The data of the first business type belongs to the business data requested to be collected by application B (second application).

[0146] Thus, the Socket kernel driver can determine the corresponding first buffer area according to the buffer index value, and can also determine that the type of data stored in the first buffer area is the first service type. Moreover, the Socket kernel driver can also determine that the data stored in the first buffer area needs to be sent to application B.

[0147] S207. The Socket kernel driver receives the message 2 indicating successful application, and copies the data in the first msg structure to the first buffer area corresponding to the buffer index value.

[0148] Correspondingly, the data cache module feeds back a message indicating that the data copy is successful to the Socket kernel driver.

[0149] S208. The Socket kernel driver writes the cache index value into the receiving queue of the data forwarding service module, and sends a wake-up message to the data forwarding service module.

[0150] S209. The data forwarding service module responds to the wake-up message by sequentially reading the cache index values ​​from the receiving queue and writing them into the second msg structure.

[0151] The second msg structure is identical to the first msg structure in structure but different in content.

[0152] Optionally, after the data forwarding service module writes the cache index value in the receiving queue into the second msg structure, the data forwarding service module may modify the first data in the first cache area. For specific processes, see S210 and S211 below.

[0153] S210. The data forwarding service module sends an instruction to modify the data in the first buffer area to the data buffer module. The instruction carries a second msg structure.

[0154] S211. The data cache module modifies the data in the first cache area in response to the instruction, and then returns a message indicating that the modification is completed to the data forwarding service module.

[0155] S212: The data forwarding service module encapsulates the cache index value in the second msg structure into a third msg structure according to the BSD specification.

[0156] The third msg structure is identical to the second msg structure in structure, and may be identical or different in content.

[0157] S213: The data forwarding service module sends the third msg structure to the Socket kernel driver.

[0158] S214. The socket kernel driver parses the cache index value from the third msg structure according to the BSD specification.

[0159] The Socket kernel driver can determine the corresponding first cache area according to the cache index value, and can also determine that the type of data stored in the first cache area is the first business type. In the case where the data of the first business type belongs to the business data requested to be collected by application B (second application), the Socket kernel driver can also determine that the data stored in the first cache area needs to be sent to application B.

[0160] S215 . The Socket kernel driver calls the Socket receiving interface, writes the cache index value into the receiving queue of application B, and sends a wake-up message to application B.

[0161] S216. Application B transmits a fourth msg structure to the Socket kernel driver in the kernel space in response to the wake-up message. The fourth msg structure is used to receive data.

[0162] S217. The Socket kernel driver requests data from the data cache module according to the cache index value read from the receiving queue of application B.

[0163] S218. The data cache module returns the first data in the first cache area corresponding to the cache index value to the Socket kernel driver.

[0164] In an embodiment of the present application, the socket kernel driver sends a data acquisition instruction to the data cache module, and the data acquisition instruction includes a cache index value. In response to the data acquisition instruction, the data cache module acquires the first data from the first cache area corresponding to the cache index value based on the cache index value, and sends the first data to the socket kernel driver.

[0165] S219. After receiving the first data, the Socket kernel driver copies the first data to a fourth msg structure.

[0166] The fourth msg structure may be the same as or different from the third msg structure in structure, and may be different in content.

[0167] S220. The Socket kernel driver calls the Socket receiving interface to send the fourth msg structure to application B.

[0168] S221. After receiving the fourth msg structure, application B parses the fourth msg structure to obtain the first data.

[0169] S222. The Socket kernel driver sends a message 3 to the data cache module. The message 3 is used to request the release of the cache area corresponding to the cache index value.

[0170] S223. After receiving message 3, the data cache module releases the cache area corresponding to the cache index value, and then returns message 4 to the Socket kernel driver, where message 4 is used to indicate that the cache area corresponding to the cache index value has been released.

[0171] In the related art, the data forwarding function between local processes is implemented based on Socket, and 4 data copies will occur in a single message transmission. In the present application, the data forwarding function between local processes is implemented based on Socket, and 2 data copies will occur in a single message transmission. Through the scheme of the present application, the problem of multiple copies in the data forwarding and filtering link using Socket is solved. The present application designs a unique shared cache management mechanism, and solves the compatibility problem with the existing data interface of Socket, thereby improving the efficiency of data transmission between local processes based on Socket.

[0172] This application mainly implements a Socket-based data forwarding service, reduces the number of data copies, and supports modification / deletion of forwarded data. This application adds a data cache module in the kernel space, which is used to cache forwarded data, and the data cache module is shared to the user space through memory mapping (Mmap), and allows the service program (data forwarding service module) in the user space to modify the forwarded data. This application also adds a Socket kernel driver in the kernel space, and realizes the reading and writing of the data cache module through the Socket kernel driver.

[0173] Below through Figure 6 and Figure 7 The sending and receiving are explained separately.

[0174] Figure 6 A schematic diagram of a process for sending data based on a Socket mechanism provided in an embodiment of the present application is shown.

[0175] S301-S303: The sender calls the Socket sending interface, and encapsulates the first data into a msg structure according to the BSD specification, and then transmits it to the kernel space.

[0176] The sender may be application A or a data forwarding service module.

[0177] In some embodiments, the sender is application A and the receiver is a data forwarding service module.

[0178] In other embodiments, the sender is a data forwarding service module and the receiver is application B.

[0179] That is to say, the process of transmitting data based on the Socket mechanism includes two stages: the first stage is the transmission from application A to the data forwarding service module, and the second stage is the transmission from the data forwarding service module to application B.

[0180] It should be noted that data needs to be specifically encapsulated at each stage to achieve Socket communication between different application programs (ie, between different processes).

[0181] It should also be noted that the encapsulated data passes through the Socket sending interface and reaches the Socket kernel driver in the kernel space, and then the Socket kernel driver completes data forwarding based on the encapsulated data.

[0182] S304: The Socket kernel driver determines whether the receiver is a data forwarding service module.

[0183] On the one hand, the Socket kernel driver determines that the receiver is the data forwarding service module, and in this case continues to execute S305 to S308, and performs data transmission according to the following Socket transmission path: The Socket kernel driver uses the data cache module to cache the new data from application A, and adds the cache index value corresponding to the new data to the receiving queue of the data forwarding service module in the user space, and notifies the data forwarding service module that new data has arrived. This sending operation requires data copying.

[0184] On the other hand, the Socket kernel driver determines that the receiver is not the data forwarding service module, and in this case, continues to execute S309, that is, the Socket kernel driver determines whether the sender is the data forwarding service module. In the case where the Socket kernel driver determines that the sender is the data forwarding service module and the receiver is application B, data transmission is performed according to the following Socket transmission path: the data forwarding service module calls the Socket kernel driver, writes the cache index value corresponding to the cache area for storing new data into the receiving queue of application B, and notifies application B to receive new data.

[0185] S309: The Socket kernel driver determines whether the sender is a data forwarding service module. If the Socket kernel driver determines that the sender is a data forwarding service module, no data copy is required for this sending operation, and S310 and S307-S308 are continued to be executed, and data transmission is performed according to the following Socket transmission path: the data forwarding service module calls the Socket kernel driver to notify application B to receive data. In addition, if the Socket kernel driver determines that the sender is not a data forwarding service module, S311 is continued to be executed, that is, the Socket kernel driver returns a message of data transmission failure to the user space.

[0186] The following describes the first sending process of transmitting data based on the Socket mechanism provided by the embodiment of the present application:

[0187] In the first sending process, application A is the sender and the data forwarding service module is the receiver. Application A sends first data, and the first data includes data related to the first service. The following is an exemplary description in combination with S301-S308.

[0188] First, the application A in the user space encapsulates the data to be sent into the first msg structure according to the BSD specification, calls the Socket kernel driver in the kernel space, and sends the first msg structure to the kernel space. The Socket kernel driver in the kernel space receives the first msg structure, and then parses the first msg structure to obtain the first data.

[0189] The Socket kernel driver determines that the first data needs to be forwarded by the data forwarding service module. The data forwarding service module enters the receiving phase. In this case, data caching is required. The data caching process involves data copying operations. The Socket kernel driver needs to copy the transmission data to the data cache module for caching. Among them, the Socket kernel driver applies for a cache area from the data cache module, and uses the cache area to cache the first data sent by application A; and the Socket kernel driver records the cache index value corresponding to the cache area into the receiving queue of the data forwarding service module.

[0190] For example, the Socket kernel driver applies for the first cache area from the data cache module, and then the Socket kernel driver copies the first data in the first msg structure sent by application A to the first cache area of ​​the data cache module, and the Socket kernel driver records the cache index value corresponding to the first cache area to the receiving queue of the data forwarding service module, and then the Socket kernel driver notifies the data forwarding service module of the arrival of new data.

[0191] It should be noted that in the present application, on the kernel space side, the first data is stored in the first cache area of ​​the data cache module; on the user space side, the corresponding cache index value of the first cache area is stored in the data forwarding service module. In other words, there is a mapping relationship between the data cache module and the data forwarding service module. In actual use, the data forwarding service module can access the first data stored in the first cache area corresponding to the cache index value in the data cache module according to the cache index value.

[0192] After the data forwarding service module receives the new data notification, the data forwarding service module can read the cache index value from the receiving queue of the data forwarding service module, and then access the first cache area corresponding to the cache index value in the data cache module of the kernel space based on the cache index value. In addition, when the data forwarding service module receives a modification / deletion instruction, the data forwarding service module can modify / delete the first data stored in the first cache area in response to the modification / deletion instruction.

[0193] The above steps S301-S308 illustrate the first sending process of the Socket transmission path from application A to the data forwarding service module. Among them, application A encapsulates the data to be sent into the first msg structure according to the BSD specification, calls the Socket interface to pass the first msg structure into the kernel space, and reaches the Socket kernel driver. Then, the Socket kernel driver applies for the first buffer area from the data cache module, and uses the first buffer area to cache the first data from application A, and records the cache index value corresponding to the first buffer area into the receiving queue of the data forwarding service module.

[0194] The following describes a second sending process for transmitting data based on the Socket mechanism provided in an embodiment of the present application:

[0195] In the second sending process, the data forwarding service module is the sender and the application B is the receiver. The data forwarding service module sends the second data, and the second data includes the cache index value. The following is an exemplary description in combination with S301-S304, S309-S310 and S307-S308.

[0196] First, the data forwarding service module reads the cache index value from the receiving queue of the data forwarding service module. The data forwarding service module can access the first cache area corresponding to the cache index value in the data cache module based on the cache index value. And, in the case where the data forwarding service module receives a modification / deletion instruction, the data forwarding service module can modify / delete the first data stored in the first cache area in response to the modification / deletion instruction.

[0197] Then, the data forwarding service module encapsulates the cache index value into the third msg structure according to the BSD specification, and then the data forwarding service module calls the Socket interface to pass the third msg structure into the kernel space to reach the Socket kernel driver.

[0198] Then, the Socket kernel driver parses the third msg structure to obtain a cache index value, and the Socket kernel driver writes the cache index value into the receiving queue of application B, and then notifies application B to receive new data.

[0199] Specifically, the Socket kernel driver determines that the data will be forwarded by the data forwarding service module. Accordingly, the Socket kernel driver parses all cache index values ​​from the msg structure sent by the data forwarding service module according to the preset specification, and records the cache index values ​​to the receiving queue of application B, and the Socket kernel driver notifies application B that new data has arrived, that is, the Socket kernel driver notifies application B to receive new data. This notification process does not involve data copying operations.

[0200] The above steps S301-S304 and S309-S3010 and S307-S3008 illustrate the sending process of the Socket transmission path from the data forwarding service module to the application B. Through the present application scheme, the data forwarding service module encapsulates the cache index value in the receiving queue into a third msg structure according to the BSD specification, and calls the Socket interface to pass the third msg structure into the kernel space. Among them, the third msg structure passes through the Socket interface and reaches the Socket kernel driver in the kernel space. The Socket kernel driver parses the cache index value from the third msg structure, and accesses the cache area corresponding to the cache index value in the data cache module based on the cache index value, writes the cache index value into the receiving queue of application B, and notifies application B to receive data.

[0201] In addition, there is also a situation where the data transmission of S311 fails. Specifically, the Socket kernel driver determines that the identity of the data forwarding service module is neither a receiver nor a sender, and determines this data transmission as an abnormal transmission and does not respond. In some embodiments, the Socket kernel driver returns an EINVAL error code to the user space. Among them, the EINVAL error code is used to indicate that the data does not support forwarding or the data transmission fails.

[0202] Figure 7 A schematic diagram of a process for receiving data based on a Socket mechanism provided in an embodiment of the present application is shown.

[0203] S401-S402: The receiver calls the Socket receiving interface to transfer the msg structure used to receive data to the Socket kernel driver in the kernel space.

[0204] The receiver may be a data forwarding service module or application B.

[0205] In some embodiments, the receiver is a data forwarding service module and the corresponding sender is application A.

[0206] In other embodiments, the receiver is application B, and the corresponding sender is a data forwarding service module.

[0207] S403: The Socket kernel driver writes the new data (cache index value) into the receiver's receiving queue (ie, the new data is queued) according to the blocking waiting mechanism.

[0208] S404: The socket kernel driver reads the cache index value from the receiver's receiving queue in order.

[0209] S405: The socket kernel driver determines whether the receiver is a data forwarding service module.

[0210] On the one hand, when the Socket kernel driver determines that the receiver is the data forwarding service module, no data copy is required for this receiving operation, and S406 is continued to be executed. Data transmission is performed according to the following Socket transmission path: the Socket kernel driver writes the cache index value read from the receiving queue of the data forwarding service module into the second msg structure according to the preset specification (for example, according to the BSD specification), and returns it to the data forwarding service module in the user space.

[0211] On the other hand, when the Socket kernel driver determines that the receiver is not the data forwarding service module, the receiving operation needs data copying, and S407 is continued to be executed, that is, the Socket kernel driver determines whether the sender is the data forwarding service module. Specifically, when the Socket kernel driver determines that the sender is the data forwarding service module (and the receiver is the application B), data transmission is performed according to the following Socket transmission path (see S408 and S409): the Socket kernel driver copies the data in the data cache module to the fourth msg structure in sequence according to the cache index value that has been read, and then releases the cache area of ​​the data cache module that has been read, and returns the fourth msg structure to the application B in the user space.

[0212] The following describes the first receiving process of transmitting data based on the Socket mechanism provided by the embodiment of the present application:

[0213] In the first receiving process, the data forwarding service module is the receiver, and the data forwarding service module receives the cache index value.

[0214] After the Socket kernel driver in the kernel space receives the first data sent from the user space, the Socket kernel driver caches the first data in the first data to the first cache area in the data cache module; at the same time, the Socket kernel driver writes the cache index value corresponding to the first cache area into the receiving queue of the data forwarding service module, and the Socket kernel driver sends a new data notification to the data forwarding service module.

[0215] The data forwarding service module receives the new data notification, and then the data forwarding service module calls the Socket receiving interface to transmit the second msg structure used for receiving data to the Socket kernel driver in the kernel space.

[0216] The socket kernel driver receives the second msg structure sent by the data forwarding service module. Then, the socket kernel driver sequentially parses the cache index value from the receiving queue of the data forwarding service module. The socket kernel driver determines whether the receiver is the data forwarding service module.

[0217] When the receiver is a data forwarding service module, no data copy is required for this receiving operation.

[0218] The socket kernel driver directly writes the read cache index value into the second msg structure according to a preset specification (for example, according to the BSD specification), and then returns the second msg structure to the data forwarding service module in the user space.

[0219] It should be noted that the data forwarding service module can obtain the cache index value list through the second msg structure.

[0220] The following describes the second receiving process of transmitting data based on the Socket mechanism provided in the embodiment of the present application:

[0221] In the second receiving process, the sender is the data forwarding service module, and the receiver is the application B. The application B receives the first data. The following is an explanation in combination with S401-S404 and S407-S409.

[0222] First, the data forwarding service module in the user space receives a new data notification, and then reads the data from the receiving queue of the data forwarding service module in sequence and parses it to obtain a cache index value.

[0223] In some embodiments, if the data forwarding service module receives a modification instruction and the modification instruction is bound to the cache index value 1, the data forwarding service module can access the cache area 1 corresponding to the cache index value 1 in the data cache module based on the cache index value 1, and modify the business data stored in the cache area 1 according to the modification instruction.

[0224] In other embodiments, if the data forwarding service module receives a deletion instruction and the deletion instruction is bound to cache index value 2, the data forwarding service module can access cache area 2 corresponding to cache index value 2 in the data cache module based on cache index value 2, and delete the business data stored in cache area 2 according to the deletion instruction.

[0225] Then, the data forwarding service module encapsulates the cache index value into the third msg structure, and sends the third msg structure to the Socket kernel driver in the kernel space.

[0226] After the Socket kernel driver in the kernel space receives the data sent by the user space, the Socket kernel driver parses the third msg structure to obtain a cache index value.

[0227] Then, the Socket kernel driver writes the cache index value into the receiving queue of application B according to the blocking waiting mechanism, and the Socket kernel driver sends a new data notification to application B.

[0228] Application B receives the new data notification, and then application B calls the Socket receiving interface to transmit the fourth msg structure used to receive data to the Socket kernel driver in the kernel space.

[0229] The socket kernel driver receives the fourth msg structure sent by application B. Then, the socket kernel driver sequentially parses the cache index value from the receiving queue of application B. The socket kernel driver determines whether the sender is a data forwarding service module.

[0230] In the case where the sender is a data forwarding service module, this receiving operation requires data copying.

[0231] The socket kernel driver accesses the data cache module according to the read cache index value, copies the data stored in the cache area corresponding to the cache index value to the fourth msg structure, then releases the accessed cache area of ​​the data cache module, and returns the fourth msg structure to the application B in the user space.

[0232] Therefore, application B can obtain the real business data through the fourth msg structure.

[0233] In addition, there is also a situation where the data transmission of S410 fails. Specifically, after the Socket kernel driver in the kernel space receives the data sent by the user space, the Socket kernel driver determines that the identity of the data forwarding service module is neither the receiver nor the sender, and determines this data transmission as an abnormal transmission and does not respond. In some embodiments, the Socket kernel driver returns an EINVAL error code to the user space. Among them, the EINVAL error code is used to indicate that the data sent by the user space does not support forwarding and the data transmission fails.

[0234] The Socket-based data transmission method provided by the embodiment of the present application only requires two data copies, which is less than the four data copies required by the related art. In addition, compared with the related art that does not support modification or deletion of forwarded data in user space, the present application adds a data cache module in the kernel space to cache forwarded data, and establishes a mapping relationship between the data cache module and the data forwarding service module in the user space, so that the kernel space and the user space can share data through the data cache module, and support access and modification of the forwarded data cached in the data cache module in the kernel space in the user space, thereby achieving the purpose of modifying or deleting the forwarded data in the user space.

[0235] The above embodiments describe in detail the Socket-based data transmission method provided by the present application. The data cache module mentioned in the present application is described below.

[0236] The present application adds a data cache module in the kernel space, and the kernel space and the user space can share data through the data cache module. In the embodiment of the present application, the entire shared memory is divided into two parts, which are respectively called the node area and the data area.

[0237] For example, Figure 8 A node area and a data area are shown. The node area may be referred to as a control area.

[0238] The node area contains all control information, such as node status, data block allocation size, data block used size, node number, associated node and data block real address. The node area includes N nodes. N is a positive integer. For example, Figure 8 Eight nodes in the node area are shown, namely, node 1, node 2, ..., node 8. Each node serves as a control block.

[0239] There is a pointing relationship between the associated nodes in the node area. For example, the next node of node 1 is node 2. The next node of node 3 is node 5, and the next node of node 5 is node 6. The next node of node 4 is node 8, and the next node of node 8 is node 7.

[0240] The data area is the area where data is actually stored. In this application, it is divided into N blocks of the same size according to the set size. For example, Figure 8 Eight data blocks in the data area are shown, namely data block 1, data block 2, ..., data block 8.

[0241] It should be noted that the N data blocks in the data area correspond to the N nodes in the node area in a one-to-one manner according to the sequence numbers, so that the data blocks are separated from the control blocks.

[0242] The first cache area described in the above embodiment corresponds to a cache set, which includes a control block and a corresponding data block, and the first cache index value described in the above embodiment corresponds to the number or sequence number of the data block.

[0243] Fig. 9 The characteristic structure of any node in the node area and the schematic diagram of the corresponding data block are shown. For the convenience of description and understanding, the following exemplary description is given by taking node 1 and data block 1 as an example.

[0244] like Fig. 9 As shown, the characteristic structure of node 1 includes node state Atomic state, data block allocation size u32real_size, used size u32 used_size, current node number u32 curr_index, next node number u32next_index, occupied service quantity u32 ref_count, and data block real address void*buff_ptr.

[0245] According to the node state Atomic state, it can be determined whether node 1 is occupied. For example, node state Atomic state = 1, indicating that node 1 is occupied. Node state Atomic state = 0, indicating that node 1 is not occupied.

[0246] The data block allocation size u32 real_size refers to the size of the initially allocated available storage space of the data block 1 corresponding to the node 1. For example, u32 real_size=512MB, which means that the actual available storage area size of the data block 1 is 512MB.

[0247] The used size u32 used_size refers to the size of the storage space occupied by the data block 1 corresponding to the node 1. For example, u32 used_size=100MB means that the data block 1 has occupied 100MB of storage space.

[0248] The current node number u32 curr_index refers to the number of the current node. For example, u32 curr_index=1 means that the number of the current node is 1.

[0249] The next node number u32 next_index refers to the number of the next node of the current node. For example, u32 next_index = 2, which means that the next node of node 1 is node 2, where node 1 and node 2 are associated nodes.

[0250] The number of occupied services u32 ref_count refers to the number of services corresponding to when node 1 is occupied by one or more services. For example, u32 ref_count = 2, which means that node 1 is occupied by two services. The specific value of u32 ref_count will increase with the creation of the forwarding service and will decrease with the completion of the forwarding service. For example, if one of the two services completes data forwarding, the storage space occupied by the service will be released, and will be updated from u32 ref_count = 2 to u32ref_count = 1 accordingly.

[0251] Among them, the real address of the data block void*buff_ptr refers to the real address in data block 1 corresponding to node 1.

[0252] The embodiment of the present application proposes a shared cache management mechanism. In the embodiment of the present application, each node of the data cache module can include the following four states: idle, kernel space read and write, waiting, and user space read and write. Fig.10 During the data forwarding process, the state of each node will switch between these four states. The node state is maintained by the Socket kernel driver and the data forwarding service module.

[0253] Exemplarily, in some embodiments, during the data forwarding process, the state switching is performed in the following manner:

[0254] First, the data cache module is in an "idle" state after initialization, waiting for allocation.

[0255] Then, when the Socket kernel driver receives the data, the node state of the data cache module is updated to the "kernel space read and write" state.

[0256] Then, after the Socket kernel driver completes the data copy, the node state of the data cache module is updated to a "waiting" state. At this time, the data cache module is in a state where there is data waiting to be processed.

[0257] Then, when the data forwarding service module performs reading and writing, the node state of the data cache module is updated to the "user space reading and writing" state.

[0258] Then, after the data forwarding service module completes reading and writing, the node state of the data cache module is updated to a "waiting" or "idle" state again.

[0259] Then, when the Socket kernel driver performs reading and writing, the node state of the data cache module is updated to the "kernel space reading and writing" state again.

[0260] When all processing is completed, all occupied cache space of the data cache module is released, and the node state of the data cache module is updated to the "idle" state.

[0261] In an embodiment of the present application, based on the Socket mechanism, the original data cache sk_buff is replaced with a newly designed shared cache, namely, a data cache module (data cache), and the present application proposes a shared cache management mechanism that can efficiently handle concurrent read and write accesses between kernel space and user space, thereby reducing the number of data copies and greatly improving the efficiency of data forwarding based on the Socket mechanism.

[0262] It should be noted that, in the embodiments of the present application, "greater than" can be replaced by "greater than or equal to", "less than or equal to" can be replaced by "less than", or "greater than or equal to" can be replaced by "greater than", and "less than" can be replaced by "less than or equal to".

[0263] The various embodiments described herein may be independent solutions or may be combined according to internal logic, and all of these solutions fall within the protection scope of this application.

[0264] The above mainly describes the solution provided by the embodiment of the present application from the perspective of method steps. It is understandable that, in order to achieve the above functions, the electronic device implementing the method includes a hardware structure and / or software module corresponding to the execution of each function. Those skilled in the art should be aware that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of protection of the present application.

[0265] The embodiment of the present application can divide the functional modules of the electronic device according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other feasible division methods in actual implementation.

[0266] The present application also provides a chip, which is coupled to a memory and is used to read and execute computer programs or instructions stored in the memory to execute the methods in the above embodiments.

[0267] The present application also provides an electronic device, which includes a chip, and the chip is used to read and execute a computer program or instruction stored in a memory, so that the method in each embodiment is executed.

[0268] This embodiment also provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the Socket-based data transmission method in the above embodiment.

[0269] This embodiment also provides a computer program product, wherein the computer-readable storage medium stores program codes. When the computer program product is run on a computer, the computer executes the above-mentioned related steps to implement the Socket-based data transmission method in the above-mentioned embodiment.

[0270] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, a component or a module, and the device may include a connected processor and a memory; wherein the memory is used to store computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory so that the chip executes the Socket-based data transmission method in the above-mentioned method embodiments.

[0271] Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here.

[0272] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0273] The term "and / or" in this article is a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The symbol " / " in this article indicates that the associated objects are in an or relationship, for example, A / B means A or B.

[0274] The terms "first" and "second" in the specification and claims herein are used to distinguish different objects rather than to describe a specific order of objects. In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more than two, for example, multiple processing units refer to two or more processing units, etc.; multiple elements refer to two or more elements, etc.

[0275] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A data transmission method based on Socket, applied to electronic equipment, characterized in that: The electronic device comprises a Socket interface, a Socket kernel driver, a data cache module and a data forwarding service module, and the method comprises: The Socket kernel driver receives first data from a first application; The Socket kernel driver copies the first data to the first buffer area of ​​the data buffer module; The Socket kernel driver writes the first cache index value corresponding to the first cache area into the receiving queue of the data forwarding service module; The Socket kernel driver receives second data sent by the data forwarding service module, where the second data is obtained based on the first cache index value; The Socket kernel driver parses the first cache index value from the second data, and writes the first cache index value into a receiving queue of the second application; The Socket kernel driver copies the first data from the first cache area based on the first cache index value, and transmits the first data to the second application.

2. The method according to claim 1, characterized in that The receiving queue of the data forwarding service module includes cache index values ​​corresponding to each cache area of ​​the data cache module.

3. The method according to claim 1 or 2, characterized in that: After the Socket kernel driver receives the first data from the first application and before the Socket kernel driver copies the first data to the first buffer area of ​​the data buffer module, the method further includes: The Socket kernel driver determines that the type of the first data is a first service type; The Socket kernel driver sends an application message to the data cache module, where the application message is used to apply for a cache area to store data of the first service type; The Socket kernel driver receives a response message from the data cache module, where the response message is used to indicate that the first cache area is allocated for data of the first service type, and the response message also includes the first cache index value corresponding to the first cache area.

4. The method according to claim 3, characterized in that There is a mapping relationship between the first service type, the first cache area, and the first cache index value.

5. The method according to claim 3 or 4, characterized in that: The data of the first business type belongs to the business data collected by the second application request.

6. The method according to any one of claims 1 to 5, characterized in that Before the Socket kernel driver receives the first data from the first application, the method further includes: In response to a user operation, the first application executes a first service and generates first data; The first application calls the Socket interface to transmit the first data to the Socket kernel driver.

7. The method according to claim 6, characterized in that The first application calls the Socket interface to transmit the first data to the Socket kernel driver, including: The first application calls the Socket interface, encapsulates the first data into a first message structure according to a preset specification, and transmits the first message structure to the Socket kernel driver.

8. The method according to any one of claims 1 to 7, characterized in that After the Socket kernel driver writes the first cache index value corresponding to the first cache area into the receiving queue of the data forwarding service module, the method further includes: The Socket kernel driver sequentially reads cache index values ​​from the receiving queue of the data forwarding service module, encapsulates the read cache index values ​​into a second message structure, and transmits the second message structure to the data forwarding service module.

9. The method according to claim 8, characterized in that The method further comprises: The data forwarding service module receives a data modification instruction; In response to the data modification instruction, the data forwarding service module accesses a first cache area in the data cache module based on the first cache index value, and modifies the data in the first cache area based on the data modification instruction.

10. The method according to any one of claims 1 to 9, characterized in that Before the Socket kernel driver receives the second data sent by the data forwarding service module, the method further includes: The data forwarding service module calls the Socket interface, encapsulates the first cache index value into a third message structure according to a preset specification, and transmits the third message structure as the second data to the Socket kernel driver.

11. The method according to any one of claims 1 to 10, characterized in that The method further comprises: In a case where the Socket kernel driver writes the first cache index value into the receiving queue of the second application, the Socket kernel driver sends a new data notification to the second application; The Socket kernel driver receives a fourth message structure sent by the second application for receiving new data.

12. The method according to claim 11, characterized in that The Socket kernel driver copies the first data from the first buffer area based on the first buffer index value, and transmits the first data to the second application, including: The Socket kernel driver accesses the first buffer area based on the first buffer index value, and copies the first data in the first buffer area to the fourth message structure; The Socket kernel driver calls the Socket interface to transmit the fourth message structure to the second application.

13. The method according to any one of claims 1 to 12, characterized in that The data cache module includes a control area and a data area, the control area includes N control blocks, the data area includes N data blocks, the N control blocks correspond to the N data blocks one by one, and some of the N control blocks have an associated relationship; The first cache area corresponds to a cache set, the cache set includes a control block and a corresponding data block, and the first cache index value corresponds to the serial number of the data block.

14. The method according to any one of claims 1 to 13, characterized in that The state of the data cache module is one of the following states: idle state, kernel space read-write state, waiting state, user space read-write state; The method further includes: the Socket kernel driver controls the data cache module to switch states between the various states.

15. The method according to claim 14, characterized in that The Socket kernel driver controls the data cache module to switch between the various states, including: The data cache module is in the idle state after initialization, waiting for allocation; After the Socket kernel driver copies the data to the data cache module, the Socket kernel driver updates the state of the data cache module to the waiting state; When the data forwarding service module reads and writes the data cache module, the Socket kernel driver updates the state of the data cache module to the user space read and write state; After the data forwarding service module completes reading and writing to the data cache module, the Socket kernel driver updates the state of the data cache module to a waiting or idle state again; When the Socket kernel driver copies data from the data cache module, the state of the data cache module is updated to the kernel space read-write state again; After the Socket kernel driver finishes copying the data from the data cache module, the occupied cache area in the data cache module is released, and the state of the data cache module is updated to an idle state.

16. An electronic device, characterized in that: The electronic device includes: one or more processors, and a memory; The memory is coupled to the one or more processors, and the memory is used to store computer program codes, wherein the computer program codes include computer instructions, and the one or more processors call the computer instructions to enable the electronic device to perform the method as claimed in any one of claims 1 to 15.

17. A chip system, characterized in that: The chip system is applied to an electronic device, and the chip system includes one or more processors, and the one or more processors are used to call computer instructions so that the electronic device executes any one of the methods described in claims 1 to 15.

18. A computer-readable storage medium, characterized in that: The computer-readable storage medium comprises instructions, which, when executed on an electronic device, cause the electronic device to perform the method as claimed in any one of claims 1 to 15.

Citation Information

Patent Citations

  • Distributed system supported transparent interprocess communication system and method

    CN105426260A

  • NFS server, data writing method and device thereof and storage medium

    CN111881104A

  • Data storage method and device, equipment and medium

    CN112346647A

  • Data transmission method and device, electronic equipment and medium

    CN114968535A

  • Inter-process data transmission method, process, electronic equipment and storage medium

    CN115033405A