From 85b0ee5320a3ef82a83aa1d2df1f3559d2e2f522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gr=C3=A9goire?= Date: Thu, 23 Jul 2026 16:37:30 -0400 Subject: [PATCH] ke/sched: fix promotion path Threads that get promoted should preempt the next thread if possible. --- src/kern/sched.zig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/kern/sched.zig b/src/kern/sched.zig index 7d42839..ce867b8 100644 --- a/src/kern/sched.zig +++ b/src/kern/sched.zig @@ -591,8 +591,19 @@ pub fn update_priority_locked(td: *ke.Thread, new_prio: u8) void { cpu.current_thread_prio.store(new_prio, .monotonic); - // Do nothing else on promotion. - if (new_prio >= old_prio) return; + // On promotion, check if a thread was already selection for preemption, + // if we now preempt that thread, then insert it back into its queue. + if (new_prio > old_prio) { + if (cpu.next_thread) |n| { + if (should_prio_preempt(td, n.priority, false)) { + cpu.next_thread = null; + insert_in_queue(cpu, n, true); + n.cpu = c; + cpu.preemption_reason = .None; + } + } + return; + } // Demotion: try to preempt the thread if possible. if (cpu.next_thread != null) return;