-
Notifications
You must be signed in to change notification settings - Fork 1.5k
sched/sched: Part 2: Add high-resolution timer (hrtimer) and os tick support with hrtimer to NuttX #17489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
25897b2 to
fa487ac
Compare
b397be3 to
0aa9b87
Compare
acassis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wangchdo please add Documentation about this new feature
0aa9b87 to
bd6b2e5
Compare
bd6b2e5 to
d609aeb
Compare
This comment has been minimized.
This comment has been minimized.
Yes, the os tick is a hr timer now, you can see from the implementation: when hrtimer is enabled an hrtimer instance(g_nxsched_hrtimer) will be used to provide OS tick |
|
@wangchdo I suggest to include the Motivation from this Summary to the Documentation, it makes our documentation more "human-like" and people reading it will understand where and why to use hrtimer. |
Done, please take a look at the latest upload or this PR. |
c78cfdc to
15bfda0
Compare
cederom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @wangchdo :-)
anchao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add nxsched_process_hrtimer() to support scheduler operations using high-resolution timers (hrtimer). Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Update nxsched_tick_expiration and nxsched_reassess_timer to use hrtimer when hrtimer is enabled. Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Enable SYSTEM_TIME64 in the Tricore architecture because the System Timer (STM) is a 64-bit timer. Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
15bfda0 to
3663e78
Compare
|
I have restarted CI to check current status :-) |
|
@cederom @acassis @xiaoxiang781216 @anchao This PR has been split into two parts. Part 1 #17517 has already been merged after SMP-specific optimizations. The remaining changes are now submitted as Part 2 in a separate PR: To avoid duplicate review effort, this PR is marked as draft. Please continue to review Part 2 #17573 instead. Once Part 2 #17573 is merged, all functionality originally planned for this PR will be completed, and this PR will be closed. |
so, let's close this pr directly and continue on #17573. If you want, we can reopen it at anytime. |
Summary
This PR is a continuation and optimized implementation, replacing the draft PR #17065 proposed two months ago.
Summary of this PR
Motivation
In hard real-time applications, nanosecond-level control of task activation is essential for certain scenarios—such as motor control—where tick-level precision is simply inadequate.
For these use cases, the main limitation of wdog is its tick-based resolution, which is typically in milliseconds. Although the tick duration can be reduced, configuring it to microsecond or nanosecond granularity is impractical, as this would lead to an interrupt storm in which the CPU becomes saturated by handling an excessive number of tick interrupts.
Therefore, an independent high-resolution timer (hrtimer) is required to support use cases—such as motor control—that demand true high-precision timing.
Additionally, hrtimer uses an RB-tree (red-black tree) for timer management, which is more efficient than the list-based structure used by wdog when dealing with a large number of timer events. This advantage becomes increasingly important in hard real-time systems, such as vehicle control systems.
Why not use wdog for high-resolution timing
wdog is highly coupled with the scheduler and has inherent limitations:
Impact
Add a new high-resolution timer (hrtimer) module to NuttX.
wdog, driving wdog by an hrtimer instance (g_nxsched_hrtimer).Testing
ostest passed on board a2g-tc397-5v-tft when hrtimer is enabled
API test coe is as below
API test log for board a2g-tc397-5v-tft is as below