-
Notifications
You must be signed in to change notification settings - Fork 1.4k
sched/sleep: replace all Signal-based sleep implement to Scheduled sleep #17204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
09f198c to
dc62f8a
Compare
d80fdec to
4cff702
Compare
|
How did you test this? Can you share? |
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>
To make checker happy: arch/arm/src/sama5/sam_classd.c:997: nd ==> and, 2nd arch/arm/src/sama5/sam_classd.c:1362: levl ==> level drivers/sensors/apds9922.c:286: persistance ==> persistence Signed-off-by: chao an <anchao.archer@bytedance.com>
@fdcavalcanti here is output: could you help test the ESP chip? Some replacements may affect the ESP driver behavior. |
Fix build break: | arm-none-eabi-ld: /home/archer/code/nuttx/nuttx section `.data' will not fit in region `kflash' | arm-none-eabi-ld: region `kflash' overflowed by 96 bytes | Memory region Used Size Region Size %age Used | kflash: 65632 B 64 KB 100.15% | uflash: 0 B 64 KB 0.00% | xflash: 0 B 128 KB 0.00% | ksram1: 4716 B 6 KB 76.76% | usram1: 0 B 4 KB 0.00% | xsram1: 0 B 22 KB 0.00% | sram2: 0 B 16 KB 0.00% | make[1]: *** [Makefile:217: nuttx] Error 1 | make: *** [tools/Unix.mk:542: nuttx] Error 2 Signed-off-by: chao an <anchao.archer@bytedance.com>
I will run our internal CI, please don't merge for a while. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new interface, but I'm not confident about changing all the calls to nxsig_sleep. It will be hard to test all of those drivers, and sometimes the difference in timing between sleep implementations can cause issues. I think this should just be the interface used going forward, and drivers can be swapped out one by one when they're able to be tested. I'm worried this will break some drivers and there's no testing for those.
The intent of this change is to make the signal framework configurable, as most RTOS devices don't require signal support and it would be too burdensome for an RTOS environment. If a complete replacement isn't made at this stage, the driver and BSP code will still rely on signal. In addition, the replacement of sleep-related implementations will not bring any impact. The implementation details of nxsched_* and nxsig_* is similar. |
|
Look good to me. |
|
One more question: if this replaces all the nxsig_sleep calls, doesn't that make the function obsolete? What's the use case for nxsig_sleep versus this new tick-based method? |
nxsig_sleep/usleep has the following two features:
Both of the above features are mandatory requirements of POSIX, so we cannot remove them.
https://pubs.opengroup.org/onlinepubs/009696799/functions/sleep.html The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. |
|
Thank you for the clarification @anchao and sorry for the basic questions! That makes much more sense to me now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it might be a good idea to document somewhere that driver implementations should use this new API to avoid mixing nxsig* back into driver code.
Summary
Continuous work of #17200
sched/sleep: replace all Signal-based sleep implement to Scheduled sleep
Nuttx currently has 2 types of sleep interfaces:
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.
Busy sleep: up_mdelay() / up_udelay()
Weaknesses:
a. Does not actively trigger scheduling, occupy the CPU loading.
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()