sched/sched: Fix roundrobin scheduler timer if SCHED_TICKLESS enabled

In tickless mode, the scheduler timer is stopped whenever the currently
running task requires no time slicing (CLOCK_MAX).  When a SCHED_RR task
was later switched in, nothing re-armed the timer, so the task could run
indefinitely without round-robin rotation.

Reassess the scheduler timer in nxsched_switch_context() before the
context switch when the task being switched in uses round-robin
scheduling, so that the timer is always armed while an RR task is
running.  Hooking into nxsched_switch_context() covers all context
switch paths (task context switch, interrupt exit, syscall and task
exit) since every architecture calls it on every switch.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen 2026-09-04 10:24:28 +08:00 committed by Alan C. Assis
parent f134a5678d
commit be9200f95a

View file

@ -65,6 +65,15 @@ void nxsched_switch_context(FAR struct tcb_s *from, FAR struct tcb_s *to)
}
#endif
#if defined(CONFIG_SCHED_TICKLESS) && CONFIG_RR_INTERVAL > 0
/* Before the context switch, we should set the timer for RR. */
if (from != to && (to->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_RR)
{
nxsched_reassess_timer();
}
#endif
/* Indicate that the task has been suspended */
#ifdef CONFIG_SCHED_CRITMONITOR