Disclosure of Invention
In order to solve the above problems, the invention provides a DPDK-based robot middleware DDS data transmission method, which can reduce the process of responding to a terminal request, reduce the performance overhead of a data distribution system, reduce the time consumption of transfer storage in the data distribution process, reduce the time delay of data distribution, and improve the processing speed of data distribution.
In order to solve the above problem, the present invention also provides an electronic device and a computer-readable storage medium.
The technical scheme adopted by the invention is that the DDS data transmission method of the robot middleware based on the DPDK comprises the following steps:
step S1, the message subscriber applies for the storage space in the DPDK memory pool bound by the message subscriber, and carries out the address naming identification to the storage space;
step S2, the message subscriber and the message publisher access the DCPS information base, the DCPS information base obtains the subject information, the MAC address and the address naming identification of the message subscriber, matches the subject information of the message publisher and the message subscriber, and sends the MAC address of the matched message subscriber and the DPDK memory pool address naming identification to the message publisher;
step S3, after DDS coding compression and address naming identification adding processing are carried out on data corresponding to the subject information by the message publisher, a data packet is written into a data queue of a DPDK-bound network card by using DMA to wait for transmission;
step S4, the network card bound with DPDK sends the data packet to the message subscriber according to the MAC address, and the message subscriber obtains corresponding data.
Further, both the message publisher and the message subscriber use the gigabit-capable network card to configure the DPDK operating environment, initialize the DPDK operating environment, and start the DPDK memory pool.
Further, the configuring the DPDK operation environment includes: setting kernel parameters of an operating system, setting a large-page memory, loading a user mode IO module, and setting a network card to run a DPDK user mode driver.
Further, the message publisher performs the operation environment initialization and the DPDK network card start in step S2 through the following processes: the message publisher calls a PDKD initialization interface rte _ eal _ init (), a port setting interface port _ init (), a data transceiving configuration interface rte _ eth _ dev _ configuration (), a transmission queue initialization interface rte _ eth _ tx _ queue _ setup (), completes the configuration and initialization of data transmission and reception, and calls a device start interface rte _ eth _ dev _ start () to start a DPDK network card.
Further, the step S2 is that the message subscriber performs the operation environment initialization and the DPDK network card start by the following procedures: the message subscriber calls a PDKD initialization interface rte _ eal _ init (), a port setting interface port _ init (), a data transceiving configuration interface rte _ eth _ dev _ configuration (), a receiving queue initialization interface rte _ eth _ rx _ queue _ setup (), completes the configuration and initialization of data transmission and reception, and calls a device starting interface rte _ eth _ dev _ start () to start a DPDK network card.
Further, the number of the message publishers and the number of the message subscribers is at least one.
Further, in step S3, the message issuer performs segmentation, DMA address padding, packet length processing, and offload parameter processing on the binary data.
Further, in step S4, the message subscriber data is parsed to obtain the data header address naming identifier, and accordingly, the data packet is read from the network card to the corresponding storage space of the DPDK memory pool.
An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the steps of the method when executing the program stored in the memory.
A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the above-mentioned method steps.
The invention has the beneficial effects that: according to the invention, the kernel of the operating system is not required to copy and rewrite the data in the data distribution process of the robot middleware, so that the context switching overhead caused by the interruption of other work by the kernel of the operating system is avoided, the time consumption of the conversion of the data between the kernel state and the user state is reduced, and the processing speed of data distribution is improved; the invention does not use a TCP/IP protocol stack, does not need to add a message header at the head of the data packet, reduces the volume of the data packet, reduces the processing flow of the data packet and improves the efficiency of data transmission.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The DDS data transmission method of the robot middleware based on the DPDK comprises the following steps:
step 1, configuring DPDK operating environments by a message publisher and a message subscriber by using a gigabit network card, respectively initializing the configured DPDK operating environments, and starting a DPDK memory pool;
the configuration operation environment comprises the steps of setting kernel parameters of an operating system, setting a large-page memory, loading a user mode IO module, and setting a gigabit-class network card to operate a user mode IO driver in a DPDK mode for data transmission;
as shown in fig. 2, the message publisher calls a PDKD initialization interface rte _ eal _ init (), a port setting interface port _ init (), a data transceiving configuration interface rte _ eth _ dev _ configuration (), a transmission queue initialization interface rte _ eth _ tx _ queue _ setup (), completes the configuration and initialization of data transmission and reception, and calls a device start interface rte _ eth _ dev _ start () to start a DPDK network card;
as shown in fig. 3, the message subscriber calls a PDKD initialization interface rte _ eal _ init (), a port setting interface port _ init (), a data transceiving configuration interface rte _ eth _ dev _ configuration (), a receiving queue initialization interface rte _ eth _ rx _ queue _ setup (), completes the configuration and initialization of data transmission and reception, and calls a device start interface rte _ eth _ dev _ start () to start a DPDK network card;
step 2, the message subscriber applies for a storage space from a DPDK memory pool (memory) bound by the message subscriber, and carries out address naming identification on the storage space;
step 3, both the message publisher and the message subscriber access the DCPS information base, the DCPS information base obtains the topic information, the MAC address and the DPDK memory pool address naming identification of the message publisher/message subscriber, matches the topic information of the message publisher and the message subscriber, and sends the MAC address and the address naming identification of the matched message subscriber to the message publisher;
the MAC address is the physical ID of a DPDK network card used by the message subscriber/message publisher, and the message publisher can access the DPDK network card of the interconnected message subscriber/message publisher through the MAC address in the local area network;
step 4, as shown in fig. 1, the message publisher calls rte _ pktmbuf _ alloc () interface to apply for a storage space on the bound DPDK memory pool, compresses data corresponding to the subject information into binary data by DDS coding, and adds a DPDK memory pool address naming identifier of the message subscriber to the head of the data packet;
then the DPDK segments the data packet, fills DMA address, data packet length, unloading parameters and other operations, and writes the data into the bound DPDK network card by using DMA to wait for transmission;
the DMA address is used for directly accessing a memory controller (DMA) to directly write the data of the address into a network card buffer zone, namely a DPDK network card bound by a message publisher;
and 5, the message publisher binds the network card of the DPDK and transmits data to the message subscriber according to the MAC address, the message subscriber calls an rte _ eth _ burst () interface to obtain a data packet, the head of the data packet is analyzed through DPDK drive, a DPDK memory pool naming identifier corresponding to the data packet is obtained, the data packet is read from the network card bound with the DPDK and is stored in a storage space corresponding to the address naming identifier, and the message subscriber obtains corresponding data.
According to the invention, after the DPDK network card of the message subscriber receives the data packet corresponding to the theme information, the data packet is directly stored in the memory so that the message subscriber can process the data packet through the corresponding interface without informing the CPU through interruption, the data is copied to the memory space and then is copied to the user mode space, the operation time of copying the data to the kernel space is reduced, the time consumption of interrupt response of an operating system and switching between the kernel mode and the user mode is reduced, and the real-time property of data transmission is improved.
When the method is used for data transmission, a message publisher and a message subscriber can be in one or more pairs, namely a plurality of users can simultaneously access a DCPS information base, a plurality of data transmission pairs are formed according to topic information matching, then each message publisher sends a topic information data packet to a DPDPK memory pool of the message subscriber for storage, at the moment, the users can be used as the message publishers and can also be used as the message subscribers, one message publisher can send the topic information data packet to a plurality of message subscribers, and one message subscriber can also receive the topic information data packets sent by a plurality of message publishers; the invention does not use TCP/IP protocol stack in the data packet transmission process, does not need to add message header at the data packet head, reduces the volume of the data packet and the processing flow of the data packet, improves the data transmission efficiency and the data distribution speed, and reduces the data transmission time delay.
When the traditional DDS is used for data distribution, the received data is read into a kernel state storage space of a computer, then the data is copied into a user state storage space, the DDS judges a transmitted object of the data, and the data is further distributed to corresponding subscribers; as shown in fig. 4, in the present invention, if a plurality of different message subscribers exist in one device at the same time, when the DPDK polls and reads the network card data, the data is directly read from the network card into the storage space of the DPDK memory pool of the corresponding message subscriber according to the header identifier of the data packet, and the subscriber to which the data packet belongs does not need to be distinguished after the data packet is read into the memory space, so that the flow of data distribution is simplified, and the data transmission efficiency is improved.
The electronic equipment comprises a memory and a processor, wherein computer program instructions for configuring a DPDK operating environment, matching a message publisher and a message subscriber and performing DMA transmission are stored in the memory, the processor executes the computer program instructions to configure the DPDK operating environment, match subject information of the message publisher and the message subscriber, perform operations such as DDS coding compression and name identifier addition on data corresponding to the subject information as the message publisher, store the data in a DPDK memory pool, write the data into a sending queue after the DPDK memory pool processes the data, send the data to the message subscriber according to an MAC address and the name identifier, perform operations such as DDS decompression on a received data packet as the message subscriber, write the data into a memory pool storage space corresponding to the name identifier, and obtain the data corresponding to the subject information.
In the invention, users can be used as a message publisher and a message subscriber at the same time, and a plurality of users can be used as the message publisher and/or the message subscriber at the same time to communicate with the DCPS information base to obtain the matched message subscriber/message publisher, thereby carrying out parallel multi-party data transmission.
The electronic device of the present invention may communicate with one or more external devices (e.g., keyboard, pointing device, bluetooth device, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device, and/or any devices that enable the electronic device to communicate with one or more other computing devices, and may also communicate with one or more networks (e.g., local area network, wide area network, and/or public network) through a network adapter.
The present invention also includes a computer readable medium storing a computer program that can be executed by a processor to implement DPDK based DDS data transmission, which can include, but is not limited to, magnetic storage devices, optical disks, digital versatile disks, smart cards, and flash memory devices, and further readable storage media of the present invention can represent one or more devices for storing information and/or other machine readable media, the term "machine readable medium" including, but not limited to, wireless channels and various other media (and/or storage media) capable of storing, containing, and/or carrying code and/or instructions and/or data.
Examples
OpenDDS is a specific open source implementation scheme of DDS, and in this embodiment, a DPDK-based transport layer instance is constructed on OpenDDS for testing; the specific method is that DPDK is used for constructing a ReceiveStrength class (used for data receiving), a SendStrategy class (used for data sending), a Transport class and a dataLink class of an OpenDDS transmission layer, a DPDK-based transmission layer dynamic library is generated, the transmission layer dynamic library is loaded when the OpenDDS is started, and data can be sent and received through a DPDK mode in the data sending and receiving stages.
The DPDK-based transport layer dynamic library implementation method comprises the following processes:
1. initializing DPDK library and port setting in a Transport class, loading a MacAddr field in a DPDKconfig.ini configuration file, and acquiring an MAC address binding a DPDK network card;
2. setting a function for receiving and analyzing matched data from a DCPS information base in a dataLink class, recording the MAC address of a DPDK network card bound by a message publisher/message subscriber, and then completing the configuration and initialization of data receiving and transmitting through a data receiving and transmitting configuration interface rte _ eth _ dev _ configuration (), a receiving queue initialization interface rte _ eth _ rx _ queue _ setup () and a transmitting queue initialization interface rte _ eth _ tx _ queue _ setup ();
3. the SendStratage class segments the data packets, writes a message subscriber naming identifier for each segment of data packets, sets a DMA address, a data packet length and unloading parameter data, puts the DMA address, the data packet length and the unloading parameter data into a data queue, and sends the data queue to a ReceiveStratage class; the receiveStrength class obtains the naming identification of the parsed data packet through rte _ eth _ rx _ burst (), and returns the data to the upper layer for calling.
In the same experimental environment, a data transmission delay test is performed by using a DDS data distribution technology and the embodiment of the invention, the data transmission delay test is to measure the round trip time RTT of each data, the data delay is defined as RTT/2, the length of the test data is 1KB, the statistical data amount is 5000, the sending interval of each data is 10ms, the experimental result pair is shown in fig. 5, the average delay of the DDS data distribution technology is 333.2us, and the average delay of data transmission of the embodiment of the invention is 270.6us, which shows that the embodiment of the invention can accelerate the data processing speed and transmission speed of a DDS transmission system, reduce the data transmission delay, and meet the real-time use requirement of strict requirement and low delay.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.