CSIT-156: DPDK support for Nested VM image
[csit.git] / resources / tools / disk-image-builder / nested / image-patches / 06-dpdk-support
1 #!/bin/sh
2
3 ### This may be a temporary file. Once DPDK is working stable in the nested
4 ### VM, and if and when ### we decide we want to do all testing with DPDK,
5 ### the steps executed here may become default configuration for the image.
6 ###
7 ### For now, to give us the flexibility to work with and without DPDK, keep
8 ### this as a separate script.
9
10 DPDK_START_FILE="start-testpmd.sh"
11 DPDK_STOP_FILE="stop-testpmd.sh"
12
13 cat - > ${DPDK_START_FILE} <<"_EOF"
14 #!/bin/sh
15
16 TARGET_DRIVER="igb_uio"
17 PATH_TO_IGB_UIO_MODULE="/usr/local/kmod/igb_uio.ko"
18 NUM_HUGEPAGES=512
19 TESTPMD_LOG=/tmp/testpmd.log
20 TESTPMD_PID=/tmp/testpmd.pid
21
22 if [ -f ${TESTPMD_PID} ]
23 then
24   echo Testpmd is already running. Please stop running instance first.
25   echo Delete PID file ${TESTPMD_PID} if you are sure this is a stale PID file.
26   exit 1
27 fi
28
29 # Load igb_uio module if this is the driver we want to use
30 if [ "${TARGET_DRIVER}" = "igb_uio" ]
31 then
32   insmod ${PATH_TO_IGB_UIO_MODULE}
33 fi
34
35 # Set up hugepages
36 echo "vm.nr_hugepages = ${NUM_HUGEPAGES}" > /etc/sysctl.conf
37 sysctl -p
38 mkdir -p /mnt/huge
39 grep -q hugetlbfs /etc/fstab || echo "hugetlbfs /mnt/huge hugetlbfs mode=1770,gid=2021 0 0" >> /etc/fstab
40 mount -a
41
42 #
43 echo 1af4 1000 > /sys/bus/pci/drivers/${TARGET_DRIVER}/new_id
44 #
45 for dev in $(find /sys/bus/pci/drivers/virtio-pci -type l -name '*:*:*.*' | sed -e 's/.*\///')
46 do
47   echo Unbinding $dev from virtio-pci
48   echo $dev > /sys/bus/pci/drivers/virtio-pci/unbind
49   echo Binding $dev to ${TARGET_DRIVER}
50   echo $dev > /sys/bus/pci/drivers/${TARGET_DRIVER}/bind
51 done
52
53 # Start testpmd in the background. This looks a bit convoluted; we need to redirect stdin
54 # (and keep stdin active) or else testpmd will quit.
55 tail -f /dev/null | nohup testpmd $@ > ${TESTPMD_LOG} 2>&1 &
56 echo $! > ${TESTPMD_PID}
57 _EOF
58
59 cat - > ${DPDK_STOP_FILE} <<"_EOF"
60 #!/bin/sh
61
62 TESTPMD_LOG=/tmp/testpmd.log
63 TESTPMD_PID=/tmp/testpmd.pid
64
65 if [ ! -f ${TESTPMD_PID} ]
66 then
67   echo Testpmd is not running.
68   exit 1
69 fi
70
71 kill $(cat ${TESTPMD_PID})
72 rm -f ${TESTPMD_PID}
73
74 cat ${TESTPMD_LOG}
75 _EOF
76
77 chmod 755 ${DPDK_START_FILE}
78 chmod 755 ${DPDK_STOP_FILE}