From 59df7bdadbfd50bfaf95cde442c7380cce535254 Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Thu, 7 Mar 2024 13:35:04 -0500 Subject: kern: sched: Refactor queue and ctx switch code Signed-off-by: Quinn Stephens Signed-off-by: Ian Moffett --- sys/kern/kern_sched.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index f61c592..266ce39 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -97,13 +97,11 @@ sched_dequeue_td(void) spinlock_acquire(&tdq_lock); - if (TAILQ_EMPTY(&td_queue)) { - goto done; + if (!TAILQ_EMPTY(&td_queue)) { + td = TAILQ_FIRST(&td_queue); + TAILQ_REMOVE(&td_queue, td, link); } - td = TAILQ_FIRST(&td_queue); - TAILQ_REMOVE(&td_queue, td, link); -done: spinlock_release(&tdq_lock); return td; } @@ -174,11 +172,9 @@ sched_context_switch(struct trapframe *tf) * If we have no threads, we should not * preempt at all. */ - if (nthread == 0) { - goto done; - } else if ((next_td = sched_dequeue_td()) == NULL) { - /* Empty */ - goto done; + if (nthread == 0 || (next_td = sched_dequeue_td()) == NULL) { + sched_oneshot(); + return; } if (state->td != NULL) { @@ -196,7 +192,7 @@ sched_context_switch(struct trapframe *tf) if (td != NULL) { sched_enqueue_td(td); } -done: + sched_oneshot(); } -- cgit v1.2.3