-
Notifications
You must be signed in to change notification settings - Fork 3k
Use RTOS wait primitive where possible #6969
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
Conversation
…ching will be faster than the resolution
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.
@stevew817 do you have rough numbers on how much power this saves?
Isn't this already handled by the logic in |
platform/mbed_wait_api_rtos.cpp
Outdated
} | ||
|
||
void wait_ms(int ms) { | ||
wait_us(ms * 1000); | ||
Thread::wait((uint32_t)ms); |
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.
Wasn't the old function - wait_us doing the same thing, but with some added checks? see line 43
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.
Looking at the old function there are some differences. That is if you enter a delay that has some us component. The old function would do a thread wait and then a busy wait:
wait_us(1500) would call Thread::wait(1); and then do a busy wait for the remaining 500 us
In this sense wait_s(float s) is quite "non deterministic". A slight change in the input to wait_s() (eg 0.002 vs 0.001999) can have a big input to the power consumption. This might also be the issue that @stevew817 was actually trying to address.
@@ -25,11 +25,11 @@ | |||
#include "platform/mbed_power_mgmt.h" | |||
|
|||
void wait(float s) { | |||
wait_us(s * 1000000.0f); | |||
wait_ms(s * 1000.0f); |
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.
this breaks the interface of wait(float s) as you can no longer wait sub ms time deltas
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.
@Oteph made a good point about sub-millisecond waits breaking the float wait function.
Is that a part of the goal of this PR?
@geky @Oteph I'll back out this change if the vision of the mbed OS team doesn't match mine, but at least consider my argument. |
This would otherwise fail, since the SVCall for the kernel to switch to another task would not be executed.
I'm there with you, unfortunately we are committed to backward compatibility for API and behavior between major versions of Mbed OS. wait is one of the areas that need unification and rethinking for next major mbed version. |
wait_us(ms * 1000); | ||
// Shouldn't be calling a wait function from a critical section, | ||
// but in case someone does... | ||
if (core_util_are_interrupts_enabled()) { |
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.
Wait_us calls thread::wait (no busy wait), if the input is a multiple of 1000, which it is if the input is in milliseconds. So the behavior of your implementation is the same as in the current one besides that you are not surrounding it with sleep_manager_lock_deep_sleep - sleep_manager_unlock_deep_sleep.
Closing this PR since looking at the feedback, we're not going to be modifying the wait API at this time. An issue can still be made separate from this PR so that it can be tracked. |
@stevew817 @c1728p9 @geky @kjbracey-arm @janjongboom - Please share your thoughts on
If the RTOS is present and delay is greater than 2 milliseconds, it will enter deep sleep and save power same as Thread::wait(). For delay in sub-millisecond precision behavior will be same as stated here https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_wait_api.h#L60 2 msec was selected to avoid issue of 1ms delay resulting into no wait. Other suggestion was to have 10 msec
|
@deepikabhavnani Your most significant suggestion here is about changing the implementation of Personally, I'd be happy to make that change, as it makes sense for a wait call to have precision equal to its granularity, and there is a route for applications to cope with the change - if they really want micro-second precision, they can say But I'm more cavalier about backwards-compatbility than many. Alternatively, could have a new function, documented to only be millisecond precision, but not sure what on earth to call it if it has to sit among |
+100 on the change, I think we should do this as soon as possible; but no comments on the quality of the patch. |
We can deprecate wait_ms and wait_us and add |
+1 for the change, though does it need to be backwards incompatible? It this switch is internal and the called by all three APIs that should keep our API backwards compatible while still removing the deepsleep lock. |
I'm not convinced that having 3 calls that are totally equivalent and only vary mode by the magnitude of value passed is the way to go for this sort of fundamental API. If making changes, I'd rather go the opposite direction - have distinct specific calls for
Maybe do have one convenience wrapper on top of those such as More on the other PR. |
Description
When an RTOS is present, use the thread wait primitive for millisecond resolution and above. This will lead to vastly improved power consumption on targets with tickless support.
Pull request type