-
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
STM32 LPTICKER with RTC : better sleep time #8777
Conversation
Test run: FAILEDSummary: 4 of 7 test jobs failed Failed test jobs:
|
@jeromecoutant The above is a test run (don't mind it at the moment). I'll restart jenkins CI now |
Test run: FAILEDSummary: 4 of 7 test jobs failed Failed test jobs:
|
Restarting CI |
Test run: SUCCESSSummary: 4 of 4 test jobs passed |
@OPpuolitaival Please review test failures (test run success ?) |
We will restart CI but after reviews are done and having some 5.11 items in. |
reviewers please review this PR |
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.
only one question - otherwise looks good
targets/TARGET_STM/rtc_api.c
Outdated
WakeUpCounter = WakeUpCounter/2; | ||
|
||
if (WakeUpCounter > 0xFFFF) { | ||
WakeUpCounter = 0xFFFF; |
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.
In case where wake-up is pushed to the upper limit, it means that we cannot sleep as much as was requested right ?
Is it then expected that higher layers (mbed-os core) takes care of synchronizing os-time again ?
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.
Wake up can always be early, due to other wakeup sources than time. As long as the HAL reports how long it actually slept, that's fine, from the OS's point of view.
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.
The common ticker layer can safely handle early wakeups, but the LowPowerTickerWrapper does not. It treats early interrupts as spurious interrupts and ignores them.
To prevent this I recommend adjusting the supported bits
from lp_ticker_get_info
to match what you can safely set. This way the common ticker layer will always schedule a wakup time the hardware can achieve. In the case of maximum clock division (1/4th normal speed) with a 16 bit counter that would be .bits=18
. This value is currently set to 32 bits which can cause failures.
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.
Isn't .bits=18
still a little off? Can't actually schedule 0x3FFFF
, only 0x3FFFC
. Is that significant enough to matter?
Test failed because of broken hardware. The board is taken off from CI and now restarted the test |
Hi
|
One question about performance here - how significant is the power saving of 32s versus 8s versus 2s sleep time? (And as part of that calculation, how long do we spend awake each time?). What would the saving be if we achieved much higher or unlimited time? |
Whether or not something is significant is difficult to quantify, justify and/or state categorically! But, I looked at this for myself the other day and can give you some figures. I'm using a STM32L4 and measured the wake up time as a little over 2 ms. The sweet spot for our application is waking up and taking a measurement every 10 minutes. To take and transmit the measurement we spend less than 100 ms in Run mode. So for 8s we spend ((10 * 60) / 8) * 2 = 150 ms in Run mode only to decide to go back to sleep. For 32s it becomes ((10 * 60) / 32) * 2 = 37.5 ms. Over a 100 ms not in Run mode feels worth it to me. Obviously hours, or even days, would be much better for the situations where the sample interval is reduced but I can see why this would be difficult to achieve while maintaining accuracy. |
I am kind of asking because I'm trying to justify (or not) some sort of API extension which would permit 1 second granularity, which would then presumably open the door to much longer sleeps here. In STM, can we sleep with 1s wakeup precision to get a longer range (RTC alarm), but still get a <1ms precision measurement of sleep time? Or would we lose sleep time measurement precision too? |
Last time I had this discussion, users were asking for an RTC Alarm API. |
The two possibilities I'm looking at initially are
so potential for rtc alarm to be built-in to the call, or maybe
So no built-in suspend wakeups, just whatever wakeup sources you have. I'm inclined to go for the first, as it can be implemented using existing LPTimer. Use of RTC alarm could be added under the surface. Getting the automatic idle to also have that RTC alarm potential under the surface would also be possible, but would probably require the ability to provide an accurate measurement of how long the sleep period actually was, even if the wakeup had 1-second granularity. Whereas for an explicit suspend we could just document the potential of 1 second system clock drift. |
I like the RTC alarm idea because application may rely on a RTC alarm handler to be called, |
I feel you, but one of my design goals is getting suspend working without the requirement for HAL changes... Leveraging that to overcome the 16-bit * 10ms limitation on STM is a side bonus. As for the alarm handler, Mbed OS already has a lot of ways to get a callback at a specific time - I'm not yet convinced there's a separate need for an API requesting a callback specifically directly from the RTC handler peripheral. Something more under-the-surface could potentially cope better with latency, such as with the latency stuff.
|
Can we start CI ? |
Marked as needing CI. Waiting for RC3 PRs to wrap up before starting CI for 5.11.1 PRs. |
CI started |
Test run: FAILEDSummary: 1 of 11 test jobs failed Failed test jobs:
|
Pipe closed in CI, restarting exporters |
This looks ready from CI point of view but not reviewers. Reviewers, please review |
@kjbracey-arm @c1728p9 Mind doing a quick re-review? This appears to be ready aside for final checks. |
Rerunning CI since it's been more than a week. |
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Hi @jeromecoutant , I've found a problem with this which really deserves a new issue. I'm busy doing other things so I'll just mention the problem with the expectation that you're not actually going to do anything! I've found this change affects our event scheduling accuracy. When scheduling events for only a minute or 2 in the future it sometimes starts selecting the least accurate wake-up clock. It is repeatable but I haven't had time to investigate. I've stopped it selecting My feeling is that the problem isn't with what you've done. I suspect that the RTOS starts misjudging the sleep time and calls |
Wouldn't fault him considering comments in a closed PR aren't tracked. In the future, please open issues instead of commenting in closed/merged PRs. |
Sorry, I didn't mean to be rude. I certainly didn't intend to imply any criticism of the ST or Mbed teams. Rather I meant, I wasn't expecting @jeromecoutant to start an investigation based on my vague and incoherent ramblings. If this was more important to me I'd do some more investigation, gather some evidence and try and write a coherent issue. I haven't got time to do that now and I'm not expecting @jeromecoutant to do it for me. But, I mentioned it in case @jeromecoutant sees, or hears about, something funny and perhaps things will start adding up into something a bit more tangible! I was actually trying to avoid making a fuss and work for everyone. I've completely failed in that regard! |
Thanks for the clarification. Sarcasm over a text-only medium is hard 😄 |
Description
With current implementation, as the WakeUp timer is a 16 bits counter, the maximum sleep duration is about 2s.
Idea is to decrease WakeUp clock source frequency for "long time".
@c1728p9 @LMESTM
Pull request type