-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Improve RTOS behavior with deep sleep #8223
Conversation
This may negatively increase power consumption so I'm marking this as do not merge until further investigation can be done |
Hi Proposition in targets.json file:
Then, it is up to each target to define it ? |
Seems like something like this is needed, given the HAL sleep spec. Implementation seems reasonable to me. Next possible refinement would be to allow a target to specify its number. |
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.
Verified with tests
(note that this current patch version doesn't compile :-))
3d1259a
to
9a51d4e
Compare
Rebased on to master and added config value with a default of 0. Removing "do not merge" since this PR should not effect power consumption in the default configuration. |
GitHub description needs update from commit message |
@c1728p9 it seems there is some conflict |
@jeromecoutant It doesn't makes sense to start CI if the PR needs to be rebased, which will require another run of CI anyways. |
if (block_deep_sleep) { | ||
sleep_manager_lock_deep_sleep(); | ||
} else { | ||
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.
Technically this subtraction should be just "wake latency".
If sleep time was 3ms and wake time was 5ms, you'd want
7ms: normal sleep, 7ms timer
8ms: normal sleep, 8ms timer
9ms: deep sleep, 4ms timer
10ms: deep sleep, 5ms timer
I think you might want separate "sleep" and "wake" numbers to do that.
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.
But then, is 1ms in deep sleep better than 9ms in normal sleep? Scope for another fudge factor... Maybe you'd want to not go deep until "actual deep sleep time >= 50% of desired total" or something.
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.
Hi @kjbracey-arm the intent here was to reduce typical latency by using the requirement defined in the sleep specification - https://github.com/ARMmbed/mbed-os/blob/master/hal/sleep_api.h#L42
This is an optimization for latency not for power savings which is why I didn't add additional logic to determine if it would be optimal for power consumption to go into deep sleep. This could definitely be done, but is outside the scope of this PR.
I think you might want separate "sleep" and "wake" numbers to do that.
Have you seen devices which take a large amount of time to enter deep sleep? I'm use to a wakeup delay since crystals and plls need time to stabalize and lock, but I don't think I have seen a case where the time to enter sleep was a concern.
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.
Okay, I think that answers my main point - I was thinking sleep and wake time might be comparable, which but if it's typically almost all wake, this is fine.
The power saving thing is something else, indeed.
The 10ms latency is something I think we'll have to be occasionally conscious of; I'd not really registered the implications. There may be external devices that keep working perfectly fine in deep sleep, except that they wouldn't cope with 10ms IRQ response latency from the CPU, so drivers may need to hold the lock purely for that reason.
bump... |
@c1728p9 Could you address @kjbracey-arm's comments, and rebase so that we can get CI going? |
targets/targets.json
Outdated
@@ -20,6 +20,10 @@ | |||
"network-default-interface-type": { | |||
"help": "Default network interface type. Typical options: null, ETHERNET, WIFI, CELLULAR, MESH", | |||
"value": null | |||
}, | |||
"deep-sleep-latency": { | |||
"help": "Time in ms required to go to and wake up from deep sleep (max 10)", |
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 know it's a nitpick but I think you've got some tabs in this change. The only 2 tabs in the file.
Only deep sleep when the wakeup time is more than MBED_CONF_TARGET_DEEP_SLEEP_LATENCY ms in the future. This ensures that RTOS events are handled at the correct time. Note - when deep sleep is allow interrupt latency may still be as high as 10ms.
9a51d4e
to
50316d0
Compare
Fixed witespace and rebased to master |
@mattbrown015 @LMESTM Please feel free to take another look at this PR. /morph build |
Build : SUCCESSBuild number : 3456 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 3077 |
Test : SUCCESSBuild number : 3247 |
I still approve this, but would welcome @c1728p9's thoughts on my comments about separate wake/sleep times. |
@@ -21,6 +21,10 @@ | |||
"help": "Default network interface type. Typical options: null, ETHERNET, WIFI, CELLULAR, MESH", | |||
"value": null | |||
}, | |||
"deep-sleep-latency": { | |||
"help": "Time in ms required to go to and wake up from deep sleep (max 10)", |
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 assume MBED_CONF_TARGET_DEEP_SLEEP_LATENCY
is the worst case scenario (the main depending factor here are the clocks that are running and need to be reenabled - can change in the runtime - in the most cases now it wont).
Max number is defined in the help text as 10, but not checked anywhere?
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.
@0xc0170 the max recommended value is 10 because deep sleep shouldn't take longer than 10ms to wake - https://github.com/ARMmbed/mbed-os/blob/master/hal/sleep_api.h#L42
Setting it to a value higher than 10 will cause higher power consumption but won't negatively effect the system otherwise.
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 understood, just checking if we set it to 11 , is this allowed and just impacts the system (no compile time error). I believe so.
/morph build |
Build : SUCCESSBuild number : 3479 Triggering tests/morph test |
Test : SUCCESSBuild number : 3267 |
Exporter Build : SUCCESSBuild number : 3099 |
Hi @jeromecoutant, Would you recommend changing this to something other than 0 for my STM32L4? The STM32L4 datasheet says it will wake from Stop 2 mode in microseconds. In another thread you said you were setting this to 5 ms but is that because you were using a difference device that's not as good at waking up? Or, is it because the wake up time in the datasheet doesn't include all the overhead required to really get mbed-os running again (enabling clocks, etc.)? Thanks, |
Hi mbed-os/targets/TARGET_STM/sleep.c Line 227 in 0fe6369
After STOP2 mode, we need to reconfigure PLL, this takes time. About the value to apply, tests are on going on my side... And finally, maybe this fix is no more useful after #8189 ...? |
@jeromecoutant this PR should still improve average wakeup latency even if it doesn't help with worst case latency. |
if (block_deep_sleep) { | ||
sleep_manager_lock_deep_sleep(); | ||
} else { | ||
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.
@c1728p9 - was discussing this with @sg-, and it occurred to me that this is being unduly pessimistic - you're subtracting the deep sleep latency from the wakeup time even if you're not going to be deep sleeping anyway, so in shallow operation there will be lots of unnecessary double firing.
May have to make the critical section wrapper bigger to synchronise a read of sleep_manager_can_deep_sleep
. Maybe we could partially compensate by stripping the sleep_manager_lock_deep_sleep_internal()
down - it doesn't need its critical section.
Description
Only deep sleep when the wakeup time is more than 10ms in the future. This ensures that RTOS events are handled at the correct time. Note - when deep sleep is allow interrupt latency may still be as high as 10ms.
Pull request type