Skip to content

Commit 9ecc4ea

Browse files
Andy Rossnashif
Andy Ross
authored andcommitted
sched: Properly account for timeslicing in tickless mode
When adding a new runnable thread in tickless mode, we need to detect whether it will timeslice with the running thread and reset the timer, otherwise it won't get any CPU time until the next interrupt fires at some indeterminate time in the future. This fixes the specific bug discussed in #7193, but the broader problem of tickless and timeslicing interacting badly remains. The code as it exists needs some rework to avoid all the #ifdef mess. Signed-off-by: Andy Ross <[email protected]>
1 parent 6dae106 commit 9ecc4ea

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

kernel/include/ksched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void *_get_next_switch_handle(void *interrupted);
4747
struct k_thread *_find_first_thread_to_unpend(_wait_q_t *wait_q,
4848
struct k_thread *from);
4949
void idle(void *a, void *b, void *c);
50+
void z_reset_timeslice(void);
5051

5152
/* find which one is the next thread to run */
5253
/* must be called with interrupts locked */
@@ -222,6 +223,10 @@ static inline void _ready_thread(struct k_thread *thread)
222223
_add_thread_to_ready_q(thread);
223224
}
224225

226+
#if defined(CONFIG_TICKLESS_KERNEL) && !defined(CONFIG_SMP)
227+
z_reset_timeslice();
228+
#endif
229+
225230
sys_trace_thread_ready(thread);
226231

227232
}

kernel/sched.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,15 @@ int _is_thread_time_slicing(struct k_thread *thread)
632632
return ret;
633633
}
634634

635+
#ifdef CONFIG_TICKLESS_KERNEL
636+
void z_reset_timeslice(void)
637+
{
638+
if (_is_thread_time_slicing(_get_next_ready_thread())) {
639+
_set_time(_time_slice_duration);
640+
}
641+
}
642+
#endif
643+
635644
/* Must be called with interrupts locked */
636645
/* Should be called only immediately before a thread switch */
637646
void _update_time_slice_before_swap(void)

0 commit comments

Comments
 (0)