Skip to content
Open
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
11 changes: 10 additions & 1 deletion core/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use axerrno::{AxError, AxResult};
use axmm::AddrSpace;
use axpoll::PollSet;
use axsync::{Mutex, spin::SpinNoIrq};
use axtask::{AxTaskRef, TaskExt, TaskInner, WeakAxTaskRef, current};
use axtask::{AxCpuMask, AxTaskRef, TaskExt, TaskInner, WeakAxTaskRef, current};
use extern_trait::extern_trait;
use hashbrown::HashMap;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -147,12 +147,18 @@ unsafe impl TaskExt for Box<Thread> {
let scope = self.proc_data.scope.read();
unsafe { ActiveScope::set(&scope) };
core::mem::forget(scope);
let mut on_cpu_mask = self.proc_data.on_cpu_mask.write();
on_cpu_mask.set(axhal::percpu::this_cpu_id(), true);
}

fn on_leave(&self) {
ActiveScope::set_global();
unsafe { self.proc_data.scope.force_read_decrement() };
}

fn on_cpu_mask(&self) -> AxCpuMask {
self.proc_data.on_cpu_mask.read().clone()
}
}

/// Helper trait to access the thread from a task.
Expand Down Expand Up @@ -184,6 +190,8 @@ pub struct ProcessData {
/// The virtual memory address space.
// TODO: scopify
pub aspace: Arc<Mutex<AddrSpace>>,
/// The CPUs on which the task has run.
pub on_cpu_mask: RwLock<AxCpuMask>,
Comment on lines +193 to +194
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

The documentation states "The CPUs on which the task has run" which implies historical tracking of all CPUs where the process has executed. However, the implementation in on_leave (line 157-158) clears CPU bits when leaving, suggesting it tracks "currently running CPUs" instead. This discrepancy between documentation and implementation needs to be resolved. Clarify whether this should track historical CPU usage (never clear bits) or current CPU presence (requires reference counting per CPU to handle multiple threads).

Copilot uses AI. Check for mistakes.
/// The resource scope
pub scope: RwLock<Scope>,
/// The user heap bottom
Expand Down Expand Up @@ -226,6 +234,7 @@ impl ProcessData {
exe_path: RwLock::new(exe_path),
cmdline: RwLock::new(cmdline),
aspace,
on_cpu_mask: RwLock::new(AxCpuMask::new()),
scope: RwLock::new(Scope::new()),
heap_bottom: AtomicUsize::new(crate::config::USER_HEAP_BASE),
heap_top: AtomicUsize::new(crate::config::USER_HEAP_BASE),
Expand Down
Loading