Skip to content

feat(ipi): tie ipi to smp feature, add sync mechanism for ipi and support lazy flush tlb#29

Draft
li041 wants to merge 10 commits intoStarry-OS:devfrom
li041:dev
Draft

feat(ipi): tie ipi to smp feature, add sync mechanism for ipi and support lazy flush tlb#29
li041 wants to merge 10 commits intoStarry-OS:devfrom
li041:dev

Conversation

@li041
Copy link

@li041 li041 commented Dec 11, 2025

Copilot AI review requested due to automatic review settings December 11, 2025 08:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces IPI (Inter-Processor Interrupt) synchronization mechanisms and ties the IPI feature to SMP support, enabling lazy TLB flushing across multiple CPUs. The changes include adding a wait/sync mechanism for IPI operations, tracking secondary CPU startup state, and implementing TLB flush operations that leverage the IPI system.

Key changes:

  • Added synchronization support to IPI operations with a wait parameter and completion tracking via AtomicBool flags
  • Introduced SECONDARY_CPUS_STARTED flag to track when secondary CPUs are ready
  • Implemented TLB flush interface that uses IPI for cross-CPU coordination

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
modules/axtask/src/task.rs Adds on_cpu_mask() method to TaskExt trait for CPU affinity tracking
modules/axruntime/src/lib.rs Initializes axipi module and signals secondary CPU startup completion
modules/axmm/Cargo.toml Enables SMP feature for page_table_multiarch dependency
modules/axipi/src/tlb.rs New file implementing TLB flush interface using IPI mechanism
modules/axipi/src/queue.rs Updates IPI event queue to track event names and completion flags
modules/axipi/src/lib.rs Adds synchronization support, secondary CPU tracking, and new multicast functions
modules/axipi/src/event.rs Extends IpiEvent structure with name field and completion flag
modules/axipi/Cargo.toml Adds dependencies for TLB flush implementation
api/axfeat/Cargo.toml Ties IPI feature to SMP and adds axmm dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings December 23, 2025 07:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@li041 li041 marked this pull request as ready for review December 23, 2025 07:09
Copilot AI review requested due to automatic review settings December 23, 2025 07:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let cpu_num = axconfig::plat::CPU_NUM;
let callback = callback.into();

let mut done_flags: Vec<Arc<AtomicBool>> = Vec::new(cpu_num - 1);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vec::new() does not accept a capacity parameter. Use Vec::with_capacity(cpu_num - 1) instead to preallocate the vector with the correct capacity.

Copilot uses AI. Check for mistakes.
// Execute callback on current CPU immediately
callback.clone().call();

let mut done_flags: Vec<Arc<AtomicBool>> = Vec::new(cpu_num);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vec::new() does not accept a capacity parameter. Use Vec::with_capacity(cpu_num) instead to preallocate the vector with the correct capacity.

Copilot uses AI. Check for mistakes.
Comment on lines 154 to 155
if done_flags.is_empty() {
return;
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The early return for empty done_flags in run_on_each_cpu_except_self prevents IPI from being sent when wait is false. This logic appears inconsistent with run_on_bitmask_except_self (lines 107-111) which always sends IPIs regardless of wait flag. Consider whether IPIs should be sent even when wait=false and done_flags is empty.

Copilot uses AI. Check for mistakes.
log.workspace = true
percpu.workspace = true
crate_interface = "0.1.4"
axcpu = { git = "https://github.com/arceos-org/axcpu.git", tag = "dev-v03" }
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The axcpu dependency is added but does not appear to be used in any of the modified axipi source files. Consider removing this dependency if it's not needed, or add it when it's actually required.

Suggested change
axcpu = { git = "https://github.com/arceos-org/axcpu.git", tag = "dev-v03" }

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings December 23, 2025 11:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

fn flush_all(vaddr: Option<VirtAddr>) {
if axconfig::plat::CPU_NUM == 1 || !secondary_cpus_ready() {
// local
axhal::asm::flush_tlb(None);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local TLB flush is called with None regardless of the vaddr parameter value. This should pass vaddr to maintain consistency with the remote flush behavior on line 20.

Suggested change
axhal::asm::flush_tlb(None);
axhal::asm::flush_tlb(vaddr);

Copilot uses AI. Check for mistakes.
let cpu_num = axconfig::plat::CPU_NUM;
let callback = callback.into();

let mut done_flags: Vec<Arc<AtomicBool>> = Vec::with_capacity(cpu_num - 1);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vector is pre-allocated with cpu_num - 1 capacity but this is only accurate when all other CPUs will receive the IPI. Consider pre-allocating with the exact capacity needed or using Vec::new() without pre-allocation.

Copilot uses AI. Check for mistakes.
// Execute callback on current CPU immediately
callback.clone().call();

let mut done_flags: Vec<Arc<AtomicBool>> = Vec::with_capacity(cpu_num);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The capacity is set to cpu_num but only cpu_num - 1 flags will be added since the current CPU is excluded. The capacity should be cpu_num - 1 to avoid over-allocation.

Suggested change
let mut done_flags: Vec<Arc<AtomicBool>> = Vec::with_capacity(cpu_num);
let mut done_flags: Vec<Arc<AtomicBool>> = Vec::with_capacity(cpu_num - 1);

Copilot uses AI. Check for mistakes.
} else {
let callback = MulticastCallback::new(move || {
axhal::asm::flush_tlb(vaddr);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't the local CPU flushing?

Copilot AI review requested due to automatic review settings December 31, 2025 04:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pub fn run_on_cpu<T: Into<Callback>>(dest_cpu: usize, callback: T) {
info!("Send IPI event to CPU {dest_cpu}");
pub fn run_on_cpu<T: Into<Callback>>(name: &'static str, dest_cpu: usize, callback: T, wait: bool) {
let gurad = kernel_guard::NoPreempt::new();
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'gurad' to 'guard'.

Copilot uses AI. Check for mistakes.
/// Executes a callback on all other CPUs via IPI.
pub fn run_on_each_cpu<T: Into<MulticastCallback>>(callback: T) {
pub fn run_on_each_cpu<T: Into<MulticastCallback>>(name: &'static str, callback: T, wait: bool) {
let gurad = kernel_guard::NoPreempt::new();
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'gurad' to 'guard'.

Copilot uses AI. Check for mistakes.
}
}
}
drop(gurad); // rescheduling may occur when preemption is re-enabled.
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'gurad' to 'guard'.

Copilot uses AI. Check for mistakes.
@AsakuraMizu AsakuraMizu marked this pull request as draft January 10, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants