diff --git a/test/benchmark/bench_linux_and_aster.sh b/test/benchmark/bench_linux_and_aster.sh index e16b9982..d1def937 100755 --- a/test/benchmark/bench_linux_and_aster.sh +++ b/test/benchmark/bench_linux_and_aster.sh @@ -76,7 +76,7 @@ run_benchmark() { -drive if=none,format=raw,id=x0,file=${BENCHMARK_DIR}/../build/ext2.img \ -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,request-merging=off,backend_defaults=off,discard=off,write-zeroes=off,event_idx=off,indirect_desc=off,queue_reset=off \ -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::6379-:6379,hostfwd=tcp::8080-:8080,hostfwd=tcp::31234-:31234 \ + -netdev user,id=net01,hostfwd=tcp::5201-:5201,hostfwd=tcp::6379-:6379,hostfwd=tcp::8080-:8080,hostfwd=tcp::31234-:31234,hostfwd=tcp::31236-:31236 \ -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 \ 2>&1" diff --git a/test/benchmark/common/host_guest_bench_runner.sh b/test/benchmark/common/host_guest_bench_runner.sh index d7f3542d..e06fa1a2 100755 --- a/test/benchmark/common/host_guest_bench_runner.sh +++ b/test/benchmark/common/host_guest_bench_runner.sh @@ -29,6 +29,9 @@ elif [[ "$BENCHMARK_PATH" =~ "redis" ]]; then elif [[ "$BENCHMARK_PATH" =~ "tcp_virtio_lat" ]]; then # Persist lmbench/tcp_lat port export LMBENCH_TCP_LAT_PORT=31234 +elif [[ "$BENCHMARK_PATH" =~ "tcp_virtio_bw" ]]; then + # Persist lmbench/bw_tcp port + export LMBENCH_TCP_BW_PORT=31236 fi # Function to run the benchmark diff --git a/test/benchmark/lmbench/summary.json b/test/benchmark/lmbench/summary.json index 4d8e8795..49eac168 100644 --- a/test/benchmark/lmbench/summary.json +++ b/test/benchmark/lmbench/summary.json @@ -32,6 +32,7 @@ "tcp_loopback_connect_lat", "tcp_loopback_select_lat", "tcp_loopback_http_bw", + "tcp_virtio_bw_64k", "udp_loopback_lat" ] } diff --git a/test/benchmark/lmbench/tcp_virtio_bw_64k/config.json b/test/benchmark/lmbench/tcp_virtio_bw_64k/config.json new file mode 100644 index 00000000..5215f853 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_64k/config.json @@ -0,0 +1,9 @@ +{ + "alert_threshold": "125%", + "alert_tool": "customBiggerIsBetter", + "search_pattern": "0.065536 ", + "result_index": "2", + "description": "bw_tcp -l", + "title": "[TCP sockets] The bandwidth (virtio-net, 64KB message)", + "benchmark_type": "host_guest" +} \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_bw_64k/host.sh b/test/benchmark/lmbench/tcp_virtio_bw_64k/host.sh new file mode 100644 index 00000000..0f31263a --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_64k/host.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +# Function to stop the guest VM +stop_guest() { + echo "Stopping guest VM..." + # `-r` means if there's no qemu, the kill won't be executed + pgrep qemu | xargs -r kill +} + +# Trap EXIT signal to ensure guest VM is stopped on script exit +trap stop_guest EXIT + +# Run lmbench tcp client +echo "Running lmbench tcp client" +/usr/local/benchmark/lmbench/bw_tcp -m 65536 -P 1 127.0.0.1 + +# The trap will automatically stop the guest VM when the script exits diff --git a/test/benchmark/lmbench/tcp_virtio_bw_64k/result_template.json b/test/benchmark/lmbench/tcp_virtio_bw_64k/result_template.json new file mode 100644 index 00000000..3b41f407 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_64k/result_template.json @@ -0,0 +1,14 @@ +[ + { + "name": "Average TCP bandwidth on Linux", + "unit": "MB/sec", + "value": 0, + "extra": "linux_result" + }, + { + "name": "Average TCP bandwidth on Asterinas", + "unit": "MB/sec", + "value": 0, + "extra": "aster_result" + } +] \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_bw_64k/run.sh b/test/benchmark/lmbench/tcp_virtio_bw_64k/run.sh new file mode 100644 index 00000000..0a99bf98 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_64k/run.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +echo "Running lmbench TCP latency over virtio-net..." + +# Start the server +/benchmark/bin/lmbench/bw_tcp -s 10.0.2.15 -b 1 + +# Sleep for a long time to ensure VM won't exit +sleep 200 \ No newline at end of file diff --git a/tools/qemu_args.sh b/tools/qemu_args.sh index cc2bbf89..ddc6d8f5 100755 --- a/tools/qemu_args.sh +++ b/tools/qemu_args.sh @@ -23,13 +23,14 @@ NGINX_RAND_PORT=${NGINX_PORT:-$(shuf -i 1024-65535 -n 1)} REDIS_RAND_PORT=${REDIS_PORT:-$(shuf -i 1024-65535 -n 1)} IPERF_RAND_PORT=${IPERF_PORT:-$(shuf -i 1024-65535 -n 1)} LMBENCH_TCP_LAT_RAND_PORT=${LMBENCH_TCP_LAT_PORT:-$(shuf -i 1024-65535 -n 1)} +LMBENCH_TCP_BW_RAND_PORT=${LMBENCH_TCP_BW_PORT:-$(shuf -i 1024-65535 -n 1)} # 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" 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" + 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 $LMBENCH_TCP_BW_RAND_PORT->31236" 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,hostfwd=tcp::$LMBENCH_TCP_BW_RAND_PORT-:31236" elif [[ "$NETDEV" =~ "tap" ]]; then THIS_SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) QEMU_IFUP_SCRIPT_PATH=$THIS_SCRIPT_DIR/net/qemu-ifup.sh