Skip to content

Commit

Permalink
sched: fix deadline init value
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
TaiJuWu committed Feb 28, 2024
1 parent 9e4e5da commit 4764049
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4764049

Please sign in to comment.