404ca2e19aa171fe3b98c6067196a600014720e0
[dpdk.git] / doc / guides / sample_app_ug / ioat.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2019 Intel Corporation.
3
4 .. include:: <isonum.txt>
5
6 Packet copying using Intel\ |reg| QuickData Technology
7 ======================================================
8
9 Overview
10 --------
11
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
14 packets copies.
15
16 Also while forwarding, the MAC addresses are affected as follows:
17
18 *   The source MAC address is replaced by the TX port MAC address
19
20 *   The destination MAC address is replaced by  02:00:00:00:00:TX_PORT_ID
21
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.
26
27 Compiling the Application
28 -------------------------
29
30 To compile the sample application see :doc:`compiling`.
31
32 The application is located in the ``ioat`` sub-directory.
33
34
35 Running the Application
36 -----------------------
37
38 In order to run the hardware copy application, the copying device
39 needs to be bound to user-space IO driver.
40
41 Refer to the "IOAT Rawdev Driver" chapter in the "Rawdev Drivers" document
42 for information on using the driver.
43
44 The application requires a number of command line options:
45
46 .. code-block:: console
47
48     ./<build_dir>/examples/dpdk-ioat [EAL options] -- [-p MASK] [-q NQ] [-s RS] [-c <sw|hw>]
49         [--[no-]mac-updating] [-b BS]
50
51 where,
52
53 *   p MASK: A hexadecimal bitmask of the ports to configure (default is all)
54
55 *   q NQ: Number of Rx queues used per port equivalent to CBDMA channels
56     per port (default is 1)
57
58 *   c CT: Performed packet copy type: software (sw) or hardware using
59     DMA (hw) (default is hw)
60
61 *   s RS: Size of IOAT rawdev ring for hardware copy mode or rte_ring for
62     software copy mode (default is 2048)
63
64 *   --[no-]mac-updating: Whether MAC address of packets should be changed
65     or not (default is mac-updating)
66
67 *   b BS: set the DMA batch size
68
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.
77
78 The application can use a maximum of 8 ports.
79
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:
83
84 .. code-block:: console
85
86     $ ./<build_dir>/examples/dpdk-ioat -l 0-2 -n 2 -- -p 0x1 --mac-updating -c sw
87
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:
91
92 .. code-block:: console
93
94     $ ./<build_dir>/examples/dpdk-ioat -l 0-1 -n 1 -- -p 0x3 --no-mac-updating -c hw
95
96 Refer to the *DPDK Getting Started Guide* for general information on
97 running applications and the Environment Abstraction Layer (EAL) options.
98
99 Explanation
100 -----------
101
102 The following sections provide an explanation of the main components of the
103 code.
104
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*.
107
108
109 The Main Function
110 ~~~~~~~~~~~~~~~~~
111
112 The ``main()`` function performs the initialization and calls the execution
113 threads for each lcore.
114
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:
118
119 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
120     :language: c
121     :start-after: Init EAL. 8<
122     :end-before: >8 End of init EAL.
123     :dedent: 1
124
125
126 The ``main()`` also allocates a mempool to hold the mbufs (Message Buffers)
127 used by the application:
128
129 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
130     :language: c
131     :start-after: Allocates mempool to hold the mbufs. 8<
132     :end-before: >8 End of allocates mempool to hold the mbufs.
133     :dedent: 1
134
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*.
137
138 The ``main()`` function also initializes the ports:
139
140 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
141     :language: c
142     :start-after: Initialize each port. 8<
143     :end-before: >8 End of initializing each port.
144     :dedent: 1
145
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:
151
152 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
153     :language: 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.
156     :dedent: 1
157
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.
161
162 The Ethernet port is then started:
163
164 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
165     :language: c
166     :start-after: Start device. 8<
167     :end-before: >8 End of starting device.
168     :dedent: 1
169
170
171 Finally the Rx port is set in promiscuous mode:
172
173 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
174     :language: 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.
177     :dedent: 1
178
179
180 After that each port application assigns resources needed.
181
182 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
183     :language: c
184     :start-after: Assigning each port resources. 8<
185     :end-before: >8 End of assigning each port resources.
186     :dedent: 1
187
188 Ring structures are assigned for exchanging packets between lcores for both SW
189 and HW copy modes.
190
191 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
192     :language: c
193     :start-after: Assign ring structures for packet exchanging. 8<
194     :end-before: >8 End of assigning ring structures for packet exchanging.
195     :dedent: 0
196
197
198 When using hardware copy each Rx queue of the port is assigned an
199 IOAT device (``assign_rawdevs()``) using IOAT Rawdev Driver API
200 functions:
201
202 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
203     :language: c
204     :start-after: Using IOAT rawdev API functions. 8<
205     :end-before: >8 End of using IOAT rawdev API functions.
206     :dedent: 0
207
208
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()``.
213
214 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
215     :language: c
216     :start-after: Configuration of device. 8<
217     :end-before: >8 End of configuration of device.
218     :dedent: 0
219
220 If initialization is successful, memory for hardware device
221 statistics is allocated.
222
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.
227
228 The processing lcores launching function are described below.
229
230 The Lcores Launching Functions
231 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232
233 As described above, ``main()`` function invokes ``start_forwarding_cores()``
234 function in order to start processing for each lcore:
235
236 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
237     :language: c
238     :start-after: Start processing for each lcore. 8<
239     :end-before: >8 End of starting to processfor each lcore.
240     :dedent: 0
241
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:
246
247 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
248     :language: 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.
251     :dedent: 0
252
253 The structure is initialized in 'main()' function with the values
254 corresponding to ports and lcores configuration provided by the user.
255
256 The Lcores Processing Functions
257 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258
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:
264
265 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
266     :language: 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.
269     :dedent: 0
270
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.
280
281 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
282     :language: 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.
285     :dedent: 0
286
287
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.
291
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()``.
295
296
297 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
298     :language: 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.
301     :dedent: 0
302
303 The Packet Copying Functions
304 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305
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()``):
309
310 .. literalinclude:: ../../../examples/ioat/ioatfwd.c
311     :language: 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.
314     :dedent: 0
315
316 The metadata in this example is copied from ``rx_descriptor_fields1`` marker of
317 ``rte_mbuf`` struct up to ``buf_len`` member.
318
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*.