Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: boot application processors after initializing scheduler #1372

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 2 additions & 6 deletions src/arch/aarch64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}

Expand Down
7 changes: 1 addition & 6 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/arch/riscv64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,8 @@ pub fn boot_application_processors() {
}
}
}

print_information();
}

#[cfg(feature = "smp")]
Expand Down
24 changes: 14 additions & 10 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");

Expand Down
Loading