CSIT-484: HC Test: Add scripts for new hc2vpp jobs
[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 for i in $(ls /proc/irq/ | grep [0-9])
54 do
55   echo 1 > /proc/irq/$i/smp_affinity
56 done
57
58 # Start testpmd in the background. This looks a bit convoluted; we need to redirect stdin
59 # (and keep stdin active) or else testpmd will quit.
60 tail -f /dev/null | nohup testpmd $@ > ${TESTPMD_LOG} 2>&1 &
61 echo $! > ${TESTPMD_PID}
62 _EOF
63
64 cat - > ${DPDK_STOP_FILE} <<"_EOF"
65 #!/bin/sh
66
67 TESTPMD_LOG=/tmp/testpmd.log
68 TESTPMD_PID=/tmp/testpmd.pid
69
70 if [ ! -f ${TESTPMD_PID} ]
71 then
72   echo Testpmd is not running.
73   exit 1
74 fi
75
76 kill $(cat ${TESTPMD_PID})
77 rm -f ${TESTPMD_PID}
78
79 cat ${TESTPMD_LOG}
80 _EOF
81
82 chmod 755 ${DPDK_START_FILE}
83 chmod 755 ${DPDK_STOP_FILE}