Fix-Point opened a new pull request, #18224: URL: https://github.com/apache/nuttx/pull/18224
## Summary This PR is part of the https://github.com/apache/nuttx/pull/17675, it introduces significant improvements to the high-resolution timer (hrtimer) subsystem and its integration with the watchdog timer system. The key changes include: 1. **Guard Timer Implementation**: Added a guard timer (`g_hrtimer_guard`) that always remains in the timer queue with maximum expiration time. This simplifies empty queue checks, reduces branch conditions, and provides health monitoring capabilities for time acquisition errors. 2. **Watchdog-HRTimer Integration**: Replaced the separate scheduler tick timer with direct hrtimer integration for watchdog processing. The watchdog now uses its own hrtimer (`g_wdog_hrtimer`) instead of a separate tick-based mechanism, simplifying the architecture. 3. **Red-Black Tree Optimization**: Fixed left-most node detection in the hrtimer RB-tree by introducing `g_cached_first` caching, eliminating incorrect NULL checks on left child nodes. 4. **API Clarifications**: Updated function comments and signatures for better documentation, particularly for `hrtimer_cancel()` and `hrtimer_cancel_sync()` to clarify ownership semantics and concurrency considerations. 5. **Code Simplification**: Removed redundant timer processing logic, inlined `hrtimer_start()` for performance, and consolidated timer expiration handling between tick and tickless modes. ## Impact - **Performance**: Reduced branch checking through guard timer improves hrtimer processing efficiency. Inlined `hrtimer_start()` eliminates function call overhead. - **Memory Footprint**: Guard timer uses minimal additional memory while providing monitoring benefits. - **Correctness**: Fixed RB-tree left-most node detection and timer cancellation edge cases prevent missed expirations and hardware timer leaks. - **Architecture**: Simplified timer subsystem by eliminating separate scheduler tick timer code (`sched_timer.c`) and unifying watchdog processing under hrtimer. - **Build System**: Updated CMakeLists.txt and Make.defs to reflect source file changes (removed `sched_timer.c`, renamed `sched_tickexpiration.c` to `sched_processtickless.c`). - **API Compatibility**: Maintains backward compatibility while clarifying documentation for safer usage patterns. - **Error Handling**: Guard timer enables system recovery from time acquisition errors through configurable callback mechanisms. - **Concurrency**: Improved documentation for cancel operations helps prevent race conditions in multi-CPU environments. ## Test Tested on `rv-virt:smp`, `ostest` passed, parallel stressed hrtimer test passed. -- 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]
