xref: /dpdk/doc/guides/sample_app_ug/vhost.rst (revision d80e42cce4c7017ed8c99dabb8ae444a492acc1c)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2010-2016 Intel Corporation.
3
4Vhost Sample Application
5========================
6
7The vhost sample application demonstrates integration of the Data Plane
8Development Kit (DPDK) with the Linux* KVM hypervisor by implementing the
9vhost-net offload API. The sample application performs simple packet
10switching between virtual machines based on Media Access Control (MAC)
11address or Virtual Local Area Network (VLAN) tag. The splitting of Ethernet
12traffic from an external switch is performed in hardware by the Virtual
13Machine Device Queues (VMDQ) and Data Center Bridging (DCB) features of
14the Intel® 82599 10 Gigabit Ethernet Controller.
15
16Testing steps
17-------------
18
19This section shows the steps how to test a typical PVP case with this
20vhost-switch sample, whereas packets are received from the physical NIC
21port first and enqueued to the VM's Rx queue. Through the guest testpmd's
22default forwarding mode (io forward), those packets will be put into
23the Tx queue. The vhost-switch example, in turn, gets the packets and
24puts back to the same physical NIC port.
25
26Build
27~~~~~
28
29To compile the sample application see :doc:`compiling`.
30
31The application is located in the ``vhost`` sub-directory.
32
33.. note::
34   In this example, you need build DPDK both on the host and inside guest.
35
36Start the vswitch example
37~~~~~~~~~~~~~~~~~~~~~~~~~
38
39.. code-block:: console
40
41        ./vhost-switch -l 0-3 -n 4 --socket-mem 1024  \
42             -- --socket-file /tmp/sock0 --client \
43             ...
44
45Check the `Parameters`_ section for the explanations on what do those
46parameters mean.
47
48.. _vhost_app_run_vm:
49
50Start the VM
51~~~~~~~~~~~~
52
53.. code-block:: console
54
55    qemu-system-x86_64 -machine accel=kvm -cpu host \
56        -m $mem -object memory-backend-file,id=mem,size=$mem,mem-path=/dev/hugepages,share=on \
57                -mem-prealloc -numa node,memdev=mem \
58        \
59        -chardev socket,id=char1,path=/tmp/sock0,server \
60        -netdev type=vhost-user,id=hostnet1,chardev=char1  \
61        -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:00:00:14 \
62        ...
63
64.. note::
65    For basic vhost-user support, QEMU 2.2 (or above) is required. For
66    some specific features, a higher version might be need. Such as
67    QEMU 2.7 (or above) for the reconnect feature.
68
69.. _vhost_app_run_dpdk_inside_guest:
70
71Run testpmd inside guest
72~~~~~~~~~~~~~~~~~~~~~~~~
73
74Make sure you have DPDK built inside the guest. Also make sure the
75corresponding virtio-net PCI device is bond to a uio driver, which
76could be done by:
77
78.. code-block:: console
79
80   modprobe uio_pci_generic
81   $RTE_SDK/usertools/dpdk-devbind.py -b=uio_pci_generic 0000:00:04.0
82
83Then start testpmd for packet forwarding testing.
84
85.. code-block:: console
86
87    ./x86_64-native-gcc/app/testpmd -l 0-1 -- -i
88    > start tx_first
89
90Inject packets
91--------------
92
93While a virtio-net is connected to vhost-switch, a VLAN tag starts with
941000 is assigned to it. So make sure configure your packet generator
95with the right MAC and VLAN tag, you should be able to see following
96log from the vhost-switch console. It means you get it work::
97
98    VHOST_DATA: (0) mac 52:54:00:00:00:14 and vlan 1000 registered
99
100
101.. _vhost_app_parameters:
102
103Parameters
104----------
105
106**--socket-file path**
107Specifies the vhost-user socket file path.
108
109**--client**
110DPDK vhost-user will act as the client mode when such option is given.
111In the client mode, QEMU will create the socket file. Otherwise, DPDK
112will create it. Put simply, it's the server to create the socket file.
113
114
115**--vm2vm mode**
116The vm2vm parameter sets the mode of packet switching between guests in
117the host.
118
119- 0 disables vm2vm, impling that VM's packets will always go to the NIC port.
120- 1 means a normal mac lookup packet routing.
121- 2 means hardware mode packet forwarding between guests, it allows packets
122  go to the NIC port, hardware L2 switch will determine which guest the
123  packet should forward to or need send to external, which bases on the
124  packet destination MAC address and VLAN tag.
125
126**--mergeable 0|1**
127Set 0/1 to disable/enable the mergeable Rx feature. It's disabled by default.
128
129**--stats interval**
130The stats parameter controls the printing of virtio-net device statistics.
131The parameter specifies an interval (in unit of seconds) to print statistics,
132with an interval of 0 seconds disabling statistics.
133
134**--rx-retry 0|1**
135The rx-retry option enables/disables enqueue retries when the guests Rx queue
136is full. This feature resolves a packet loss that is observed at high data
137rates, by allowing it to delay and retry in the receive path. This option is
138enabled by default.
139
140**--rx-retry-num num**
141The rx-retry-num option specifies the number of retries on an Rx burst, it
142takes effect only when rx retry is enabled.  The default value is 4.
143
144**--rx-retry-delay msec**
145The rx-retry-delay option specifies the timeout (in micro seconds) between
146retries on an RX burst, it takes effect only when rx retry is enabled. The
147default value is 15.
148
149**--dequeue-zero-copy**
150Dequeue zero copy will be enabled when this option is given. it is worth to
151note that if NIC is binded to driver with iommu enabled, dequeue zero copy
152cannot work at VM2NIC mode (vm2vm=0) due to currently we don't setup iommu
153dma mapping for guest memory.
154
155**--vlan-strip 0|1**
156VLAN strip option is removed, because different NICs have different behaviors
157when disabling VLAN strip. Such feature, which heavily depends on hardware,
158should be removed from this example to reduce confusion. Now, VLAN strip is
159enabled and cannot be disabled.
160
161Common Issues
162-------------
163
164* QEMU fails to allocate memory on hugetlbfs, with an error like the
165  following::
166
167      file_ram_alloc: can't mmap RAM pages: Cannot allocate memory
168
169  When running QEMU the above error indicates that it has failed to allocate
170  memory for the Virtual Machine on the hugetlbfs. This is typically due to
171  insufficient hugepages being free to support the allocation request. The
172  number of free hugepages can be checked as follows:
173
174  .. code-block:: console
175
176      cat /sys/kernel/mm/hugepages/hugepages-<pagesize>/nr_hugepages
177
178  The command above indicates how many hugepages are free to support QEMU's
179  allocation request.
180
181* Failed to build DPDK in VM
182
183  Make sure "-cpu host" QEMU option is given.
184
185* Device start fails if NIC's max queues > the default number of 128
186
187  mbuf pool size is dependent on the MAX_QUEUES configuration, if NIC's
188  max queue number is larger than 128, device start will fail due to
189  insufficient mbuf.
190
191  Change the default number to make it work as below, just set the number
192  according to the NIC's property. ::
193
194      make EXTRA_CFLAGS="-DMAX_QUEUES=320"
195