Refactor the this_cpu API with PinCurrentCpu

This commit is contained in:
Zhang Junyang
2024-08-19 20:32:14 +08:00
committed by Tate, Hongliang Tian
parent 9a94ba23aa
commit f7a9510be0
17 changed files with 123 additions and 75 deletions

View File

@ -1,11 +1,12 @@
// SPDX-License-Identifier: MPL-2.0
use ostd::{
cpu::{num_cpus, this_cpu},
cpu::{num_cpus, PinCurrentCpu},
task::{
scheduler::{inject_scheduler, EnqueueFlags, LocalRunQueue, Scheduler, UpdateFlags},
AtomicCpuId, Priority, Task,
},
trap::disable_local,
};
use crate::prelude::*;
@ -71,13 +72,15 @@ impl<T: Sync + Send + PreemptSchedInfo> Scheduler<T> for PreemptScheduler<T> {
}
fn local_rq_with(&self, f: &mut dyn FnMut(&dyn LocalRunQueue<T>)) {
let local_rq: &PreemptRunQueue<T> = &self.rq[this_cpu() as usize].disable_irq().lock();
let irq_guard = disable_local();
let local_rq: &PreemptRunQueue<T> = &self.rq[irq_guard.current_cpu() as usize].lock();
f(local_rq);
}
fn local_mut_rq_with(&self, f: &mut dyn FnMut(&mut dyn LocalRunQueue<T>)) {
let irq_guard = disable_local();
let local_rq: &mut PreemptRunQueue<T> =
&mut self.rq[this_cpu() as usize].disable_irq().lock();
&mut self.rq[irq_guard.current_cpu() as usize].lock();
f(local_rq);
}
}

View File

@ -6,9 +6,10 @@ use core::time::Duration;
use aster_time::read_monotonic_time;
use ostd::{
arch::timer::Jiffies,
cpu::{num_cpus, this_cpu},
cpu::{num_cpus, PinCurrentCpu},
cpu_local,
sync::SpinLock,
task::disable_preempt,
};
use paste::paste;
use spin::Once;
@ -35,7 +36,11 @@ impl RealTimeClock {
/// Get the cpu-local system-wide `TimerManager` singleton of this clock.
pub fn timer_manager() -> &'static Arc<TimerManager> {
CLOCK_REALTIME_MANAGER.get_on_cpu(this_cpu()).get().unwrap()
let preempt_guard = disable_preempt();
CLOCK_REALTIME_MANAGER
.get_on_cpu(preempt_guard.current_cpu())
.get()
.unwrap()
}
}
@ -53,8 +58,9 @@ impl MonotonicClock {
/// Get the cpu-local system-wide `TimerManager` singleton of this clock.
pub fn timer_manager() -> &'static Arc<TimerManager> {
let preempt_guard = disable_preempt();
CLOCK_MONOTONIC_MANAGER
.get_on_cpu(this_cpu())
.get_on_cpu(preempt_guard.current_cpu())
.get()
.unwrap()
}
@ -135,7 +141,11 @@ impl BootTimeClock {
/// Get the cpu-local system-wide `TimerManager` singleton of this clock.
pub fn timer_manager() -> &'static Arc<TimerManager> {
CLOCK_BOOTTIME_MANAGER.get_on_cpu(this_cpu()).get().unwrap()
let preempt_guard = disable_preempt();
CLOCK_BOOTTIME_MANAGER
.get_on_cpu(preempt_guard.current_cpu())
.get()
.unwrap()
}
}