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

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

commit 5b978a7f9b82169da4c4010b2a400b41526bd16e
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Thu Jan 29 11:00:18 2026 +0800

    sched/hrtimer: workaround for SCHED_RR in tickless mode.
    
    This commit provided workaround for incorrect SCHED_RR behavior in
    tickless mode.
    
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 sched/sched/sched_processtickless.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/sched/sched/sched_processtickless.c 
b/sched/sched/sched_processtickless.c
index 6778607f27a..352d9f105ba 100644
--- a/sched/sched/sched_processtickless.c
+++ b/sched/sched/sched_processtickless.c
@@ -351,22 +351,40 @@ static void nxsched_timer_start(clock_t ticks, clock_t 
interval)
  * Name: nxsched_process_timer
  *
  * Description:
- *   if CONFIG_SCHED_TICKLESS is defined, then this function is provided by
+ *   If CONFIG_SCHED_TICKLESS is defined, then this function is provided by
  *   the RTOS base code and called from platform-specific code when the
  *   interval timer used to implement the tick-less OS expires.
  *
  * Input Parameters:
+ *   None.
  *
  * Returned Value:
  *   Base code implementation assumes that this function is called from
  *   interrupt handling logic with interrupts disabled.
  *
+ * Note:
+ *   The current SCHED_RR implementation has an issue: if a round-robin task
+ *   is preempted, its timeslice counter does not decrement properly.
+ *   Therefore, we must trigger the scheduler on each timer expiration to
+ *   minimize the occurrence of this problem.
+ *   This workaround can be removed once the SCHED_RR behavior is fixed.
+ *
  ****************************************************************************/
 
 void nxsched_process_timer(void)
 {
 #ifdef CONFIG_HRTIMER
-  hrtimer_process(clock_systime_nsec());
+  uint64_t nsec = clock_systime_nsec();
+  hrtimer_process(nsec);
+
+#  if CONFIG_RR_INTERVAL > 0
+  /* Workaround for SCHED_RR, see the note. */
+
+  irqstate_t flags = enter_critical_section();
+  nxsched_process_event(div_const(nsec, (uint32_t)NSEC_PER_TICK), true);
+  leave_critical_section(flags);
+#  endif
+
 #else
   irqstate_t flags;
   clock_t ticks;
@@ -380,12 +398,7 @@ void nxsched_process_timer(void)
   up_timer_gettick(&ticks);
 
 #if CONFIG_RR_INTERVAL > 0
-  /* The current SCHED_RR implementation has an issue: if a round-robin task
-   * is preempted, its timeslice counter does not decrement properly.
-   * Therefore, we must trigger the scheduler on each timer expiration to
-   * minimize the occurrence of this problem.
-   * This workaround can be removed once the SCHED_RR behavior is fixed.
-   */
+  /* Workaround for SCHED_RR, see the note. */
 
   nxsched_process_event(ticks, true);
 #endif

Reply via email to