5990f0925bc08888d0e80a29ea79422259821f00
[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 echo "vm.swappiness = 0" >> /etc/sysctl.conf
38 echo "kernel.randomize_va_space = 0" >> /etc/sysctl.conf
39 sysctl -p
40 mkdir -p /mnt/huge
41 grep -q hugetlbfs /etc/fstab || echo "hugetlbfs /mnt/huge hugetlbfs mode=1770,gid=2021 0 0" >> /etc/fstab
42 mount -a
43
44 #
45 echo 1af4 1000 > /sys/bus/pci/drivers/${TARGET_DRIVER}/new_id
46 #
47 for dev in $(find /sys/bus/pci/drivers/virtio-pci -type l -name '*:*:*.*' | sed -e 's/.*\///')
48 do
49   echo Unbinding $dev from virtio-pci
50   echo $dev > /sys/bus/pci/drivers/virtio-pci/unbind
51   echo Binding $dev to ${TARGET_DRIVER}
52   echo $dev > /sys/bus/pci/drivers/${TARGET_DRIVER}/bind
53 done
54
55 # RCU and IRQ affinity
56 for i in $(ls /proc/irq/ | grep [0-9])
57 do
58   echo 1 > /proc/irq/$i/smp_affinity
59 done
60 echo 1 | sudo tee /sys/bus/workqueue/devices/writeback/cpumask
61
62 # There is a bug causing packet loss when VM is initialized. This workaround is
63 # supposed to re-initialize CPUs.
64 for i in $(ls -d /sys/devices/system/cpu/cpu[1-9]/online); do
65     echo 0 | sudo tee $i
66     sleep 2
67     echo 1 | sudo tee $i
68 done
69
70 # Start testpmd in the background. This looks a bit convoluted; we need to redirect stdin
71 # (and keep stdin active) or else testpmd will quit.
72 tail -f /dev/null | nohup testpmd $@ > ${TESTPMD_LOG} 2>&1 &
73 echo $! > ${TESTPMD_PID}
74 _EOF
75
76 cat - > ${DPDK_STOP_FILE} <<"_EOF"
77 #!/bin/sh
78
79 TESTPMD_LOG=/tmp/testpmd.log
80 TESTPMD_PID=/tmp/testpmd.pid
81
82 if [ ! -f ${TESTPMD_PID} ]
83 then
84   echo Testpmd is not running.
85   exit 1
86 fi
87
88 kill $(cat ${TESTPMD_PID})
89 rm -f ${TESTPMD_PID}
90
91 cat ${TESTPMD_LOG}
92 _EOF
93
94 chmod 755 ${DPDK_START_FILE}
95 chmod 755 ${DPDK_STOP_FILE}