Enabling the DPDK and OVS
The procedure for enabling the DPDK and OVS includes starting OVS, configuring the DPDK parameters and binding polling CPUs, loading user-mode drivers, creating DPDK-based OVS Bridge, enabling shared memory in the VM XML configuration file, and adding the DPDK network ports.
- Start OVS.
mkdir -p /var/log/openvswitch/ mkdir /var/run/openvswitch/ ovsdb-tool create /etc/openvswitch/conf.db service openvswitch restart
- Configure the DPDK and bind polling CPUs.
ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true other_config:dpdk-socket-mem="4096,4096,4096,4096" other_config:dpdk-lcore-mask="0xf8" other_config:pmd-cpu-mask="0xf0" service openvswitch restart
- dpdk-socket-mem configures the memory allocation for four NUMA nodes. If the actual number of NUMA nodes is not 4, modify the configuration as required.
- dpdk-lcore-mask and pmd-cpu-mask indicate the CPU mask. For example, to bind CPUs 4 to 7 to a specific task, the binary value of pmd-cpu-mask is 11110000 (the fifth to eighth digits from right to left are 1, and the CPU ID starts from 0). The binary value of dpdk-lcore-mask is 11111000, which has one more digit than the binary value of pmd-cpu-mask. Convert the two binary numbers to decimal numbers and then to hexadecimal numbers to obtain 0xf8 and 0xf0. You can use Python to quickly perform such a conversion, for example, print(hex(int('11110000', 2))).
- You are advised to bind the NIC to the CPU core of the NUMA node where the NIC is located.
- Check the network port name.
ip a
- Query the NUMA node where the NIC resides. Replace Network_port_name with an actual one.
cat /sys/class/net/Network_port_name/device/numa_node
- Check the network port name.
- Load the user-mode driver.
modprobe vfio modprobe vfio-pci
- Create a DPDK-based OVS Bridge.
- Create a Bridge.
ovs-vsctl add-br br-int -- set bridge br-int datapath_type=netdev ovs-vsctl add-port br-int p-tap-dpdk -- set Interface p-tap-dpdk type=patch options:peer=p-tap-dpdk-int
- Create a user-mode TAP port.
ovs-vsctl add-br br-ply$i -- set bridge br-ply$i datapath_type=netdev ovs-vsctl add-port br-ply$i tap$i -- set Interface tap$i type=dpdkvhostuser ovs-vsctl add-port br-ply$i p-tap$i-int -- set Interface p-tap$i-int type=patch options:peer=p-tap$i ovs-vsctl add-port br-int p-tap$i -- set Interface p-tap$i type=patch options:peer=p-tap$i-int
In the preceding commands, replace $i with the serial number of the TAP port. To create multiple TAP ports, modify $i and run the preceding commands again.
- Bind the NIC.
ovs-vsctl add-br br-dpdk -- set bridge br-dpdk datapath_type=netdev ovs-vsctl add-port br-dpdk p0 -- set Interface p0 type=dpdk options:dpdk-devargs=0000:9b:00.0 options:n_rxq=10 ovs-vsctl add-port br-dpdk p-tap-dpdk-int -- set Interface p-tap-dpdk-int type=patch options:peer=p-tap-dpdk
0000:9b:00.0 indicates the device ID corresponding to the physical function (PF) network port. Change it based on actual requirements.
- Check the OVS status.
ovs-vsctl show
- Create a Bridge.
- Configure the VM XML file.
- Enable the shared memory in the XML configuration of the VM. Locate the following configuration and add the following fields:
memAccess='shared'
The following is an example of how to add the fields:
1 2 3 4 5 6
<cpu mode='host-passthrough' check='none'> <topology sockets='1' dies='1' clusters='1' cores='4' threads='1'/> <numa> <cell id='0' cpus='0-3' memory='16777216' unit='KiB' memAccess='shared'/> </numa> </cpu>
- Add a DPDK network.
1 2 3 4 5 6 7 8 9
<interface type='vhostuser'> <mac address='52:54:00:62:9a:43'/> <source type='unix' path='/var/run/openvswitch/tap1' mode='client'> <reconnect enabled='yes' timeout='10'/> </source> <target dev='tap1'/> <model type='virtio'/> <driver name='vhost' queues='8' rx_queue_size='1024' tx_queue_size='1024'/> </interface>
tap1 indicates the name of the network port within the VM, which is created in 4. Change it based on actual requirements.
Query the actual TAP port.ls /var/run/openvswitch/
- Enable the shared memory in the XML configuration of the VM. Locate the following configuration and add the following fields:
Parent topic: VM Network Tuning