Fix-Point opened a new pull request, #21001: URL: https://github.com/apache/nuttx/pull/21001
## Summary This series improves the high-resolution timer (HRTIMER) subsystem and its integration with the WDOG. The motivation is threefold: 1. **Correctness fixes in the hrtimer hot path.** Several issues were found and fixed: a multiplication overflow in `hrtimer_reprogram()` when the computed delay wraps `g_oneshot_maxnsec`; a `-Werror=strict-aliasing` violation in `sched/hrtimer`; a spurious `expired != now` check that could leave the hardware timer wrongly armed; and an unbalanced `#ifdef CONFIG_SMP` / `irq_save()` porting issue that only surfaced with `CONFIG_HRTIMER=y` on non-SMP builds (covered by the `inline hrtimer_process` commit). 2. **Reduced interrupt overhead.** `hrtimer_process()` is moved from a standalone translation unit into `hrtimer.h` as a `static inline` function, eliminating the function-call overhead in the timer interrupt path. On uniprocessor builds, the seqlock acquire/release in `hrtimer_lock()`/`hrtimer_unlock()` is replaced by plain interrupt-disable/enable. 3. **Fewer spurious hardware reprogrammings.** A cache of the programmed expiration target, plus precision-mask (`CONFIG_HRTIMER_PRECISION_SHIFT`) ceiling-alignment of the expiration time, reduces the frequency of one-shot timer reprogramming. New `CONFIG_TIMER_ADJUST_NSEC` compensates for the interrupt latency in the periodic/tickless wake-up path. 4. **Watchdog overflow/underflow hardening with HRTIMER.** The `wd_timer_start()` HRTIMER path no longer multiplies the absolute expiration tick directly (`TICK2NSEC()`), which overflowed once uptime grew; the relative delay from `g_wdexpired` is used and clamped to `HRTIMER_MAX_DELAY`. A matching unsigned-underflow fix is applied to the tickless path. A new public header `include/sys/tree_type.h` separates the red-black tree type definitions from `sys/tree.h`, avoiding macro redefinition when both `tree.h` and the hrtimer tree are included in the same TU. ## Impact * **User impact:** POSIX APIs and kernel APIs are unchanged; the changes are internal to `sched/hrtimer`, `sched/wdog`, and `include/sys/tree_type.h`. Users of `CONFIG_HRTIMER` get fewer timer interrupts and more predictable expiration times. * **Build:** Two new Kconfig options are introduced, `CONFIG_HRTIMER_PRECISION_SHIFT` and `CONFIG_TIMER_ADJUST_NSEC` (both default to disabled/0). A new header `include/sys/tree_type.h` is added. No build-system changes other than the normal Make.defs / CMakeLists adjustments for the removed `hrtimer_process.c`. * **Hardware:** No new hardware dependency; validated on `qemu-armv7a` (see Testing). * **Documentation:** None (internal behavior changes). * **Security:** No impact. * **Compatibility:** The inline `hrtimer_process` and the `wdog` delay computation retain the same external behavior, while fixing the overflow/underflow corner cases exposed by `CONFIG_HRTIMER=y`. ## Testing **Host:** x86-64 Linux, `arm-none-eabi-gcc`, `qemu-system-arm` (QEMU 6.2). **Configuration:** `boards/arm/qemu/qemu-armv7a/configs/nsh`, with `CONFIG_HRTIMER=y`, `CONFIG_TESTING_OSTEST=y`, `CONFIG_TESTING_OSTEST_LOOPS=512`. **Result:** The full OSTest application is started from NSH and completes 512 loop iterations with zero assertions and no errors (`ostest_main: Exiting with status 0`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
