-
Notifications
You must be signed in to change notification settings - Fork 1.4k
sched/hrtimer: Part 2: refine hrtimer state machine and introduce scheduler support with hrtimer #17573
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
base: master
Are you sure you want to change the base?
Conversation
6847a0c to
c073a95
Compare
c073a95 to
f1e9f9a
Compare
f1e9f9a to
e0f1573
Compare
e0f1573 to
424634c
Compare
424634c to
ba4a61f
Compare
ba4a61f to
9bcc6ae
Compare
9bcc6ae to
2c0c6b0
Compare
b32da5d to
32bc91f
Compare
Allow running/armed hrtimer to be restarted to fix hrtimer bug: apache#17567 Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Update the hrtimer documentation to describe the hrtimer state machine, which is introduced to handle safe cancellation and execution in SMP environments. Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Improve hrtimer to only enable SMP related logic when in SMP mode to improve performance in non-SMP mode Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
32bc91f to
4f3dcdd
Compare
|
@cederom @acassis @anchao @xiaoxiang781216 Conflicts resolved, please double check |
4f3dcdd to
19097a7
Compare
@cederom just renaming an internal C file shouldn't be considered a breaking change if it didn't change the API. In other hand renaming a header file could be considered a breaking change, because now drivers needs to point to a new file. |
19097a7 to
98beb06
Compare
d88ae85 to
26f4bbc
Compare
5ec7cf1 to
dc73f9e
Compare
This commit add hrtimer support to scheduler
tick without altering the existing scheduler behavior.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
…t issue
When hrtimer is enabled, the tickless scheduler should call
nxsched_hrtimer_start to start the timer, this is because
the tick system is support by hrtimer
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
dc73f9e to
765aa3b
Compare
| #ifdef CONFIG_SMP | ||
| if (hrtimer->cpus == 0) | ||
| { | ||
| #endif | ||
| hrtimer->state = HRTIMER_STATE_INACTIVE; | ||
| #ifdef CONFIG_SMP | ||
| } | ||
| #endif |
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.
| #ifdef CONFIG_SMP | |
| if (hrtimer->cpus == 0) | |
| { | |
| #endif | |
| hrtimer->state = HRTIMER_STATE_INACTIVE; | |
| #ifdef CONFIG_SMP | |
| } | |
| #endif | |
| #ifdef CONFIG_SMP | |
| if (hrtimer->cpus == 0) | |
| #endif | |
| { | |
| hrtimer->state = HRTIMER_STATE_INACTIVE; | |
| } |
| { | ||
| /* Timer was canceled during callback execution */ | ||
|
|
||
| #ifdef CONFIG_SMP |
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.
ditto
|
|
||
| static void nxsched_process_hrtimer(void) | ||
| { | ||
| uint64_t now = hrtimer_gettime(); |
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.
move hrtimer_gettime() before hrtimer_process()
Summary
This PR introduces high-resolution timer (hrtimer) support as a fully independent and optional module for support of the scheduler, without affecting existing scheduler behavior.
Hrtimer is strictly isolated from the current scheduling logic:
The module does not modify any scheduler data structures or timing paths.
Hrtimer acts solely as an alternative time source. Core scheduler functions (nxsched_process_tick(), nxsched_tick_expiration(), etc.) remain unchanged and are reused as-is.
Additional safeguards:
Integration benefit
This design enables incremental development and review of hrtimer while ensuring that existing NuttX scheduling behavior remains stable even if the hrtimer feature is explicitly enabled.
Development benefit
With this design, developers interested in optimizing the scheduler and those focused on optimizing hrtimer can work independently on their respective improvements.
One other key update
This PR also includes an improvement(also in a seperate PR #17570) to hrtimer by refining its state machine, this is to fix some issues in SMP mode found by @Fix-Point. The refined state-machine is as shown below, and the corresponding diagram is also added in the hrtimer documentation.
Impact
Add hrtimer support to nuttx scheduelr, without altering the existing scheduler behavior.
Testing
Test 1 passed (integrated in ostest):
- test implementation:
test log on rv-virt:smp64:
test 2 passed (provided by @Fix-Point )
test implementation
test passed log on rv-virt:smp64
test 3 passed (provided by @Fix-Point )
test implementation
test passed log on rv-virt:smp64