Skip to content

Conversation

@wangchdo
Copy link
Contributor

@wangchdo wangchdo commented Jan 27, 2026

Summary

Change1:
The hrtimer subsystem is independent of the OS scheduler tick mechanism and
tickless mode. In fact, it operates below the OS scheduler and provides
scheduler tick support through an hrtimer object. Therefore, it must always
be able to reprogram the hardware timer to achieve nanosecond-level
resolution.

A recent update restricted hardware timer reprogramming to tickless mode
only. As a result, hrtimer no longer functions correctly when the scheduler
is running in tick-based mode.

This change removes the incorrect dependency on tickless mode and restores
proper hrtimer operation.

Change2:

add support for tickless with hrtimer

Impact

Fix the in-proper update of hrtimer module, this change is isolated in hrtimer moduler
no impact to other NuttX parts.

Testing

depends on apache/nuttx-apps#3380

**ostest passed on rv-virt:smp64 with hrtimer enabled on both non-tickless and tickless node **

1. tickless mode

NuttShell (NSH)
nsh> 
nsh> uname -a
NuttX 0.0.0 d819e61456-dirty Jan 27 2026 11:11:00 risc-v rv-virt
nsh> 
nsh> ostest

(...)

user_main: smp call test
smp_call_test: Test start
smp_call_test: Call cpu 0, nowait
smp_call_test: Call cpu 0, wait
smp_call_test: Call cpu 1, nowait
smp_call_test: Call cpu 1, wait
smp_call_test: Call cpu 2, nowait
smp_call_test: Call cpu 2, wait
smp_call_test: Call cpu 3, nowait
smp_call_test: Call cpu 3, wait
smp_call_test: Call cpu 4, nowait
smp_call_test: Call cpu 4, wait
smp_call_test: Call cpu 5, nowait
smp_call_test: Call cpu 5, wait
smp_call_test: Call cpu 6, nowait
smp_call_test: Call cpu 6, wait
smp_call_test: Call cpu 7, nowait
smp_call_test: Call cpu 7, wait
smp_call_test: Call multi cpu, nowait
smp_call_test: Call in interrupt, wait
smp_call_test: Call multi cpu, wait
smp_call_test: Test success

user_main: hrtimer test

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     1fc1080  1fc1080
ordblks         6       11
mxordblk  1faa1e0  1f72e98
uordblks    107c8    1dbf8
fordblks  1fb08b8  1fa3488

Final memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     1fc1080  1fc1080
ordblks         1       11
mxordblk  1fb5f70  1f72e98
uordblks     b110    1dbf8
fordblks  1fb5f70  1fa3488
user_main: Exiting
ostest_main: Exiting with status 0

2. non-tickless mode

NuttShell (NSH)
nsh> 
nsh> uname -a
NuttX 0.0.0 d819e61456-dirty Jan 27 2026 11:19:53 risc-v rv-virt
nsh> 
nsh> ostest

(...)

user_main: smp call test
smp_call_test: Test start
smp_call_test: Call cpu 0, nowait
smp_call_test: Call cpu 0, wait
smp_call_test: Call cpu 1, nowait
smp_call_test: Call cpu 1, wait
smp_call_test: Call cpu 2, nowait
smp_call_test: Call cpu 2, wait
smp_call_test: Call cpu 3, nowait
smp_call_test: Call cpu 3, wait
smp_call_test: Call cpu 4, nowait
smp_call_test: Call cpu 4, wait
smp_call_test: Call cpu 5, nowait
smp_call_test: Call cpu 5, wait
smp_call_test: Call cpu 6, nowait
smp_call_test: Call cpu 6, wait
smp_call_test: Call cpu 7, nowait
smp_call_test: Call cpu 7, wait
smp_call_test: Call multi cpu, nowait
smp_call_test: Call in interrupt, wait
smp_call_test: Call multi cpu, wait
smp_call_test: Test success

user_main: hrtimer test

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     1fc11e0  1fc11e0
ordblks         6       11
mxordblk  1f77500  1f77500
uordblks     dd58    1dbf8
fordblks  1fb3488  1fa35e8

Final memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     1fc11e0  1fc11e0
ordblks         1       11
mxordblk  1fb60d0  1f77500
uordblks     b110    1dbf8
fordblks  1fb60d0  1fa35e8
user_main: Exiting
ostest_main: Exiting with status 0

The hrtimer subsystem is independent of the OS tick mechanism and tickless
mode. It must always be able to reprogram the hardware timer to achieve
nanosecond-level resolution.

A recent update restricted hardware timer reprogramming to tickless mode
only. As a result, hrtimer no longer functions correctly when the scheduler
is running in tick-based mode.

This change removes the incorrect dependency on tickless mode and restores
proper hrtimer operation.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Add support for running the OS in tickless mode with hrtimer, allowing
the scheduler to operate without periodic ticks while maintaining
high-resolution timer functionality.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
@xiaoxiang781216 xiaoxiang781216 merged commit 165f1cc into apache:master Jan 27, 2026
40 checks passed
@wangchdo wangchdo deleted the hrtimer_bugfix branch January 27, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants