This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 37ccc03dfec sched/wdog: Don't hand the timer a negative delay.
37ccc03dfec is described below
commit 37ccc03dfec81644a27cfed24fa8d31e131136af
Author: Max Kriegleder <[email protected]>
AuthorDate: Fri Oct 23 16:37:38 2026 +0200
sched/wdog: Don't hand the timer a negative delay.
In non-alarm tickless mode, wd_timer_start() passed next_tick - now to
up_timer_tick_start(). When the next deadline has already passed (an
absolute tick in the past given to wd_start_abstick(), or watchdog
callbacks that ran past the next expiry) that delay is negative.
The generic up_timer_tick_start() in drivers/timers/arch_timer.c passes
it to update_timeout(), which takes a uint32_t, so a delay of -1 tick
becomes 0xffffffff ticks. The timer is then set as far ahead as the lower
half allows, and the expired watchdog, and every one queued after it,
waits for some other interrupt to wake the scheduler.
Pass 0 for a deadline that has already passed. A delay of 0 is already
what the timer gets for a deadline equal to the current tick.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Max Kriegleder <[email protected]>
---
sched/wdog/wdog.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sched/wdog/wdog.h b/sched/wdog/wdog.h
index bd726af57d7..317df6ba330 100644
--- a/sched/wdog/wdog.h
+++ b/sched/wdog/wdog.h
@@ -176,7 +176,11 @@ static inline_function void wd_timer_start(clock_t tick,
bool in_expiration)
#ifdef CONFIG_SCHED_TICKLESS_ALARM
up_alarm_tick_start(next_tick);
#else
- up_timer_tick_start(next_tick - clock_systime_ticks());
+ clock_t now = clock_systime_ticks();
+
+ /* A passed deadline must fire now: timers may read the delay unsigned */
+
+ up_timer_tick_start(clock_compare(next_tick, now) ? 0 : next_tick - now);
#endif
}