From 0b532ae00f7d0ec2f198267ea82993429ad9c42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 26 Aug 2024 20:05:04 +0200 Subject: [PATCH 1/2] fix: boot application processors after initializing scheduler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/aarch64/kernel/mod.rs | 8 ++------ src/arch/mod.rs | 7 +------ src/arch/riscv64/kernel/mod.rs | 10 ++++------ src/arch/x86_64/kernel/apic.rs | 2 ++ src/arch/x86_64/kernel/mod.rs | 24 ++++++++++++++---------- src/lib.rs | 5 ++--- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/arch/aarch64/kernel/mod.rs b/src/arch/aarch64/kernel/mod.rs index c73b017b00..ae58bd364a 100644 --- a/src/arch/aarch64/kernel/mod.rs +++ b/src/arch/aarch64/kernel/mod.rs @@ -156,12 +156,6 @@ pub fn boot_processor_init() { finish_processor_init(); } -/// Boots all available Application Processors on bare-metal or QEMU. -/// Called after the Boot Processor has been fully initialized along with its scheduler. -pub fn boot_application_processors() { - // Nothing to do here yet. -} - /// Application Processor initialization #[allow(dead_code)] pub fn application_processor_init() { @@ -171,7 +165,9 @@ pub fn application_processor_init() { fn finish_processor_init() { debug!("Initialized Processor"); +} +pub fn boot_next_processor() { CPU_ONLINE.fetch_add(1, Ordering::Release); } diff --git a/src/arch/mod.rs b/src/arch/mod.rs index aa3e3c9460..cd3a87fbb6 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -19,7 +19,6 @@ cfg_if::cfg_if! { #[cfg(feature = "smp")] pub(crate) use self::aarch64::kernel::application_processor_init; pub(crate) use self::aarch64::kernel::{ - boot_application_processors, get_processor_count, message_output_init, output_message_buf, @@ -44,10 +43,7 @@ cfg_if::cfg_if! { pub(crate) use self::x86_64::kernel::scheduler; pub(crate) use self::x86_64::kernel::switch; #[cfg(target_os = "none")] - pub(crate) use self::x86_64::kernel::{ - boot_application_processors, - boot_processor_init, - }; + pub(crate) use self::x86_64::kernel::boot_processor_init; pub(crate) use self::x86_64::kernel::{ get_processor_count, message_output_init, @@ -68,7 +64,6 @@ cfg_if::cfg_if! { pub(crate) use self::riscv64::kernel::pci; pub(crate) use self::riscv64::kernel::processor::{self, set_oneshot_timer, wakeup_core}; pub(crate) use self::riscv64::kernel::{ - boot_application_processors, boot_processor_init, core_local, get_processor_count, diff --git a/src/arch/riscv64/kernel/mod.rs b/src/arch/riscv64/kernel/mod.rs index 68bf45f02a..5adcb3376e 100644 --- a/src/arch/riscv64/kernel/mod.rs +++ b/src/arch/riscv64/kernel/mod.rs @@ -141,12 +141,6 @@ pub fn boot_processor_init() { interrupts::enable(); } -/// Boots all available Application Processors on bare-metal or QEMU. -/// Called after the Boot Processor has been fully initialized along with its scheduler. -pub fn boot_application_processors() { - // Nothing to do here yet. -} - /// Application Processor initialization #[cfg(feature = "smp")] pub fn application_processor_init() { @@ -179,6 +173,10 @@ fn finish_processor_init() { // Remove current hart from the hart_mask let new_hart_mask = get_hart_mask() & (u64::MAX - (1 << current_hart_id)); HART_MASK.store(new_hart_mask, Ordering::Relaxed); +} + +pub fn boot_next_processor() { + let new_hart_mask = HART_MASK.load(Ordering::Relaxed); let next_hart_index = lsb(new_hart_mask); diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index 983d55df90..538a24c429 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -804,6 +804,8 @@ pub fn boot_application_processors() { } } } + + print_information(); } #[cfg(feature = "smp")] diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index e6243eea57..6671ce84ec 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -194,15 +194,6 @@ pub fn boot_processor_init() { interrupts::enable(); } -/// Boots all available Application Processors on bare-metal or QEMU. -/// Called after the Boot Processor has been fully initialized along with its scheduler. -#[cfg(target_os = "none")] -pub fn boot_application_processors() { - #[cfg(feature = "smp")] - apic::boot_application_processors(); - apic::print_information(); -} - /// Application Processor initialization #[cfg(all(target_os = "none", feature = "smp"))] pub fn application_processor_init() { @@ -231,10 +222,23 @@ fn finish_processor_init() { // Therefore, the current processor already needs to prepare the processor variables for a possible next processor. apic::init_next_processor_variables(); } +} +pub fn boot_next_processor() { // This triggers apic::boot_application_processors (bare-metal/QEMU) or uhyve // to initialize the next processor. - CPU_ONLINE.fetch_add(1, Ordering::Release); + let cpu_online = CPU_ONLINE.fetch_add(1, Ordering::Release); + + if !env::is_uhyve() { + if cpu_online == 0 { + #[cfg(all(target_os = "none", feature = "smp"))] + apic::boot_application_processors(); + } + + if !cfg!(feature = "smp") { + apic::print_information(); + } + } } pub fn print_statistics() { diff --git a/src/lib.rs b/src/lib.rs index 89eb303463..964c8e2e95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,9 +211,7 @@ fn boot_processor_main() -> ! { #[cfg(not(target_arch = "riscv64"))] scheduler::add_current_core(); - if !env::is_uhyve() { - arch::boot_application_processors(); - } + arch::kernel::boot_next_processor(); #[cfg(feature = "smp")] synch_all_cores(); @@ -253,6 +251,7 @@ fn application_processor_main() -> ! { arch::application_processor_init(); #[cfg(not(target_arch = "riscv64"))] scheduler::add_current_core(); + arch::kernel::boot_next_processor(); debug!("Entering idle loop for application processor"); From 7666e29982633ee2cf9ba8d58cd83c08014c7637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 26 Aug 2024 22:59:36 +0200 Subject: [PATCH 2/2] ci: test SMP Uhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73f606b397..9c09ab053d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -250,5 +250,7 @@ jobs: if: matrix.arch == 'x86_64' - run: UHYVE=$CARGO_HOME/bin/uhyve cargo xtask ci uhyve --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --sudo --package rusty_demo if: matrix.arch == 'x86_64' + - run: UHYVE=$CARGO_HOME/bin/uhyve cargo xtask ci uhyve --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --sudo --package rusty_demo --smp + if: matrix.arch == 'x86_64' - run: FIRECRACKER=$HOME/.local/bin/firecracker cargo xtask ci firecracker --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --sudo --package hello_world --no-default-features if: matrix.arch == 'x86_64'