Data interaction method and device based on shared memory, virtual electronic equipment and storage medium
By setting a shared descriptor ring between the terminal devices on the PCIe link, the problem of lacking complete data communication channels during the data transmission process of EP in the data transmission process is solved. Data transmission requirements.
Patent Information
- Application Number
- CN202411230211.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2025-01-28
AI Technical Summary
In the prior art, the terminal device EP on the PCIe link lacks a complete and continuous data exchange path during data transmission, and only transports data through DMA, and the transferred data cannot be read directly by the upper layer application through the general network interface function. .
By setting a shared descriptor ring between the first virtual network equipment and the second virtual network equipment, the packaging, sending and receiving the data packets. Specific steps include detection of packet requests, packaging data packets, obtaining the tail value of the shared descriptor ring, update the end value and initiate interruption to achieve data transmission of direct memory access methods.
The function of data transmission through the PCIe slot and connection cable is implemented. No need to use network cards and other peripherals to increase the stability of data transmission and save the cost of hardware configuration. The one -way data transmission rate is about 1.5Gbps, which meets that it is not necessary or not needed or not required Data transmission requirements cannot be used in the network card environment.
Smart Images

Figure CN119376969A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to data processing technology, and in particular to a data interaction method and device based on shared memory, a virtual electronic device, and a storage medium. Background Art
[0002] The high-speed serial computer expansion bus standard (Peripheral Component InterConnect Express, PCIe) is an upgraded version of the Peripheral Component Interconnect standard (Peripheral Component InterConnect, PCI), which is mainly an optimization of the implementation method generated by the upgrade of the physical link. For example, the access mechanism of the configuration space is not only compatible with the configuration space access mechanism of PCI, but also provides an enhanced configuration space access mechanism. The topology of PCIe contains at least a root complex (RC) and an endpoint (EP). As a terminal device on the PCIe link, EP can interact with RC to realize data transmission. It can initiate transmission as a master end, and can also complete related services as a receiving end. In terms of implementation, EP needs to have a PCIe interface and a corresponding driver so that it can communicate with the PCIe bus. During the data transmission process, EP needs to send data to the PCIe bus or receive data from the PCIe bus. In addition, although data communication between RC and EP can be completed with the help of DMA, there is no complete and continuous data exchange path between them. Data is only transferred through direct memory access (DMA), and the transferred data cannot be directly read by most upper-level applications through general network interface functions. Summary of the invention
[0003] The present disclosure provides a data interaction method and device based on shared memory, a virtual electronic device, and a storage medium to at least solve the above technical problems existing in the prior art.
[0004] According to a first aspect of the present disclosure, a shared memory-based data interaction method is provided, which is applied to a first virtual network device, wherein the first virtual network device is communicatively connected to a second virtual network device via a peripheral component interconnect interface, and a shared descriptor ring is provided between the first virtual network device and the second virtual network device; the method comprises:
[0005] In response to detecting a packet sending request from a first application to a first protocol stack of the first virtual network device, calling a first packet sending function;
[0006] Based on the first packet sending function, encapsulate the data to be sent into a first data packet; the first data packet at least includes the destination MAC address and cyclic redundancy check data information;
[0007] Obtain a tail value corresponding to the shared descriptor ring for sending the first data packet, update the tail value, and initiate an interrupt in a direct memory access mode of the first data packet.
[0008] In some executable embodiments, the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring, and the method further comprises:
[0009] In response to the occurrence of a set event, the tail value of the shared descriptor ring is detected in a polling manner. If the tail value changes, the physical address of the to-be-received message in the second virtual network device is searched in the descriptor corresponding to the changed tail value, and the message is read from the physical address to the memory space pointed to by the receive data packet ring in a direct memory access manner.
[0010] In some executable embodiments, before calling the first packet sending function, the method further includes:
[0011] Determine whether the difference between the head and tail pointers of the shared descriptor ring is the maximum value of the descriptor ring. If it is the maximum value of the descriptor ring, the data on the second virtual network device side is full, and the sending of the first data packet is stopped. If it is not the maximum value of the descriptor ring, the sending of the first data packet is started.
[0012] In some executable embodiments, the tail value changes include:
[0013] It is determined whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value is changed; if there is no difference, the tail value is not changed.
[0014] In some executable embodiments, the method further includes:
[0015] An address storage space is configured for the first physical device, and the address storage space is mapped to a data receiving space.
[0016] In some executable embodiments, the second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring;
[0017] The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
[0018] In some executable embodiments, before responding to the occurrence of a setting event, the method further includes:
[0019] In response to detecting an electrical signal change of the PCIe slot, calling a first driver application of the first virtual network device, and configuring a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot;
[0020] A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
[0021] In some executable embodiments, after configuring the general network device, the method further includes:
[0022] A MAC address is configured for the universal network device.
[0023] In some executable embodiments, the step of responding to a setting event occurring includes:
[0024] In response to the arrival of the detection cycle of the timer, or the arrival of the processing time of the delay queue.
[0025] According to a second aspect of the present disclosure, a shared memory-based data interaction method is provided, which is applied to a first virtual network device, wherein the first virtual network device is communicatively connected to a second virtual network device via a peripheral component interconnect interface, and a shared descriptor ring is provided between the first virtual network device and the second virtual network device; the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring; the method comprises:
[0026] In response to the occurrence of a set event, the tail value of the shared descriptor ring is detected in a polling manner. If the tail value changes, the physical address of the to-be-received message in the second virtual network device is searched in the descriptor corresponding to the changed tail value, and the message is read from the physical address to the memory space pointed to by the receive data packet ring in a direct memory access manner.
[0027] In some executable embodiments, the tail value changes include:
[0028] It is determined whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value is changed; if there is no difference, the tail value is not changed.
[0029] In some executable embodiments, the method further includes:
[0030] An address storage space is configured for the first physical device, and the address storage space is mapped to a data receiving space.
[0031] In some executable embodiments, the second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring;
[0032] The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
[0033] In some executable embodiments, before responding to the occurrence of a setting event, the method further includes:
[0034] In response to detecting an electrical signal change of the PCIe slot, calling a first driver application of the first virtual network device, and configuring a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot;
[0035] A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
[0036] According to a third aspect of the present disclosure, a data interaction device based on a shared memory is provided, which is applied to a first virtual network device, wherein the first virtual network device is communicatively connected with a second virtual network device through a peripheral component interconnect interface, and a shared descriptor ring is set between the first virtual network device and the second virtual network device; the device comprises:
[0037] A calling unit, configured to call a first packet sending function in response to detecting a packet sending request of a first application for a first protocol stack of the first virtual network device;
[0038] An encapsulation unit, configured to encapsulate the data to be sent into a first data packet based on the first packet sending function; the first data packet at least includes information of a destination MAC address and cyclic redundancy check data;
[0039] The processing unit is used to obtain a tail value corresponding to the shared descriptor ring for sending the first data packet, update the tail value, and initiate an interrupt of a direct memory access mode of the first data packet.
[0040] In some executable embodiments, the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring, and the apparatus further comprises:
[0041] A detection unit, configured to detect a tail value of a shared descriptor in a polling manner in response to occurrence of a detection event;
[0042] The processing unit is also used to search the physical address of the to-be-received message in the second virtual network device in the descriptor corresponding to the changed tail value when the tail value changes, and read the message from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner.
[0043] In some executable embodiments, the device further includes:
[0044] The judging unit is used to judge whether the difference between the head and tail pointers of the shared descriptor ring is the maximum value of the descriptor ring. If it is the maximum value of the descriptor ring, the data on the second virtual network device side is full, and the sending of the first data packet is stopped. If it is not the maximum value of the descriptor ring, the sending of the first data packet is started.
[0045] In some executable embodiments, the determining unit is further configured to:
[0046] It is determined whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value is changed; if there is no difference, the tail value is not changed.
[0047] In some executable embodiments, the device further includes:
[0048] The first configuration unit is used to configure an address storage space for the first physical device and map the address storage space into a data receiving space.
[0049] In some executable embodiments, the second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring;
[0050] The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
[0051] In some executable embodiments, the device further includes:
[0052] A second configuration unit is configured to call a first driver application of the first virtual network device in response to detecting an electrical signal change of the PCIe slot, and configure a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot;
[0053] A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
[0054] In some executable embodiments, the second configuration unit is further used to:
[0055] A MAC address is configured for the universal network device.
[0056] According to a fourth aspect of the present disclosure, a data interaction device based on shared memory is provided, which is applied to a first virtual network device, wherein the first virtual network device is communicatively connected with a second virtual network device through a peripheral component interconnect interface, and a shared descriptor ring is provided between the first virtual network device and the second virtual network device; the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring; the device comprises:
[0057] A detection unit, configured to detect a tail value of a shared descriptor in a polling manner in response to occurrence of a detection event;
[0058] The processing unit is used to search the physical address of the message to be received in the second virtual network device in the descriptor corresponding to the changed tail value when the tail value changes, and read the message from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner.
[0059] In some executable embodiments, the device further includes:
[0060] The judging unit is used to judge whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value changes; if there is no difference, the tail value does not change.
[0061] In some executable embodiments, the device further includes:
[0062] The first configuration unit is used to configure an address storage space for the first physical device and map the address storage space into a data receiving space.
[0063] In some executable embodiments, the second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring;
[0064] The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
[0065] In some executable embodiments, the device further includes:
[0066] A second configuration unit is configured to call a first driver application of the first virtual network device in response to detecting an electrical signal change of the PCIe slot, and configure a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot;
[0067] A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
[0068] According to a fifth aspect of the present disclosure, a virtual electronic device is provided, comprising:
[0069] at least one processor; and
[0070] a memory communicatively connected to the at least one processor; wherein,
[0071] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the steps of the shared memory-based data interaction method.
[0072] According to a sixth aspect of the present disclosure, a non-temporary computer-readable storage medium is provided, and when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the steps of the shared memory-based data interaction method.
[0073] The data interaction method and device based on shared memory, virtual electronic device, and storage medium disclosed in the present invention can register RC and EP as virtual network cards through network driver technology, thereby realizing the function of communicating through PCIe slots and with the help of PCIe connection lines, without the need for peripherals such as network cards to realize data message transmission, which not only increases the stability of data transmission, but also saves hardware configuration costs. The present invention accelerates the transmission speed of data messages by means of descriptor rings and polling technical means, and its one-way data transmission rate is about 1.5Gbps, which greatly meets the data transmission requirements in an environment where a network card is not needed or cannot be used, and can respond to data call requests from upper-layer applications, meeting the data interaction function with the application layer.
[0074] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:
[0076] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.
[0077] Figure 1 A schematic diagram of a process flow of a data interaction method based on shared memory according to an embodiment of the present disclosure is shown;
[0078] Figure 2 A schematic diagram of a process flow of a data interaction method based on shared memory according to an embodiment of the present disclosure is shown;
[0079] Figure 3 It is a schematic diagram of the hardware connection structure of RC and EP in the embodiment of the present disclosure;
[0080] Figure 4 A schematic diagram of data message interaction between RC and EP in an embodiment of the present disclosure;
[0081] Figure 5 A schematic diagram of a process of EP receiving a data message according to an embodiment of the present disclosure is shown;
[0082] Figure 6 A schematic diagram showing a process of EP sending a data message according to an embodiment of the present disclosure is shown;
[0083] Figure 7 A schematic diagram of a process of changing the size of a descriptor ring according to an embodiment of the present disclosure is shown;
[0084] Figure 8 A schematic diagram showing the composition structure of a data interaction device based on a shared memory according to an embodiment of the present disclosure is shown;
[0085] Fig. 9 A schematic diagram showing the composition structure of a data interaction device based on a shared memory according to an embodiment of the present disclosure is shown;
[0086] Fig.10 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0087] In order to make the purpose, features, and advantages of the present disclosure more obvious and easy to understand, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0088] Figure 1 A flow chart of a data interaction method based on shared memory according to an embodiment of the present disclosure is shown. Figure 1 As shown, the data interaction method based on shared memory of the embodiment of the present disclosure is applied to the first virtual network device, the first virtual network device is connected to the second virtual network device through a PCIe connection line, and a shared descriptor ring is set between the first virtual network device and the second virtual network device. The data interaction method based on shared memory of the embodiment of the present disclosure includes the following processing steps:
[0089] Step 101: In response to detecting a packet sending request from a first application to a first protocol stack of the first virtual network device, calling a first packet sending function.
[0090] In the disclosed embodiment, the first virtual network device may be an EP, and correspondingly, the first protocol stack is a general network protocol stack, which enables the electronic device inserted into the PCIe slot to have a communication function, so that the electronic device can communicate data with the opposite end device such as RC through the PCIe slot. The second virtual network device may be an RC.
[0091] The first application includes various applications installed in the electronic device, such as instant messaging applications, text applications that require network authentication and information interaction, etc. The first packet sending function includes a message sending function, and functions such as rx_poll, which mainly receive messages and release memory space for messages that have been received.
[0092] In the disclosed embodiment, DMA packet transmission is mainly performed between EP and RC based on the New Application Programming Interface (NAPI), and NAPI adopts a combination of interrupt and polling to transmit data packets. The disclosed embodiment introduces the New Application Programming Interface (NAPI) mechanism to switch the virtual network card packet receiving mode to the poll mode, thereby improving the receiving and sending performance of network communication.
[0093] In an embodiment of the present disclosure, before executing data packet transmission, in response to detecting an electrical signal change in a PCIe slot, a first driver application of a first virtual network device is called, and a first physical device is configured for the first virtual network device based on an identification table of a PCI device; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot; a general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device. After configuring the general network device, a MAC address is configured for the general network device. The embodiment of the present disclosure is different from a general network card, and uses a shared descriptor ring and a timer / queue polling packet receiving method, and thereby derives that both EP and RC synchronously update the bit difference between the packet receiving pointer and the packet sending pointer in the shared descriptor to determine whether data transmission is required.
[0094] Step 102: based on the first packet sending function, encapsulate the data to be sent into a first data packet.
[0095] In the disclosed embodiment, the first data packet at least includes the destination MAC address and cyclic redundancy check (CRC) data information. The data packet is encapsulated in a message frame format, and the data packet at least includes information such as a packet header, a source address, a destination address, and CRC data.
[0096] Step 103: obtain a tail value corresponding to the shared descriptor ring for sending the first data packet, update the tail value, and initiate an interruption of a direct memory access mode of the first data packet.
[0097] Specifically, when transmitting data from the upper layer protocol, the EP protocol stack sends a message, triggers the packet sending process, calls the EP virtual network card device driver sending interface, and puts the network port on the EP side in the link state. Wait for interruption. In this interface, the EP virtual network card device first determines whether the receiving queue on the RC side is full through the shared descriptor of the PCIe base address register (BAR) space. The judgment condition for whether the receiving queue on the RC side is full or not is whether the difference between the first pointer of the shared descriptor ring is the descriptor ring value. If the difference is the ring value, that is, the queue is full, the packet sending is stopped; if the difference is not the ring value, that is, the queue is not full, it can be sent, and then under the condition that it can be sent, the data packet transmitted by the upper layer protocol stack is handed over to the DMA for sending, and finally continues to wait for the upper layer protocol stack to call the sending interface. Specifically, the EP end completes the destination MAC address filling and CRC check calculation. The DMA writes the data to be sent by the EP end to the memory pointed to by the receiving queue ring on the RC end, where the memory address stored in the shared descriptor ring of the BAR space is used by the EP to write through DMA.
[0098] The disclosed embodiment registers RC and EP as virtual network cards through network driver technology, thereby realizing the function of communicating through the PCIe slot and with the help of PCIe connection lines. The disclosed embodiment configures a protocol configuration file for the electronic device, so that the EP does not need to rely on peripherals such as a network card to realize the transmission of data packets, and can provide data transmission support for related applications in the electronic device.
[0099] In the disclosed embodiment, in response to the occurrence of a setting event, the tail value of the shared descriptor ring is detected in a polling manner. If the tail value changes, the physical address of the message to be received in the second virtual network device is searched in the descriptor corresponding to the changed tail value, and the message is read from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner. Here, the setting event occurrence includes the arrival of the detection cycle of the timer, or the arrival of the processing time of the delay queue. The physical address is the storage address of the second virtual network device, i.e., RC, which stores the message in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and filled in the corresponding descriptor in the shared descriptor ring.
[0100] Specifically, after the EP as a virtual network card device is ready, it will enter the polling detection and packet receiving process. During the packet receiving process, the condition for judging whether there are data packets to be received is based on the difference between the head and tail pointers of the shared descriptor ring of the PCIe BAR space, that is, the difference between the send and receive packet pointers. If there is no difference between the two, there is no data packet to be received by the EP, otherwise it means that the RC has a data packet to send to the EP; then jump from polling to DMA read operation to receive the data packet, until the pointer difference when entering polling is zero, that is, the data packet pre-sent by the RC is transmitted to the EP receiving end at one time, and finally enter the next polling after the DMA read operation is completed.
[0101] Figure 2 A flow chart of a data interaction method based on shared memory according to an embodiment of the present disclosure is shown. Figure 2 As shown, the data interaction method based on shared memory in the embodiment of the present disclosure is applied to the first virtual network device, the first virtual network device is connected to the second virtual network device through a PCIe interface, a shared descriptor ring is provided between the first virtual network device and the second virtual network device; the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring. In the embodiment of the present disclosure, the first virtual network device may be an EP, and correspondingly, the first protocol stack is a general network protocol stack, which enables the electronic device inserted into the PCIe slot to have a communication function, so that the electronic device can communicate data with the opposite device such as RC through the PCIe slot. The second virtual network device may be an RC. The data interaction method based on shared memory in the embodiment of the present disclosure includes the following processing steps:
[0102] Step 201 : In response to a setting event occurring, detecting the tail value of a shared descriptor ring in a polling manner.
[0103] In the disclosed embodiment, the setting event occurrence includes the arrival of a detection period of a timer, or the arrival of a processing time of a delay queue.
[0104] Step 202, the tail value changes, the physical address of the message to be received in the second virtual network device is searched in the descriptor corresponding to the changed tail value, and the message is read from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner.
[0105] In the disclosed embodiment, the physical address is the storage address of the second virtual network device, namely RC, storing the message in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and filled in the corresponding descriptor in the shared descriptor ring.
[0106] After the EP as a virtual network card device is ready, it will enter the polling detection and packet receiving process. During the packet receiving process, the condition for judging whether there are data packets to be received is based on the difference between the head and tail pointers of the shared descriptor ring of the PCIe BAR space, that is, the difference between the send and receive packet pointers. If there is no difference between the two, there is no data packet to be received by the EP, otherwise it means that the RC has a data packet to send to the EP; then jump from polling to DMA read operation to receive the data packet, until the pointer difference when entering polling is zero, that is, the data packet pre-sent by the RC is transmitted to the EP receiving end at one time, and finally enter the next polling after the DMA read operation is completed.
[0107] Those skilled in the art should understand that, as the relevant configuration of the EP and the setting of the storage address are the same as those in the aforementioned embodiment, the details are not repeated here.
[0108] The essence of the technical solution of the embodiment of the present disclosure is further illustrated below through specific examples.
[0109] The technical solution of the disclosed embodiment is different from the physical network card device. It can initialize the EP board as a virtual network card and operate the virtual network card device through the general network card operation method. It uses the timer / delay queue as the entrance for receiving network packets, and checks the queue status of both parties through the shared descriptor ring. The ring synchronization modification mechanism of both parties under the high degree of coupling of the shared descriptor ring greatly solves the problem that applications on the two machines cannot exchange information when there is no network card device.
[0110] Figure 3 FIG. 1 is a schematic diagram of the hardware support structure of RC and EP of the embodiment of the present disclosure, such as Figure 3As shown, the hardware support structure of the embodiment of the present disclosure mainly includes a CPU, a memory and a PCIe slot, wherein the CPU is used to control the MEM memory module and the PCIe slot, especially to provide the electronic device connected through the PCIe slot with the configuration information and driver files of RC or EP, so that it can be enabled with RC and / or EP, and establish a communication link based on the PCIe slot. The CPU includes but is not limited to server chips and embedded series CPUs, etc.
[0111] After the electronic device is inserted into the PCIe slot, it is enabled as a PCI device. Specifically, the electronic device registers pdev for the EP through the identification list (id_table) of the PCI device, and applies for a general network device (netdev) for pdev, associates the general network device netdev with the PCI device pdev, and at the same time, fills in the MAC address of the network device, sets the maximum transmission unit (Maximum Transmission Unit, MTU) of the network device; and maps the BAR space of the PCI device pdev, taking BAR0 and BAR2 as the sending and receiving queues of RC respectively. EP can also access these two queues, preparing for the subsequent design of the queues shared by the EP and RC into a shared descriptor ring.
[0112] In the PCIe architecture, EP and RC are the two ends of the PCIe link connection relationship and can interact through the PCIe bus. When two boards are connected through a PCIe cross cable, they can be physically connected to the same PCIe bus. Under this condition, one of the boards is set as an EP node to achieve interaction between the two boards. On this basis, the EP is registered as a network device. At this time, the EP will have the characteristics of a network card and can be used for information interaction and upper-layer application calls.
[0113] Figure 4 Schematic diagram of data message interaction between RC and EP in the embodiment of the present disclosure, such as Figure 4As shown, the main difference between the embodiment of the present disclosure and other technical solutions is that in the entire data transmission processing flow, unlike general network card data transmission, it uses the concept of shared descriptors and timer / queue polling for packet reception, and derives that both EP and RC synchronously update the bit difference between the packet receiving pointer and the packet sending pointer in the shared descriptor to determine whether data transmission is required. Since the descriptor ring required in the data transmission of EP and RC requires a shared descriptor ring in addition to their own descriptor rings, and the shared descriptor ring stores the physical addresses required for DMA transmission, the modification of the ring needs to be supported in the data processing flow to be suitable for large traffic environments. The ring modification method in general network cards is not applicable to the technical solution of the embodiment of the present disclosure. The ring in the embodiment of the present disclosure refers to the size of the descriptor rings of EP and RC, that is, the number of descriptors that can be stored in the descriptor ring, so a new ring modification method is proposed, that is, to determine whether to modify the ring and synchronize it through timer / delay queue polling.
[0114] like Figure 4 As shown in FIG. 1 , the data transmission process on the EP side includes the EP packet receiving implementation process. The DMA reads the data pointed to by the RC end send queue ring directly into the memory pointed to by the EP receive queue ring, where the data address stored in the BAR space shared descriptor ring is used by the EP to read using DMA.
[0115] During the EP packet sending process, DMA writes the data to be sent by the EP end into the memory pointed to by the receiving queue ring of the RC end, where the memory address stored in the BAR space shared descriptor ring is used by the EP to write using DMA.
[0116] Figure 5 FIG. 4 shows a flow chart of an EP receiving a data message according to an embodiment of the present disclosure, such as Figure 5 As shown, after the virtual network card device EP of the embodiment of the present disclosure is ready, it enters the polling detection and packet receiving process. During the packet receiving process, the condition for judging whether there are data packets to be received is whether the difference between the head and tail pointers of the shared descriptor ring of the PCIe BAR space is 0, that is, judging whether the difference between the send and receive packet pointers is 0. If there is no difference between the two, that is, the difference is 0, no data packet can be received, otherwise it means that there is a data packet to be sent on the RC side; then, from the physical storage address of the data packet obtained by polling, jump to the DMA read operation to receive the data packet, until the difference between the head and tail pointers of the shared descriptor ring is 0, that is, the data packet pre-sent by the RC is transmitted to the EP receiving end at one time, and finally, after the DMA read operation is completed, enter the next polling.
[0117] Figure 6 FIG. 4 shows a schematic diagram of a process of sending a data message by an EP according to an embodiment of the present disclosure, such as Figure 6As shown in the figure, when data needs to be transmitted from the upper layer protocol, the EP virtual network card device driver sending interface will be called. In this interface, the EP virtual network card device first determines whether the receiving queue of the other party is full through the shared descriptor of the PCIe BAR space. The judgment condition is whether the difference of the first pointer of the shared descriptor ring is the ring value. If the difference is the ring value, that is, the queue is full, the packet transmission is stopped; if the difference is not the ring value, that is, the queue is not full, it can be sent, and then under the condition that it can be sent, the data packet transmitted by the upper layer protocol stack is handed over to the DMA for transmission, and finally continues to wait for the upper layer protocol stack to call the sending interface. .
[0118] Figure 7 A schematic diagram of the process of changing the size of the descriptor ring according to an embodiment of the present disclosure is shown. Figure 7 As shown in the figure, two variables are set in the BAR space, one variable is used for synchronous modification message communication, and the other variable is used to record the modified ring value size. If the EP actively modifies the ring size, it can directly call the general interface for modifying the ring, and set the BAR space synchronous modification message variable to 1 and save the modified ring value in the variable for recording the ring value. The synchronous modification message variable is set to 1 to indicate that the RC needs to synchronously modify the ring size; if the RC actively modifies the ring size, after the EP polls the BAR space synchronous modification message variable and finds that its value has changed, it calls the corresponding interface to modify it to the same size ring value as the RC.
[0119] Figure 8 The schematic diagram of the structure of the data interaction device based on shared memory in the embodiment of the present disclosure is shown as follows: Figure 8 As shown, the data interaction device based on shared memory of the embodiment of the present disclosure is applied to a first virtual network device, the first virtual network device is connected to a second virtual network device through a peripheral component interconnect interface, and a shared descriptor ring is set between the first virtual network device and the second virtual network device; the device includes:
[0120] The calling unit 80 is configured to call a first packet sending function in response to detecting a packet sending request of the first application for the first protocol stack of the first virtual network device;
[0121] The encapsulation unit 81 is used to encapsulate the data to be sent into a first data packet based on the first packet sending function; the first data packet at least includes the destination MAC address and cyclic redundancy check data information;
[0122] The processing unit 82 is used to obtain a tail value corresponding to the shared descriptor ring for sending the first data packet, update the tail value, and initiate an interrupt of a direct memory access mode of the first data packet.
[0123] In some executable embodiments, the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring. Figure 8 The data interaction device based on shared memory shown in the figure also includes:
[0124] Detection unit ( Figure 8 (not shown), for detecting the tail value of the shared descriptor in a polling manner in response to the occurrence of a detection event;
[0125] The processing unit 82 is also used to search the physical address of the to-be-received message in the second virtual network device in the descriptor corresponding to the changed tail value when the tail value changes, and read the message from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner.
[0126] exist Figure 8 Based on the data interaction device based on shared memory shown, the device also includes:
[0127] Judgment Unit ( Figure 8 (not shown) is used to determine whether the difference between the head and tail pointers of the shared descriptor ring is the maximum value of the descriptor ring. If it is the maximum value of the descriptor ring, the data on the second virtual network device side is full, and the sending of the first data packet is stopped. If it is not the maximum value of the descriptor ring, the sending of the first data packet is started.
[0128] In some executable embodiments, the determining unit is further configured to:
[0129] It is determined whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value is changed; if there is no difference, the tail value is not changed.
[0130] exist Figure 8 Based on the data interaction device based on shared memory shown, the device also includes:
[0131] The first configuration unit ( Figure 8 ), which is used to configure an address storage space for the first physical device and map the address storage space into a data receiving space.
[0132] In some executable embodiments, the second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring;
[0133] The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
[0134] In some executable embodiments, the device further includes:
[0135] The second configuration unit ( Figure 8 (not shown), for in response to detecting an electrical signal change of the PCIe slot, calling a first driver application of the first virtual network device, and configuring a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot;
[0136] A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
[0137] In some executable embodiments, the second configuration unit is further used to:
[0138] A MAC address is configured for the universal network device.
[0139] In an exemplary embodiment, the aforementioned units and the like may be implemented by one or more central processing units (CPU), graphics processing units (GPU), application specific integrated circuits (ASIC), DSPs, programmable logic devices (PLD), complex programmable logic devices (CPLD), field programmable gate arrays (FPGA), general-purpose processors, controllers, microcontrollers (MCU), microprocessors, or other electronic components.
[0140] Regarding the device in the above embodiment, the specific manner in which each module and unit performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0141] Fig. 9 The schematic diagram of the structure of the data interaction device based on shared memory in the embodiment of the present disclosure is shown as follows: Fig. 9As shown, the data interaction device based on shared memory of the embodiment of the present disclosure is applied to a first virtual network device, the first virtual network device is connected to a second virtual network device through a peripheral component interconnect interface, a shared descriptor ring is set between the first virtual network device and the second virtual network device; the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring;
[0142] A detection unit 90, configured to detect the tail value of the shared descriptor in a polling manner in response to the occurrence of a detection event;
[0143] The processing unit 91 is used to search the physical address of the to-be-received message in the second virtual network device in the descriptor corresponding to the changed tail value when the tail value changes, and read the message from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner.
[0144] exist Fig. 9 Based on the data interaction device based on shared memory shown, the device also includes:
[0145] Judgment Unit ( Fig. 9 ), which is used to determine whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value changes; if there is no difference, the tail value does not change.
[0146] exist Fig. 9 Based on the data interaction device based on shared memory shown, the device also includes:
[0147] The first configuration unit ( Fig. 9 ), which is used to configure an address storage space for the first physical device and map the address storage space into a data receiving space.
[0148] In some executable embodiments, the second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring;
[0149] The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
[0150] exist Fig. 9 Based on the data interaction device based on shared memory shown, the device also includes:
[0151] The second configuration unit ( Fig. 9(not shown), for in response to detecting an electrical signal change of the PCIe slot, calling a first driver application of the first virtual network device, and configuring a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot;
[0152] A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
[0153] In an exemplary embodiment, the aforementioned units and the like may be implemented by one or more central processing units (CPU), graphics processing units (GPU), application specific integrated circuits (ASIC), DSPs, programmable logic devices (PLD), complex programmable logic devices (CPLD), field programmable gate arrays (FPGA), general-purpose processors, controllers, microcontrollers (MCU), microprocessors, or other electronic components.
[0154] Regarding the device in the above embodiment, the specific manner in which each module and unit performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0155] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0156] Fig.10 8 is a schematic block diagram of an example network element 800 that can be used to implement an embodiment of the present disclosure. Fig.10 As shown, the network element 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 to a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the network element 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0157] Multiple components in the network element 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a data processing transceiver, etc. The communication unit 809 allows the network element 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0158] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as a data interaction method based on shared memory. For example, in some embodiments, the data interaction method based on shared memory may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the network element 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the data interaction method based on shared memory described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to execute a shared memory-based data interaction method in any other appropriate manner (eg, by means of firmware).
[0159] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0160] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0161] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0162] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0163] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0164] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0165] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0166] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0167] The above is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A data interaction method based on shared memory, applied to a first virtual network device, wherein the first virtual network device is connected to a second virtual network device through a peripheral component interconnect (PCIe) interface, and a shared descriptor ring is set between the first virtual network device and the second virtual network device; characterized in that: The method comprises: In response to detecting a packet sending request from a first application to a first protocol stack of the first virtual network device, calling a first packet sending function; Based on the first packet sending function, encapsulate the data to be sent into a first data packet; the first data packet at least includes the destination MAC address and cyclic redundancy check data information; Obtain a tail value corresponding to the shared descriptor ring for sending the first data packet, update the tail value, and initiate an interrupt in a direct memory access mode of the first data packet.
2. The method according to claim 1, characterized in that The first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring, and the method further comprises: In response to the occurrence of a set event, the tail value of the shared descriptor ring is detected in a polling manner. If the tail value changes, the physical address of the to-be-received message in the second virtual network device is searched in the descriptor corresponding to the changed tail value, and the message is read from the physical address to the memory space pointed to by the receive data packet ring in a direct memory access manner.
3. The method according to claim 1, characterized in that Before calling the first packet sending function, the method further includes: Determine whether the difference between the head and tail pointers of the shared descriptor ring is the maximum value of the descriptor ring. If it is the maximum value of the descriptor ring, the data on the second virtual network device side is full, and the sending of the first data packet is stopped. If it is not the maximum value of the descriptor ring, the sending of the first data packet is started.
4. The method according to claim 2, characterized in that: The tail value changes include: It is determined whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value is changed; if there is no difference, the tail value is not changed.
5. The method according to claim 2, characterized in that: The method further comprises: An address storage space is configured for the first physical device, and the address storage space is mapped to a data receiving space.
6. The method according to claim 5, characterized in that The second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring; The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
7. The method according to any one of claims 2 to 6, characterized in that: Before responding to the occurrence of a setting event, the method further includes: In response to detecting an electrical signal change of the PCIe slot, calling a first driver application of the first virtual network device, and configuring a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot; A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
8. The method according to claim 2, characterized in that: The step of responding to a setting event occurrence comprises: In response to the arrival of the detection cycle of the timer, or the arrival of the processing time of the delay queue.
9. A data interaction method based on shared memory, applied to a first virtual network device, wherein the first virtual network device is connected to a second virtual network device through a peripheral component interconnect interface, a shared descriptor ring is set between the first virtual network device and the second virtual network device; the first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring; characterized in that: The method comprises: In response to the occurrence of a set event, the tail value of the shared descriptor ring is detected in a polling manner. If the tail value changes, the physical address of the to-be-received message in the second virtual network device is searched in the descriptor corresponding to the changed tail value, and the message is read from the physical address to the memory space pointed to by the receive data packet ring in a direct memory access manner.
10. The method according to claim 8, characterized in that The tail value changes include: It is determined whether there is a difference between the head and tail pointers of the shared descriptor ring. If there is a difference, the tail value is changed; if there is no difference, the tail value is not changed.
11. The method according to claim 9, characterized in that The method further comprises: An address storage space is configured for the first physical device, and the address storage space is mapped to a data receiving space.
12. The method according to claim 11, characterized in that The second virtual network device is provided with a send queue ring corresponding to the shared descriptor ring; The physical address is a storage address where the second virtual network device stores messages in the sending queue ring. The storage address is obtained by mapping through a direct memory access mapping interface and is filled into a corresponding descriptor in the shared descriptor ring.
13. The method according to any one of claims 9 to 12, characterized in that: Before responding to the occurrence of a setting event, the method further includes: In response to detecting an electrical signal change of the PCIe slot, calling a first driver application of the first virtual network device, and configuring a first physical device for the first virtual network device based on an identification table of PCI devices; wherein the electrical signal change is caused by the first virtual network device being inserted into the PCIe slot; A general network device is configured to associate the general network device with the first physical device, so that the general network device is enabled as the first virtual network device.
14. A data interaction device based on shared memory, applied to a first virtual network device, wherein the first virtual network device is connected to a second virtual network device through a peripheral component interconnect interface, and a shared descriptor ring is set between the first virtual network device and the second virtual network device; characterized in that: The device comprises: A calling unit, configured to call a first packet sending function in response to detecting a packet sending request of a first application for a first protocol stack of the first virtual network device; An encapsulation unit, configured to encapsulate the data to be sent into a first data packet based on the first packet sending function; the first data packet at least includes information of a destination MAC address and cyclic redundancy check data; The processing unit is used to obtain a tail value corresponding to the shared descriptor ring for sending the first data packet, update the tail value, and initiate an interrupt of a direct memory access mode of the first data packet.
15. A data interaction device based on shared memory, applied to a first virtual network device, the first virtual network device is connected to a second virtual network device through a peripheral component interconnect interface, and a shared descriptor ring is set between the first virtual network device and the second virtual network device; The first virtual network device is provided with a receiving data packet ring corresponding to the shared descriptor ring; characterized in that: The device comprises: A detection unit, configured to detect a tail value of a shared descriptor in a polling manner in response to occurrence of a detection event; The processing unit is used to search the physical address of the message to be received in the second virtual network device in the descriptor corresponding to the changed tail value when the tail value changes, and read the message from the physical address to the memory space pointed to by the receiving data packet ring in a direct memory access manner.
16. A virtual electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the steps of the shared memory-based data interaction method described in any one of claims 1 to 13.
17. A non-temporary computer-readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute the steps of the shared memory-based data interaction method as described in any one of claims 1 to 13.
Citation Information
Cited By
Shared network card, control method and device of shared network card and electronic equipment
CN120567871A