]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/doc/guides/sample_app_ug/kernel_nic_interface.rst
update download target update for octopus release
[ceph.git] / ceph / src / spdk / dpdk / doc / guides / sample_app_ug / kernel_nic_interface.rst
CommitLineData
11fdf7f2
TL
1.. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
3
4Kernel NIC Interface Sample Application
5=======================================
6
7The Kernel NIC Interface (KNI) is a DPDK control plane solution that
8allows userspace applications to exchange packets with the kernel networking stack.
9To accomplish this, DPDK userspace applications use an IOCTL call
10to request the creation of a KNI virtual device in the Linux* kernel.
11The IOCTL call provides interface information and the DPDK's physical address space,
12which is re-mapped into the kernel address space by the KNI kernel loadable module
13that saves the information to a virtual device context.
14The DPDK creates FIFO queues for packet ingress and egress
15to the kernel module for each device allocated.
16
17The KNI kernel loadable module is a standard net driver,
18which upon receiving the IOCTL call access the DPDK's FIFO queue to
19receive/transmit packets from/to the DPDK userspace application.
20The FIFO queues contain pointers to data packets in the DPDK. This:
21
22* Provides a faster mechanism to interface with the kernel net stack and eliminates system calls
23
24* Facilitates the DPDK using standard Linux* userspace net tools (tcpdump, ftp, and so on)
25
26* Eliminate the copy_to_user and copy_from_user operations on packets.
27
28The Kernel NIC Interface sample application is a simple example that demonstrates the use
29of the DPDK to create a path for packets to go through the Linux* kernel.
30This is done by creating one or more kernel net devices for each of the DPDK ports.
31The application allows the use of standard Linux tools (ethtool, ifconfig, tcpdump) with the DPDK ports and
32also the exchange of packets between the DPDK application and the Linux* kernel.
33
34Overview
35--------
36
37The Kernel NIC Interface sample application uses two threads in user space for each physical NIC port being used,
38and allocates one or more KNI device for each physical NIC port with kernel module's support.
39For a physical NIC port, one thread reads from the port and writes to KNI devices,
40and another thread reads from KNI devices and writes the data unmodified to the physical NIC port.
41It is recommended to configure one KNI device for each physical NIC port.
42If configured with more than one KNI devices for a physical NIC port,
43it is just for performance testing, or it can work together with VMDq support in future.
44
45The packet flow through the Kernel NIC Interface application is as shown in the following figure.
46
47.. _figure_kernel_nic:
48
49.. figure:: img/kernel_nic.*
50
51 Kernel NIC Application Packet Flow
52
53Compiling the Application
54-------------------------
55
56To compile the sample application see :doc:`compiling`.
57
58The application is located in the ``kni`` sub-directory.
59
60.. note::
61
62 This application is intended as a linuxapp only.
63
64Loading the Kernel Module
65-------------------------
66
67Loading the KNI kernel module without any parameter is the typical way a DPDK application
68gets packets into and out of the kernel net stack.
69This way, only one kernel thread is created for all KNI devices for packet receiving in kernel side:
70
71.. code-block:: console
72
73 #insmod rte_kni.ko
74
75Pinning the kernel thread to a specific core can be done using a taskset command such as following:
76
77.. code-block:: console
78
79 #taskset -p 100000 `pgrep --fl kni_thread | awk '{print $1}'`
80
81This command line tries to pin the specific kni_thread on the 20th lcore (lcore numbering starts at 0),
82which means it needs to check if that lcore is available on the board.
83This command must be sent after the application has been launched, as insmod does not start the kni thread.
84
85For optimum performance,
86the lcore in the mask must be selected to be on the same socket as the lcores used in the KNI application.
87
88To provide flexibility of performance, the kernel module of the KNI,
89located in the kmod sub-directory of the DPDK target directory,
90can be loaded with parameter of kthread_mode as follows:
91
92* #insmod rte_kni.ko kthread_mode=single
93
94 This mode will create only one kernel thread for all KNI devices for packet receiving in kernel side.
95 By default, it is in this single kernel thread mode.
96 It can set core affinity for this kernel thread by using Linux command taskset.
97
98* #insmod rte_kni.ko kthread_mode =multiple
99
100 This mode will create a kernel thread for each KNI device for packet receiving in kernel side.
101 The core affinity of each kernel thread is set when creating the KNI device.
102 The lcore ID for each kernel thread is provided in the command line of launching the application.
103 Multiple kernel thread mode can provide scalable higher performance.
104
105To measure the throughput in a loopback mode, the kernel module of the KNI,
106located in the kmod sub-directory of the DPDK target directory,
107can be loaded with parameters as follows:
108
109* #insmod rte_kni.ko lo_mode=lo_mode_fifo
110
111 This loopback mode will involve ring enqueue/dequeue operations in kernel space.
112
113* #insmod rte_kni.ko lo_mode=lo_mode_fifo_skb
114
115 This loopback mode will involve ring enqueue/dequeue operations and sk buffer copies in kernel space.
116
117Running the Application
118-----------------------
119
120The application requires a number of command line options:
121
122.. code-block:: console
123
124 kni [EAL options] -- -P -p PORTMASK --config="(port,lcore_rx,lcore_tx[,lcore_kthread,...])[,port,lcore_rx,lcore_tx[,lcore_kthread,...]]"
125
126Where:
127
128* -P: Set all ports to promiscuous mode so that packets are accepted regardless of the packet's Ethernet MAC destination address.
129 Without this option, only packets with the Ethernet MAC destination address set to the Ethernet address of the port are accepted.
130
131* -p PORTMASK: Hexadecimal bitmask of ports to configure.
132
133* --config="(port,lcore_rx, lcore_tx[,lcore_kthread, ...]) [, port,lcore_rx, lcore_tx[,lcore_kthread, ...]]":
134 Determines which lcores of RX, TX, kernel thread are mapped to which ports.
135
136Refer to *DPDK Getting Started Guide* for general information on running applications and the Environment Abstraction Layer (EAL) options.
137
138The -c coremask or -l corelist parameter of the EAL options should include the lcores indicated by the lcore_rx and lcore_tx,
139but does not need to include lcores indicated by lcore_kthread as they are used to pin the kernel thread on.
140The -p PORTMASK parameter should include the ports indicated by the port in --config, neither more nor less.
141
142The lcore_kthread in --config can be configured none, one or more lcore IDs.
143In multiple kernel thread mode, if configured none, a KNI device will be allocated for each port,
144while no specific lcore affinity will be set for its kernel thread.
145If configured one or more lcore IDs, one or more KNI devices will be allocated for each port,
146while specific lcore affinity will be set for its kernel thread.
147In single kernel thread mode, if configured none, a KNI device will be allocated for each port.
148If configured one or more lcore IDs,
149one or more KNI devices will be allocated for each port while
150no lcore affinity will be set as there is only one kernel thread for all KNI devices.
151
152For example, to run the application with two ports served by six lcores, one lcore of RX, one lcore of TX,
153and one lcore of kernel thread for each port:
154
155.. code-block:: console
156
157 ./build/kni -l 4-7 -n 4 -- -P -p 0x3 --config="(0,4,6,8),(1,5,7,9)"
158
159KNI Operations
160--------------
161
162Once the KNI application is started, one can use different Linux* commands to manage the net interfaces.
163If more than one KNI devices configured for a physical port,
164only the first KNI device will be paired to the physical device.
165Operations on other KNI devices will not affect the physical port handled in user space application.
166
167Assigning an IP address:
168
169.. code-block:: console
170
171 #ifconfig vEth0_0 192.168.0.1
172
173Displaying the NIC registers:
174
175.. code-block:: console
176
177 #ethtool -d vEth0_0
178
179Dumping the network traffic:
180
181.. code-block:: console
182
183 #tcpdump -i vEth0_0
184
185Change the MAC address:
186
187.. code-block:: console
188
189 #ifconfig vEth0_0 hw ether 0C:01:02:03:04:08
190
191When the DPDK userspace application is closed, all the KNI devices are deleted from Linux*.
192
193Explanation
194-----------
195
196The following sections provide some explanation of code.
197
198Initialization
199~~~~~~~~~~~~~~
200
201Setup of mbuf pool, driver and queues is similar to the setup done in the :doc:`l2_forward_real_virtual`..
202In addition, one or more kernel NIC interfaces are allocated for each
203of the configured ports according to the command line parameters.
204
205The code for allocating the kernel NIC interfaces for a specific port is
206in the function ``kni_alloc``.
207
208The other step in the initialization process that is unique to this sample application
209is the association of each port with lcores for RX, TX and kernel threads.
210
211* One lcore to read from the port and write to the associated one or more KNI devices
212
213* Another lcore to read from one or more KNI devices and write to the port
214
215* Other lcores for pinning the kernel threads on one by one
216
217This is done by using the ``kni_port_params_array[]`` array, which is indexed by the port ID.
218The code is in the function ``parse_config``.
219
220Packet Forwarding
221~~~~~~~~~~~~~~~~~
222
223After the initialization steps are completed, the main_loop() function is run on each lcore.
224This function first checks the lcore_id against the user provided lcore_rx and lcore_tx
225to see if this lcore is reading from or writing to kernel NIC interfaces.
226
227For the case that reads from a NIC port and writes to the kernel NIC interfaces (``kni_ingress``),
228the packet reception is the same as in L2 Forwarding sample application
229(see :ref:`l2_fwd_app_rx_tx_packets`).
230The packet transmission is done by sending mbufs into the kernel NIC interfaces by rte_kni_tx_burst().
231The KNI library automatically frees the mbufs after the kernel successfully copied the mbufs.
232
233For the other case that reads from kernel NIC interfaces
234and writes to a physical NIC port (``kni_egress``),
235packets are retrieved by reading mbufs from kernel NIC interfaces by ``rte_kni_rx_burst()``.
236The packet transmission is the same as in the L2 Forwarding sample application
237(see :ref:`l2_fwd_app_rx_tx_packets`).
238
239Callbacks for Kernel Requests
240~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241
242To execute specific PMD operations in user space requested by some Linux* commands,
243callbacks must be implemented and filled in the struct rte_kni_ops structure.
244Currently, setting a new MTU, change in MAC address, configuring promiscusous mode and
245configuring the network interface(up/down) re supported.
246Default implementation for following is available in rte_kni library.
247Application may choose to not implement following callbacks:
248
249- ``config_mac_address``
250- ``config_promiscusity``