sched/hrtimer: add a high resolution timer module in sched and tricore porting to support hard real time cases
Add a high resolution timer module in sched to support hard real time cases
Note: Please adhere to Contributing Guidelines.
Summary
Nuttx only provide wdog for delayed function execution, wdog is mainly used for OS-internal timeouts (e.g., task scheduling, time slicing) and periodic callbacks. Resolution depends on system tick.
This PR introduces hrtimer to Nuttx acting as a high-resolution timer, it can deliver deliver precise timing events (nanosecond or microsecond accuracy).
hrtimer VS wdog:
Purpose:
hrtimer: High-resolution timer for precise event scheduling.
wdog: Lightweight software timer for delayed callbacks and OS timeouts.
Resolution:
hrtimer: Nanosecond / microsecond accuracy, independent of system tick.
wdog: tick-based (ms level)
Accuracy:
hrtimer: Very high, suitable for hard real-time and multimedia workloads.
wdog: Limited by system tick; not sufficient for hard real-time control.
Implementation:
hrtimer: rb tree for timers, sorted by expiration,
wdog: Linked list of timers, sorted by expiration, integrated into scheduler.
Usage Pattern
hrtimer: Create with hrtimer_int(), start with hrtimer_start(), cancel with hrtimer_cancel().
wdog:Allocate wdog_t, start with wd_start(), cancel with wd_cancel().
Callback Context:
hrtimer: Runs in interrupt context
wdog: Runs in interrupt context(scheduler tick or hrtimer).
Use Cases
hrtimer: Precise scheduling, hard RT tasks, multimedia, networking, low-latency wake-ups
wdog: Task time slicing,timeout handling, simple periodic events.
Complexity
hrtimer: A little Complex using rb-tree, but optimized for embedded RTOS,
wdog: Simple and lightweight;
Footprint :
hrtimer: Larger memory and CPU overhead.
wdog: Minimal memory and CPU usage.
Impact
A new module added in sched,
if CONFIG_HRTIMER is enabled:
- new functions will be introduced, hrtimer_init(), hrtimer_start(), hrtimer_cancel()
- wdog will be driven by hrtimer as a timer
if CONFIG_HRTIMER is not enabled:
nothing happen
Testing
enable hrtimer in a2g-tc397-5v-tft:
ostest passed
Hi @wangchdo, has it also been tested with Make?
Hi @wangchdo, has it also been tested with Make?
Not, yet,I will upload a Makefile update soon
Hi @wangchdo, has it also been tested with Make?
I uploaded the Makefile update, and the test also passed with Make
@wangchdo I'm ok with this PR, but please answer @GUIDINGLI questions/suggestions.