aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/disk-image-builder/nested/image-patches/06-dpdk-support
blob: 5990f0925bc08888d0e80a29ea79422259821f00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh

### This may be a temporary file. Once DPDK is working stable in the nested
### VM, and if and when ### we decide we want to do all testing with DPDK,
### the steps executed here may become default configuration for the image.
###
### For now, to give us the flexibility to work with and without DPDK, keep
### this as a separate script.

DPDK_START_FILE="start-testpmd.sh"
DPDK_STOP_FILE="stop-testpmd.sh"

cat - > ${DPDK_START_FILE} <<"_EOF"
#!/bin/sh

TARGET_DRIVER="igb_uio"
PATH_TO_IGB_UIO_MODULE="/usr/local/kmod/igb_uio.ko"
NUM_HUGEPAGES=512
TESTPMD_LOG=/tmp/testpmd.log
TESTPMD_PID=/tmp/testpmd.pid

if [ -f ${TESTPMD_PID} ]
then
  echo Testpmd is already running. Please stop running instance first.
  echo Delete PID file ${TESTPMD_PID} if you are sure this is a stale PID file.
  exit 1
fi

# Load igb_uio module if this is the driver we want to use
if [ "${TARGET_DRIVER}" = "igb_uio" ]
then
  insmod ${PATH_TO_IGB_UIO_MODULE}
fi

# Set up hugepages
echo "vm.nr_hugepages = ${NUM_HUGEPAGES}" > /etc/sysctl.conf
echo "vm.swappiness = 0" >> /etc/sysctl.conf
echo "kernel.randomize_va_space = 0" >> /etc/sysctl.conf
sysctl -p
mkdir -p /mnt/huge
grep -q hugetlbfs /etc/fstab || echo "hugetlbfs /mnt/huge hugetlbfs mode=1770,gid=2021 0 0" >> /etc/fstab
mount -a

#
echo 1af4 1000 > /sys/bus/pci/drivers/${TARGET_DRIVER}/new_id
#
for dev in $(find /sys/bus/pci/drivers/virtio-pci -type l -name '*:*:*.*' | sed -e 's/.*\///')
do
  echo Unbinding $dev from virtio-pci
  echo $dev > /sys/bus/pci/drivers/virtio-pci/unbind
  echo Binding $dev to ${TARGET_DRIVER}
  echo $dev > /sys/bus/pci/drivers/${TARGET_DRIVER}/bind
done

# RCU and IRQ affinity
for i in $(ls /proc/irq/ | grep [0-9])
do
  echo 1 > /proc/irq/$i/smp_affinity
done
echo 1 | sudo tee /sys/bus/workqueue/devices/writeback/cpumask

# There is a bug causing packet loss when VM is initialized. This workaround is
# supposed to re-initialize CPUs.
for i in $(ls -d /sys/devices/system/cpu/cpu[1-9]/online); do
    echo 0 | sudo tee $i
    sleep 2
    echo 1 | sudo tee $i
done

# Start testpmd in the background. This looks a bit convoluted; we need to redirect stdin
# (and keep stdin active) or else testpmd will quit.
tail -f /dev/null | nohup testpmd $@ > ${TESTPMD_LOG} 2>&1 &
echo $! > ${TESTPMD_PID}
_EOF

cat - > ${DPDK_STOP_FILE} <<"_EOF"
#!/bin/sh

TESTPMD_LOG=/tmp/testpmd.log
TESTPMD_PID=/tmp/testpmd.pid

if [ ! -f ${TESTPMD_PID} ]
then
  echo Testpmd is not running.
  exit 1
fi

kill $(cat ${TESTPMD_PID})
rm -f ${TESTPMD_PID}

cat ${TESTPMD_LOG}
_EOF

chmod 755 ${DPDK_START_FILE}
chmod 755 ${DPDK_STOP_FILE}