-
Notifications
You must be signed in to change notification settings - Fork 3k
Sys timer should let deep sleep happen #11522
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
Sys timer should let deep sleep happen #11522
Conversation
29e44c4
to
f8a8845
Compare
When next SysTimer wake-up is scheduler far enough, always consider that deep sleep may be entered and program an early wake-up. So that even if deep sleep is only allowed some time later, it can be entered. If not doing this, then the deep sleep would be prevented by SysTimer itself and may not be entered at all. This has been proved to happen in a simple blinly example.
f8a8845
to
cd3105b
Compare
Thanks for the investigation. I've been studying this issue/PR, and considering alternatives. This does work, but does mean we always get double wake-up on boards with latency, even when not deep sleeping. That's not the end of the world, so maybe it's the way to go, but I was trying a different approach, which was to prepare the timer on the basis of the current That doesn't work, because changing the timer re-locks the sleep. We get stuck in an endless timer reprogramming loop. I'm not very happy with the HAL timer drivers locking deep sleep. Seems like a layer violation, and I'm worried it may cause more upsets. Is there any alternative? My assumption was always that the unlock race there would be rare to non-existent, not something that would occur regularly due to a HAL timer interaction with the lock. So. You need the programming to be complete before entering your deep sleep mode? And that completion generates an interrupt (in which you currently unlock deep sleep?) Could you just have a HAL-local lock - if the "lp timer programming progress" flag is set, |
@kjbracey-arm
During the extra latency we would be in sleep / WFI which is the same anyway we would have when we can't deep sleep .. so power loss would be insignificant
If doing this, we would actually make all cpu stats wrong. We would tell the system we're in deep sleep when we're not and that could be pretty confusing in the end. If we return from deep sleep like we do for serial (something we should get rid of one day ...) then we will continuously be executing code in and out of deep sleep (mbed power management layer checks deep sleep is allower, enters deep sleep, u we actually exit immediately, then again .... ) - here the power less can be significant because CPU is active instead of WFI ... |
But you're potentially doubling the run-time - a simple LED blink is going to wake twice for every transition. Isn't doubling run-time significant? Admittedly it's an increase for the intermediate not-deep-sleeping power state, not the actually minimum deep sleep, so maybe it's not that significant. (Feedback like this is welcome, as I've done quite a lot of work on the sleep stuff, but very much from a theoretical angle - I don't have an intuitive feel for the power/time ratios).
True. That's a good enough argument to dissuade me. I've also noticed another issue in that when going around again for So this patch wins for simplicity. I'll review. |
platform/source/SysTimer.cpp
Outdated
if (MBED_CONF_TARGET_DEEP_SLEEP_LATENCY > 0 && | ||
ticks_to_sleep > MBED_CONF_TARGET_DEEP_SLEEP_LATENCY && | ||
sleep_manager_can_deep_sleep()) { | ||
ticks_to_sleep > MBED_CONF_TARGET_DEEP_SLEEP_LATENCY) { |
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 think you can instead replace the sleep_manager_can_deep_sleep()
with !_deep_sleep_locked
. If we know we've taken the lock because we're using us_ticker, no need to do the early wake.
The comments need a bit of rework I think. The "race" no longer exists. Something like:
/* Consider whether we will need early or precise wake-up */
/* If there is deep sleep latency, but we still have enough time,
* and we haven't blocked deep sleep ourselves, allow for that latency by requesting early wake-up.
* Actual sleep may or may not be deep, depending on other actors.
*/
/* Otherwise, set up to wake at the precise time.
* If there is a deep sleep latency, ensure that we're holding the lock so the sleep
* is shallow. (If there is no deep sleep latency, we're fine with it being deep).
*/
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.
PR updated with your changes (and your github name added for reference)
@0xc0170 I would really like this PR to be considered for 15.4 release - unless 15.4 is not deployed to the online compiler, mbed studio and so on ... I'd like to avoid having a release where deep sleep is not entered at all after all the efforts we've been through before summer time |
I'll run a power measurement on this concrete example and share the results here so that we have concrete data to discuss with. |
CI started |
If it passes CI in the next couple of hours then we can try and get this into RC3 |
Test run: FAILEDSummary: 1 of 4 test jobs failed Failed test jobs:
|
I'll restart tests, @LMESTM can you fix astyle first? |
Suggested-by: @kjbracey-arm Replace the sleep_manager_can_deep_sleep() with !_deep_sleep_locked. Indeed, if we know we've taken the lock because we're using us_ticker, no need to do the early wake. Updated comments accordingly.
ce647bd
to
9858b16
Compare
Sorry about that - this is now fixed ! |
CI started |
@kjbracey-arm some data measured today on NUCLEO_L073RZ using mbed-os Blinky example Deep sleep current ~6µA Then average MCU power (well average current here) can be considered as : the fewer wake-ups the better. But the extra wake-up cost when Sleep mode only is possible seems to be low ... the big saving comes when you start entering Deep Sleep |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
Pull request type
Reviewers
@kjbracey-arm @0xc0170 @jeromecoutant
Release Notes
Proposed fixes to #11509
Has been tested with simple blinky example, but should be reviewed and tested by mbed-os core team.