sched/clock: Add clock_increase_sched_ticks() and clock_get_sched_ticks()#17192
sched/clock: Add clock_increase_sched_ticks() and clock_get_sched_ticks()#17192wangchdo wants to merge 4 commits into
Conversation
|
@wangchdo should we update CLOCK_MONOTONIC or CLOCK_BOOTTIME too? |
263eb50 to
8270190
Compare
I added update for clock_systime_timespec() and clock_resynchronize() please check. |
from https://man7.org/linux/man-pages/man3/clock_gettime.3.html: CLOCK_BOOTTIME contain the suspend time, but CLOCK_MONOTONIC not. Since you add the new api to distinguish these two cases, we could implement CLOCK_MONOTONIC better now. |
8270190 to
643c871
Compare
I uploaded a new commit to improve CLOCK_MONOTONIC, please help to check. |
34ce476 to
892eeb5
Compare
| * | ||
| ****************************************************************************/ | ||
|
|
||
| clock_t clock_get_sched_ticks(void) |
There was a problem hiding this comment.
Are we worried only about the 64 and 32 bit architectures?
What about 16 and 8 bit supported architectures? It seems that this changes will affect all architectures if I am not mistaken.
There was a problem hiding this comment.
Good point! NuttX still needs to support 8, 16, 32 and 64-bit arch
There was a problem hiding this comment.
There was a problem hiding this comment.
It looks like nuttx clock module does not consider systems below 32-bit, the new function I added clock_get_sched_ticks() is in align with the current clock module implementation, below is the implementation before. @xiaoxiang781216 How do you think about this?
There was a problem hiding this comment.
NuttX require the arch support at least 32bit int, and 64bit is optional, but the recent discuss suggesting to enforce 64bit for POSIX compliant. Please reference the discuss here: #14460
hartmannathan
left a comment
There was a problem hiding this comment.
Is the CI test failing because of lines like this:
====================================================================================
Configuration/Tool: sam4l-xplained/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
2025-10-13 16:53:05
------------------------------------------------------------------------------------
Cleaning...
Configuring...
Disabling CONFIG_ARM_TOOLCHAIN_BUILDROOT_OABI
Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
Building NuttX...
[1/1] Normalize sam4l-xplained/nsh
/usr/bin/bash: line 1: arm-nuttx-elf-gcc: command not found
/usr/bin/bash: line 1: arm-nuttx-elf-gcc: command not found
(Maybe the script should be updated to output an actual Error: line that will be highlighted in the GitHub CI web interface?)
…ks()
In the current NuttX kernel implementation, there is no function
to represent pure scheduler ticks.
The existing clock_systime_ticks() cannot serve this purpose,
because it keeps increasing even when the scheduler is not running.
This happens since the returned value reflects real hardware time:
as long as the timer or alarm hardware is active,
clock_systime_ticks() will continuously increase.
This patch introduces two new functions that provide access to
scheduler ticks — a counter that only increases when the scheduler
itself is running.
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
Replace direct usage of g_system_ticks with clock_increase_sched_ticks() and clock_get_sched_ticks() Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
892eeb5 to
eef64e8
Compare
Improve nxclock_gettime(), to get the system time excluding the time that the system is suspended, when the clockid is CLOCK_MONOTONIC Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
eef64e8 to
fa1a28a
Compare
Hi @hartmannathan, Thank you for catching that. |
I think you are correct: it seems the CI is missing the compiler for some platforms, but I don't know how this can be. I am out of time for today but hopefully someone who understands the CI better can help. |
Enlarge kflash memory size for the sam3u-ek board
to resolve the build error.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
jerpelea
left a comment
There was a problem hiding this comment.
according to the datasheet the flash size is 256k
https://ww1.microchip.com/downloads/en/DeviceDoc/doc6478.pdf
Hi @jerpelea, The flash memory is divided into three regions. In this update, I have enlarged the kflash region and reduced the uflash region accordingly to fix the build issue. The total flash size remains unchanged as 256k . |
Hi @jerpelea Do you have any further comments? |
|
This PR duplicates PR #17199 |

Note: Please adhere to Contributing Guidelines.
Summary
add two new functions to maintain a pure scheduler related ticks in nuttx
Impact
new functions added, now impact to the existing nuttx functions
Testing
ostest passed on board a2g-tc397-5v-tft
ostest passed on board fvp-armv8r-aarch32