Skip to content

sched/sleep: Add nxsched_nanosleep() API#17368

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
wangchdo:add_sched_nano_sleep
Nov 25, 2025
Merged

sched/sleep: Add nxsched_nanosleep() API#17368
xiaoxiang781216 merged 1 commit into
apache:masterfrom
wangchdo:add_sched_nano_sleep

Conversation

@wangchdo
Copy link
Copy Markdown
Contributor

@wangchdo wangchdo commented Nov 23, 2025

Summary

Introduce the nxsched_nanosleep() API to provide a lightweight nanosecond-level sleep based on nxsched_ticksleep(). This API offers the same functionality as nxsig_nanosleep() but without signal-related overhead, making it suitable for implementing libc sleep() or usleep() when signals are disabled.

Impact

New api added, no impact to existing nuttx functions

Testing

ostest passed on board fvp-armv8r-aarch32

NuttShell (NSH)
nsh> [ 0] Idle_Task: nx_start: CPU0: Beginning Idle Loop
nsh>
nsh> uname -a
NuttX 0.0.0 3e83236063 Nov 23 2025 23:19:00 arm fvp-armv8r-aarch32
nsh> ostest

(...)

user_main: vfork() test
[ 4] ostest: arm_fork: fork context [0x2000f6b8]:
[ 4] ostest: arm_fork:   r4:20003860 r5:00000000 r6:00000000 r7:00000000
[ 4] ostest: arm_fork:   r8:00000000 r9:00000000 r10:00000000
[ 4] ostest: arm_fork:   r11:00000000 sp:2000f6e0 lr:00055f04
[ 4] ostest: nxtask_setup_fork: Child priority=100 start=0x55f04
[ 4] ostest: nxtask_setup_fork: parent=0x2000d358, returning child=0x2000f790
[ 4] ostest: arm_fork: TCBs: Parent=0x2000d358 Child=0x2000f790
[ 4] ostest: arm_fork: Parent: stackutil:152
[ 4] ostest: arm_fork: Old stack top:2000f778 SP:2000f6e0 FP:00000000
[ 4] ostest: arm_fork: New stack top:20013a80 SP:200139e8 FP:00000000
[ 4] ostest: nxtask_start_fork: Starting Child TCB=0x2000f790
[ 4] ostest: nxtask_activate: ostest pid=85,TCB=0x2000f790
[85] ostest: nxtask_exit: ostest pid=85,TCB=0x2000f790
vfork_test: Child 85 ran successfully

Final memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     7ff9d3c  7ff9d3c
ordblks         1        5
mxordblk  7ff0880  7febf08
uordblks     94bc     b55c
fordblks  7ff0880  7fee7e0
user_main: Exiting
[ 4] ostest: nxtask_exit: ostest pid=4,TCB=0x2000d358
ostest_main: Exiting with status 0
stdio_test: Standard I/O Check: fprintf to stderr
[ 3] ostest: nxtask_exit: ostest pid=3,TCB=0x2000af38
nsh>

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Nov 23, 2025
@wangchdo wangchdo force-pushed the add_sched_nano_sleep branch from 3e83236 to e312992 Compare November 23, 2025 15:59
@wangchdo wangchdo force-pushed the add_sched_nano_sleep branch from e312992 to 9fce966 Compare November 24, 2025 05:26
@wangchdo wangchdo changed the title sched/sleep: Add nxched_nanosleep() API sched/sleep: Add nxsched_nanosleep() API Nov 24, 2025
Introduce the nxched_nanosleep() API to provide a lightweight
nanosecond-level sleep based on nxsched_ticksleep().
This API offers the same functionality as nxsig_nanosleep() but without
signal-related overhead, making it suitable for implementing libc
sleep() or usleep() when signals are disabled.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
@wangchdo wangchdo force-pushed the add_sched_nano_sleep branch from 9fce966 to e5cd5f6 Compare November 24, 2025 05:27
@xiaoxiang781216 xiaoxiang781216 merged commit bc561c6 into apache:master Nov 25, 2025
40 checks passed
@wangchdo wangchdo deleted the add_sched_nano_sleep branch December 2, 2025 13:37
Lenoids added a commit to Lenoids/nuttx that referenced this pull request Dec 3, 2025
As pull request apache#17200 & apache#17368 introduced support for scheduling sleep, a documentation is needed for different sleep interfaces.
This patch adds the description for sleep interfaces currently provided in NuttX, including Scheduled sleep(nxsched_sleep()...), Signal-scheduled sleep(nxsig_sleep()...), and Busy sleep(up_udelay()).

Signed-off-by: Haokun Dong <donghaokun@lixiang.com>
Lenoids added a commit to Lenoids/nuttx that referenced this pull request Dec 3, 2025
As pull request apache#17200 & apache#17368 introduced support for scheduling sleep, a documentation is needed for different sleep interfaces.
This patch adds the description for sleep interfaces currently provided in NuttX, including Scheduled sleep(nxsched_sleep()...), Signal-scheduled sleep(nxsig_sleep()...), and Busy sleep(up_udelay()).

Signed-off-by: Haokun Dong <donghaokun@lixiang.com>
Lenoids added a commit to Lenoids/nuttx that referenced this pull request Dec 3, 2025
As pull request apache#17200 & apache#17368 introduced support for scheduling sleep, a documentation is needed for different sleep interfaces.
This patch adds the description for sleep interfaces currently provided in NuttX, including Scheduled sleep(nxsched_sleep()...), Signal-scheduled sleep(nxsig_sleep()...), and Busy sleep(up_udelay()).

Signed-off-by: Haokun Dong <donghaokun@lixiang.com>
Lenoids added a commit to Lenoids/nuttx that referenced this pull request Dec 3, 2025
As pull request apache#17200 & apache#17368 introduced support for scheduling sleep, a documentation is needed for different sleep interfaces.
This patch adds the description for sleep interfaces currently provided in NuttX, including Scheduled sleep(nxsched_sleep()...), Signal-scheduled sleep(nxsig_sleep()...), and Busy sleep(up_udelay()).

Signed-off-by: Haokun Dong <donghaokun@lixiang.com>
Lenoids added a commit to Lenoids/nuttx that referenced this pull request Dec 4, 2025
As pull request apache#17200 & apache#17368 introduced support for scheduling sleep, a documentation is needed for different sleep interfaces.
This patch adds the description for sleep interfaces currently provided in NuttX, including Scheduled sleep(nxsched_sleep()...), Signal-scheduled sleep(nxsig_sleep()...), and Busy sleep(up_udelay()).

Signed-off-by: Haokun Dong <donghaokun@lixiang.com>
simbit18 pushed a commit that referenced this pull request Dec 4, 2025
As pull request #17200 & #17368 introduced support for scheduling sleep, a documentation is needed for different sleep interfaces.
This patch adds the description for sleep interfaces currently provided in NuttX, including Scheduled sleep(nxsched_sleep()...), Signal-scheduled sleep(nxsig_sleep()...), and Busy sleep(up_udelay()).

Signed-off-by: Haokun Dong <donghaokun@lixiang.com>
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.

3 participants