mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: kernel/scheduler: skip idle thread if there are any other threads available to run
This commit is contained in:
parent
7b54abcc13
commit
9f4a804e30
@ -2,7 +2,7 @@ use crate::objects::*;
|
|||||||
use core::sync::atomic::AtomicPtr;
|
use core::sync::atomic::AtomicPtr;
|
||||||
use log::{error, trace};
|
use log::{error, trace};
|
||||||
use spin::lazy::Lazy;
|
use spin::lazy::Lazy;
|
||||||
use tcb::SCHED_QUEUE_LINK_ID;
|
use tcb::{ThreadState, SCHED_QUEUE_LINK_ID};
|
||||||
use utils::{container_of_mut, linked_list::Link};
|
use utils::{container_of_mut, linked_list::Link};
|
||||||
|
|
||||||
#[thread_local]
|
#[thread_local]
|
||||||
@ -38,10 +38,29 @@ impl Scheduler {
|
|||||||
self.head.prepend(tcb);
|
self.head.prepend(tcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_next(&self, tcb: &TcbObject) {
|
||||||
|
self.head.append(tcb);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn schedule(&self) {
|
pub fn schedule(&self) {
|
||||||
|
let mut idle_found = false;
|
||||||
|
|
||||||
while let Some(next) = self.head.next_mut() {
|
while let Some(next) = self.head.next_mut() {
|
||||||
if next.timetick() > 0 && next.schedulable() {
|
if next.state() == ThreadState::Idle {
|
||||||
trace!("Scheduling thread {}", next.tid());
|
debug_assert!(next.tid() == 0, "IDLE thread should have TID 0");
|
||||||
|
|
||||||
|
if !idle_found {
|
||||||
|
// we are meeting the idle thread for the first time, bypass it
|
||||||
|
idle_found = true;
|
||||||
|
} else {
|
||||||
|
// no other thread could be scheduled
|
||||||
|
trace!("[Scheduler] Scheduling IDLE thread");
|
||||||
|
next.refill_timetick();
|
||||||
|
next.activate();
|
||||||
|
}
|
||||||
|
} else if next.timetick() > 0 && next.schedulable() {
|
||||||
|
trace!("[Scheduler] Scheduling thread {}", next.tid());
|
||||||
|
idle_found = false;
|
||||||
next.activate();
|
next.activate();
|
||||||
} else if next.timetick() == 0 {
|
} else if next.timetick() == 0 {
|
||||||
next.refill_timetick();
|
next.refill_timetick();
|
||||||
|
Loading…
Reference in New Issue
Block a user