Skip to content

Commit 9bf9b81

Browse files
committed
feat(smp): track per-task CPU residency to avoid unnecessary cross-core TLB shootdowns
1 parent 513f924 commit 9bf9b81

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/src/task.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use axerrno::{AxError, AxResult};
1818
use axmm::AddrSpace;
1919
use axpoll::PollSet;
2020
use axsync::{Mutex, spin::SpinNoIrq};
21-
use axtask::{AxTaskRef, TaskExt, TaskInner, WeakAxTaskRef, current};
21+
use axtask::{AxCpuMask, AxTaskRef, TaskExt, TaskInner, WeakAxTaskRef, current};
2222
use extern_trait::extern_trait;
2323
use hashbrown::HashMap;
2424
use lazy_static::lazy_static;
@@ -147,11 +147,19 @@ unsafe impl TaskExt for Box<Thread> {
147147
let scope = self.proc_data.scope.read();
148148
unsafe { ActiveScope::set(&scope) };
149149
core::mem::forget(scope);
150+
let mut on_cpu_mask = self.proc_data.on_cpu_mask.write();
151+
on_cpu_mask.set(axhal::percpu::this_cpu_id(), true);
150152
}
151153

152154
fn on_leave(&self) {
153155
ActiveScope::set_global();
154156
unsafe { self.proc_data.scope.force_read_decrement() };
157+
let mut on_cpu_mask = self.proc_data.on_cpu_mask.write();
158+
on_cpu_mask.set(axhal::percpu::this_cpu_id(), false);
159+
}
160+
161+
fn on_cpu_mask(&self) -> AxCpuMask {
162+
self.proc_data.on_cpu_mask.read().clone()
155163
}
156164
}
157165

@@ -184,6 +192,8 @@ pub struct ProcessData {
184192
/// The virtual memory address space.
185193
// TODO: scopify
186194
pub aspace: Arc<Mutex<AddrSpace>>,
195+
/// The CPUs on which the task has run.
196+
pub on_cpu_mask: RwLock<AxCpuMask>,
187197
/// The resource scope
188198
pub scope: RwLock<Scope>,
189199
/// The user heap bottom
@@ -226,6 +236,7 @@ impl ProcessData {
226236
exe_path: RwLock::new(exe_path),
227237
cmdline: RwLock::new(cmdline),
228238
aspace,
239+
on_cpu_mask: RwLock::new(AxCpuMask::new()),
229240
scope: RwLock::new(Scope::new()),
230241
heap_bottom: AtomicUsize::new(crate::config::USER_HEAP_BASE),
231242
heap_top: AtomicUsize::new(crate::config::USER_HEAP_BASE),

0 commit comments

Comments
 (0)