From ab279683fcd0a6facd9f03ec6ddad9be3314ca00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Costa?= Date: Fri, 1 Nov 2024 11:33:45 +0100 Subject: [PATCH] Run ci/cd pipeline in a multicore setup Now we run the ci/cd pipeline with a single core. Going multicore make the tests overall more robust to pass as we might encounters race conditions. --- Cargo.lock | 32 ++++++++++- .../test/qemu-rustsbi-test-kernel-spike.toml | 57 ------------------- config/test/qemu-virt-benchmark.toml | 2 +- .../qemu-virt-hello-world-payload-spike.toml | 57 ------------------- .../test/qemu-virt-hello-world-payload.toml | 2 +- config/test/qemu-virt-release.toml | 2 +- config/test/qemu-virt-sifive-u54-spike.toml | 23 -------- config/test/qemu-virt-sifive-u54.toml | 2 +- config/test/qemu-virt-test-payload-lock.toml | 2 +- .../test/qemu-virt-test-protect-payload.toml | 2 +- config/test/qemu-virt-u-boot-payload.toml | 2 +- crates/abi/Cargo.toml | 3 +- crates/abi/src/logger.rs | 13 +++-- justfile | 9 +-- src/Cargo.toml | 2 +- src/logger.rs | 21 +++---- 16 files changed, 60 insertions(+), 171 deletions(-) delete mode 100644 config/test/qemu-rustsbi-test-kernel-spike.toml delete mode 100644 config/test/qemu-virt-hello-world-payload-spike.toml delete mode 100644 config/test/qemu-virt-sifive-u54-spike.toml diff --git a/Cargo.lock b/Cargo.lock index 8063e66f..a248dad8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anstream" @@ -51,6 +51,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + [[package]] name = "benchmark_analyzer" version = "0.1.0" @@ -234,6 +240,16 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.22" @@ -280,6 +296,7 @@ dependencies = [ "config_helpers", "log", "miralis_core", + "spin", ] [[package]] @@ -376,6 +393,12 @@ dependencies = [ "miralis_abi", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.196" @@ -407,9 +430,12 @@ dependencies = [ [[package]] name = "spin" -version = "0.5.2" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] [[package]] name = "strsim" diff --git a/config/test/qemu-rustsbi-test-kernel-spike.toml b/config/test/qemu-rustsbi-test-kernel-spike.toml deleted file mode 100644 index 4a4cafda..00000000 --- a/config/test/qemu-rustsbi-test-kernel-spike.toml +++ /dev/null @@ -1,57 +0,0 @@ -# A test configuration to run on QEMU virt platform - -[log] -level = "info" -color = true - -[debug] -max_firmware_exits = 2000 - -[vcpu] -max_pmp = 8 - -[platform] -nb_harts = 1 -name = "spike" - -[benchmark] -enable = false - -[target.miralis] -# Build profile for Miralis (dev profile is set by default) -profile = "dev" - -# Miralis binary will be compiled with this value as a start address -# Default to "0x80000000" -start_address = 0x80000000 - -# Size of the Miralis' stack for each hart (i.e. core) -# Default to 0x8000 -stack_size = 0x8000 - -[target.firmware] -# Build profile for the firmware (dev profile is set by default) -profile = "dev" - -# Firmware binary will be compiled with this value as a start address -# Default to "0x80200000" -start_address = 0x80200000 - -# Size of the firmware stack for each hart (i.e. core) -# Default to 0x8000 -stack_size = 0x8000 - -[target.payload] -# Name or path to the payload binary -name = "rustsbi-test-kernel" - -# Build profile for the payload (dev profile is set by default) -profile = "dev" - -# Payload binary will be compiled with this value as a start address -# Default to "0x80400000" -start_address = 0x80400000 - -# Size of the payload stack for each hart (i.e. core) -# Default to 0x8000 -stack_size = 0x8000 diff --git a/config/test/qemu-virt-benchmark.toml b/config/test/qemu-virt-benchmark.toml index 6240ef3b..8a36abc2 100644 --- a/config/test/qemu-virt-benchmark.toml +++ b/config/test/qemu-virt-benchmark.toml @@ -11,7 +11,7 @@ color = true max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 [benchmark] enable = true diff --git a/config/test/qemu-virt-hello-world-payload-spike.toml b/config/test/qemu-virt-hello-world-payload-spike.toml deleted file mode 100644 index 24dd14eb..00000000 --- a/config/test/qemu-virt-hello-world-payload-spike.toml +++ /dev/null @@ -1,57 +0,0 @@ -# A test configuration to run on QEMU virt platform - -[log] -level = "info" -color = true - -[debug] -max_firmware_exits = 2000 - -[vcpu] -max_pmp = 8 - -[platform] -nb_harts = 1 -name = "spike" - -[benchmark] -enable = false - -[target.miralis] -# Build profile for Miralis (dev profile is set by default) -profile = "dev" - -# Miralis binary will be compiled with this value as a start address -# Default to "0x80000000" -start_address = 0x80000000 - -# Size of the Miralis' stack for each hart (i.e. core) -# Default to 0x8000 -stack_size = 0x8000 - -[target.firmware] -# Build profile for the firmware (dev profile is set by default) -profile = "dev" - -# Firmware binary will be compiled with this value as a start address -# Default to "0x80200000" -start_address = 0x80200000 - -# Size of the firmware stack for each hart (i.e. core) -# Default to 0x8000 -stack_size = 0x8000 - -[target.payload] -# Name or path to the payload binary -name = "hello_world" - -# Build profile for the payload (dev profile is set by default) -profile = "dev" - -# Payload binary will be compiled with this value as a start address -# Default to "0x80400000" -start_address = 0x80400000 - -# Size of the payload stack for each hart (i.e. core) -# Default to 0x8000 -stack_size = 0x8000 diff --git a/config/test/qemu-virt-hello-world-payload.toml b/config/test/qemu-virt-hello-world-payload.toml index 24a690b3..4708ee2b 100644 --- a/config/test/qemu-virt-hello-world-payload.toml +++ b/config/test/qemu-virt-hello-world-payload.toml @@ -11,7 +11,7 @@ max_firmware_exits = 2000 max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 [benchmark] enable = false diff --git a/config/test/qemu-virt-release.toml b/config/test/qemu-virt-release.toml index 75a1d21c..a76f7a0b 100644 --- a/config/test/qemu-virt-release.toml +++ b/config/test/qemu-virt-release.toml @@ -11,7 +11,7 @@ max_firmware_exits = 2000 max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 [benchmark] enable = false diff --git a/config/test/qemu-virt-sifive-u54-spike.toml b/config/test/qemu-virt-sifive-u54-spike.toml deleted file mode 100644 index 7a0019f8..00000000 --- a/config/test/qemu-virt-sifive-u54-spike.toml +++ /dev/null @@ -1,23 +0,0 @@ -# A simple configuration to run on QEMU virt platform - -[log] -level = "info" -color = true - -[debug] -# max_firmware_exits = 2000 - -[vcpu] -max_pmp = 8 - -[platform] -nb_harts = 1 -boot_hart_id = 0 -name = "spike" - -[benchmark] -enable = false - -[qemu] -machine = "virt" -cpu = "sifive-u54" \ No newline at end of file diff --git a/config/test/qemu-virt-sifive-u54.toml b/config/test/qemu-virt-sifive-u54.toml index d30b435f..0c6b79b1 100644 --- a/config/test/qemu-virt-sifive-u54.toml +++ b/config/test/qemu-virt-sifive-u54.toml @@ -11,7 +11,7 @@ color = true max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 boot_hart_id = 0 [benchmark] diff --git a/config/test/qemu-virt-test-payload-lock.toml b/config/test/qemu-virt-test-payload-lock.toml index 741f40cc..bb9a7646 100644 --- a/config/test/qemu-virt-test-payload-lock.toml +++ b/config/test/qemu-virt-test-payload-lock.toml @@ -11,7 +11,7 @@ color = true max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 boot_hart_id = 0 [benchmark] diff --git a/config/test/qemu-virt-test-protect-payload.toml b/config/test/qemu-virt-test-protect-payload.toml index ec8587e5..bc6f166d 100644 --- a/config/test/qemu-virt-test-protect-payload.toml +++ b/config/test/qemu-virt-test-protect-payload.toml @@ -9,7 +9,7 @@ color = true max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 [benchmark] enable = false diff --git a/config/test/qemu-virt-u-boot-payload.toml b/config/test/qemu-virt-u-boot-payload.toml index 2b6a1e7e..6cad10dd 100644 --- a/config/test/qemu-virt-u-boot-payload.toml +++ b/config/test/qemu-virt-u-boot-payload.toml @@ -11,7 +11,7 @@ max_firmware_exits = 2000 max_pmp = 8 [platform] -nb_harts = 1 +nb_harts = 8 [benchmark] enable = false diff --git a/crates/abi/Cargo.toml b/crates/abi/Cargo.toml index 5086d3ca..ad9aa7ef 100644 --- a/crates/abi/Cargo.toml +++ b/crates/abi/Cargo.toml @@ -8,4 +8,5 @@ license = "MIT" [dependencies] miralis_core = { path = "../core" } log = { workspace = true } -config_helpers = { path = "../config_helpers"} \ No newline at end of file +config_helpers = { path = "../config_helpers"} +spin = "0.9.8" \ No newline at end of file diff --git a/crates/abi/src/logger.rs b/crates/abi/src/logger.rs index 03f87289..14e62fd0 100644 --- a/crates/abi/src/logger.rs +++ b/crates/abi/src/logger.rs @@ -5,6 +5,7 @@ use core::fmt::Write; use log::{LevelFilter, Metadata, Record}; +use spin::Once; use crate::miralis_log; @@ -34,14 +35,18 @@ impl log::Log for Logger { fn flush(&self) {} } +static LOGGER_INIT: Once = Once::new(); + /// Initialize the firmware logger /// /// This function is called automatically by `setup_binary!`. pub fn init() { - static LOGGER: Logger = Logger {}; - - log::set_logger(&LOGGER).unwrap(); - log::set_max_level(LevelFilter::Trace); + LOGGER_INIT.call_once(|| { + if let Err(err) = log::set_logger(&Logger {}) { + panic!("Failed to set logger: {}", err); + } + log::set_max_level(LevelFilter::Trace); + }); } // —————————————————————————————— Stack Buffer —————————————————————————————— // diff --git a/justfile b/justfile index d67478b1..1df837ac 100644 --- a/justfile +++ b/justfile @@ -3,6 +3,7 @@ config := "config.toml" benchmark := "ecall_benchmark" spike := "./config/spike.toml" qemu_virt := "./config/test/qemu-virt.toml" +qemu_virt_multicore := "./config/test/qemu-virt-multicore.toml" qemu_virt_protect_payload := "./config/test/qemu-virt-test-payload-lock.toml" qemu_virt_2harts := "./config/test/qemu-virt.toml" qemu_virt_benchmark := "./config/test/qemu-virt-benchmark.toml" @@ -11,12 +12,9 @@ spike_latency_benchmark := "./config/test/spike-latency-benchmark.toml" qemu_virt_release := "./config/test/qemu-virt-release.toml" qemu_virt_hello_world_payload := "./config/test/qemu-virt-hello-world-payload.toml" qemu_virt_test_protect_paylod := "./config/test/qemu-virt-test-protect-payload.toml" -qemu_virt_hello_world_payload_spike := "./config/test/qemu-virt-hello-world-payload-spike.toml" qemu_virt_u_boot_payload := "./config/test/qemu-virt-u-boot-payload.toml" qemu_virt_sifive_u54 := "./config/test/qemu-virt-sifive-u54.toml" -qemu_virt_sifive_u54_spike := "./config/test/qemu-virt-sifive-u54-spike.toml" qemu_virt_rustsbi_test_kernel := "./config/test/qemu-rustsbi-test-kernel.toml" -qemu_virt_rustsbi_test_kernel_spike := "./config/test/qemu-rustsbi-test-kernel-spike.toml" benchmark_folder := "./benchmark-out" default_iterations := "1" @@ -55,7 +53,6 @@ test: cargo run -- run --config {{qemu_virt}} --firmware mret cargo run -- run --config {{qemu_virt}} --firmware os_ctx_switch cargo run -- run --config {{qemu_virt}} --firmware sandbox - cargo run -- run --config {{qemu_virt}} --firmware interrupt cargo run -- run --config {{qemu_virt}} --firmware os_ecall cargo run -- run --config {{qemu_virt}} --firmware vectored_mtvec cargo run -- run --config {{qemu_virt}} --firmware device @@ -66,8 +63,8 @@ test: cargo run -- run --config {{qemu_virt}} --firmware miralis # Testing with external projects - cargo run -- run --config {{qemu_virt}} --firmware opensbi - cargo run -- run --config {{qemu_virt}} --firmware zephyr --max-exits 1000000 + cargo run -- run --config {{qemu_virt_multicore}} --firmware opensbi + cargo run -- run --config {{qemu_virt_multicore}} --firmware zephyr --max-exits 1000000 cargo run -- run --config {{qemu_virt_sifive_u54}} --firmware linux cargo run -- run --config {{qemu_virt_rustsbi_test_kernel}} --firmware rustsbi-qemu diff --git a/src/Cargo.toml b/src/Cargo.toml index 5ca46c28..dd9d25b4 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -11,7 +11,7 @@ path = "main.rs" [dependencies] uart_16550 = "0.3.0" -spin = "0.5.2" +spin = "0.9.8" log = { workspace = true } miralis_core = { path = "../crates/core" } miralis_abi = { path = "../crates/abi" } diff --git a/src/logger.rs b/src/logger.rs index 49386ab1..ae427762 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,8 +1,7 @@ //! Structured logging implementation -use core::sync::atomic::{AtomicBool, Ordering}; - use log::{Level, LevelFilter, Metadata, Record}; +use spin::Once; use crate::config; use crate::platform::{Plat, Platform}; @@ -86,18 +85,16 @@ impl log::Log for Logger { fn flush(&self) {} } -pub fn init() { - static IS_INITIALIZED: AtomicBool = AtomicBool::new(false); - match IS_INITIALIZED.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) { - Ok(_) => { - log::set_logger(&Logger {}).unwrap(); - log::set_max_level(LevelFilter::Trace); - } - Err(_) => { - log::warn!("Logger is already initialized, skipping init"); +static LOGGER_INIT: Once = Once::new(); + +pub fn init() { + LOGGER_INIT.call_once(|| { + if let Err(err) = log::set_logger(&Logger {}) { + panic!("Failed to set logger: {}", err); } - }; + log::set_max_level(LevelFilter::Trace); + }); } // ————————————————————————————————— Utils —————————————————————————————————— //