From f807d4db7e3d8bba458b7c8c8ba229bf92f0b840 Mon Sep 17 00:00:00 2001 From: Youvedeep Singh Date: Tue, 18 Jul 2017 16:13:16 +0530 Subject: [PATCH] Scheduler: Same priority Preemptive threads should get equal time slice If there are multiple preemptive threads with same priority, and any one thread preempts before its time slice expires (due to yields/ semaphore take/queue etc), then next schedules thread is getting lower time slide than expected. This patch fixes this issue by accounting time expired when a thread releases CPU before its time slide expires. Jira: ZEP-2217/ZEP-2218 Signed-off-by: Youvedeep Singh --- kernel/sched.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/sched.c b/kernel/sched.c index eb702e2819a..bf2f9d834ca 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -432,7 +432,13 @@ void _update_time_slice_before_swap(void) if (!remaining || (_time_slice_duration < remaining)) { _set_time(_time_slice_duration); + } else { + /* Account previous elapsed time and reprogram + * timer with remaining time + */ + _set_time(remaining); } + #endif /* Restart time slice count at new thread switch */ _time_slice_elapsed = 0;