Add iperf3 benchmark

This commit is contained in:
Fabing Li
2024-09-25 09:41:28 +00:00
committed by Tate, Hongliang Tian
parent fb718fd440
commit 9abdebbae3
12 changed files with 237 additions and 59 deletions

View File

@ -10,46 +10,9 @@ command -v jq >/dev/null 2>&1 || { echo >&2 "jq is not installed. Aborting."; ex
# Script directory
BENCHMARK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Dependencies for Linux
LINUX_DEPENDENCIES_DIR="/opt/linux_binary_cache"
LINUX_KERNEL="${LINUX_DEPENDENCIES_DIR}/vmlinuz"
LINUX_KERNEL_VERSION="5.15.0-105-generic"
LINUX_MODULES_DIR="${BENCHMARK_DIR}/../build/initramfs/lib/modules/${LINUX_KERNEL_VERSION}/kernel"
# Atomic wget script
WGET_SCRIPT="${BENCHMARK_DIR}/../../tools/atomic_wget.sh"
# Prepare Linux kernel and modules
prepare_libs() {
# Download the Linux kernel and modules
mkdir -p "${LINUX_DEPENDENCIES_DIR}"
if [ ! -f "${LINUX_KERNEL}" ]; then
echo "Downloading the Linux kernel image..."
${WGET_SCRIPT} "${LINUX_KERNEL}" "https://raw.githubusercontent.com/asterinas/linux_binary_cache/8a5b6fd/vmlinuz-${LINUX_KERNEL_VERSION}" || {
echo "Failed to download the Linux kernel image."
exit 1
}
fi
if [ ! -f "${LINUX_DEPENDENCIES_DIR}/virtio_blk.ko" ]; then
echo "Downloading the virtio_blk kernel module..."
${WGET_SCRIPT} "${LINUX_DEPENDENCIES_DIR}/virtio_blk.ko" "https://raw.githubusercontent.com/asterinas/linux_binary_cache/8a5b6fd/kernel/drivers/block/virtio_blk.ko" || {
echo "Failed to download the Linux kernel module."
exit 1
}
fi
# Copy the kernel modules to the initramfs directory
if [ ! -f "${LINUX_MODULES_DIR}/drivers/block/virtio_blk.ko" ]; then
mkdir -p "${LINUX_MODULES_DIR}/drivers/block"
cp ${LINUX_DEPENDENCIES_DIR}/virtio_blk.ko "${LINUX_MODULES_DIR}/drivers/block/virtio_blk.ko"
fi
}
# Prepare fs for Linux
prepare_fs() {
# Disable unsupported ext2 features of Asterinas on Linux to ensure fairness
mke2fs -F -O ^ext_attr -O ^resize_inode -O ^dir_index ${BENCHMARK_DIR}/../build/ext2.img
make initramfs
}
# Source the prepare_host.sh script
source "${BENCHMARK_DIR}/common/prepare_host.sh"
# Parse the results from the benchmark output
parse_results() {
@ -80,23 +43,21 @@ parse_results() {
# Run the benchmark on Linux and Asterinas
run_benchmark() {
local benchmark="$1"
local search_pattern="$2"
local result_index="$3"
local benchmark_type="$2"
local search_pattern="$3"
local result_index="$4"
local linux_output="${BENCHMARK_DIR}/linux_output.txt"
local aster_output="${BENCHMARK_DIR}/aster_output.txt"
local result_template="${BENCHMARK_DIR}/${benchmark}/result_template.json"
local benchmark_name=$(basename "${benchmark}")
local benchmark_root=$(dirname "${benchmark}")
local result_file="result_${benchmark_name}.json"
echo "Preparing libraries..."
prepare_libs
local asterinas_cmd="make run BENCHMARK=${benchmark} ENABLE_KVM=1 RELEASE_LTO=1 2>&1 | tee ${aster_output}"
echo "Running benchmark ${benchmark} on Asterinas..."
eval "$asterinas_cmd"
prepare_fs
local asterinas_cmd="make run BENCHMARK=${benchmark} ENABLE_KVM=1 RELEASE_LTO=1 2>&1"
local linux_cmd="/usr/local/qemu/bin/qemu-system-x86_64 \
--no-reboot \
-smp 1 \
@ -109,10 +70,37 @@ 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,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' \
-netdev user,id=net01,hostfwd=tcp::5201-:5201 \
-device virtio-net-pci,netdev=net01,disable-legacy=on,disable-modern=off \
-nographic \
2>&1 | tee ${linux_output}"
echo "Running benchmark ${benchmark} on Linux..."
eval "$linux_cmd"
2>&1"
case "${benchmark_type}" in
"guest_only")
echo "Running benchmark ${benchmark} on Asterinas..."
eval "$asterinas_cmd" | tee ${aster_output}
prepare_fs
echo "Running benchmark ${benchmark} on Linux..."
eval "$linux_cmd" | tee ${linux_output}
;;
"host_guest")
echo "Running benchmark ${benchmark} on host and guest..."
bash "${BENCHMARK_DIR}/${benchmark_root}/bench_runner.sh" \
"${BENCHMARK_DIR}/${benchmark}" \
"${asterinas_cmd}" \
"${linux_cmd}" \
"${aster_output}" \
"${linux_output}"
;;
"guest-guest")
echo "Running benchmark ${benchmark} between guests..."
echo "TODO"
exit 1
;;
*)
echo "Error: Unknown benchmark type '${benchmark_type}'" >&2
exit 1
;;
esac
echo "Parsing results..."
parse_results "$benchmark" "$search_pattern" "$result_index" "$linux_output" "$aster_output" "$result_template" "$result_file"
@ -125,6 +113,11 @@ run_benchmark() {
# Main
BENCHMARK="$1"
if [ -z "$2" ] || [ "$2" = "null" ]; then
BENCHMARK_TYPE="guest_only"
else
BENCHMARK_TYPE="$2"
fi
echo "Running benchmark ${BENCHMARK}..."
pwd
@ -136,6 +129,6 @@ fi
search_pattern=$(jq -r '.search_pattern' "$BENCHMARK_DIR/$BENCHMARK/config.json")
result_index=$(jq -r '.result_index' "$BENCHMARK_DIR/$BENCHMARK/config.json")
run_benchmark "$BENCHMARK" "$search_pattern" "$result_index"
run_benchmark "$BENCHMARK" "$BENCHMARK_TYPE" "$search_pattern" "$result_index"
echo "Benchmark completed successfully."