@@ -17,6 +17,9 @@ constexpr uint16_t TIME_SLICE_QUANTA[64] = {
1717} // namespace
1818
1919void Scheduler::add_thread (Thread* t) {
20+ cpu::CpuCoreManager& cpu_manager = cpu::CpuCoreManager::get ();
21+ cpu::PerCpuData* cpu = cpu_manager.get_core_by_index (this ->cpu_id );
22+
2023 if (t->priority >= MLFQ_LEVELS) {
2124 t->priority = MLFQ_LEVELS - 1 ;
2225 }
@@ -25,9 +28,8 @@ void Scheduler::add_thread(Thread* t) {
2528 t->quantum = TIME_SLICE_QUANTA[t->priority ];
2629 }
2730
28- t->state = Ready;
29- cpu::PerCpuData* cpu = cpu::CpuCoreManager::get ().get_core_by_index (this ->cpu_id );
30- t->cpu = cpu;
31+ t->state = Ready;
32+ t->cpu = cpu;
3133
3234 {
3335 LockGuard guard (this ->lock );
@@ -45,8 +47,8 @@ void Scheduler::add_thread(Thread* t) {
4547 cpu->reschedule_needed = true ;
4648
4749 // If this is running on a different core, send an IPI to wake it up
48- if (cpu::CpuCoreManager::get () .get_current_core ()->core_idx != this ->cpu_id ) {
49- cpu::CpuCoreManager::get () .send_ipi (this ->cpu_id , IPI_RESCHEDULE_VECTOR);
50+ if (cpu_manager .get_current_core ()->core_idx != this ->cpu_id ) {
51+ cpu_manager .send_ipi (this ->cpu_id , IPI_RESCHEDULE_VECTOR);
5052 }
5153 }
5254}
@@ -77,8 +79,9 @@ Thread* Scheduler::get_next_thread() {
7779}
7880
7981Thread* Scheduler::try_steal () {
82+ cpu::CpuCoreManager& cpu_manager = cpu::CpuCoreManager::get ();
8083 // Iterate over all other CPUs
81- size_t max_cpus = cpu::CpuCoreManager::get () .get_total_cores ();
84+ size_t max_cpus = cpu_manager .get_total_cores ();
8285
8386 for (size_t i = 0 ; i < max_cpus; ++i) {
8487 size_t victim_id = (this ->cpu_id + i) % max_cpus;
@@ -89,7 +92,7 @@ Thread* Scheduler::try_steal() {
8992 }
9093
9194 cpu::PerCpuData* victim_cpu =
92- cpu::CpuCoreManager::get () .get_core_by_index (static_cast <uint32_t >(victim_id));
95+ cpu_manager .get_core_by_index (static_cast <uint32_t >(victim_id));
9396 Scheduler& victim_sched = victim_cpu->sched ;
9497
9598 // Use `try_lock()` to avoid deadlock
@@ -119,7 +122,7 @@ Thread* Scheduler::try_steal() {
119122
120123 if (stolen) {
121124 // Migrate the thread to this cpu
122- stolen->cpu = cpu::CpuCoreManager::get () .get_core_by_index (this ->cpu_id );
125+ stolen->cpu = cpu_manager .get_core_by_index (this ->cpu_id );
123126 return stolen;
124127 }
125128 }
0 commit comments