This commit added the guard timer for hrtimer.
The guard timer uses a small memory footprint, offering two main advantages:
- Reduced branches checking for an empty hrtimer queue, simplifying code implementation and improving the performance.
- Additional health monitoring allows the system to enter a safe state in case of time acquisition errors, and supports custom error handling callback functions.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit fixed the overflow check and renamed the period to delay, since the callback return value is the next delay not the period.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
On 32-bit platform with 64-bit pointer, read/write to the
`g_hrtimer_running` is not atomic, we should protect it with the
seqcount to ensure the value we read is correct.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Since the hrtimer->expired is not monotonic, it can not be used as the
version. This commit added the ownership encoding to ensure the
invariant that the cancelled the timer can not modify the hrtimer again.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
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>
Several code comments in the hrtimer subsystem have become outdated
following recent implementation changes. This patch updates them to
accurately describe the current code behavior and algorithms.
Signed-off-by: Chengdong Wang <wangcd91@gmail.com>
The hrtimer is designed to replace the wdog timer in future, so it
should have the callback function in its API. The evaluation results showed there is no any
performance degradation since the CPU pipeline can hide the latency.
This commit also decoupled the rb-tree implementation with the pending
state checking.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Separate SMP-specific logic from the hrtimer core to improve
performance and maintainability.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
This commit renamed the callback type to `hrtimer_entry_t`, aligning with
the `wdentry_t` in wdog..
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Allow running/armed hrtimer to be restarted to
fix hrtimer bug: #17567
Co-authored-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
NuttX provides the wdog module to implement timers for the scheduler.
While it is lightweight and efficient, wdog only supports tick-level timers,
typically in milliseconds. Although the tick duration can be configured,
setting it to microsecond or nanosecond resolution is not practical.
Doing so may cause an interrupt storm, where the CPU is constantly
occupied handling tick interrupts.
To address this limitation, a new hrtimer module is introduced.
It coexists with the wdog module, providing both tick-level timers
for wdog and high-resolution timers (nanosecond-level) directly to users.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>