sched/sched: add nxsched_wakeup(), introduce TSTATE_SLEEPING and improve nxsched_ticksleep()#17222
Conversation
|
I think this needs to be tested with more than just CI. It is a code change that needs runtime testing, not just building. Also, why would we want to wake up a sleeping task before its timeout? Maybe I'm unfamiliar with the semantics of sleeping, but isn't it a requirement that the caller is never woken up prior to the timeout? Only on or after? |
Sleep and wakeup sometimes should be in pair in terms of syncronization For example task1 can not move on because some condition is not met and choose to sleep for a while in the simplest case, but before timeout task2 which has lower priority than task1 met the condition, then it can wakeup task1 to let task1 preempt it sleep/wakeup is simpler and lighter than mutex, semaphore or event in this case |
I will add test it and put the results in this PR later |
But this isn't what sleeping is for? If you want to wait for a condition, you block on a semaphore/mutex, not sleep (unless it's some hardware polling condition that requires sleeping). I personally don't support the addition of the wakeup function since now all the |
I see now that even the previous implementation of |
HI @linguini1 I used this sleep/wakeup pair to improve event implementation in #17223 |
c24f03d to
aae81a3
Compare
aae81a3 to
8b77e97
Compare
8b77e97 to
4d85777
Compare
4d85777 to
17edd89
Compare
17edd89 to
45a7fb2
Compare
c972d68 to
a2a4835
Compare
Add a new function nxsched_wakeup() to the scheduler,
which allows waking up a sleeping task before its timeout.
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
Refactor nxsched_timeout() to use nxsched_wakeup() in order to
eliminate code duplication and improve maintainability.
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
a2a4835 to
b61e676
Compare
This PR includes two commits:
commit 1:
commit 2:
Summary
Improved implementation of nxsched_ticksleep() and introduced new function nxsched_wakeup()
Impact
Improvement of newly added function nxsched_ticksleep() and introduced a new function nxsched_wakeup()
No impact to other nuttx functions
Testing
PR 17204 has already replace all Signal-based sleep implement to Scheduled sleep, So CI will verify this PR's improvement of nxsched_ticksleep() is OK
also,
on the one hand:
sleep related api test were added on sim/nsh, sabre-6quad/smp: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
on the other hand:
sched/event implementation has been modified to use sleep/wakeup pair, and the ostest including event test cases passed on board a2g-tc397-5v-tft: