mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 21:06:48 +00:00
Enable tap mode network and vhost
This commit is contained in:
parent
1b23182dcc
commit
7c3e3738a1
5
Makefile
5
Makefile
@ -34,6 +34,11 @@ EXTRA_BLOCKLISTS_DIRS ?= ""
|
|||||||
SYSCALL_TEST_DIR ?= /tmp
|
SYSCALL_TEST_DIR ?= /tmp
|
||||||
# End of auto test features.
|
# End of auto test features.
|
||||||
|
|
||||||
|
# Network settings
|
||||||
|
NETDEV ?= user # Possible values are user,tap
|
||||||
|
VHOST ?= off
|
||||||
|
# End of network settings
|
||||||
|
|
||||||
# ========================= End of Makefile options. ==========================
|
# ========================= End of Makefile options. ==========================
|
||||||
|
|
||||||
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
|
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
|
||||||
|
@ -71,7 +71,7 @@ run_benchmark() {
|
|||||||
-device virtio-blk-pci,bus=pcie.0,addr=0x6,drive=x0,serial=vext2,disable-legacy=on,disable-modern=off,queue-size=64,num-queues=1,config-wce=off,request-merging=off,write-cache=off,backend_defaults=off,discard=off,event_idx=off,indirect_desc=off,ioeventfd=off,queue_reset=off \
|
-device virtio-blk-pci,bus=pcie.0,addr=0x6,drive=x0,serial=vext2,disable-legacy=on,disable-modern=off,queue-size=64,num-queues=1,config-wce=off,request-merging=off,write-cache=off,backend_defaults=off,discard=off,event_idx=off,indirect_desc=off,ioeventfd=off,queue_reset=off \
|
||||||
-append 'console=ttyS0 rdinit=/benchmark/common/bench_runner.sh ${benchmark} linux mitigations=off hugepages=0 transparent_hugepage=never quiet' \
|
-append 'console=ttyS0 rdinit=/benchmark/common/bench_runner.sh ${benchmark} linux mitigations=off hugepages=0 transparent_hugepage=never quiet' \
|
||||||
-netdev user,id=net01,hostfwd=tcp::5201-:5201,hostfwd=tcp::8080-:8080,hostfwd=tcp::31234-:31234 \
|
-netdev user,id=net01,hostfwd=tcp::5201-:5201,hostfwd=tcp::8080-:8080,hostfwd=tcp::31234-:31234 \
|
||||||
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off \
|
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off,mrg_rxbuf=off,ctrl_rx=off,ctrl_rx_extra=off,ctrl_vlan=off,ctrl_vq=off,ctrl_guest_offloads=off,ctrl_mac_addr=off,event_idx=off,queue_reset=off,guest_announce=off,indirect_desc=off \
|
||||||
-nographic \
|
-nographic \
|
||||||
2>&1"
|
2>&1"
|
||||||
case "${benchmark_type}" in
|
case "${benchmark_type}" in
|
||||||
|
@ -15,4 +15,4 @@ else
|
|||||||
IMAGE_NAME="asterinas/asterinas:${VERSION}"
|
IMAGE_NAME="asterinas/asterinas:${VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker run -it --privileged --network=host --device=/dev/kvm -v ${ASTER_SRC_DIR}:/root/asterinas ${IMAGE_NAME}
|
docker run -it --privileged --network=host --device=/dev/kvm --device=/dev/vhost-net -v ${ASTER_SRC_DIR}:/root/asterinas ${IMAGE_NAME}
|
||||||
|
16
tools/net/qemu-ifdown.sh
Executable file
16
tools/net/qemu-ifdown.sh
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
# Delete the TAP interface.
|
||||||
|
#
|
||||||
|
# It's used for the cleanup script of QEMU netdev, DO NOT run it manually.
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
ip link set dev "$1" down
|
||||||
|
ip link delete dev "$1"
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "Error: no interface specified"
|
||||||
|
exit 1
|
||||||
|
fi
|
19
tools/net/qemu-ifup.sh
Executable file
19
tools/net/qemu-ifup.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
# Create a TAP interface.
|
||||||
|
#
|
||||||
|
# It's used for the startup script of QEMU netdev, DO NOT run it manually.
|
||||||
|
|
||||||
|
# This IP address should be set the same as gateway address of Asterinas
|
||||||
|
IP=10.0.2.2/24
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
ip addr add $IP dev "$1"
|
||||||
|
ip link set dev "$1" up
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "Error: no interface specified"
|
||||||
|
exit 1
|
||||||
|
fi
|
@ -16,7 +16,18 @@ LMBENCH_TCP_LAT_RAND_PORT=${LMBENCH_TCP_LAT_PORT:-$(shuf -i 1024-65535 -n 1)}
|
|||||||
# Optional QEMU arguments. Opt in them manually if needed.
|
# Optional QEMU arguments. Opt in them manually if needed.
|
||||||
# QEMU_OPT_ARG_DUMP_PACKETS="-object filter-dump,id=filter0,netdev=net01,file=virtio-net.pcap"
|
# QEMU_OPT_ARG_DUMP_PACKETS="-object filter-dump,id=filter0,netdev=net01,file=virtio-net.pcap"
|
||||||
|
|
||||||
echo "[$1] Forwarded QEMU guest port: $SSH_RAND_PORT->22; $NGINX_RAND_PORT->8080 $REDIS_RAND_PORT->6379 $IPERF_RAND_PORT->5201 $LMBENCH_TCP_LAT_RAND_PORT->31234" 1>&2
|
if [[ "$NETDEV" =~ "user" ]]; then
|
||||||
|
echo "[\$1] Forwarded QEMU guest port: $SSH_RAND_PORT->22; $NGINX_RAND_PORT->8080 $REDIS_RAND_PORT->6379 $IPERF_RAND_PORT->5201 $LMBENCH_TCP_LAT_RAND_PORT->31234" 1>&2
|
||||||
|
NETDEV_ARGS="-netdev user,id=net01,hostfwd=tcp::$SSH_RAND_PORT-:22,hostfwd=tcp::$NGINX_RAND_PORT-:8080,hostfwd=tcp::$REDIS_RAND_PORT-:6379,hostfwd=tcp::$IPERF_RAND_PORT-:5201,hostfwd=tcp::$LMBENCH_TCP_LAT_RAND_PORT-:31234"
|
||||||
|
elif [[ "$NETDEV" =~ "tap" ]]; then
|
||||||
|
THIS_SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||||
|
QEMU_IFUP_SCRIPT_PATH=$THIS_SCRIPT_DIR/net/qemu-ifup.sh
|
||||||
|
QEMU_IFDOWN_SCRIPT_PATH=$THIS_SCRIPT_DIR/net/qemu-ifdown.sh
|
||||||
|
NETDEV_ARGS="-netdev tap,id=net01,script=$QEMU_IFUP_SCRIPT_PATH,downscript=$QEMU_IFDOWN_SCRIPT_PATH,vhost=$VHOST"
|
||||||
|
else
|
||||||
|
echo "Invalid netdev" 1>&2
|
||||||
|
NETDEV_ARGS="-nic none"
|
||||||
|
fi
|
||||||
|
|
||||||
COMMON_QEMU_ARGS="\
|
COMMON_QEMU_ARGS="\
|
||||||
-cpu Icelake-Server,+x2apic \
|
-cpu Icelake-Server,+x2apic \
|
||||||
@ -28,7 +39,7 @@ COMMON_QEMU_ARGS="\
|
|||||||
-serial chardev:mux \
|
-serial chardev:mux \
|
||||||
-monitor chardev:mux \
|
-monitor chardev:mux \
|
||||||
-chardev stdio,id=mux,mux=on,signal=off,logfile=qemu.log \
|
-chardev stdio,id=mux,mux=on,signal=off,logfile=qemu.log \
|
||||||
-netdev user,id=net01,hostfwd=tcp::$SSH_RAND_PORT-:22,hostfwd=tcp::$NGINX_RAND_PORT-:8080,hostfwd=tcp::$REDIS_RAND_PORT-:6379,hostfwd=tcp::$IPERF_RAND_PORT-:5201,hostfwd=tcp::$LMBENCH_TCP_LAT_RAND_PORT-:31234 \
|
$NETDEV_ARGS \
|
||||||
$QEMU_OPT_ARG_DUMP_PACKETS \
|
$QEMU_OPT_ARG_DUMP_PACKETS \
|
||||||
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
|
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
|
||||||
-drive if=none,format=raw,id=x0,file=./test/build/ext2.img \
|
-drive if=none,format=raw,id=x0,file=./test/build/ext2.img \
|
||||||
@ -49,7 +60,7 @@ QEMU_ARGS="\
|
|||||||
-device virtio-blk-pci,bus=pcie.0,addr=0x6,drive=x0,serial=vext2,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
-device virtio-blk-pci,bus=pcie.0,addr=0x6,drive=x0,serial=vext2,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
||||||
-device virtio-blk-pci,bus=pcie.0,addr=0x7,drive=x1,serial=vexfat,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
-device virtio-blk-pci,bus=pcie.0,addr=0x7,drive=x1,serial=vexfat,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
||||||
-device virtio-keyboard-pci,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
-device virtio-keyboard-pci,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
||||||
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off,mrg_rxbuf=off,ctrl_rx=off,ctrl_rx_extra=off,ctrl_vlan=off,ctrl_vq=off,ctrl_guest_offloads=off,ctrl_mac_addr=off,event_idx=off,queue_reset=off,guest_announce=off,indirect_desc=off$IOMMU_DEV_EXTRA \
|
||||||
-device virtio-serial-pci,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
-device virtio-serial-pci,disable-legacy=on,disable-modern=off$IOMMU_DEV_EXTRA \
|
||||||
-device virtconsole,chardev=mux \
|
-device virtconsole,chardev=mux \
|
||||||
$IOMMU_EXTRA_ARGS \
|
$IOMMU_EXTRA_ARGS \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user