]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/doc/guides/sample_app_ug/kernel_nic_interface.rst
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / doc / guides / sample_app_ug / kernel_nic_interface.rst
CommitLineData
9f95a23c
TL
1.. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
7c673cae
FG
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
9f95a23c
TL
34The Kernel NIC Interface sample application requires that the
35KNI kernel module ``rte_kni`` be loaded into the kernel. See
36:doc:`../prog_guide/kernel_nic_interface` for more information on loading
37the ``rte_kni`` kernel module.
38
7c673cae
FG
39Overview
40--------
41
9f95a23c
TL
42The Kernel NIC Interface sample application ``kni`` allocates one or more
43KNI interfaces for each physical NIC port. For each physical NIC port,
44``kni`` uses two DPDK threads in user space; one thread reads from the port and
45writes to the corresponding KNI interfaces and the other thread reads from
46the KNI interfaces and writes the data unmodified to the physical NIC port.
47
48It is recommended to configure one KNI interface for each physical NIC port.
49The application can be configured with more than one KNI interface for
50each physical NIC port for performance testing or it can work together with
51VMDq support in future.
7c673cae 52
9f95a23c
TL
53The packet flow through the Kernel NIC Interface application is as shown
54in the following figure.
7c673cae
FG
55
56.. _figure_kernel_nic:
57
58.. figure:: img/kernel_nic.*
59
60 Kernel NIC Application Packet Flow
61
9f95a23c
TL
62If link monitoring is enabled with the ``-m`` command line flag, one
63additional pthread is launched which will check the link status of each
64physical NIC port and will update the carrier status of the corresponding
65KNI interface(s) to match the physical NIC port's state. This means that
66the KNI interface(s) will be disabled automatically when the Ethernet link
67goes down and enabled when the Ethernet link goes up.
68
69If link monitoring is enabled, the ``rte_kni`` kernel module should be loaded
70such that the :ref:`default carrier state <kni_default_carrier_state>` is
71set to *off*. This ensures that the KNI interface is only enabled *after*
72the Ethernet link of the corresponding NIC port has reached the linkup state.
73
74If link monitoring is not enabled, the ``rte_kni`` kernel module should be
75loaded with the :ref:`default carrier state <kni_default_carrier_state>`
76set to *on*. This sets the carrier state of the KNI interfaces to *on*
77when the KNI interfaces are enabled without regard to the actual link state
78of the corresponding NIC port. This is useful for testing in loopback
79mode where the NIC port may not be physically connected to anything.
7c673cae
FG
80
81Compiling the Application
82-------------------------
83
9f95a23c 84To compile the sample application see :doc:`compiling`.
7c673cae 85
9f95a23c 86The application is located in the ``examples/kni`` sub-directory.
7c673cae 87
9f95a23c 88.. note::
7c673cae 89
9f95a23c 90 This application is intended as a linux only.
7c673cae 91
9f95a23c
TL
92Running the kni Example Application
93-----------------------------------
7c673cae 94
9f95a23c 95The ``kni`` example application requires a number of command line options:
7c673cae
FG
96
97.. code-block:: console
98
9f95a23c 99 kni [EAL options] -- -p PORTMASK --config="(port,lcore_rx,lcore_tx[,lcore_kthread,...])[,(port,lcore_rx,lcore_tx[,lcore_kthread,...])]" [-P] [-m]
7c673cae 100
9f95a23c 101Where:
7c673cae 102
9f95a23c 103* ``-p PORTMASK``:
7c673cae 104
9f95a23c 105 Hexadecimal bitmask of ports to configure.
7c673cae 106
9f95a23c 107* ``--config="(port,lcore_rx,lcore_tx[,lcore_kthread,...])[,(port,lcore_rx,lcore_tx[,lcore_kthread,...])]"``:
7c673cae 108
9f95a23c
TL
109 Determines which lcores the Rx and Tx DPDK tasks, and (optionally)
110 the KNI kernel thread(s) are bound to for each physical port.
7c673cae 111
9f95a23c 112* ``-P``:
7c673cae 113
9f95a23c
TL
114 Optional flag to set all ports to promiscuous mode so that packets are
115 accepted regardless of the packet's Ethernet MAC destination address.
116 Without this option, only packets with the Ethernet MAC destination
117 address set to the Ethernet address of the port are accepted.
7c673cae 118
9f95a23c 119* ``-m``:
7c673cae 120
9f95a23c
TL
121 Optional flag to enable monitoring and updating of the Ethernet
122 carrier state. With this option set, a thread will be started which
123 will periodically check the Ethernet link status of the physical
124 Ethernet ports and set the carrier state of the corresponding KNI
125 network interface to match it. This means that the KNI interface will
126 be disabled automatically when the Ethernet link goes down and enabled
127 when the Ethernet link goes up.
7c673cae 128
9f95a23c
TL
129Refer to *DPDK Getting Started Guide* for general information on running
130applications and the Environment Abstraction Layer (EAL) options.
7c673cae 131
9f95a23c
TL
132The ``-c coremask`` or ``-l corelist`` parameter of the EAL options must
133include the lcores specified by ``lcore_rx`` and ``lcore_tx`` for each port,
134but does not need to include lcores specified by ``lcore_kthread`` as those
135cores are used to pin the kernel threads in the ``rte_kni`` kernel module.
7c673cae 136
9f95a23c
TL
137The ``--config`` parameter must include a set of
138``(port,lcore_rx,lcore_tx,[lcore_kthread,...])`` values for each physical
139port specified in the ``-p PORTMASK`` parameter.
7c673cae 140
9f95a23c
TL
141The optional ``lcore_kthread`` lcore ID parameter in ``--config`` can be
142specified zero, one or more times for each physical port.
7c673cae 143
9f95a23c
TL
144If no lcore ID is specified for ``lcore_kthread``, one KNI interface will
145be created for the physical port ``port`` and the KNI kernel thread(s)
146will have no specific core affinity.
7c673cae 147
9f95a23c
TL
148If one or more lcore IDs are specified for ``lcore_kthread``, a KNI interface
149will be created for each lcore ID specified, bound to the physical port
150``port``. If the ``rte_kni`` kernel module is loaded in :ref:`multiple
151kernel thread <kni_kernel_thread_mode>` mode, a kernel thread will be created
152for each KNI interface and bound to the specified core. If the ``rte_kni``
153kernel module is loaded in :ref:`single kernel thread <kni_kernel_thread_mode>`
154mode, only one kernel thread is started for all KNI interfaces. The kernel
155thread will be bound to the first ``lcore_kthread`` lcore ID specified.
7c673cae 156
9f95a23c
TL
157Example Configurations
158~~~~~~~~~~~~~~~~~~~~~~~
7c673cae 159
9f95a23c
TL
160The following commands will first load the ``rte_kni`` kernel module in
161:ref:`multiple kernel thread <kni_kernel_thread_mode>` mode. The ``kni``
162application is then started using two ports; Port 0 uses lcore 4 for the
163Rx task, lcore 6 for the Tx task, and will create a single KNI interface
164``vEth0_0`` with the kernel thread bound to lcore 8. Port 1 uses lcore
1655 for the Rx task, lcore 7 for the Tx task, and will create a single KNI
166interface ``vEth1_0`` with the kernel thread bound to lcore 9.
7c673cae
FG
167
168.. code-block:: console
169
9f95a23c
TL
170 # rmmod rte_kni
171 # insmod kmod/rte_kni.ko kthread_mode=multiple
172 # ./build/kni -l 4-7 -n 4 -- -P -p 0x3 -m --config="(0,4,6,8),(1,5,7,9)"
7c673cae 173
9f95a23c
TL
174The following example is identical, except an additional ``lcore_kthread``
175core is specified per physical port. In this case, ``kni`` will create
176four KNI interfaces: ``vEth0_0``/``vEth0_1`` bound to physical port 0 and
177``vEth1_0``/``vEth1_1`` bound to physical port 1.
7c673cae 178
9f95a23c 179The kernel thread for each interface will be bound as follows:
7c673cae 180
9f95a23c
TL
181 * ``vEth0_0`` - bound to lcore 8.
182 * ``vEth0_1`` - bound to lcore 10.
183 * ``vEth1_0`` - bound to lcore 9.
184 * ``vEth1_1`` - bound to lcore 11
7c673cae 185
9f95a23c 186.. code-block:: console
7c673cae 187
9f95a23c
TL
188 # rmmod rte_kni
189 # insmod kmod/rte_kni.ko kthread_mode=multiple
190 # ./build/kni -l 4-7 -n 4 -- -P -p 0x3 -m --config="(0,4,6,8,10),(1,5,7,9,11)"
7c673cae 191
9f95a23c
TL
192The following example can be used to test the interface between the ``kni``
193test application and the ``rte_kni`` kernel module. In this example,
194the ``rte_kni`` kernel module is loaded in :ref:`single kernel thread
195mode <kni_kernel_thread_mode>`, :ref:`loopback mode <kni_loopback_mode>`
196enabled, and the :ref:`default carrier state <kni_default_carrier_state>`
197is set to *on* so that the corresponding physical NIC port does not have
198to be connected in order to use the KNI interface. One KNI interface
199``vEth0_0`` is created for port 0 and one KNI interface ``vEth1_0`` is
200created for port 1. Since ``rte_kni`` is loaded in "single kernel thread"
201mode, the one kernel thread is bound to lcore 8.
7c673cae 202
9f95a23c
TL
203Since the physical NIC ports are not being used, link monitoring can be
204disabled by **not** specifying the ``-m`` flag to ``kni``:
7c673cae
FG
205
206.. code-block:: console
207
9f95a23c
TL
208 # rmmod rte_kni
209 # insmod kmod/rte_kni.ko lo_mode=lo_mode_fifo carrier=on
210 # ./build/kni -l 4-7 -n 4 -- -P -p 0x3 --config="(0,4,6,8),(1,5,7,9)"
7c673cae
FG
211
212KNI Operations
213--------------
214
9f95a23c
TL
215Once the ``kni`` application is started, the user can use the normal
216Linux commands to manage the KNI interfaces as if they were any other
217Linux network interface.
7c673cae 218
9f95a23c 219Enable KNI interface and assign an IP address:
7c673cae
FG
220
221.. code-block:: console
222
9f95a23c 223 # ifconfig vEth0_0 192.168.0.1
7c673cae 224
9f95a23c 225Show KNI interface configuration and statistics:
7c673cae
FG
226
227.. code-block:: console
228
9f95a23c 229 # ifconfig vEth0_0
7c673cae 230
9f95a23c
TL
231The user can also check and reset the packet statistics inside the ``kni``
232application by sending the app the USR1 and USR2 signals:
7c673cae
FG
233
234.. code-block:: console
235
9f95a23c
TL
236 # Print statistics
237 # kill -SIGUSR1 `pidof kni`
7c673cae 238
9f95a23c
TL
239 # Zero statistics
240 # kill -SIGUSR2 `pidof kni`
7c673cae 241
9f95a23c 242Dump network traffic:
7c673cae 243
9f95a23c 244.. code-block:: console
7c673cae 245
9f95a23c 246 # tcpdump -i vEth0_0
7c673cae 247
9f95a23c
TL
248The normal Linux commands can also be used to change the MAC address and
249MTU size used by the physical NIC which corresponds to the KNI interface.
250However, if more than one KNI interface is configured for a physical port,
251these commands will only work on the first KNI interface for that port.
7c673cae 252
9f95a23c 253Change the MAC address:
7c673cae 254
9f95a23c 255.. code-block:: console
7c673cae 256
9f95a23c 257 # ifconfig vEth0_0 hw ether 0C:01:02:03:04:08
7c673cae 258
9f95a23c 259Change the MTU size:
7c673cae 260
9f95a23c 261.. code-block:: console
7c673cae 262
9f95a23c 263 # ifconfig vEth0_0 mtu 1450
7c673cae 264
9f95a23c
TL
265If DPDK is compiled with ``CONFIG_RTE_KNI_KMOD_ETHTOOL=y`` and an Intel
266NIC is used, the user can use ``ethtool`` on the KNI interface as if it
267were a normal Linux kernel interface.
7c673cae 268
9f95a23c 269Displaying the NIC registers:
7c673cae 270
9f95a23c 271.. code-block:: console
7c673cae 272
9f95a23c 273 # ethtool -d vEth0_0
7c673cae 274
9f95a23c
TL
275When the ``kni`` application is closed, all the KNI interfaces are deleted
276from the Linux kernel.
7c673cae 277
9f95a23c
TL
278Explanation
279-----------
7c673cae 280
9f95a23c 281The following sections provide some explanation of code.
7c673cae 282
9f95a23c
TL
283Initialization
284~~~~~~~~~~~~~~
7c673cae 285
9f95a23c
TL
286Setup of mbuf pool, driver and queues is similar to the setup done in the :doc:`l2_forward_real_virtual`..
287In addition, one or more kernel NIC interfaces are allocated for each
288of the configured ports according to the command line parameters.
7c673cae 289
9f95a23c
TL
290The code for allocating the kernel NIC interfaces for a specific port is
291in the function ``kni_alloc``.
7c673cae
FG
292
293The other step in the initialization process that is unique to this sample application
294is the association of each port with lcores for RX, TX and kernel threads.
295
296* One lcore to read from the port and write to the associated one or more KNI devices
297
298* Another lcore to read from one or more KNI devices and write to the port
299
300* Other lcores for pinning the kernel threads on one by one
301
9f95a23c
TL
302This is done by using the ``kni_port_params_array[]`` array, which is indexed by the port ID.
303The code is in the function ``parse_config``.
7c673cae
FG
304
305Packet Forwarding
306~~~~~~~~~~~~~~~~~
307
308After the initialization steps are completed, the main_loop() function is run on each lcore.
309This function first checks the lcore_id against the user provided lcore_rx and lcore_tx
310to see if this lcore is reading from or writing to kernel NIC interfaces.
311
9f95a23c 312For the case that reads from a NIC port and writes to the kernel NIC interfaces (``kni_ingress``),
7c673cae
FG
313the packet reception is the same as in L2 Forwarding sample application
314(see :ref:`l2_fwd_app_rx_tx_packets`).
9f95a23c 315The packet transmission is done by sending mbufs into the kernel NIC interfaces by ``rte_kni_tx_burst()``.
7c673cae
FG
316The KNI library automatically frees the mbufs after the kernel successfully copied the mbufs.
317
9f95a23c
TL
318For the other case that reads from kernel NIC interfaces
319and writes to a physical NIC port (``kni_egress``),
320packets are retrieved by reading mbufs from kernel NIC interfaces by ``rte_kni_rx_burst()``.
7c673cae
FG
321The packet transmission is the same as in the L2 Forwarding sample application
322(see :ref:`l2_fwd_app_rx_tx_packets`).