From 2d59adbe0e3d1dab52441e11701ebe8e7ddf81c1 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 2 Mar 2021 21:46:14 +0800 Subject: [PATCH] fix thread scheduling bug the code originally would pick the same thread over and over again this fix starts the thread search at one plus the current thread wrapping around to one plus the current thread, so we always try to pick a new thread compared to the current one, instead of generally picking the same thread most of the time. --- kernel/src/services.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index 54c68fde2..245116e7c 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -789,7 +789,7 @@ impl SystemServices { ) -> Result { let previous_pid = self.current_pid(); - let debug = true; + let debug = false; if debug { println!( "\n\r KERNEL({},{}): Activating process {} thread {}", @@ -825,12 +825,12 @@ impl SystemServices { new_pid, x, ); //new_tid = 0; - new_tid = new.current_thread as usize; + new_tid = (new.current_thread + 1) as usize; while x & (1 << new_tid) == 0 { new_tid += 1; if new_tid > arch::process::MAX_THREAD { new_tid = 0; - } else if new_tid == new.current_thread as usize { + } else if new_tid == (new.current_thread + 1) as usize { // If we've looped around, return an error. println!("Looked through all contexts and couldn't find one that was ready"); return Err(xous_kernel::Error::ProcessNotFound);