From 476404953b47b726e914b0fad7c96122c89c6ed9 Mon Sep 17 00:00:00 2001 From: TaiJu Wu Date: Mon, 26 Feb 2024 07:01:00 +0000 Subject: [PATCH] sched: fix deadline init value The init value of deadline scheduler algorithm should be INT_MIN. Case study 1: both tasks are deadline task. These condition already include test/kernel/sched/deadline In below, I will use 4-bit to replace 32-bit operation. Case study 2: T1 is deadline task, T2 is also deadline task and will make overflow Example: If T1's deadline is 0100 -> both signed and unsingend is 4. If T2's deadline is 1001 (uint4_t + int4_t) -> signed is -7 and unsigned is 9. (uint4_t)T2-(uint4_t)T1 = 9 -2 = 7 -> 0111 > 0. T1 execute first. Case study 3: T1 is normal task and T2 is deadline task. Example: If normal task deadline is INT_MIN(1000 in this case.) If deadline is 0100->both signed and unsigned is 4. (uint4_t)T2 - (uint4_t)T1 = 0100 - 1000 = -4 < 0. T2 execute first. Signed-off-by: TaiJu Wu --- kernel/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/thread.c b/kernel/thread.c index 31b92fdb2c63..f3229680eb30 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -715,7 +715,7 @@ char *z_setup_new_thread(struct k_thread *new_thread, } #endif #ifdef CONFIG_SCHED_DEADLINE - new_thread->base.prio_deadline = 0; + new_thread->base.prio_deadline = INT_MIN; #endif new_thread->resource_pool = _current->resource_pool;