Skip to content

Instantly share code, notes, and snippets.

@dmarion
Last active November 23, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmarion/161d83165d27af7c39ab807beae4746c to your computer and use it in GitHub Desktop.
Save dmarion/161d83165d27af7c39ab807beae4746c to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ ! -d boot ] ; then
PKG=$(apt-cache depends -i linux-image-kvm | grep Depends: | cut -d: -f2)
apt-get download ${PKG}
dpkg --fsys-tarfile ${PKG}_*.deb | tar xvf - ./boot
echo $PKG
fi
TESTPMD_BIN=${HOME}/src/dpdk/x86_64-native-linuxapp-gcc/app/testpmd
KERNEL_BIN=$(ls boot/vmlinuz-*-kvm)
INIT=$(mktemp)
cat > ${INIT} << __EOF__
#!/bin/bash
echo "========================================================================="
mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
mount -t proc -o nodev,noexec,nosuid proc /proc
mkdir /dev/pts
mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
mount -t tmpfs -o "noexec,nosuid,size=10%,mode=0755" tmpfs /run
lspci
echo "========================================================================="
echo 0000:00:06.0 > /sys/bus/pci/devices/0000:00:06.0/driver/unbind
echo 0000:00:07.0 > /sys/bus/pci/devices/0000:00:07.0/driver/unbind
echo uio_pci_generic > /sys/bus/pci/devices/0000:00:06.0/driver_override
echo uio_pci_generic > /sys/bus/pci/devices/0000:00:07.0/driver_override
echo 0000:00:06.0 > /sys/bus/pci/drivers/uio_pci_generic/bind
echo 0000:00:07.0 > /sys/bus/pci/drivers/uio_pci_generic/bind
echo "========================================================================="
${TESTPMD_BIN} \
--in-memory \
--master-lcore 1 \
-l 1-3 \
-- \
--forward-mode=io \
--burst=64 \
--txd=1024 \
--rxd=1024 \
--txq=1 \
--rxq=1
poweroff -f
__EOF__
chmod +x ${INIT}
sudo taskset -c 5-8 qemu-system-x86_64 \
-nodefaults \
-name testpmd_vm \
-chardev stdio,mux=on,id=char0 \
-mon chardev=char0,mode=readline,pretty=on \
-serial chardev:char0 \
-machine pc,accel=kvm,usb=off,mem-merge=off \
-object memory-backend-file,id=mem,size=1024M,mem-path=/dev/hugepages,share=on \
-numa node,memdev=mem \
-cpu host \
-smp 4,sockets=1,cores=4,threads=1 \
-m 1G \
-no-user-config \
-kernel ${KERNEL_BIN} \
-fsdev local,id=root9p,path=/,security_model=none \
-device virtio-9p-pci,fsdev=root9p,mount_tag=/dev/root \
-device virtio-net-pci,netdev=net0,mac=52:54:00:00:04:01,bus=pci.0,addr=6.0,mq=on,tx_queue_size=1024,rx_queue_size=1024 \
-device virtio-net-pci,netdev=net1,mac=52:54:00:00:04:01,bus=pci.0,addr=7.0,mq=on,tx_queue_size=1024,rx_queue_size=1024 \
-chardev socket,id=socket0,path=/tmp/sock1,server \
-chardev socket,id=socket1,path=/tmp/sock2,server \
-netdev vhost-user,id=net0,chardev=socket0,queues=1 \
-netdev vhost-user,id=net1,chardev=socket1,queues=1 \
-nographic \
-append "ro rootfstype=9p rootflags=trans=virtio console=ttyS0 hugepages=256 init=${INIT}"
rm ${INIT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment