-
Notifications
You must be signed in to change notification settings - Fork 3k
equeue: add config option to use different timer classes #5328
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
…se LowPowerTimer, LowPowerTimeout and LowPowerTicker instead of Timer/Timeout/Ticker. This way, on SiLabs boards the low power sleep states will be used when using event queue.
Isn't this an issue about queue clean-up (destructor/destroy function) ? I glanced at the implementation, equeue_tick creates timer objects, but destroy does not destroy them, thus they are still active and blocking deep sleep? cc @geky @kjbracey-arm |
@0xc0170 Sleep state which can be entered may also be managed by the MCU itself depending on the state of its peripherals. Outside sleep consideration, using low power timing primitives should help to reduce the power consumption footprint. I've looked at the implementation and you're correct, the Timer and Ticker allocated dynamically allocated are not released. Thankfully they are allocated once and will be used by all event queue instantiated for the rest of the application lifetime. |
events/mbed_lib.json
Outdated
@@ -21,6 +21,7 @@ | |||
"shared-highprio-eventsize": { | |||
"help": "Event buffer size (bytes) for shared high-priority event queue", | |||
"value": 256 | |||
} | |||
}, | |||
"use-lowpower-timer-ticker": 0 |
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.
Could you expand this to have a "help" field as well. Something like:
"Enable use of low power timer and ticker classes. May reduce the accuracy of the event queue."
This looks perfect 👍 Though quick question, what is the accuracy of the low power tickers? Are they less accurate than 1ms? It doesn't matter if this is added as a config option, but if it's more accurate than 1ms it may be worthwhile to use low power by default if it's available. |
If there's a "low power X", it must presumably have a downside compared to the default one, so there's some trade-off. If there is, not sure how this choice can be made globally. Wouldn't it have to be per-event-queue? If it is acceptable to be the default for all event queues, why not for the entire system? Is it just an assumption that there are fewer event queue users, so switching all event queues at one once is less likely to break stuff than switching everything? Afraid I'm not familiar with these LowPowerXXX classes - pointer welcome. |
@geky I updated to include a help text ... I took yours, as this seems accurate ;) @kjbracey-arm When I do a grep DEVICE_LOWPOWERTIMER over all sources, I can see that several targets implement a lp_ticker.c file - these are:
So ... a rather small amount of targets actually claim to support this ;) |
This is a bit vague: https://os.mbed.com/blog/entry/Using-the-new-mbed-power-management-API/
It would be nice to have some sort of proper cross-platform specification for that. Looking at STM and some other platforms, I see a fair few use 32.768kHz RTCs, which is 30µs. Maybe we can assume it's at least 1ms, so always suitable? In which case I kind of feel that rather than being local and based on config, But staring at equeue a bit further, does it really need to use dedicated timers at all (in an RTOS)? Doesn't it just need millisecond precision to read current time ( And the other ticker is running infrequently to reset the first timer to avoid wrap - unnecessary with appropriate care with the kernel tick count wrap? |
I second @kjbracey-arm on using timer and ticker in the OS context. It seems unnecessary and from my perspective it is strange to use different time sources (us_ticker or lp_ticker and the systick clock) and interact with them as if they were equal. |
Ah yep, looks like |
@MikeDK Could you please address the latest comments. |
I can't think of a reason we can't go ahead and merge this in? It's opt-in, the patch for okKernelGetTickCount can come in seperately, and the low-power option is still useful without the rtos. |
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.
Coding style change request, the concept looks fine.
events/equeue/equeue_mbed.cpp
Outdated
@@ -23,27 +23,36 @@ | |||
#include <stdbool.h> | |||
#include "mbed.h" | |||
|
|||
#if MBED_CONF_EVENTS_USE_LOWPOWER_TIMER_TICKER | |||
#define AliasTimer LowPowerTimer |
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.
macros should start at the line beginning and should use capital letters , see https://docs.mbed.com/docs/mbed-os-handbook/en/latest/cont/code_style/
#if MBED_xxx
#define ALIAS_TIMER
@MikeDK Can you please sign https://os.mbed.com/contributor_agreement/ ? I requested some styling changes.
@geky / @kjbracey-arm Can we capture this, to track it? |
And if the RTOS tick count change happens later, then this JSON option can remain but will no longer do anything with an RTOS (as there will be no tickers etc). Seems reasonable to me. |
@0xc0170 are you happy with the changes ? |
Question: is there any further action required from my side? I'm not sure, because the bot tells me that there are still changes requested... I committed one change for geky's review, and one for 0xc0170... |
To run CI here, will trigger the job (we are currently investigating one target failing) |
/morph build |
Build : SUCCESSBuild number : 465 Triggering tests/morph test |
Test : SUCCESSBuild number : 285 |
@alzix Please trigger uvisor CI job for this PR (seems it is not active for us at the moment for some reason, testing right below) /morph uvisor-test |
@MikeDK Could you please read https://chris.beams.io/posts/git-commit/#seven-rules and update this PR accordingly. Thanks |
…use LowPowerTimer, LowPowerTimeout and LowPowerTicker instead of Timer/Timeout/Ticker.
This way, on SiLabs boards the low power sleep states will be used when using event queue.