You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "anchao (via GitHub)" <gi...@apache.org> on 2026/03/03 09:53:17 UTC
[PR] sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks [nuttx]
anchao opened a new pull request, #18486:
URL: https://github.com/apache/nuttx/pull/18486
## Summary
sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks
Fix the issue where clock_gettime(CLOCK_MONOTONIC) always returns 0 in
tickless mode, caused by the scheduler tick counter (g_system_ticks) not
being updated with the actual timer ticks.
1. Add clock_update_sched_ticks() function to sched/clock/clock_sched_ticks.c:
a. This function directly sets the system tick counter to a specific value
(vs incrementing in clock_increase_sched_ticks), with full documentation
matching the existing code style.
b. Uses seqlock to ensure thread-safe access to g_system_ticks.
2. Call clock_update_sched_ticks() in nxsched_process_timer() (sched_processtickless.c):
a. Syncs the scheduler tick counter with the actual timer ticks retrieved via up_timer_gettick().
With this fix, g_system_ticks is properly updated in tickless mode,
and clock_gettime(CLOCK_MONOTONIC) returns the correct non-zero monotonic time.
Signed-off-by: chao an <an...@bytedance.com>
## Impact
sched/tickless
## Testing
sim/nsh:
enable config:
+CONFIG_SCHED_TICKLESS=y
+CONFIG_SYSLOG_TIMESTAMP=y
print syslog in exmaple hello:
```
$ git diff .
diff --git a/examples/hello/hello_main.c b/examples/hello/hello_main.c
index fd194a623..c92ec0788 100644
--- a/examples/hello/hello_main.c
+++ b/examples/hello/hello_main.c
@@ -38,5 +38,6 @@
int main(int argc, FAR char *argv[])
{
printf("Hello, World!!\n");
+ syslog(0, "Hello, World!!\n");
return 0;
}
```
Before this patch:
```
nsh> hello
Hello, World!!
[ 0.000000] Hello, World!!
nsh> hello
Hello, World!!
[ 0.000000] Hello, World!!
nsh>
```
after this patch:
```
nsh> hello
Hello, World!!
[ 1.130000] Hello, World!!
nsh> hello
Hello, World!!
[ 2.420000] Hello, World!!
nsh>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks [nuttx]
Posted by "anchao (via GitHub)" <gi...@apache.org>.
anchao commented on code in PR #18486:
URL: https://github.com/apache/nuttx/pull/18486#discussion_r2877819117
##########
sched/sched/sched_processtickless.c:
##########
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks [nuttx]
Posted by "anchao (via GitHub)" <gi...@apache.org>.
anchao commented on PR #18486:
URL: https://github.com/apache/nuttx/pull/18486#issuecomment-3989891447
cc @wangchdo
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks [nuttx]
Posted by "wangchdo (via GitHub)" <gi...@apache.org>.
wangchdo commented on code in PR #18486:
URL: https://github.com/apache/nuttx/pull/18486#discussion_r2877790121
##########
sched/sched/sched_processtickless.c:
##########
Review Comment:
We also need to update tick when HRTIMER is enabled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks [nuttx]
Posted by "linguini1 (via GitHub)" <gi...@apache.org>.
linguini1 merged PR #18486:
URL: https://github.com/apache/nuttx/pull/18486
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org