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 <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen 2026-01-07 20:19:39 +08:00 committed by GUIDINGLI
parent 78d05ff811
commit 47ce6590b7
4 changed files with 17 additions and 17 deletions

View file

@ -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(&current);
clock_nsec2time(&ts, next_expired);
clock_timespec_subtract(&ts, &current, &ts);
ret = up_timer_start(&ts);
# endif
DEBUGASSERT(ret == 0);
#endif
return ret;
}
/****************************************************************************

View file

@ -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);
}
}

View file

@ -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 */

View file

@ -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 */