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

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

commit 2ae62d71a632f111fd025aeac4d719bac8c80c9e
Author: wangchengdong <[email protected]>
AuthorDate: Tue Jan 27 10:38:22 2026 +0800

    sched/hrtimer: fix hrtimer regression introduced by recent update
    
    The hrtimer subsystem is independent of the OS tick mechanism and tickless
    mode. It must always be able to reprogram the hardware timer to achieve
    nanosecond-level resolution.
    
    A recent update restricted hardware timer reprogramming to tickless mode
    only. As a result, hrtimer no longer functions correctly when the scheduler
    is running in tick-based mode.
    
    This change removes the incorrect dependency on tickless mode and restores
    proper hrtimer operation.
    
    Signed-off-by: Chengdong Wang <[email protected]>
---
 include/nuttx/arch.h    |  7 ++++---
 sched/hrtimer/hrtimer.h | 19 +++++++++++--------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 45cbe9f0176..70eb53e3a41 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -2063,8 +2063,8 @@ int up_alarm_tick_cancel(FAR clock_t *ticks);
  *
  ****************************************************************************/
 
-#if defined(CONFIG_HRTIMER) || \
-    defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
+#if (defined(CONFIG_HRTIMER) && defined(CONFIG_ALARM_ARCH)) || \
+    (defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM))
 int up_alarm_start(FAR const struct timespec *ts);
 int up_alarm_tick_start(clock_t ticks);
 #endif
@@ -2135,7 +2135,8 @@ int up_timer_tick_cancel(FAR clock_t *ticks);
  *
  ****************************************************************************/
 
-#if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM)
+#if (defined(CONFIG_HRTIMER) && defined(CONFIG_TIMER_ARCH)) || \
+    (defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM))
 int up_timer_start(FAR const struct timespec *ts);
 int up_timer_tick_start(clock_t ticks);
 #endif
diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h
index 606cd086350..2b6386910bd 100644
--- a/sched/hrtimer/hrtimer.h
+++ b/sched/hrtimer/hrtimer.h
@@ -122,26 +122,29 @@ void hrtimer_process(uint64_t now);
  *   ns - Expiration time in nanoseconds.
  *
  * Returned Value:
- *   OK (0) on success, negated errno on failure.
+ *   None.
+ *
+ * Assumptions:
+ *   The underlying timer start function returns 0 on success.
  ****************************************************************************/
 
 static inline_function void hrtimer_reprogram(uint64_t next_expired)
 {
-#ifdef CONFIG_SCHED_TICKLESS
-  int ret;
+  int ret = 0;
   struct timespec ts;
-#  ifdef CONFIG_SCHED_TICKLESS_ALARM
+
   clock_nsec2time(&ts, next_expired);
+
+#ifdef CONFIG_ALARM_ARCH
   ret = up_alarm_start(&ts);
-#  else
+#else
   struct timespec current;
   up_timer_gettime(&current);
-  clock_nsec2time(&ts, next_expired);
   clock_timespec_subtract(&ts, &current, &ts);
   ret = up_timer_start(&ts);
-#  endif
-  DEBUGASSERT(ret == 0);
 #endif
+
+  DEBUGASSERT(ret == 0);
 }
 
 /****************************************************************************

Reply via email to