This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit be9200f95a45eafc6877d24e8402f686f16bcca7
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Fri Sep 4 10:24:28 2026 +0800

    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 <[email protected]>
---
 sched/sched/sched_switchcontext.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sched/sched/sched_switchcontext.c 
b/sched/sched/sched_switchcontext.c
index aa4c5e7e564..f2a708f5c4f 100644
--- a/sched/sched/sched_switchcontext.c
+++ b/sched/sched/sched_switchcontext.c
@@ -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

Reply via email to