image image image image image image



On This Page

Created on Jul 11, 2019 

Introduction

This post shows how to launch a Virtual Machine (VM) over OVS-DPDK 18.02 using Nvidia ConnectX-4 or ConnectX-5 adapters.

Compilation now allow DL-open dynamic linkage which benefits transparent use for none Nvidia users. In case Nvidia nics are not explicitly used, Nvidia code is not loaded.

In this example MLNX_OFED 4.2-1.0.0.0 is used.

References

Prerequisites

1. Install MLNX_OFED and using ofed_info command verify the version is 4.2-1.0.0.0 or 4.3-0.1.6.0:

OFED download link: http://www.mellanox.com/page/products_dyn?product_family=26

Make sure OFED installation script done as follow:

CLI Command
 /mnt/mlnxofedinstall --dpdk --upstream-libs

Check OFED version:

CLI Command
ofed_info -s

2. Check CPU support for 1G hugepages by checking for pdpe1gb flag:

CLI Command
cat /proc/cpuinfo | grep pdpe1gb

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nxpdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology n_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid
Make sure that the flag list includes pdpe1gb flag.

3. Find the NUMA number per PCI slot:

CLI Commands
mst start

mst status -v

MST modules:
------------
MST PCI module is not loaded
MST PCI configuration module is not loaded
PCI devices:
------------
DEVICE_TYPE MST PCI RDMA NET NUMA
ConnectX4LX(rev:0) NA 07:00.0 mlx5_1 net-ens2f0 0

4. Check QEMU version information. It must be Rev. 2.1 or above.

CLI Command
qemu-system-x86_64 --version
QEMU emulator version 2.7.50 (v2.7.0-456-gffd455a), Copyright (c) 2003-2016 Fabrice Bellard and the QEMU Project developers

To download a new qemu version refer to the official qemu site:

http://wiki.qemu.org/Download

5. Download required packages:

CLI Command
apt-get install unzip libnuma-dev python-six git


Configuration

Hugepages configuration

Configure the grub File and Mount hugepages

1. Update the grub.conf file.

Updating grub files is different for each Linux OS distribution. Refer to OS documentation.

Edit the grub.conf file in the GRUB_CMDLINE_LINUX line as follows:

"default_hugepagesz=1G hugepagesz=1G hugepages=8"

The following line defines the hugepages size and quantity. For most Intel processors, 2Mb and 1G sizes are supported. It is recommended to leave the OS at least 2G RAM free.

2. Update grub using OS grub script.

3. Reboot the server. The configuration will apply after reboot.

4 . Check that hugepages are loaded correctly after reboot:

CLI Command
cat /proc/meminfo | grep Hug

AnonHugePages: 2314240 kB
HugePages_Total: 8
HugePages_Free: 8
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 1048576 kB

The output shows eight hugepages free, each at 1G size.

5. Mount hugepages at size of 1G.

CLI Commands
mkdir -p /dev/hugepages

mount -t hugetlbfs -o pagesize=1G none /dev/hugepages
The mount of hugepages is not persistent. You must mount hugepages after each reboot.


DPDK Configuration

1. Download and extract DPDK 18.02 package.

CLI Commands
cd /usr/src/
git clone git://dpdk.org/dpdk
cd /usr/src/dpdk
git checkout v18.02

2. Set DPDK environment variables as follows:

CLI Commands
export DPDK_DIR=/usr/src/dpdk-stable-18.02.2
cd $DPDK_DIR
export DPDK_TARGET=x86_64-native-linuxapp-gcc
export DPDK_BUILD=$DPDK_DIR/$DPDK_TARGET

3. Modify compilation settings to support ConnectX-4 and ConnectX-5 interfaces with Dlopen dynamic linkage.

CLI Commands
sed -i 's/\(CONFIG_RTE_LIBRTE_MLX5_PMD=\)n/\1y/g' $DPDK_DIR/config/common_base
sed -i 's/\(CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS=\)n/\1y/g' $DPDK_DIR/config/common_base

4. Compile your DPDK code.

CLI Command
make -j install T=$DPDK_TARGET DESTDIR=install

5. Copy shared linked library to LD library path.

CLI Command
cp x86_64-native-linuxapp-gcc/lib/librte_pmd_mlx5_glue* /usr/lib64/

OVS Configuration

1. Download OVS version 2.9.0 or later.

CLI Commands
cd /usr/src/
git clone https://github.com/openvswitch/ovs.git -b branch-2.9

2. Configure OVS to compile with DPDK 18.02.

CLI Commands
cd /usr/src/ovs
./boot.sh
./configure --with-dpdk=$DPDK_BUILD CFLAGS="-g -O2 -Wno-cast-align"

3. Compile your code.

CLI Commands
make -j
make install

4. Reset OVS environment.

CLI Commands
pkill -9 ovs
rm -rf /usr/local/var/run/openvswitch/
rm -rf /usr/local/etc/openvswitch/
rm -f /usr/local/etc/openvswitch/conf.db
mkdir -p /usr/local/var/run/openvswitch/
mkdir -p /usr/local/etc/openvswitch/
rm -f /tmp/conf.db
mkdir -p /usr/local/etc/openvswitch
mkdir -p /usr/local/var/run/openvswitch
ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/share/openvswitch/vswitch.ovsschema
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach

5. Specify initial Open vSwitch (OVS) database to use:

CLI Commands
export PATH=$PATH:/usr/local/share/openvswitch/scripts
export DB_SOCK=/usr/local/var/run/openvswitch/db.sock

6. Configure OVS to support DPDK ports:

CLI Command
ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true

7. Start OVS-DPDK service:

CLI Command
ovs-ctl --no-ovsdb-server --db-sock="$DB_SOCK" start

Each time you reboot or there is an OVS termination, you need to rebuild the OVS environment and repeat steps 4-7 of this section.

8. Configure the source code analyzer (PMD) to work with 2G hugespages and NUMA node0.

CLI Command
ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-socket-mem="2048,0"

Find the correct NUMA number according to the prerequisites section. This example shows 2G (=2048) Hugepages and NUMA number 0.

9. Set core mask to enable several PMDs. In this example cores 1 - 4 are used 6=Bin 1110.

CLI Command
ovs-vsctl --no-wait set Open_vSwitch . other_config:pmd-cpu-mask=0xe

11. Create an OVS bridge.

CLI Command
ovs-vsctl add-br br0 -- set bridge br0 datapath_type=netdev

12. Create a DPDK port (dpdk0) with single RX queue using n_rxq=1 option. Inset dpdk-devargs pci slot number, taken from prerequisites section step 3 output.

CLI Command
ovs-vsctl add-port br0 dpdk0 -- set Interface dpdk0 type=dpdk options:dpdk-devargs=0000:07:00.0,n_rxq_desc=1024,n_txq_desc=1024,n_rxq=1,pmd-rxq-affinity="0:1" ofport_request=1

PMD 0 is set by affinity to cores 1

RXQ/TXQ descriptors set to 1024

13. Create a vhost-user port toward the guest machine with two RX queues and core affinity:

CLI Command
ovs-vsctl add-port br0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuserclient options:n_rxq=2,pmd-rxq-affinity="0:2,1:3"

PMD 0 and 1 are set by affinity to cores 2 and 3 respectively for host machine.

  • Make sure that you have enough free cores for host and guest PMDs, depending on the amount of RX queues configured. For the configuration above, 3 PMD cores are required for host and 2 cores for guest (5 cores total).

  • Use the top command to see that two PMD cores are running at 100% CPU usage.

  • If you do not use ofport_request in the OVS control command, the OVS will select a random port ID.

14. Set the environment parameter to identify the port IDs.

CLI Commands
DPDK0_INDEX=$(echo `ovs-ofctl show br1 | grep dpdk0 | cut -d '(' -f 1`)

VHOST_USER1_INDEX=$(echo `ovs-ofctl show br1 | grep vhost-user1 | cut -d '(' -f 1`)

Verify the assigned IDs:

CLI Commands
echo $DPDK0_INDEX
1
echo $VHOST_USER1_INDEX
2

15. Set OVS flow rules:

CLI Commands
ovs-ofctl add-flow br1 in_port=$DPDK0_INDEX,action=output:$VHOST_USER1_INDEX

ovs-ofctl add-flow br1 in_port=$VHOST_USER1_INDEX,action=output:$DPDK0_INDEX

Verify the new flows' insertion:

CLI Command
ovs-ofctl dump-flows br1

NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=4.903s, table=0, n_packets=8035688, n_bytes=482141280, idle_age=0, in_port=1 actions=output:2
cookie=0x0, duration=3.622s, table=0, n_packets=0, n_bytes=0, idle_age=3, in_port=2 actions=output:1
cookie=0x0, duration=353.725s, table=0, n_packets=284039649, n_bytes=17042378940, idle_age=5, priority=0 actions=NORMAL

VM Configuration

1. Launch a guest machine.

CLI Command
numactl --cpunodebind 0 --membind 0 -- \

echo 'info cpus' | \

/usr/src/qemu/x86_64-softmmu/qemu-system-x86_64 \

-enable-kvm \

-name gen-l-vrt-019-006-Ubuntu-15.10 \

-cpu host -m 6G \

-realtime mlock=off \

-smp 8,sockets=8,cores=1,threads=1 \

-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/gen-l-vrt-019-006-Ubuntu-15.10.monitor,server,nowait \

-drive file=/images/gen-l-vrt-019-006/gen-l-vrt-019-006.img,if=none,id=drive-ide0-0-0,format=qcow2 \

-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \

-netdev tap,id=hostnet0,script=no,downscript=no \

-device e1000,netdev=hostnet0,id=net0,mac=00:50:56:1b:b2:05,bus=pci.0,addr=0x3 \

-chardev socket,id=char1,path=/usr/local/var/run/openvswitch/vhost-user1 \

-netdev type=vhost-user,id=iface1,chardev=char1,vhostforce,queues=2 \

-device virtio-net-pci,netdev=iface1,mac=12:34:00:00:50:2c,csum=off,gso=off,guest_tso4=off,guest_tso6=off,guest_ecn=off,mrg_rxbuf=off,mq=on,vectors=6 \

-object memory-backend-file,id=mem,size=6144M,mem-path=/dev/hugepages,share=on \

-numa node,memdev=mem \

-mem-prealloc \

-monitor stdio \

> /tmp/qemu_cpu_info.txt&
  • Choose the right number of vhost-user queues to match the RX queues configured. In this example queue=2.
  • In some environments the external e1000 interface fails to come up. If it fails, add the following script=no,downscript=no.
    While the guest boots, bring up the interface manually as follows (in this example br0 is the main host bridge to the public network):

    CLI Commands
    brctl addif br0 tap0
    ifconfig tap0 up
  • The number of shared memory size (mem,size) must be equal to "cpu host -m". Also the amount of memory must not exceed the total amount of free memory for hugepages on the host.



2. Set CPU affinity for eight cores :

CLI Commands
a=( $(cat /tmp/qemu_cpu_info.txt | grep thread_id | cut -d '=' -f 3 | tr -d '\r' ) )
taskset -p 0x004 ${a[0]}
taskset -p 0x008 ${a[1]}
taskset -p 0x010 ${a[2]}
taskset -p 0x020 ${a[3]}
taskset -p 0x040 ${a[4]}
taskset -p 0x080 ${a[5]}
taskset -p 0x100 ${a[6]}
taskset -p 0x200 ${a[7]}
Make sure that the chosen cores for affinity do not correlate with the host number of PMD cores configured (see OVS configuration in section 8). In this example eight cores cores from 3-10 are pinned to guest machine.

3. Configure the guest machine to have 1G mounted hugepages.

Refer to (grub and hugepages configuration section above).

4. Load guest DPDK driver to use virtio interfaces.

It is assumed guest image already include compiled DPDK driver.

For further information on how to compile DPDK-18.02 inside guest machine refer to:

Compiling the DPDK Target from Source — Data Plane Development Kit 18.02.0-rc0 documentation

5. Find the virtio interface bus number:

CLI Command
lspci -nn | grep -i virtio
00:04.0 Ethernet controller [0200]: Red Hat, Inc Virtio network device [1af4:1000]

6. Load the DPDK driver:

CLI Commands
modprobe uio
insmod /usr/src/dpdk-18.02/x86_64-ivshmem-linuxapp-gcc/kmod/igb_uio.ko

7. Bind the DPDK driver to the PCI slot of the virtio interface:

CLI Command
 /usr/src/dpdk-18.02/tools/dpdk-devbind.py --bind=igb_uio 0000:00:04.0

Verification

1. Run testpmd to loop traffic for single port with UDP RSS.

The example that follows runs with 2G hugepages and two PMD cores.

The number of --rxq --txq queues must be equal to the number of queues defined before in 'Launch guest machine' section.

CLI Command
/usr/src/dpdk-18.02/x86_64-ivshmem-linuxapp-gcc/app/testpmd -v -c 0x1f -n 4 -m 2048 -- --burst=64 --rxq=2 --txq=2 --nb-cores=4 -a -i --mbcache=256 --rss-udp --port-topology=chained

UDP RSS takes effect only if you are injecting various source UDP ports.

Performance Tuning Recommendations

1. Configure the grub.conf file (in the GRUB_CMDLINE_LINUX line) to isolate and remove interrupts from the PMD CPUs.

It is not recommended that you list core0.

"isolcpus=1-8 nohz_full=1-8 rcu_nocbs=1-8"

2. Set scaling_governor to performance mode:

CLI Command
for (( i=0; i<$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | wc -l); i++ )); do echo performance > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor; done

3. Stop the irq balancing service:

CLI Command
service irqbalance stop

4. Disable kernel memory compaction:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
echo never > /sys/kernel/mm/transparent_hugepage/defrag]
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
sysctl -w vm.zone_reclaim_mode=0
sysctl -w vm.swappiness=0

5. Inside the VM, disable ksm/run.

CLI Command
echo 0 > /sys/kernel/mm/ksm/run

Related Documents

Notice

This document is provided for information purposes only and shall not be regarded as a warranty of a certain functionality, condition, or quality of a product. Neither NVIDIA Corporation nor any of its direct or indirect subsidiaries and affiliates (collectively: “NVIDIA”) make any representations or warranties, expressed or implied, as to the accuracy or completeness of the information contained in this document and assumes no responsibility for any errors contained herein. NVIDIA shall have no liability for the consequences or use of such information or for any infringement of patents or other rights of third parties that may result from its use. This document is not a commitment to develop, release, or deliver any Material (defined below), code, or functionality.
NVIDIA reserves the right to make corrections, modifications, enhancements, improvements, and any other changes to this document, at any time without notice.
Customer should obtain the latest relevant information before placing orders and should verify that such information is current and complete.
NVIDIA products are sold subject to the NVIDIA standard terms and conditions of sale supplied at the time of order acknowledgement, unless otherwise agreed in an individual sales agreement signed by authorized representatives of NVIDIA and customer (“Terms of Sale”). NVIDIA hereby expressly objects to applying any customer general terms and conditions with regards to the purchase of the NVIDIA product referenced in this document. No contractual obligations are formed either directly or indirectly by this document.
NVIDIA products are not designed, authorized, or warranted to be suitable for use in medical, military, aircraft, space, or life support equipment, nor in applications where failure or malfunction of the NVIDIA product can reasonably be expected to result in personal injury, death, or property or environmental damage. NVIDIA accepts no liability for inclusion and/or use of NVIDIA products in such equipment or applications and therefore such inclusion and/or use is at customer’s own risk.
NVIDIA makes no representation or warranty that products based on this document will be suitable for any specified use. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to evaluate and determine the applicability of any information contained in this document, ensure the product is suitable and fit for the application planned by customer, and perform the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this document. NVIDIA accepts no liability related to any default, damage, costs, or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this document or (ii) customer product designs.
No license, either expressed or implied, is granted under any NVIDIA patent right, copyright, or other NVIDIA intellectual property right under this document. Information published by NVIDIA regarding third-party products or services does not constitute a license from NVIDIA to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property rights of the third party, or a license from NVIDIA under the patents or other intellectual property rights of NVIDIA.
Reproduction of information in this document is permissible only if approved in advance by NVIDIA in writing, reproduced without alteration and in full compliance with all applicable export laws and regulations, and accompanied by all associated conditions, limitations, and notices.
THIS DOCUMENT AND ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL NVIDIA BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF ANY USE OF THIS DOCUMENT, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the products described herein shall be limited in accordance with the Terms of Sale for the product.

Trademarks
NVIDIA, the NVIDIA logo, and Mellanox are trademarks and/or registered trademarks of NVIDIA Corporation and/or Mellanox Technologies Ltd. in the U.S. and in other countries. Other company and product names may be trademarks of the respective companies with which they are associated.

Copyright
© 2022 NVIDIA Corporation & affiliates. All Rights Reserved.