1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2019 Intel Corporation.
4 .. include:: <isonum.txt>
6 Packet copying using Intel\ |reg| QuickData Technology
7 ======================================================
12 This sample is intended as a demonstration of the basic components of a DPDK
13 forwarding application and example of how to use IOAT driver API to make
16 Also while forwarding, the MAC addresses are affected as follows:
18 * The source MAC address is replaced by the TX port MAC address
20 * The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID
22 This application can be used to compare performance of using software packet
23 copy with copy done using a DMA device for different sizes of packets.
24 The example will print out statistics each second. The stats shows
25 received/send packets and packets dropped or failed to copy.
27 Compiling the Application
28 -------------------------
30 To compile the sample application see :doc:`compiling`.
32 The application is located in the ``ioat`` sub-directory.
35 Running the Application
36 -----------------------
38 In order to run the hardware copy application, the copying device
39 needs to be bound to user-space IO driver.
41 Refer to the "IOAT Rawdev Driver" chapter in the "Rawdev Drivers" document
42 for information on using the driver.
44 The application requires a number of command line options:
46 .. code-block:: console
48 ./<build_dir>/examples/dpdk-ioat [EAL options] -- [-p MASK] [-q NQ] [-s RS] [-c <sw|hw>]
49 [--[no-]mac-updating] [-b BS]
53 * p MASK: A hexadecimal bitmask of the ports to configure (default is all)
55 * q NQ: Number of Rx queues used per port equivalent to CBDMA channels
56 per port (default is 1)
58 * c CT: Performed packet copy type: software (sw) or hardware using
59 DMA (hw) (default is hw)
61 * s RS: Size of IOAT rawdev ring for hardware copy mode or rte_ring for
62 software copy mode (default is 2048)
64 * --[no-]mac-updating: Whether MAC address of packets should be changed
65 or not (default is mac-updating)
67 * b BS: set the DMA batch size
69 The application can be launched in various configurations depending on
70 provided parameters. The app can use up to 2 lcores: one of them receives
71 incoming traffic and makes a copy of each packet. The second lcore then
72 updates MAC address and sends the copy. If one lcore per port is used,
73 both operations are done sequentially. For each configuration an additional
74 lcore is needed since the main lcore does not handle traffic but is
75 responsible for configuration, statistics printing and safe shutdown of
76 all ports and devices.
78 The application can use a maximum of 8 ports.
80 To run the application in a Linux environment with 3 lcores (the main lcore,
81 plus two forwarding cores), a single port (port 0), software copying and MAC
82 updating issue the command:
84 .. code-block:: console
86 $ ./<build_dir>/examples/dpdk-ioat -l 0-2 -n 2 -- -p 0x1 --mac-updating -c sw
88 To run the application in a Linux environment with 2 lcores (the main lcore,
89 plus one forwarding core), 2 ports (ports 0 and 1), hardware copying and no MAC
90 updating issue the command:
92 .. code-block:: console
94 $ ./<build_dir>/examples/dpdk-ioat -l 0-1 -n 1 -- -p 0x3 --no-mac-updating -c hw
96 Refer to the *DPDK Getting Started Guide* for general information on
97 running applications and the Environment Abstraction Layer (EAL) options.
102 The following sections provide an explanation of the main components of the
105 All DPDK library functions used in the sample code are prefixed with
106 ``rte_`` and are explained in detail in the *DPDK API Documentation*.
112 The ``main()`` function performs the initialization and calls the execution
113 threads for each lcore.
115 The first task is to initialize the Environment Abstraction Layer (EAL).
116 The ``argc`` and ``argv`` arguments are provided to the ``rte_eal_init()``
117 function. The value returned is the number of parsed arguments:
119 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
121 :start-after: Init EAL. 8<
122 :end-before: >8 End of init EAL.
126 The ``main()`` also allocates a mempool to hold the mbufs (Message Buffers)
127 used by the application:
129 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
131 :start-after: Allocates mempool to hold the mbufs. 8<
132 :end-before: >8 End of allocates mempool to hold the mbufs.
135 Mbufs are the packet buffer structure used by DPDK. They are explained in
136 detail in the "Mbuf Library" section of the *DPDK Programmer's Guide*.
138 The ``main()`` function also initializes the ports:
140 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
142 :start-after: Initialize each port. 8<
143 :end-before: >8 End of initializing each port.
146 Each port is configured using ``port_init()`` function. The Ethernet
147 ports are configured with local settings using the ``rte_eth_dev_configure()``
148 function and the ``port_conf`` struct. The RSS is enabled so that
149 multiple Rx queues could be used for packet receiving and copying by
150 multiple CBDMA channels per port:
152 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
154 :start-after: Configuring port to use RSS for multiple RX queues. 8<
155 :end-before: >8 End of configuring port to use RSS for multiple RX queues.
158 For this example the ports are set up with the number of Rx queues provided
159 with -q option and 1 Tx queue using the ``rte_eth_rx_queue_setup()``
160 and ``rte_eth_tx_queue_setup()`` functions.
162 The Ethernet port is then started:
164 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
166 :start-after: Start device. 8<
167 :end-before: >8 End of starting device.
171 Finally the Rx port is set in promiscuous mode:
173 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
175 :start-after: RX port is set in promiscuous mode. 8<
176 :end-before: >8 End of RX port is set in promiscuous mode.
180 After that each port application assigns resources needed.
182 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
184 :start-after: Assigning each port resources. 8<
185 :end-before: >8 End of assigning each port resources.
188 Ring structures are assigned for exchanging packets between lcores for both SW
191 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
193 :start-after: Assign ring structures for packet exchanging. 8<
194 :end-before: >8 End of assigning ring structures for packet exchanging.
198 When using hardware copy each Rx queue of the port is assigned an
199 IOAT device (``assign_rawdevs()``) using IOAT Rawdev Driver API
202 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
204 :start-after: Using IOAT rawdev API functions. 8<
205 :end-before: >8 End of using IOAT rawdev API functions.
209 The initialization of hardware device is done by ``rte_rawdev_configure()``
210 function using ``rte_rawdev_info`` struct. After configuration the device is
211 started using ``rte_rawdev_start()`` function. Each of the above operations
212 is done in ``configure_rawdev_queue()``.
214 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
216 :start-after: Configuration of device. 8<
217 :end-before: >8 End of configuration of device.
220 If initialization is successful, memory for hardware device
221 statistics is allocated.
223 Finally ``main()`` function starts all packet handling lcores and starts
224 printing stats in a loop on the main lcore. The application can be
225 interrupted and closed using ``Ctrl-C``. The main lcore waits for
226 all worker lcores to finish, deallocates resources and exits.
228 The processing lcores launching function are described below.
230 The Lcores Launching Functions
231 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233 As described above, ``main()`` function invokes ``start_forwarding_cores()``
234 function in order to start processing for each lcore:
236 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
238 :start-after: Start processing for each lcore. 8<
239 :end-before: >8 End of starting to processfor each lcore.
242 The function launches Rx/Tx processing functions on configured lcores
243 using ``rte_eal_remote_launch()``. The configured ports, their number
244 and number of assigned lcores are stored in user-defined
245 ``rxtx_transmission_config`` struct:
247 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
249 :start-after: Configuring ports and number of assigned lcores in struct. 8<
250 :end-before: >8 End of configuration of ports and number of assigned lcores.
253 The structure is initialized in 'main()' function with the values
254 corresponding to ports and lcores configuration provided by the user.
256 The Lcores Processing Functions
257 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 For receiving packets on each port, the ``ioat_rx_port()`` function is used.
260 The function receives packets on each configured Rx queue. Depending on the
261 mode the user chose, it will enqueue packets to IOAT rawdev channels and
262 then invoke copy process (hardware copy), or perform software copy of each
263 packet using ``pktmbuf_sw_copy()`` function and enqueue them to an rte_ring:
265 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
267 :start-after: Receive packets on one port and enqueue to IOAT rawdev or rte_ring. 8<
268 :end-before: >8 End of receive packets on one port and enqueue to IOAT rawdev or rte_ring.
271 The packets are received in burst mode using ``rte_eth_rx_burst()``
272 function. When using hardware copy mode the packets are enqueued in
273 copying device's buffer using ``ioat_enqueue_packets()`` which calls
274 ``rte_ioat_enqueue_copy()``. When all received packets are in the
275 buffer the copy operations are started by calling ``rte_ioat_perform_ops()``.
276 Function ``rte_ioat_enqueue_copy()`` operates on physical address of
277 the packet. Structure ``rte_mbuf`` contains only physical address to
278 start of the data buffer (``buf_iova``). Thus the ``rte_pktmbuf_iova()`` API is
279 used to get the address of the start of the data within the mbuf.
281 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
283 :start-after: Receive packets on one port and enqueue to IOAT rawdev or rte_ring. 8<
284 :end-before: >8 End of receive packets on one port and enqueue to IOAT rawdev or rte_ring.
288 Once the copies have been completed (this includes gathering the completions in
289 HW copy mode), the copied packets are enqueued to the ``rx_to_tx_ring``, which
290 is used to pass the packets to the TX function.
292 All completed copies are processed by ``ioat_tx_port()`` function. This function
293 dequeues copied packets from the ``rx_to_tx_ring``. Then each packet MAC address is changed
294 if it was enabled. After that copies are sent in burst mode using ``rte_eth_tx_burst()``.
297 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
299 :start-after: Transmit packets from IOAT rawdev/rte_ring for one port. 8<
300 :end-before: >8 End of transmitting packets from IOAT.
303 The Packet Copying Functions
304 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
306 In order to perform SW packet copy, there are user-defined functions to first copy
307 the packet metadata (``pktmbuf_metadata_copy()``) and then the packet data
308 (``pktmbuf_sw_copy()``):
310 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
312 :start-after: Perform packet copy there is a user-defined function. 8<
313 :end-before: >8 End of perform packet copy there is a user-defined function.
316 The metadata in this example is copied from ``rx_descriptor_fields1`` marker of
317 ``rte_mbuf`` struct up to ``buf_len`` member.
319 In order to understand why software packet copying is done as shown
320 above please refer to the "Mbuf Library" section of the
321 *DPDK Programmer's Guide*.