]> git.proxmox.com Git - mirror_ovs.git/blob - INSTALL.DPDK-ADVANCED.md
system-traffic: Flush conntrack after debug ping6.
[mirror_ovs.git] / INSTALL.DPDK-ADVANCED.md
1 OVS DPDK ADVANCED INSTALL GUIDE
2 =================================
3
4 ## Contents
5
6 1. [Overview](#overview)
7 2. [Building Shared Library](#build)
8 3. [System configuration](#sysconf)
9 4. [Performance Tuning](#perftune)
10 5. [OVS Testcases](#ovstc)
11 6. [Vhost Walkthrough](#vhost)
12 7. [QOS](#qos)
13 8. [Rate Limiting](#rl)
14 9. [Flow Control](#fc)
15 10. [Vsperf](#vsperf)
16
17 ## <a name="overview"></a> 1. Overview
18
19 The Advanced Install Guide explains how to improve OVS performance using
20 DPDK datapath. This guide also provides information on tuning, system configuration,
21 troubleshooting, static code analysis and testcases.
22
23 ## <a name="build"></a> 2. Building Shared Library
24
25 DPDK can be built as static or shared library and shall be linked by applications
26 using DPDK datapath. The section lists steps to build shared library and dynamically
27 link DPDK against OVS.
28
29 Note: Minor performance loss is seen with OVS when using shared DPDK library as
30 compared to static library.
31
32 Check section [INSTALL DPDK], [INSTALL OVS] of INSTALL.DPDK on download instructions
33 for DPDK and OVS.
34
35 * Configure the DPDK library
36
37 Set `CONFIG_RTE_BUILD_SHARED_LIB=y` in `config/common_base`
38 to generate shared DPDK library
39
40
41 * Build and install DPDK
42
43 For Default install (without IVSHMEM), set `export DPDK_TARGET=x86_64-native-linuxapp-gcc`
44 For IVSHMEM case, set `export DPDK_TARGET=x86_64-ivshmem-linuxapp-gcc`
45
46 ```
47 export DPDK_DIR=/usr/src/dpdk-16.07
48 export DPDK_BUILD=$DPDK_DIR/$DPDK_TARGET
49 make install T=$DPDK_TARGET DESTDIR=install
50 ```
51
52 * Build, Install and Setup OVS.
53
54 Export the DPDK shared library location and setup OVS as listed in
55 section 3.3 of INSTALL.DPDK.
56
57 `export LD_LIBRARY_PATH=$DPDK_DIR/x86_64-native-linuxapp-gcc/lib`
58
59 ## <a name="sysconf"></a> 3. System Configuration
60
61 To achieve optimal OVS performance, the system can be configured and that includes
62 BIOS tweaks, Grub cmdline additions, better understanding of NUMA nodes and
63 apt selection of PCIe slots for NIC placement.
64
65 ### 3.1 Recommended BIOS settings
66
67 ```
68 | Settings | values | comments
69 |---------------------------|-----------|-----------
70 | C3 power state | Disabled | -
71 | C6 power state | Disabled | -
72 | MLC Streamer | Enabled | -
73 | MLC Spacial prefetcher | Enabled | -
74 | DCU Data prefetcher | Enabled | -
75 | DCA | Enabled | -
76 | CPU power and performance | Performance -
77 | Memory RAS and perf | | -
78 config-> NUMA optimized | Enabled | -
79 ```
80
81 ### 3.2 PCIe Slot Selection
82
83 The fastpath performance also depends on factors like the NIC placement,
84 Channel speeds between PCIe slot and CPU, proximity of PCIe slot to the CPU
85 cores running DPDK application. Listed below are the steps to identify
86 right PCIe slot.
87
88 - Retrieve host details using cmd `dmidecode -t baseboard | grep "Product Name"`
89 - Download the technical specification for Product listed eg: S2600WT2.
90 - Check the Product Architecture Overview on the Riser slot placement,
91 CPU sharing info and also PCIe channel speeds.
92
93 example: On S2600WT, CPU1 and CPU2 share Riser Slot 1 with Channel speed between
94 CPU1 and Riser Slot1 at 32GB/s, CPU2 and Riser Slot1 at 16GB/s. Running DPDK app
95 on CPU1 cores and NIC inserted in to Riser card Slots will optimize OVS performance
96 in this case.
97
98 - Check the Riser Card #1 - Root Port mapping information, on the available slots
99 and individual bus speeds. In S2600WT slot 1, slot 2 has high bus speeds and are
100 potential slots for NIC placement.
101
102 ### 3.3 Advanced Hugepage setup
103
104 Allocate and mount 1G Huge pages:
105
106 - For persistent allocation of huge pages, add the following options to the kernel bootline
107
108 Add `default_hugepagesz=1GB hugepagesz=1G hugepages=N`
109
110 For platforms supporting multiple huge page sizes, Add options
111
112 `default_hugepagesz=<size> hugepagesz=<size> hugepages=N`
113 where 'N' = Number of huge pages requested, 'size' = huge page size,
114 optional suffix [kKmMgG]
115
116 - For run-time allocation of huge pages
117
118 `echo N > /sys/devices/system/node/nodeX/hugepages/hugepages-1048576kB/nr_hugepages`
119 where 'N' = Number of huge pages requested, 'X' = NUMA Node
120
121 Note: For run-time allocation of 1G huge pages, Contiguous Memory Allocator(CONFIG_CMA)
122 has to be supported by kernel, check your Linux distro.
123
124 - Mount huge pages
125
126 `mount -t hugetlbfs -o pagesize=1G none /dev/hugepages`
127
128 Note: Mount hugepages if not already mounted by default.
129
130 ### 3.4 Enable Hyperthreading
131
132 Requires BIOS changes
133
134 With HT/SMT enabled, A Physical core appears as two logical cores.
135 SMT can be utilized to spawn worker threads on logical cores of the same
136 physical core there by saving additional cores.
137
138 With DPDK, When pinning pmd threads to logical cores, care must be taken
139 to set the correct bits in the pmd-cpu-mask to ensure that the pmd threads are
140 pinned to SMT siblings.
141
142 Example System configuration:
143 Dual socket Machine, 2x 10 core processors, HT enabled, 40 logical cores
144
145 To use two logical cores which share the same physical core for pmd threads,
146 the following command can be used to identify a pair of logical cores.
147
148 `cat /sys/devices/system/cpu/cpuN/topology/thread_siblings_list`, where N is the
149 logical core number.
150
151 In this example, it would show that cores 1 and 21 share the same physical core.
152 The pmd-cpu-mask to enable two pmd threads running on these two logical cores
153 (one physical core) is.
154
155 `ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=100002`
156
157 ### 3.5 Isolate cores
158
159 'isolcpus' option can be used to isolate cores from the linux scheduler.
160 The isolated cores can then be used to dedicatedly run HPC applications/threads.
161 This helps in better application performance due to zero context switching and
162 minimal cache thrashing. To run platform logic on core 0 and isolate cores
163 between 1 and 19 from scheduler, Add `isolcpus=1-19` to GRUB cmdline.
164
165 Note: It has been verified that core isolation has minimal advantage due to
166 mature Linux scheduler in some circumstances.
167
168 ### 3.6 NUMA/Cluster on Die
169
170 Ideally inter NUMA datapaths should be avoided where possible as packets
171 will go across QPI and there may be a slight performance penalty when
172 compared with intra NUMA datapaths. On Intel Xeon Processor E5 v3,
173 Cluster On Die is introduced on models that have 10 cores or more.
174 This makes it possible to logically split a socket into two NUMA regions
175 and again it is preferred where possible to keep critical datapaths
176 within the one cluster.
177
178 It is good practice to ensure that threads that are in the datapath are
179 pinned to cores in the same NUMA area. e.g. pmd threads and QEMU vCPUs
180 responsible for forwarding. If DPDK is built with
181 CONFIG_RTE_LIBRTE_VHOST_NUMA=y, vHost User ports automatically
182 detect the NUMA socket of the QEMU vCPUs and will be serviced by a PMD
183 from the same node provided a core on this node is enabled in the
184 pmd-cpu-mask. libnuma packages are required for this feature.
185
186 ### 3.7 Compiler Optimizations
187
188 The default compiler optimization level is '-O2'. Changing this to
189 more aggressive compiler optimization such as '-O3 -march=native'
190 with gcc(verified on 5.3.1) can produce performance gains though not
191 siginificant. '-march=native' will produce optimized code on local machine
192 and should be used when SW compilation is done on Testbed.
193
194 ## <a name="perftune"></a> 4. Performance Tuning
195
196 ### 4.1 Affinity
197
198 For superior performance, DPDK pmd threads and Qemu vCPU threads
199 needs to be affinitized accordingly.
200
201 * PMD thread Affinity
202
203 A poll mode driver (pmd) thread handles the I/O of all DPDK
204 interfaces assigned to it. A pmd thread shall poll the ports
205 for incoming packets, switch the packets and send to tx port.
206 pmd thread is CPU bound, and needs to be affinitized to isolated
207 cores for optimum performance.
208
209 By setting a bit in the mask, a pmd thread is created and pinned
210 to the corresponding CPU core. e.g. to run a pmd thread on core 2
211
212 `ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=4`
213
214 Note: pmd thread on a NUMA node is only created if there is
215 at least one DPDK interface from that NUMA node added to OVS.
216
217 * Qemu vCPU thread Affinity
218
219 A VM performing simple packet forwarding or running complex packet
220 pipelines has to ensure that the vCPU threads performing the work has
221 as much CPU occupancy as possible.
222
223 Example: On a multicore VM, multiple QEMU vCPU threads shall be spawned.
224 when the DPDK 'testpmd' application that does packet forwarding
225 is invoked, 'taskset' cmd should be used to affinitize the vCPU threads
226 to the dedicated isolated cores on the host system.
227
228 ### 4.2 Multiple poll mode driver threads
229
230 With pmd multi-threading support, OVS creates one pmd thread
231 for each NUMA node by default. However, it can be seen that in cases
232 where there are multiple ports/rxq's producing traffic, performance
233 can be improved by creating multiple pmd threads running on separate
234 cores. These pmd threads can then share the workload by each being
235 responsible for different ports/rxq's. Assignment of ports/rxq's to
236 pmd threads is done automatically.
237
238 A set bit in the mask means a pmd thread is created and pinned
239 to the corresponding CPU core. e.g. to run pmd threads on core 1 and 2
240
241 `ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=6`
242
243 For example, when using dpdk and dpdkvhostuser ports in a bi-directional
244 VM loopback as shown below, spreading the workload over 2 or 4 pmd
245 threads shows significant improvements as there will be more total CPU
246 occupancy available.
247
248 NIC port0 <-> OVS <-> VM <-> OVS <-> NIC port 1
249
250 ### 4.3 DPDK physical port Rx Queues
251
252 `ovs-vsctl set Interface <DPDK interface> options:n_rxq=<integer>`
253
254 The command above sets the number of rx queues for DPDK physical interface.
255 The rx queues are assigned to pmd threads on the same NUMA node in a
256 round-robin fashion.
257
258 ### 4.4 Exact Match Cache
259
260 Each pmd thread contains one EMC. After initial flow setup in the
261 datapath, the EMC contains a single table and provides the lowest level
262 (fastest) switching for DPDK ports. If there is a miss in the EMC then
263 the next level where switching will occur is the datapath classifier.
264 Missing in the EMC and looking up in the datapath classifier incurs a
265 significant performance penalty. If lookup misses occur in the EMC
266 because it is too small to handle the number of flows, its size can
267 be increased. The EMC size can be modified by editing the define
268 EM_FLOW_HASH_SHIFT in lib/dpif-netdev.c.
269
270 As mentioned above an EMC is per pmd thread. So an alternative way of
271 increasing the aggregate amount of possible flow entries in EMC and
272 avoiding datapath classifier lookups is to have multiple pmd threads
273 running. This can be done as described in section 4.2.
274
275 ### 4.5 Rx Mergeable buffers
276
277 Rx Mergeable buffers is a virtio feature that allows chaining of multiple
278 virtio descriptors to handle large packet sizes. As such, large packets
279 are handled by reserving and chaining multiple free descriptors
280 together. Mergeable buffer support is negotiated between the virtio
281 driver and virtio device and is supported by the DPDK vhost library.
282 This behavior is typically supported and enabled by default, however
283 in the case where the user knows that rx mergeable buffers are not needed
284 i.e. jumbo frames are not needed, it can be forced off by adding
285 mrg_rxbuf=off to the QEMU command line options. By not reserving multiple
286 chains of descriptors it will make more individual virtio descriptors
287 available for rx to the guest using dpdkvhost ports and this can improve
288 performance.
289
290 ## <a name="ovstc"></a> 5. OVS Testcases
291 ### 5.1 PHY-VM-PHY [VHOST LOOPBACK]
292
293 The section 5.2 in INSTALL.DPDK guide lists steps for PVP loopback testcase
294 and packet forwarding using DPDK testpmd application in the Guest VM.
295 For users wanting to do packet forwarding using kernel stack below are the steps.
296
297 ```
298 ifconfig eth1 1.1.1.2/24
299 ifconfig eth2 1.1.2.2/24
300 systemctl stop firewalld.service
301 systemctl stop iptables.service
302 sysctl -w net.ipv4.ip_forward=1
303 sysctl -w net.ipv4.conf.all.rp_filter=0
304 sysctl -w net.ipv4.conf.eth1.rp_filter=0
305 sysctl -w net.ipv4.conf.eth2.rp_filter=0
306 route add -net 1.1.2.0/24 eth2
307 route add -net 1.1.1.0/24 eth1
308 arp -s 1.1.2.99 DE:AD:BE:EF:CA:FE
309 arp -s 1.1.1.99 DE:AD:BE:EF:CA:EE
310 ```
311
312 ### 5.2 PHY-VM-PHY [IVSHMEM]
313
314 The steps (1-5) in 3.3 section of INSTALL.DPDK guide will create & initialize DB,
315 start vswitchd and add dpdk devices to bridge br0.
316
317 1. Add DPDK ring port to the bridge
318
319 ```
320 ovs-vsctl add-port br0 dpdkr0 -- set Interface dpdkr0 type=dpdkr
321 ```
322
323 2. Build modified Qemu (Qemu-2.2.1 + ivshmem-qemu-2.2.1.patch)
324
325 ```
326 cd /usr/src/
327 wget http://wiki.qemu.org/download/qemu-2.2.1.tar.bz2
328 tar -jxvf qemu-2.2.1.tar.bz2
329 cd /usr/src/qemu-2.2.1
330 wget https://raw.githubusercontent.com/netgroup-polito/un-orchestrator/master/orchestrator/compute_controller/plugins/kvm-libvirt/patches/ivshmem-qemu-2.2.1.patch
331 patch -p1 < ivshmem-qemu-2.2.1.patch
332 ./configure --target-list=x86_64-softmmu --enable-debug --extra-cflags='-g'
333 make -j 4
334 ```
335
336 3. Generate Qemu commandline
337
338 ```
339 mkdir -p /usr/src/cmdline_generator
340 cd /usr/src/cmdline_generator
341 wget https://raw.githubusercontent.com/netgroup-polito/un-orchestrator/master/orchestrator/compute_controller/plugins/kvm-libvirt/cmdline_generator/cmdline_generator.c
342 wget https://raw.githubusercontent.com/netgroup-polito/un-orchestrator/master/orchestrator/compute_controller/plugins/kvm-libvirt/cmdline_generator/Makefile
343 export RTE_SDK=/usr/src/dpdk-16.07
344 export RTE_TARGET=x86_64-ivshmem-linuxapp-gcc
345 make
346 ./build/cmdline_generator -m -p dpdkr0 XXX
347 cmdline=`cat OVSMEMPOOL`
348 ```
349
350 4. start Guest VM
351
352 ```
353 export VM_NAME=ivshmem-vm
354 export QCOW2_IMAGE=/root/CentOS7_x86_64.qcow2
355 export QEMU_BIN=/usr/src/qemu-2.2.1/x86_64-softmmu/qemu-system-x86_64
356
357 taskset 0x20 $QEMU_BIN -cpu host -smp 2,cores=2 -hda $QCOW2_IMAGE -m 4096 --enable-kvm -name $VM_NAME -nographic -vnc :2 -pidfile /tmp/vm1.pid $cmdline
358 ```
359
360 5. Running sample "dpdk ring" app in VM
361
362 ```
363 echo 1024 > /proc/sys/vm/nr_hugepages
364 mount -t hugetlbfs nodev /dev/hugepages (if not already mounted)
365
366 # Build the DPDK ring application in the VM
367 export RTE_SDK=/root/dpdk-16.07
368 export RTE_TARGET=x86_64-ivshmem-linuxapp-gcc
369 make
370
371 # Run dpdkring application
372 ./build/dpdkr -c 1 -n 4 -- -n 0
373 where "-n 0" refers to ring '0' i.e dpdkr0
374 ```
375
376 ## <a name="vhost"></a> 6. Vhost Walkthrough
377
378 DPDK 16.07 supports two types of vhost:
379
380 1. vhost-user - enabled default
381
382 2. vhost-cuse - Legacy, disabled by default
383
384 ### 6.1 vhost-user
385
386 - Prerequisites:
387
388 QEMU version >= 2.2
389
390 - Adding vhost-user ports to Switch
391
392 Unlike DPDK ring ports, DPDK vhost-user ports can have arbitrary names,
393 except that forward and backward slashes are prohibited in the names.
394
395 For vhost-user, the name of the port type is `dpdkvhostuser`
396
397 ```
398 ovs-vsctl add-port br0 vhost-user-1 -- set Interface vhost-user-1
399 type=dpdkvhostuser
400 ```
401
402 This action creates a socket located at
403 `/usr/local/var/run/openvswitch/vhost-user-1`, which you must provide
404 to your VM on the QEMU command line. More instructions on this can be
405 found in the next section "Adding vhost-user ports to VM"
406
407 Note: If you wish for the vhost-user sockets to be created in a
408 sub-directory of `/usr/local/var/run/openvswitch`, you may specify
409 this directory in the ovsdb like so:
410
411 `./utilities/ovs-vsctl --no-wait \
412 set Open_vSwitch . other_config:vhost-sock-dir=subdir`
413
414 - Adding vhost-user ports to VM
415
416 1. Configure sockets
417
418 Pass the following parameters to QEMU to attach a vhost-user device:
419
420 ```
421 -chardev socket,id=char1,path=/usr/local/var/run/openvswitch/vhost-user-1
422 -netdev type=vhost-user,id=mynet1,chardev=char1,vhostforce
423 -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1
424 ```
425
426 where vhost-user-1 is the name of the vhost-user port added
427 to the switch.
428 Repeat the above parameters for multiple devices, changing the
429 chardev path and id as necessary. Note that a separate and different
430 chardev path needs to be specified for each vhost-user device. For
431 example you have a second vhost-user port named 'vhost-user-2', you
432 append your QEMU command line with an additional set of parameters:
433
434 ```
435 -chardev socket,id=char2,path=/usr/local/var/run/openvswitch/vhost-user-2
436 -netdev type=vhost-user,id=mynet2,chardev=char2,vhostforce
437 -device virtio-net-pci,mac=00:00:00:00:00:02,netdev=mynet2
438 ```
439
440 2. Configure huge pages.
441
442 QEMU must allocate the VM's memory on hugetlbfs. vhost-user ports access
443 a virtio-net device's virtual rings and packet buffers mapping the VM's
444 physical memory on hugetlbfs. To enable vhost-user ports to map the VM's
445 memory into their process address space, pass the following parameters
446 to QEMU:
447
448 ```
449 -object memory-backend-file,id=mem,size=4096M,mem-path=/dev/hugepages,
450 share=on -numa node,memdev=mem -mem-prealloc
451 ```
452
453 3. Enable multiqueue support(OPTIONAL)
454
455 QEMU needs to be configured to use multiqueue.
456 The $q below is the number of queues.
457 The $v is the number of vectors, which is '$q x 2 + 2'.
458
459 ```
460 -chardev socket,id=char2,path=/usr/local/var/run/openvswitch/vhost-user-2
461 -netdev type=vhost-user,id=mynet2,chardev=char2,vhostforce,queues=$q
462 -device virtio-net-pci,mac=00:00:00:00:00:02,netdev=mynet2,mq=on,vectors=$v
463 ```
464
465 The vhost-user interface will be automatically reconfigured with required
466 number of rx and tx queues after connection of virtio device.
467 Manual configuration of `n_rxq` is not supported because OVS will work
468 properly only if `n_rxq` will match number of queues configured in QEMU.
469
470 A least 2 PMDs should be configured for the vswitch when using multiqueue.
471 Using a single PMD will cause traffic to be enqueued to the same vhost
472 queue rather than being distributed among different vhost queues for a
473 vhost-user interface.
474
475 If traffic destined for a VM configured with multiqueue arrives to the
476 vswitch via a physical DPDK port, then the number of rxqs should also be
477 set to at least 2 for that physical DPDK port. This is required to increase
478 the probability that a different PMD will handle the multiqueue
479 transmission to the guest using a different vhost queue.
480
481 If one wishes to use multiple queues for an interface in the guest, the
482 driver in the guest operating system must be configured to do so. It is
483 recommended that the number of queues configured be equal to '$q'.
484
485 For example, this can be done for the Linux kernel virtio-net driver with:
486
487 ```
488 ethtool -L <DEV> combined <$q>
489 ```
490 where `-L`: Changes the numbers of channels of the specified network device
491 and `combined`: Changes the number of multi-purpose channels.
492
493 - VM Configuration with libvirt
494
495 * change the user/group, access control policty and restart libvirtd.
496
497 - In `/etc/libvirt/qemu.conf` add/edit the following lines
498
499 ```
500 user = "root"
501 group = "root"
502 ```
503
504 - Disable SELinux or set to permissive mode
505
506 `setenforce 0`
507
508 - Restart the libvirtd process, For example, on Fedora
509
510 `systemctl restart libvirtd.service`
511
512 * Instantiate the VM
513
514 - Copy the xml configuration from [Guest VM using libvirt] in to workspace.
515
516 - Start the VM.
517
518 `virsh create demovm.xml`
519
520 - Connect to the guest console
521
522 `virsh console demovm`
523
524 * VM configuration
525
526 The demovm xml configuration is aimed at achieving out of box performance
527 on VM.
528
529 - The vcpus are pinned to the cores of the CPU socket 0 using vcpupin.
530
531 - Configure NUMA cell and memory shared using memAccess='shared'.
532
533 - Disable mrg_rxbuf='off'.
534
535 Note: For information on libvirt and further tuning refer [libvirt].
536
537 ### 6.2 vhost-cuse
538
539 - Prerequisites:
540
541 QEMU version >= 2.2
542
543 - Enable vhost-cuse support
544
545 1. Enable vhost cuse support in DPDK
546
547 Set `CONFIG_RTE_LIBRTE_VHOST_USER=n` in config/common_linuxapp and follow the
548 steps in 2.2 section of INSTALL.DPDK guide to build DPDK with cuse support.
549 OVS will detect that DPDK has vhost-cuse libraries compiled and in turn will enable
550 support for it in the switch and disable vhost-user support.
551
552 2. Insert the Cuse module
553
554 `modprobe cuse`
555
556 3. Build and insert the `eventfd_link` module
557
558 ```
559 cd $DPDK_DIR/lib/librte_vhost/eventfd_link/
560 make
561 insmod $DPDK_DIR/lib/librte_vhost/eventfd_link.ko
562 ```
563
564 - Adding vhost-cuse ports to Switch
565
566 Unlike DPDK ring ports, DPDK vhost-cuse ports can have arbitrary names.
567 For vhost-cuse, the name of the port type is `dpdkvhostcuse`
568
569 ```
570 ovs-vsctl add-port br0 vhost-cuse-1 -- set Interface vhost-cuse-1
571 type=dpdkvhostcuse
572 ```
573
574 When attaching vhost-cuse ports to QEMU, the name provided during the
575 add-port operation must match the ifname parameter on the QEMU cmd line.
576
577 - Adding vhost-cuse ports to VM
578
579 vhost-cuse ports use a Linux* character device to communicate with QEMU.
580 By default it is set to `/dev/vhost-net`. It is possible to reuse this
581 standard device for DPDK vhost, which makes setup a little simpler but it
582 is better practice to specify an alternative character device in order to
583 avoid any conflicts if kernel vhost is to be used in parallel.
584
585 1. This step is only needed if using an alternative character device.
586
587 ```
588 ./utilities/ovs-vsctl --no-wait set Open_vSwitch . \
589 other_config:cuse-dev-name=my-vhost-net
590 ```
591
592 In the example above, the character device to be used will be
593 `/dev/my-vhost-net`.
594
595 2. In case of reusing kernel vhost character device, there would be conflict
596 user should remove it.
597
598 `rm -rf /dev/vhost-net`
599
600 3. Configure virtio-net adapters
601
602 The following parameters must be passed to the QEMU binary, repeat
603 the below parameters for multiple devices.
604
605 ```
606 -netdev tap,id=<id>,script=no,downscript=no,ifname=<name>,vhost=on
607 -device virtio-net-pci,netdev=net1,mac=<mac>
608 ```
609
610 The DPDK vhost library will negotiate its own features, so they
611 need not be passed in as command line params. Note that as offloads
612 are disabled this is the equivalent of setting
613
614 `csum=off,gso=off,guest_tso4=off,guest_tso6=off,guest_ecn=off`
615
616 When using an alternative character device, it must be explicitly
617 passed to QEMU using the `vhostfd` argument
618
619 ```
620 -netdev tap,id=<id>,script=no,downscript=no,ifname=<name>,vhost=on,
621 vhostfd=<open_fd> -device virtio-net-pci,netdev=net1,mac=<mac>
622 ```
623
624 The open file descriptor must be passed to QEMU running as a child
625 process. This could be done with a simple python script.
626
627 ```
628 #!/usr/bin/python
629 fd = os.open("/dev/usvhost", os.O_RDWR)
630 subprocess.call("qemu-system-x86_64 .... -netdev tap,id=vhostnet0,\
631 vhost=on,vhostfd=" + fd +"...", shell=True)
632 ```
633
634 4. Configure huge pages
635
636 QEMU must allocate the VM's memory on hugetlbfs. Vhost ports access a
637 virtio-net device's virtual rings and packet buffers mapping the VM's
638 physical memory on hugetlbfs. To enable vhost-ports to map the VM's
639 memory into their process address space, pass the following parameters
640 to QEMU
641
642 `-object memory-backend-file,id=mem,size=4096M,mem-path=/dev/hugepages,
643 share=on -numa node,memdev=mem -mem-prealloc`
644
645 - VM Configuration with QEMU wrapper
646
647 The QEMU wrapper script automatically detects and calls QEMU with the
648 necessary parameters. It performs the following actions:
649
650 * Automatically detects the location of the hugetlbfs and inserts this
651 into the command line parameters.
652 * Automatically open file descriptors for each virtio-net device and
653 inserts this into the command line parameters.
654 * Calls QEMU passing both the command line parameters passed to the
655 script itself and those it has auto-detected.
656
657 Before use, you **must** edit the configuration parameters section of the
658 script to point to the correct emulator location and set additional
659 settings. Of these settings, `emul_path` and `us_vhost_path` **must** be
660 set. All other settings are optional.
661
662 To use directly from the command line simply pass the wrapper some of the
663 QEMU parameters: it will configure the rest. For example:
664
665 ```
666 qemu-wrap.py -cpu host -boot c -hda <disk image> -m 4096 -smp 4
667 --enable-kvm -nographic -vnc none -net none -netdev tap,id=net1,
668 script=no,downscript=no,ifname=if1,vhost=on -device virtio-net-pci,
669 netdev=net1,mac=00:00:00:00:00:01
670 ```
671
672 - VM Configuration with libvirt
673
674 If you are using libvirt, you must enable libvirt to access the character
675 device by adding it to controllers cgroup for libvirtd using the following
676 steps.
677
678 1. In `/etc/libvirt/qemu.conf` add/edit the following lines:
679
680 ```
681 clear_emulator_capabilities = 0
682 user = "root"
683 group = "root"
684 cgroup_device_acl = [
685 "/dev/null", "/dev/full", "/dev/zero",
686 "/dev/random", "/dev/urandom",
687 "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
688 "/dev/rtc", "/dev/hpet", "/dev/net/tun",
689 "/dev/<my-vhost-device>",
690 "/dev/hugepages"]
691 ```
692
693 <my-vhost-device> refers to "vhost-net" if using the `/dev/vhost-net`
694 device. If you have specificed a different name in the database
695 using the "other_config:cuse-dev-name" parameter, please specify that
696 filename instead.
697
698 2. Disable SELinux or set to permissive mode
699
700 3. Restart the libvirtd process
701 For example, on Fedora:
702
703 `systemctl restart libvirtd.service`
704
705 After successfully editing the configuration, you may launch your
706 vhost-enabled VM. The XML describing the VM can be configured like so
707 within the <qemu:commandline> section:
708
709 1. Set up shared hugepages:
710
711 ```
712 <qemu:arg value='-object'/>
713 <qemu:arg value='memory-backend-file,id=mem,size=4096M,mem-path=/dev/hugepages,share=on'/>
714 <qemu:arg value='-numa'/>
715 <qemu:arg value='node,memdev=mem'/>
716 <qemu:arg value='-mem-prealloc'/>
717 ```
718
719 2. Set up your tap devices:
720
721 ```
722 <qemu:arg value='-netdev'/>
723 <qemu:arg value='type=tap,id=net1,script=no,downscript=no,ifname=vhost0,vhost=on'/>
724 <qemu:arg value='-device'/>
725 <qemu:arg value='virtio-net-pci,netdev=net1,mac=00:00:00:00:00:01'/>
726 ```
727
728 Repeat for as many devices as are desired, modifying the id, ifname
729 and mac as necessary.
730
731 Again, if you are using an alternative character device (other than
732 `/dev/vhost-net`), please specify the file descriptor like so:
733
734 `<qemu:arg value='type=tap,id=net3,script=no,downscript=no,ifname=vhost0,vhost=on,vhostfd=<open_fd>'/>`
735
736 Where <open_fd> refers to the open file descriptor of the character device.
737 Instructions of how to retrieve the file descriptor can be found in the
738 "DPDK vhost VM configuration" section.
739 Alternatively, the process is automated with the qemu-wrap.py script,
740 detailed in the next section.
741
742 Now you may launch your VM using virt-manager, or like so:
743
744 `virsh create my_vhost_vm.xml`
745
746 - VM Configuration with libvirt & QEMU wrapper
747
748 To use the qemu-wrapper script in conjuntion with libvirt, follow the
749 steps in the previous section before proceeding with the following steps:
750
751 1. Place `qemu-wrap.py` in libvirtd binary search PATH ($PATH)
752 Ideally in the same directory that the QEMU binary is located.
753
754 2. Ensure that the script has the same owner/group and file permissions
755 as the QEMU binary.
756
757 3. Update the VM xml file using "virsh edit VM.xml"
758
759 Set the VM to use the launch script.
760 Set the emulator path contained in the `<emulator><emulator/>` tags.
761 For example, replace `<emulator>/usr/bin/qemu-kvm<emulator/>` with
762 `<emulator>/usr/bin/qemu-wrap.py<emulator/>`
763
764 4. Edit the Configuration Parameters section of the script to point to
765 the correct emulator location and set any additional options. If you are
766 using a alternative character device name, please set "us_vhost_path" to the
767 location of that device. The script will automatically detect and insert
768 the correct "vhostfd" value in the QEMU command line arguments.
769
770 5. Use virt-manager to launch the VM
771
772 ### 6.3 DPDK backend inside VM
773
774 Please note that additional configuration is required if you want to run
775 ovs-vswitchd with DPDK backend inside a QEMU virtual machine. Ovs-vswitchd
776 creates separate DPDK TX queues for each CPU core available. This operation
777 fails inside QEMU virtual machine because, by default, VirtIO NIC provided
778 to the guest is configured to support only single TX queue and single RX
779 queue. To change this behavior, you need to turn on 'mq' (multiqueue)
780 property of all virtio-net-pci devices emulated by QEMU and used by DPDK.
781 You may do it manually (by changing QEMU command line) or, if you use
782 Libvirt, by adding the following string:
783
784 `<driver name='vhost' queues='N'/>`
785
786 to <interface> sections of all network devices used by DPDK. Parameter 'N'
787 determines how many queues can be used by the guest.This may not work with
788 old versions of QEMU found in some distros and need Qemu version >= 2.2.
789
790 ## <a name="qos"></a> 7. QOS
791
792 Here is an example on QOS usage.
793 Assuming you have a vhost-user port transmitting traffic consisting of
794 packets of size 64 bytes, the following command would limit the egress
795 transmission rate of the port to ~1,000,000 packets per second
796
797 `ovs-vsctl set port vhost-user0 qos=@newqos -- --id=@newqos create qos
798 type=egress-policer other-config:cir=46000000 other-config:cbs=2048`
799
800 To examine the QoS configuration of the port:
801
802 `ovs-appctl -t ovs-vswitchd qos/show vhost-user0`
803
804 To clear the QoS configuration from the port and ovsdb use the following:
805
806 `ovs-vsctl destroy QoS vhost-user0 -- clear Port vhost-user0 qos`
807
808 For more details regarding egress-policer parameters please refer to the
809 vswitch.xml.
810
811 ## <a name="rl"></a> 8. Rate Limiting
812
813 Here is an example on Ingress Policing usage.
814 Assuming you have a vhost-user port receiving traffic consisting of
815 packets of size 64 bytes, the following command would limit the reception
816 rate of the port to ~1,000,000 packets per second:
817
818 `ovs-vsctl set interface vhost-user0 ingress_policing_rate=368000
819 ingress_policing_burst=1000`
820
821 To examine the ingress policer configuration of the port:
822
823 `ovs-vsctl list interface vhost-user0`
824
825 To clear the ingress policer configuration from the port use the following:
826
827 `ovs-vsctl set interface vhost-user0 ingress_policing_rate=0`
828
829 For more details regarding ingress-policer see the vswitch.xml.
830
831 ## <a name="fc"></a> 9. Flow control.
832 Flow control can be enabled only on DPDK physical ports.
833 To enable flow control support at tx side while adding a port, add the
834 'tx-flow-ctrl' option to the 'ovs-vsctl add-port' as in the eg: below.
835
836 ```
837 ovs-vsctl add-port br0 dpdk0 -- \
838 set Interface dpdk0 type=dpdk options:tx-flow-ctrl=true
839 ```
840
841 Similarly to enable rx flow control,
842
843 ```
844 ovs-vsctl add-port br0 dpdk0 -- \
845 set Interface dpdk0 type=dpdk options:rx-flow-ctrl=true
846 ```
847
848 And to enable the flow control auto-negotiation,
849
850 ```
851 ovs-vsctl add-port br0 dpdk0 -- \
852 set Interface dpdk0 type=dpdk options:flow-ctrl-autoneg=true
853 ```
854
855 To turn ON the tx flow control at run time(After the port is being added
856 to OVS), the command-line input will be,
857
858 `ovs-vsctl set Interface dpdk0 options:tx-flow-ctrl=true`
859
860 The flow control parameters can be turned off by setting 'false' to the
861 respective parameter. To disable the flow control at tx side,
862
863 `ovs-vsctl set Interface dpdk0 options:tx-flow-ctrl=false`
864
865 ## <a name="vsperf"></a> 10. Vsperf
866
867 Vsperf project goal is to develop vSwitch test framework that can be used to
868 validate the suitability of different vSwitch implementations in a Telco deployment
869 environment. More information can be found in below link.
870
871 https://wiki.opnfv.org/display/vsperf/VSperf+Home
872
873
874 Bug Reporting:
875 --------------
876
877 Please report problems to bugs@openvswitch.org.
878
879
880 [INSTALL.userspace.md]:INSTALL.userspace.md
881 [INSTALL.md]:INSTALL.md
882 [DPDK Linux GSG]: http://www.dpdk.org/doc/guides/linux_gsg/build_dpdk.html#binding-and-unbinding-network-ports-to-from-the-igb-uioor-vfio-modules
883 [DPDK Docs]: http://dpdk.org/doc
884 [libvirt]: http://libvirt.org/formatdomain.html
885 [Guest VM using libvirt]: INSTALL.DPDK.md#ovstc
886 [INSTALL DPDK]: INSTALL.DPDK.md#build
887 [INSTALL OVS]: INSTALL.DPDK.md#build