Skip to content

Conversation

@anchao
Copy link
Contributor

@anchao anchao commented Oct 15, 2025

Summary

sched/sleep: add support for scheduling sleep

Nuttx currently has 2 types of sleep interfaces:

  1. Signal-scheduled sleep: nxsig_sleep() / nxsig_usleep() / nxsig_nanosleep()
    Weaknesses:
    a. Signal-dependent: The signal-scheduled sleep method is bound to the signal framework, while some driver sleep operations do not depend on signals.
    b. Timespec conversion: Signal-scheduled sleep involves timespec conversion, which has a significant impact on performance.

  2. Busy sleep: up_mdelay() / up_udelay()
    Weaknesses:
    a. Does not actively trigger scheduling, occupy the CPU loading.

  3. New interfaces: Scheduled sleep: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
    Strengths:
    a. Does not depend on the signal framework.
    b. Tick-based, without additional computational overhead.

Currently, the Nuttx driver framework extensively uses nxsig_* interfaces. However, the driver does not need to rely on signals or timespec conversion.
Therefore, a new set of APIs is added to reduce dependencies on other modules.

(This PR also aims to make signals optional, further reducing the code size of Nuttx.)

Signed-off-by: chao an anchao.archer@bytedance.com

Impact

N/A

Testing

new api test on sim/nsh, sabre-6quad/smp:

nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()

@github-actions github-actions bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Oct 15, 2025
@simbit18
Copy link
Contributor

Hi @anchao , add sched_sleep.c also in the CMakeLists.txt file.

https://github.com/anchao/nuttx/blob/e2743c5002f13975ba345878bca56f12c4d82151/sched/sched/CMakeLists.txt#L50

@linguini1
Copy link
Contributor

Will this work for tickless?

@anchao
Copy link
Contributor Author

anchao commented Oct 16, 2025

Will this work for tickless?

Yes, this feature is implemented by the wd timer. Tickless is a behavior of the timer subsystem and has no related with the current implementation.

@anchao anchao force-pushed the 25101501 branch 2 times, most recently from 9d65144 to e7e9295 Compare October 16, 2025 02:22
@anchao
Copy link
Contributor Author

anchao commented Oct 16, 2025

Hi @anchao , add sched_sleep.c also in the CMakeLists.txt file.

https://github.com/anchao/nuttx/blob/e2743c5002f13975ba345878bca56f12c4d82151/sched/sched/CMakeLists.txt#L50

Done, please review again

Nuttx currently has 2 types of sleep interfaces:

1. Signal-scheduled sleep: nxsig_sleep() / nxsig_usleep() / nxsig_nanosleep()
Weaknesses:
  a. Signal-dependent: The signal-scheduled sleep method is bound to the signal framework, while some driver sleep operations do not depend on signals.
  b. Timespec conversion: Signal-scheduled sleep involves timespec conversion, which has a significant impact on performance.
2. Busy sleep: up_mdelay() / up_udelay()
Weaknesses:
  a. Does not actively trigger scheduling, occupy the CPU loading.

3. New interfaces: Scheduled sleep: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
Strengths:
  a. Does not depend on the signal framework.
  b. Tick-based, without additional computational overhead.

Currently, the Nuttx driver framework extensively uses nxsig_* interfaces. However, the driver does not need to rely on signals or timespec conversion.
Therefore, a new set of APIs is added to reduce dependencies on other modules.

(This PR also aims to make signals optional, further reducing the code size of Nuttx.)

Signed-off-by: chao an <anchao.archer@bytedance.com>
@jerpelea jerpelea merged commit 02bfd29 into apache:master Oct 16, 2025
40 checks passed
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: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants