diff --git a/.github/workflows/benchmark_asterinas.yml b/.github/workflows/benchmark_asterinas.yml index 16a199605..3c0bcbf06 100644 --- a/.github/workflows/benchmark_asterinas.yml +++ b/.github/workflows/benchmark_asterinas.yml @@ -59,16 +59,21 @@ jobs: - fio/ext2_seq_read_bw - fio/ext2_seq_write_bw_no_iommu - fio/ext2_seq_read_bw_no_iommu - # Network-related benchmarks + # Loopback-related network benchmarks + - lmbench/tcp_loopback_bw_128 - lmbench/tcp_loopback_bw_4k - lmbench/tcp_loopback_bw_64k - lmbench/tcp_loopback_lat - lmbench/tcp_loopback_connect_lat - lmbench/tcp_loopback_select_lat - lmbench/tcp_loopback_http_bw - - lmbench/tcp_virtio_bw_64k - - lmbench/tcp_virtio_lat - lmbench/udp_loopback_lat + # VirtIO-net-related network benchmarks + - lmbench/tcp_virtio_bw_128 + - lmbench/tcp_virtio_bw_64k + - lmbench/tcp_virtio_connect_lat + - lmbench/tcp_virtio_lat + - lmbench/udp_virtio_lat - iperf3/tcp_virtio_bw # Scheduler-related benchmarks - hackbench/group8_smp1 diff --git a/ostd/src/arch/x86/mod.rs b/ostd/src/arch/x86/mod.rs index 6034c31ef..6d3784d21 100644 --- a/ostd/src/arch/x86/mod.rs +++ b/ostd/src/arch/x86/mod.rs @@ -129,7 +129,6 @@ pub(crate) unsafe fn init_on_ap() { pub(crate) fn interrupts_ack(irq_number: usize) { if !cpu::CpuException::is_cpu_exception(irq_number as u16) { - kernel::pic::ack(); kernel::apic::with_borrow(|apic| { apic.eoi(); }); diff --git a/ostd/src/arch/x86/serial.rs b/ostd/src/arch/x86/serial.rs index 0e8484f28..d72a7fe3d 100644 --- a/ostd/src/arch/x86/serial.rs +++ b/ostd/src/arch/x86/serial.rs @@ -11,7 +11,10 @@ use core::fmt::Write; use log::debug; use spin::Once; -use super::{device::serial::SerialPort, kernel::IO_APIC}; +use super::{ + device::serial::SerialPort, + kernel::{self, IO_APIC}, +}; use crate::{ sync::SpinLock, trap::{IrqLine, TrapFrame}, @@ -63,15 +66,21 @@ pub(crate) fn init() { } pub(crate) fn callback_init() { - let mut irq = if !IO_APIC.is_completed() { - crate::arch::x86::kernel::pic::allocate_irq(4).unwrap() + let irq = if !IO_APIC.is_completed() { + let mut irq = crate::arch::x86::kernel::pic::allocate_irq(4).unwrap(); + irq.on_active(|trapframe: &TrapFrame| { + handle_serial_input(trapframe); + kernel::pic::ack(); + }); + irq } else { - let irq = IrqLine::alloc().unwrap(); + let mut irq = IrqLine::alloc().unwrap(); let mut io_apic = IO_APIC.get().unwrap().first().unwrap().lock(); io_apic.enable(4, irq.clone()).unwrap(); + irq.on_active(handle_serial_input); irq }; - irq.on_active(handle_serial_input); + CONSOLE_IRQ_CALLBACK.call_once(|| SpinLock::new(irq)); } diff --git a/test/benchmark/lmbench/summary.json b/test/benchmark/lmbench/summary.json index 506693d8e..5374263a6 100644 --- a/test/benchmark/lmbench/summary.json +++ b/test/benchmark/lmbench/summary.json @@ -28,13 +28,18 @@ "ramfs_create_delete_files_0k_ops", "ramfs_create_delete_files_10k_ops", "ext2_copy_files_bw", + "tcp_loopback_bw_128", "tcp_loopback_bw_4k", "tcp_loopback_bw_64k", "tcp_loopback_lat", "tcp_loopback_connect_lat", "tcp_loopback_select_lat", "tcp_loopback_http_bw", + "udp_loopback_lat", + "tcp_virtio_bw_128", "tcp_virtio_bw_64k", - "udp_loopback_lat" + "tcp_virtio_connect_lat", + "tcp_virtio_lat", + "udp_virtio_lat" ] } \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_loopback_bw_128/bench_result.json b/test/benchmark/lmbench/tcp_loopback_bw_128/bench_result.json new file mode 100644 index 000000000..2ce3b0662 --- /dev/null +++ b/test/benchmark/lmbench/tcp_loopback_bw_128/bench_result.json @@ -0,0 +1,16 @@ +{ + "alert": { + "threshold": "125%", + "bigger_is_better": true + }, + "result_extraction": { + "search_pattern": "0.000128 +[0-9.]+", + "result_index": 2 + }, + "chart": { + "title": "[TCP sockets] The bandwidth (localhost, 128B message)", + "description": "bw_tcp -l", + "unit": "MB/s", + "legend": "Average TCP bandwidth on {system}" + } +} \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_loopback_bw_128/run.sh b/test/benchmark/lmbench/tcp_loopback_bw_128/run.sh new file mode 100644 index 000000000..06a24e7fc --- /dev/null +++ b/test/benchmark/lmbench/tcp_loopback_bw_128/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +echo "*** Running lmbench TCP bandwidth test ***" + +/benchmark/bin/lmbench/bw_tcp -s 127.0.0.1 -b 1 +/benchmark/bin/lmbench/bw_tcp -m 128 -P 1 127.0.0.1 +/benchmark/bin/lmbench/bw_tcp -S 127.0.0.1 \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_bw_128/bench_result.json b/test/benchmark/lmbench/tcp_virtio_bw_128/bench_result.json new file mode 100644 index 000000000..bdcca99b9 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_128/bench_result.json @@ -0,0 +1,16 @@ +{ + "alert": { + "threshold": "125%", + "bigger_is_better": true + }, + "result_extraction": { + "search_pattern": "0.000128 +[0-9.]+ +MB", + "result_index": 2 + }, + "chart": { + "title": "[TCP sockets] The bandwidth (virtio-net, 128B message)", + "description": "bw_tcp -l", + "unit": "MB/sec", + "legend": "Average TCP bandwidth on {system}" + } +} \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_bw_128/host.sh b/test/benchmark/lmbench/tcp_virtio_bw_128/host.sh new file mode 100644 index 000000000..fa35a4db3 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_128/host.sh @@ -0,0 +1,22 @@ +#!/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 connected to $GUEST_SERVER_IP_ADDRESS" +# The -W parameter of bw_tcp refers to the number of bytes transferred during the warm-up phase. +/usr/local/benchmark/lmbench/bw_tcp -m 128 -P 1 -W 50000000 -N 100 $GUEST_SERVER_IP_ADDRESS + +# The trap will automatically stop the guest VM when the script exits \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_bw_128/run.sh b/test/benchmark/lmbench/tcp_virtio_bw_128/run.sh new file mode 100644 index 000000000..0a99bf982 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_bw_128/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/test/benchmark/lmbench/tcp_virtio_connect_lat/bench_result.json b/test/benchmark/lmbench/tcp_virtio_connect_lat/bench_result.json new file mode 100644 index 000000000..bb0a2e3c7 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_connect_lat/bench_result.json @@ -0,0 +1,16 @@ +{ + "alert": { + "threshold": "125%", + "bigger_is_better": false + }, + "result_extraction": { + "search_pattern": "TCP\\/IP connection cost to [0-9.]+: +[0-9.]+", + "result_index": 6 + }, + "chart": { + "title": "[TCP sockets] The latency of connect", + "description": "lat_connect", + "unit": "\u00b5s", + "legend": "Average TCP connection latency on {system}" + } +} \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_connect_lat/host.sh b/test/benchmark/lmbench/tcp_virtio_connect_lat/host.sh new file mode 100644 index 000000000..739bc4ef5 --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_connect_lat/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 connected to $GUEST_SERVER_IP_ADDRESS" +/usr/local/benchmark/lmbench/lat_connect $GUEST_SERVER_IP_ADDRESS + +# The trap will automatically stop the guest VM when the script exits \ No newline at end of file diff --git a/test/benchmark/lmbench/tcp_virtio_connect_lat/run.sh b/test/benchmark/lmbench/tcp_virtio_connect_lat/run.sh new file mode 100644 index 000000000..3ad78b18e --- /dev/null +++ b/test/benchmark/lmbench/tcp_virtio_connect_lat/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/lat_connect -s 10.0.2.15 -b 1000 + +# Sleep for a long time to ensure VM won't exit +sleep 200 \ No newline at end of file diff --git a/test/benchmark/lmbench/udp_virtio_lat/bench_result.json b/test/benchmark/lmbench/udp_virtio_lat/bench_result.json new file mode 100644 index 000000000..2d067f2c4 --- /dev/null +++ b/test/benchmark/lmbench/udp_virtio_lat/bench_result.json @@ -0,0 +1,16 @@ +{ + "alert": { + "threshold": "125%", + "bigger_is_better": false + }, + "result_extraction": { + "search_pattern": "UDP latency using [0-9.]+: +[0-9.]+", + "result_index": 5 + }, + "chart": { + "title": "[UDP sockets] The latency of write+read (virtio-net)", + "description": "lat_udp", + "unit": "\u00b5s", + "legend": "Average UDP latency over virtio-net on {system}" + } +} \ No newline at end of file diff --git a/test/benchmark/lmbench/udp_virtio_lat/host.sh b/test/benchmark/lmbench/udp_virtio_lat/host.sh new file mode 100644 index 000000000..94e9e621c --- /dev/null +++ b/test/benchmark/lmbench/udp_virtio_lat/host.sh @@ -0,0 +1,25 @@ +#!/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 + +# Warm up: We intentionally run another test for warmup here. +# Note that we can't use -W option for warmup here because it will fail due to receiving timeout. +echo "Warm up......" +/usr/local/benchmark/lmbench/lat_udp -P 1 -N 10 $GUEST_SERVER_IP_ADDRESS >/dev/null 2>&1 +# Run lmbench udp client +echo "Running lmbench udp client connected to $GUEST_SERVER_IP_ADDRESS" +/usr/local/benchmark/lmbench/lat_udp -P 1 -N 10 $GUEST_SERVER_IP_ADDRESS + +# The trap will automatically stop the guest VM when the script exits \ No newline at end of file diff --git a/test/benchmark/lmbench/udp_virtio_lat/run.sh b/test/benchmark/lmbench/udp_virtio_lat/run.sh new file mode 100644 index 000000000..d22eab810 --- /dev/null +++ b/test/benchmark/lmbench/udp_virtio_lat/run.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +echo "Running lmbench UDP latency over virtio-net..." + +# Start the server +/benchmark/bin/lmbench/lat_udp -s 10.0.2.15 + +# Sleep for a long time to ensure VM won't exit +sleep 200 \ No newline at end of file