This is an automated email from the ASF dual-hosted git repository. ligd pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 47ce6590b77fd63549e1ea9989005d4748b50d8f Author: ouyangxiangzhen <[email protected]> AuthorDate: Wed Jan 7 20:19:39 2026 +0800 sched/hrtimer: Fixed hrtimer_starttimer. This commit fixed the functional correctness issues in tick mode and non-tickless alarm mode. - In tick mode, we do not need reprogram the timer. - In non-tickless alarm mode, the up_timer_start receive the relative time as the parameter. Signed-off-by: ouyangxiangzhen <[email protected]> --- sched/hrtimer/hrtimer.h | 28 ++++++++++++++-------------- sched/hrtimer/hrtimer_cancel.c | 2 +- sched/hrtimer/hrtimer_process.c | 2 +- sched/hrtimer/hrtimer_start.c | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h index 2e64624fa6a..fabcbcf2dd2 100644 --- a/sched/hrtimer/hrtimer.h +++ b/sched/hrtimer/hrtimer.h @@ -124,10 +124,10 @@ uint64_t hrtimer_gettime(void) } /**************************************************************************** - * Name: hrtimer_starttimer + * Name: hrtimer_reprogram * * Description: - * Start the hardware timer to expire at a specified nanosecond time. + * Reprogram the hardware timer to expire at a specified nanosecond time. * Converts the nanosecond time to timespec and calls the platform-specific * timer start function. * @@ -138,23 +138,23 @@ uint64_t hrtimer_gettime(void) * OK (0) on success, negated errno on failure. ****************************************************************************/ -static inline_function -int hrtimer_starttimer(uint64_t ns) +static inline_function void hrtimer_reprogram(uint64_t next_expired) { - struct timespec ts; +#ifdef CONFIG_SCHED_TICKLESS int ret; - - /* Convert nanoseconds to timespec */ - - clock_nsec2time(&ts, ns); - -#ifdef CONFIG_ALARM_ARCH + struct timespec ts; +# ifdef CONFIG_SCHED_TICKLESS_ALARM + clock_nsec2time(&ts, next_expired); ret = up_alarm_start(&ts); -#elif defined(CONFIG_TIMER_ARCH) +# else + struct timespec current; + up_timer_gettime(¤t); + clock_nsec2time(&ts, next_expired); + clock_timespec_subtract(&ts, ¤t, &ts); ret = up_timer_start(&ts); +# endif + DEBUGASSERT(ret == 0); #endif - - return ret; } /**************************************************************************** diff --git a/sched/hrtimer/hrtimer_cancel.c b/sched/hrtimer/hrtimer_cancel.c index b0b66c624b4..a93f9ba437d 100644 --- a/sched/hrtimer/hrtimer_cancel.c +++ b/sched/hrtimer/hrtimer_cancel.c @@ -143,7 +143,7 @@ int hrtimer_cancel(FAR hrtimer_t *hrtimer) first = hrtimer_get_first(); if (first != NULL) { - ret = hrtimer_starttimer(first->expired); + hrtimer_reprogram(first->expired); } } diff --git a/sched/hrtimer/hrtimer_process.c b/sched/hrtimer/hrtimer_process.c index 314e410d244..ff7f945b6d3 100644 --- a/sched/hrtimer/hrtimer_process.c +++ b/sched/hrtimer/hrtimer_process.c @@ -155,7 +155,7 @@ void hrtimer_process(uint64_t now) { /* Start timer for the next earliest expiration */ - (void)hrtimer_starttimer(hrtimer->expired); + hrtimer_reprogram(hrtimer->expired); } /* Leave critical section */ diff --git a/sched/hrtimer/hrtimer_start.c b/sched/hrtimer/hrtimer_start.c index ca35a62422f..81f688de23d 100644 --- a/sched/hrtimer/hrtimer_start.c +++ b/sched/hrtimer/hrtimer_start.c @@ -103,7 +103,7 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t func, if (hrtimer_is_first(hrtimer)) { - ret = hrtimer_starttimer(hrtimer->expired); + hrtimer_reprogram(hrtimer->expired); } /* Release spinlock and restore interrupts */
