Learning DPDK : KNI interface

KNI (Kernel Network Interface) is an approach that is used in DPDK to connect user space applications with the kernel network stack.

The following slides present the concept using a number of functional block diagrams.

The code that we are interested in is located by the following locations.

  • Sample KNI application
    • example/kni
  • KNI kernel module
    • lib/librte_eal/linuxapp/kni
  • KNI library
    • lib/librte_kni

To begin testing KNI we need to build DPDK libraries first

git clone git://dpdk.org/dpdk
export RTE_SDK=~/dpdk/
make config T=x86_64-native-linuxapp-gcc O=x86_64-native-linuxapp-gcc
cd x86_64-native-linuxapp-gcc
make

Then we need to compile KNI sample application

cd ${RTE_SDK}/examples/kni
export RTE_TARGET=x86_64-native-linuxapp-gcc
make

To run the above application we need to load KNI kernel module

insmod ${RTE_SDK}/${RTE_TARGET}/kmod/rte_kni.ko

The following kernel module options are available in case if a loopback mode is required.

  • kthread_mode=single/multiple – number of kernel threads
  • lo_mode=lo_mode_fifo/lo_mode_fifo_skb – loopback mode

Enable enough huge pages

mkdir -p /mnt/huge
mount -t hugetlbfs nodev /mnt/huge
echo 512 /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages

Load UIO kernel module and bind network interfaces to it. Note that you will not be able to bind interface in case if there exist any route associated with it.

modprobe uio_pci_generic
${RTE_SDK}/tools/dpdk_nic_bind.py --status
${RTE_SDK}/tools/dpdk_nic_bind.py --bind=uio_pci_generic eth1
${RTE_SDK}/tools/dpdk_nic_bind.py --bind=uio_pci_generic eth2
${RTE_SDK}/tools/dpdk_nic_bind.py --status

In the case of PC/VM with four cores we can run KNI application using the following commands.

export LD_LIBRARY_PATH=${RTE_SDK}/${RTE_TARGET}/lib/
${RTE_SDK}/examples/kni/build/kni -c 0x0f -n 4 -- -P -p 0x3 --config="(0,0,1),(1,2,3)"

Where:

  • -c = core bitmask
  • -P = promiscuous mode
  • -p = port hex bitmask
  • –config=”(port, lcore_rx, lcore_tx [,lcore_kthread, …]) …”

Note that each core can do either TX or RX for one port only.

You can use the following script to setup and run KNI test application.


#/bin/sh
#setup path to DPDK
export RTE_SDK=/home/dpdk
export RTE_TARGET=x86_64-native-linuxapp-gcc
#setup 512 huge pages
mkdir -p /mnt/huge
umount -t hugetlbfs nodev /mnt/huge
mount -t hugetlbfs nodev /mnt/huge
echo 512 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
#bind eth1 and eth2 to Linux generic UIO
modprobe uio_pci_generic
${RTE_SDK}/tools/dpdk_nic_bind.py –bind=uio_pci_generic eth1
${RTE_SDK}/tools/dpdk_nic_bind.py –bind=uio_pci_generic eth2
#insert KNI kernel driver
insmod ${RTE_SDK}/${RTE_TARGET}/kmod/rte_kni.ko
#start KNI sample application
export LD_LIBRARY_PATH=${RTE_SDK}/${RTE_TARGET}/lib/
${RTE_SDK}/examples/kni/build/kni -c 0x0f -n 4 — -P -p 0x3 –config="(0,0,1),(1,2,3)"

view raw

start_kni.sh

hosted with ❤ by GitHub

Let’s set ip addresses to KNI interfaces

sudo ifconfig vEth0 192.168.56.100
sudo ifconfig vEth1 192.168.56.101

Now we are set to test the application. To see statistics we need to send the SIGUSR1 signal.

watch -n 10 sudo pkill -10 kni

References

17 thoughts on “Learning DPDK : KNI interface

  1. Hi,
    I have one question. If my computer has only 1 NIC, can I use KNI to pass packets to and from DPDK to kernel network stack in order to let my computer access the Internet normally?
    Thanks

    Like

      • Thanks so much for your information.
        Can I use Sample KNI application (with some modifications if needed) to achieve my purpose?
        Pardon me for such a silly question, but I’m new to DPDK and trying to learn it.
        Thanks again.

        Like

  2. Hello, after running the DPDK KNI sample application, I cannot ping the server outside while when I stop this application, the server is reachable. I wonder what happened to the application? By the way, when I check the details of the application runs, I found there are only rx_packets received. The tx_packets stay 0. Could you please tell me what’s wrong?

    Thank you.

    Like

  3. Hi, I have one question. If i want to create multiple Rx queues and want to process incoming packets based on , say protocol, am I better off using the DPDK RSS (hash etc), or should I create software queues and KNI.

    Like

  4. While trying to run dpdk Kni application I ran in to a problem, with following error message
    BUG: unable to handle kernel paging request at 000007ffe2b92780

    To run the application I first unbinded the ports from kernel module and binded them to igb_uio
    >echo 0000:05:00.1 > /sys/bus/pci/drivers/ixgbe/unbind
    >echo 0000:05:00.0 > /sys/bus/pci/drivers/ixgbe/unbind
    >echo 0x8086 0x1528 > /sys/bus/pci/drivers/igb_uio/new_id

    I created hugepages and mounted them

    And I ran it with the gdb and here’s the output
    EAL: Detected 4 lcore(s)
    EAL: Probing VFIO support…
    EAL: PCI device 0000:05:00.0 on NUMA socket -1
    EAL: probe driver: 8086:1528 net_ixgbe
    EAL: PCI device 0000:05:00.1 on NUMA socket -1
    EAL: probe driver: 8086:1528 net_ixgbe
    Address of pktmbuf_pool 0x7ffff5a7dec0
    APP: Initialising port 0 …
    KNI: pci: 05:00:00 8086:1528
    kni created for port 0 with kni[i] address 0x7fff75638280 with i 0
    APP: Initialising port 1 …
    KNI: pci: 05:00:01 8086:1528
    kni created for port 1 with kni[i] address 0x7fff75629e00 with i 0
    APP: Lcore 1 is writing to port 0
    APP: Lcore 2 is reading from port 1
    APP: Lcore 3 is writing to port 1
    APP: Lcore 0 is reading from port 0
    ^C
    Program received signal SIGINT, Interrupt.
    0x000000000044e916 in rte_kni_tx_burst ()
    (gdb) backtrace
    #0 0x000000000044e916 in rte_kni_tx_burst ()
    #1 0x0000000000619758 in main_loop(void*) ()
    #2 0x0000000000431183 in rte_eal_mp_remote_launch ()
    #3 0x000000000040d312 in main ()

    Any idea or suggestion on where the problem could be ?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s