f159608a844cc84f2d17a6806494b6f6ee1f37f4
[dpdk.git] / doc / guides / howto / lm_virtio_vhost_user.rst
1 ..  BSD LICENSE
2     Copyright(c) 2016 Intel Corporation. All rights reserved.
3     All rights reserved.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
9     * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in
13     the documentation and/or other materials provided with the
14     distribution.
15     * Neither the name of Intel Corporation nor the names of its
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31
32 Live Migration of VM with Virtio on host running vhost_user
33 ===========================================================
34
35 Overview
36 --------
37
38 Live Migration of a VM with DPDK Virtio PMD on a host which is
39 running the Vhost sample application (vhost-switch) and using the DPDK PMD (ixgbe or i40e).
40
41 The Vhost sample application uses VMDQ so SRIOV must be disabled on the NIC's.
42
43 The following sections show an example of how to do this migration.
44
45 Test Setup
46 ----------
47
48 To test the Live Migration two servers with identical operating systems installed are used.
49 KVM and QEMU is also required on the servers.
50
51 QEMU 2.5 is required for Live Migration of a VM with vhost_user running on the hosts.
52
53 In this example, the servers have Niantic and or Fortville NIC's installed.
54 The NIC's on both servers are connected to a switch
55 which is also connected to the traffic generator.
56
57 The switch is configured to broadcast traffic on all the NIC ports.
58
59 The ip address of host_server_1 is 10.237.212.46
60
61 The ip address of host_server_2 is 10.237.212.131
62
63 Live Migration steps
64 --------------------
65
66 The sample scripts mentioned in the steps below can be found in the
67 :ref:`Sample host scripts <lm_virtio_vhost_user_host_scripts>` and
68 :ref:`Sample VM scripts <lm_virtio_vhost_user_vm_scripts>` sections.
69
70 On host_server_1: Terminal 1
71 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
73 Setup DPDK on host_server_1
74
75 .. code-block:: console
76
77    cd /root/dpdk/host_scripts
78    ./setup_dpdk_on_host.sh
79
80 On host_server_1: Terminal 2
81 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
83 Bind the Niantic or Fortville NIC to igb_uio on host_server_1.
84
85 For Fortville NIC.
86
87 .. code-block:: console
88
89    cd /root/dpdk/tools
90    ./dpdk_nic_bind.py -b igb_uio 0000:02:00.0
91
92 For Niantic NIC.
93
94 .. code-block:: console
95
96    cd /root/dpdk/tools
97    ./dpdk_nic_bind.py -b igb_uio 0000:09:00.0
98
99 On host_server_1: Terminal 3
100 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
102 For Fortville and Niantic NIC's reset SRIOV and run the
103 vhost_user sample application (vhost-switch) on host_server_1.
104
105 .. code-block:: console
106
107    cd /root/dpdk/host_scripts
108    ./reset_vf_on_212_46.sh
109    ./run_vhost_switch_on_host.sh
110
111 On host_server_1: Terminal 1
112 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
114 Start the VM on host_server_1
115
116 .. code-block:: console
117
118    ./vm_virtio_vhost_user.sh
119
120 On host_server_1: Terminal 4
121 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122
123 Connect to the QEMU monitor on host_server_1.
124
125 .. code-block:: console
126
127    cd /root/dpdk/host_scripts
128    ./connect_to_qemu_mon_on_host.sh
129    (qemu)
130
131 On host_server_1: Terminal 1
132 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133
134 **In VM on host_server_1:**
135
136 Setup DPDK in the VM and run testpmd in the VM.
137
138 .. code-block:: console
139
140    cd /root/dpdk/vm_scripts
141    ./setup_dpdk_in_vm.sh
142    ./run_testpmd_in_vm.sh
143
144    testpmd> show port info all
145    testpmd> set fwd mac retry
146    testpmd> start tx_first
147    testpmd> show port stats all
148
149 Virtio traffic is seen at P1 and P2.
150
151 On host_server_2: Terminal 1
152 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153
154 Set up DPDK on the host_server_2.
155
156 .. code-block:: console
157
158    cd /root/dpdk/host_scripts
159    ./setup_dpdk_on_host.sh
160
161 On host_server_2: Terminal 2
162 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163
164 Bind the Niantic or Fortville NIC to igb_uio on host_server_2.
165
166 For Fortville NIC.
167
168 .. code-block:: console
169
170    cd /root/dpdk/tools
171    ./dpdk_nic_bind.py -b igb_uio 0000:03:00.0
172
173 For Niantic NIC.
174
175 .. code-block:: console
176
177    cd /root/dpdk/tools
178    ./dpdk_nic_bind.py -b igb_uio 0000:06:00.0
179
180 On host_server_2: Terminal 3
181 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182
183 For Fortville and Niantic NIC's reset SRIOV, and run
184 the vhost_user sample application on host_server_2.
185
186 .. code-block:: console
187
188    cd /root/dpdk/host_scripts
189    ./reset_vf_on_212_131.sh
190    ./run_vhost_switch_on_host.sh
191
192 On host_server_2: Terminal 1
193 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194
195 Start the VM on host_server_2.
196
197 .. code-block:: console
198
199    ./vm_virtio_vhost_user_migrate.sh
200
201 On host_server_2: Terminal 4
202 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
204 Connect to the QEMU monitor on host_server_2.
205
206 .. code-block:: console
207
208    cd /root/dpdk/host_scripts
209    ./connect_to_qemu_mon_on_host.sh
210    (qemu) info status
211    VM status: paused (inmigrate)
212    (qemu)
213
214 On host_server_1: Terminal 4
215 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216
217 Check that switch is up before migrating the VM.
218
219 .. code-block:: console
220
221    (qemu) migrate tcp:10.237.212.131:5555
222    (qemu) info status
223    VM status: paused (postmigrate)
224
225    (qemu) info migrate
226    capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off
227    Migration status: completed
228    total time: 11619 milliseconds
229    downtime: 5 milliseconds
230    setup: 7 milliseconds
231    transferred ram: 379699 kbytes
232    throughput: 267.82 mbps
233    remaining ram: 0 kbytes
234    total ram: 1590088 kbytes
235    duplicate: 303985 pages
236    skipped: 0 pages
237    normal: 94073 pages
238    normal bytes: 376292 kbytes
239    dirty sync count: 2
240    (qemu) quit
241
242 On host_server_2: Terminal 1
243 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244
245 **In VM on host_server_2:**
246
247    Hit Enter key. This brings the user to the testpmd prompt.
248
249 .. code-block:: console
250
251    testpmd>
252
253 On host_server_2: Terminal 4
254 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255
256 **In QEMU monitor on host_server_2**
257
258 .. code-block:: console
259
260    (qemu) info status
261    VM status: running
262
263 On host_server_2: Terminal 1
264 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265
266 **In VM on host_server_2:**
267
268 .. code-block:: console
269
270    testomd> show port info all
271    testpmd> show port stats all
272
273 Virtio traffic is seen at P0 and P1.
274
275
276 .. _lm_virtio_vhost_user_host_scripts:
277
278 Sample host scripts
279 -------------------
280
281 reset_vf_on_212_46.sh
282 ~~~~~~~~~~~~~~~~~~~~~
283
284 .. code-block:: sh
285
286    #!/bin/sh
287    # This script is run on the host 10.237.212.46 to reset SRIOV
288
289    # BDF for Fortville NIC is 0000:02:00.0
290    cat /sys/bus/pci/devices/0000\:02\:00.0/max_vfs
291    echo 0 > /sys/bus/pci/devices/0000\:02\:00.0/max_vfs
292    cat /sys/bus/pci/devices/0000\:02\:00.0/max_vfs
293
294    # BDF for Niantic NIC is 0000:09:00.0
295    cat /sys/bus/pci/devices/0000\:09\:00.0/max_vfs
296    echo 0 > /sys/bus/pci/devices/0000\:09\:00.0/max_vfs
297    cat /sys/bus/pci/devices/0000\:09\:00.0/max_vfs
298
299 vm_virtio_vhost_user.sh
300 ~~~~~~~~~~~~~~~~~~~~~~~
301
302 .. code-block:: sh
303
304    #/bin/sh
305    # Script for use with vhost_user sample application
306    # The host system has 8 cpu's (0-7)
307
308    # Path to KVM tool
309    KVM_PATH="/usr/bin/qemu-system-x86_64"
310
311    # Guest Disk image
312    DISK_IMG="/home/user/disk_image/virt1_sml.disk"
313
314    # Number of guest cpus
315    VCPUS_NR="6"
316
317    # Memory
318    MEM=1024
319
320    VIRTIO_OPTIONS="csum=off,gso=off,guest_tso4=off,guest_tso6=off,guest_ecn=off"
321
322    # Socket Path
323    SOCKET_PATH="/root/dpdk/host_scripts/usvhost"
324
325    taskset -c 2-7 $KVM_PATH \
326     -enable-kvm \
327     -m $MEM \
328     -smp $VCPUS_NR \
329     -object memory-backend-file,id=mem,size=1024M,mem-path=/mnt/huge,share=on \
330     -numa node,memdev=mem,nodeid=0 \
331     -cpu host \
332     -name VM1 \
333     -no-reboot \
334     -net none \
335     -vnc none \
336     -nographic \
337     -hda $DISK_IMG \
338     -chardev socket,id=chr0,path=$SOCKET_PATH \
339     -netdev type=vhost-user,id=net1,chardev=chr0,vhostforce \
340     -device virtio-net-pci,netdev=net1,mac=CC:BB:BB:BB:BB:BB,$VIRTIO_OPTIONS \
341     -chardev socket,id=chr1,path=$SOCKET_PATH \
342     -netdev type=vhost-user,id=net2,chardev=chr1,vhostforce \
343     -device virtio-net-pci,netdev=net2,mac=DD:BB:BB:BB:BB:BB,$VIRTIO_OPTIONS \
344     -monitor telnet::3333,server,nowait
345
346 connect_to_qemu_mon_on_host.sh
347 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348
349 .. code-block:: sh
350
351    #!/bin/sh
352    # This script is run on both hosts when the VM is up,
353    # to connect to the Qemu Monitor.
354
355    telnet 0 3333
356
357 reset_vf_on_212_131.sh
358 ~~~~~~~~~~~~~~~~~~~~~~
359
360 .. code-block:: sh
361
362    #!/bin/sh
363    # This script is run on the host 10.237.212.131 to reset SRIOV
364
365    # BDF for Ninatic NIC is 0000:06:00.0
366    cat /sys/bus/pci/devices/0000\:06\:00.0/max_vfs
367    echo 0 > /sys/bus/pci/devices/0000\:06\:00.0/max_vfs
368    cat /sys/bus/pci/devices/0000\:06\:00.0/max_vfs
369
370    # BDF for Fortville NIC is 0000:03:00.0
371    cat /sys/bus/pci/devices/0000\:03\:00.0/max_vfs
372    echo 0 > /sys/bus/pci/devices/0000\:03\:00.0/max_vfs
373    cat /sys/bus/pci/devices/0000\:03\:00.0/max_vfs
374
375 vm_virtio_vhost_user_migrate.sh
376 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
377
378 .. code-block:: sh
379
380    #/bin/sh
381    # Script for use with vhost user sample application
382    # The host system has 8 cpu's (0-7)
383
384    # Path to KVM tool
385    KVM_PATH="/usr/bin/qemu-system-x86_64"
386
387    # Guest Disk image
388    DISK_IMG="/home/user/disk_image/virt1_sml.disk"
389
390    # Number of guest cpus
391    VCPUS_NR="6"
392
393    # Memory
394    MEM=1024
395
396    VIRTIO_OPTIONS="csum=off,gso=off,guest_tso4=off,guest_tso6=off,guest_ecn=off"
397
398    # Socket Path
399    SOCKET_PATH="/root/dpdk/host_scripts/usvhost"
400
401    taskset -c 2-7 $KVM_PATH \
402     -enable-kvm \
403     -m $MEM \
404     -smp $VCPUS_NR \
405     -object memory-backend-file,id=mem,size=1024M,mem-path=/mnt/huge,share=on \
406     -numa node,memdev=mem,nodeid=0 \
407     -cpu host \
408     -name VM1 \
409     -no-reboot \
410     -net none \
411     -vnc none \
412     -nographic \
413     -hda $DISK_IMG \
414     -chardev socket,id=chr0,path=$SOCKET_PATH \
415     -netdev type=vhost-user,id=net1,chardev=chr0,vhostforce \
416     -device virtio-net-pci,netdev=net1,mac=CC:BB:BB:BB:BB:BB,$VIRTIO_OPTIONS \
417     -chardev socket,id=chr1,path=$SOCKET_PATH \
418     -netdev type=vhost-user,id=net2,chardev=chr1,vhostforce \
419     -device virtio-net-pci,netdev=net2,mac=DD:BB:BB:BB:BB:BB,$VIRTIO_OPTIONS \
420     -incoming tcp:0:5555 \
421     -monitor telnet::3333,server,nowait
422
423 .. _lm_virtio_vhost_user_vm_scripts:
424
425 Sample VM scripts
426 -----------------
427
428 setup_dpdk_virtio_in_vm.sh
429 ~~~~~~~~~~~~~~~~~~~~~~~~~~
430
431 .. code-block:: sh
432
433    #!/bin/sh
434    # this script matches the vm_virtio_vhost_user script
435    # virtio port is 03
436    # virtio port is 04
437
438    cat  /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
439    echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
440    cat  /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
441
442    ifconfig -a
443    /root/dpdk/tools/dpdk_nic_bind.py --status
444
445    rmmod virtio-pci
446
447    modprobe uio
448    insmod /root/dpdk/x86_64-default-linuxapp-gcc/kmod/igb_uio.ko
449
450    /root/dpdk/tools/dpdk_nic_bind.py -b igb_uio 0000:00:03.0
451    /root/dpdk/tools/dpdk_nic_bind.py -b igb_uio 0000:00:04.0
452
453    /root/dpdk/tools/dpdk_nic_bind.py --status
454
455 run_testpmd_in_vm.sh
456 ~~~~~~~~~~~~~~~~~~~~
457
458 .. code-block:: sh
459
460    #!/bin/sh
461    # Run testpmd for use with vhost_user sample app.
462    # test system has 8 cpus (0-7), use cpus 2-7 for VM
463
464    /root/dpdk/x86_64-default-linuxapp-gcc/app/testpmd \
465    -c 3f -n 4 --socket-mem 350 -- --burst=64 --i --disable-hw-vlan-filter