Skip to content

Commit 23e61c0

Browse files
LMESTMadbridge
authored andcommitted
SysTimer deep sleep: Add local lock check and update comments
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.
1 parent 5df60b5 commit 23e61c0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

platform/source/SysTimer.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,21 @@ void SysTimer<US_IN_TICK, IRQ>::set_wake_time(uint64_t at)
112112
_deep_sleep_locked = true;
113113
sleep_manager_lock_deep_sleep();
114114
}
115-
116-
/* If we have enough time for deep sleep, let's consider we may enter it */
115+
/* Consider whether we will need early or precise wake-up */
117116
if (MBED_CONF_TARGET_DEEP_SLEEP_LATENCY > 0 &&
118-
ticks_to_sleep > MBED_CONF_TARGET_DEEP_SLEEP_LATENCY) {
119-
/* Schedule the wake up interrupt early, allowing for the deep sleep latency */
117+
ticks_to_sleep > MBED_CONF_TARGET_DEEP_SLEEP_LATENCY &&
118+
!_deep_sleep_locked) {
119+
/* If there is deep sleep latency, but we still have enough time,
120+
* and we haven't blocked deep sleep ourselves,
121+
* allow for that latency by requesting early wake-up.
122+
* Actual sleep may or may not be deep, depending on other actors.
123+
*/
120124
_wake_early = true;
121125
insert_absolute(wake_time - MBED_CONF_TARGET_DEEP_SLEEP_LATENCY * US_IN_TICK);
122126
} else {
123-
/* Otherwise, we'll set up for shallow sleep at the precise time.
124-
* To make absolutely sure it's shallow so we don't incur the latency,
125-
* take our own lock, to avoid a race on a thread unlocking it.
127+
/* Otherwise, set up to wake at the precise time.
128+
* If there is a deep sleep latency, ensure that we're holding the lock so the sleep
129+
* is shallow. (If there is no deep sleep latency, we're fine with it being deep).
126130
*/
127131
_wake_early = false;
128132
if (MBED_CONF_TARGET_DEEP_SLEEP_LATENCY > 0 && !_deep_sleep_locked) {

0 commit comments

Comments
 (0)