Skip to content
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

pm: fix pm fallback selection #7726

Merged
merged 3 commits into from
Oct 16, 2017
Merged

Conversation

haukepetersen
Copy link
Contributor

Created this PR just to illustrate my ideas for #7648 and I'd rather have the changes merged in #7648 instead of merging this PR...

But anyhow, I think this approach simplifies matters compared to #7648 and could be the way to go? This approach does not depend on any weak symbols, nor on the order of the include paths, so it should be pretty dependable. What do you think?

66 additions and 15 deletions vs. 531 additions and 13 deletions

@@ -24,7 +24,7 @@
#include "cpu.h"
#include "periph/pm.h"

#ifndef FEATURE_PERIPH_PM
#ifndef MODULE_PM_LAYERED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be #ifndef PROVIDES_PM_SET_LOWEST? Because any other CPU could in theory define pm_set_lowest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with using PROVIDES_PM_SET_LOWEST here is, that it does not clearly differentiate from the fallback implementation in drivers/periph_common/pm.c (which uses the that guard).

But true, this line needs to be changed, how about

#if !defined(MODULE_PM_LAYERED) && !defined(PROVIDES_PM_SET_LOWEST_CORTEXM)

So we have 4 possible cases:

  • CPU branch uses pm_set_lowest() from periph_common -> do nothing
  • CPU uses 'set_lowest()defined by architecture -> definePROVIDES_PM_SET_LOWEST` by CPU architecture, do nothing else
  • CPU uses pm_layered -> simply use that module, it defines PROVIDES_PM_SET_LOWEST in any case (if not done already by the CPU architecture config)
  • CPU wants to use its own implementation -> CPU defines PROVIDES_PM_SET_LOWEST_CORTEXM', and do not use pm_layered`

* @{
*/
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)
#define PROVIDES_PM_LAYERED_OFF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be #define PROVIDES_PM_OFF in my opinion. As the function is still called pm_off().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, as we want to explicitly override the pm_off function provided by the pm_layered module.

Rationale: for the 3 CPU families specified above, we know that we use the pm_layered module. So if we want to use a custom pm_off function, we need to explicitly override the one provided by pm_layered (which in turn overrides the default one from periph_common).

extern "C" {
#endif

#ifndef PROVIDES_PM_OFF
Copy link
Member

@roberthartung roberthartung Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't like mixing PROVIDED_PM_OFF and PROVIDES_PM_LAYERED_OFF. Can we get rid of this? Or is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this is required, as each of those defines overrides a specific function in the 'fallback hierarchy'. As I see it, this is the price to pay for having multiple tiers of fallback functions.

But maybe we come up with an even better idea?

@haukepetersen haukepetersen added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 12, 2017
@kaspar030
Copy link
Contributor

Very nice idea: provide instead of need... Also re-using the existing config headers.

@roberthartung what do you think?

@haukepetersen
Copy link
Contributor Author

fixed all boards but the MIPS, need to install the toolchain locally to debug this... fix follows asap.

@roberthartung
Copy link
Member

fixed all boards but the MIPS, need to install the toolchain locally to debug this... fix follows asap.

make BUILD_IN_DOCKER=1 buildtest :-)

@haukepetersen
Copy link
Contributor Author

done, at least locally they should be all set.

@haukepetersen
Copy link
Contributor Author

@roberthartung @kaspar030: what is your verdict? And how to proceed? Would be nice to get one of the fixes merged today, so we have it for sure in the release!

@roberthartung
Copy link
Member

@haukepetersen I'd vote for merging your PR as it is (if all tests are passing ofc). The solution is good and I want to make progress with my own atmega PM implementations.

@MichelRottleuthner
Copy link
Contributor

I agree with @roberthartung. I prefer this solution. Also I did a quick measurement on samr21-xpro and can confirm the low power modes actually work as intended. This is already an improvement compared to the broken weak implementation.

@roberthartung
Copy link
Member

@MichelRottleuthner thanks for checking on the board! That's great. I think it's far more than an improvement. This might be a very good, clean solution while keeping flexibility.
I will pull this PR locally and check if I can rebase my implementation and will then do some energy measurements on my board.

@haukepetersen
Copy link
Contributor Author

Very cool. Then I will fix this PR now and let's merge it!

@haukepetersen
Copy link
Contributor Author

rebased and fixed missing doc for pic32. Will wait for Murdock to do one more run and then squash.

@haukepetersen
Copy link
Contributor Author

Murdock seems ok, so I will squash now.

@kaspar030
Copy link
Contributor

yes, please squash!

@haukepetersen
Copy link
Contributor Author

squashed.

@@ -51,6 +51,14 @@ extern "C" {
#define STACK_CANARY_WORD (0xE7FEE7FEu)

/**
* @brief All Cortex-m-based CPUs provide pm_set_lowest
*
* The pm_set_lowest is provided either the pm_layered module if used, or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think there's a "by" missing in this sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jupp. Fixed and squashed

@haukepetersen
Copy link
Contributor Author

Murdock is happy -> feel free to ACK and press the green button :-)

@kaspar030
Copy link
Contributor

should we set PM_BLOCKER_INITIAL to a safe default?

@haukepetersen
Copy link
Contributor Author

should we set PM_BLOCKER_INITIAL to a safe default?

possibly. But how about a quick follow-up PR for this?

@kaspar030
Copy link
Contributor

But how about a quick follow-up PR for this?

I'll make a commit that you can cherry-pick. IMO it belongs in here.

@kaspar030
Copy link
Contributor

169cffa

@kaspar030 kaspar030 changed the title pm: alternate approach for selecting correct fallback functions pm: fix pm fallback function selection Oct 16, 2017
@kaspar030 kaspar030 changed the title pm: fix pm fallback function selection pm: fix pm fallback selection Oct 16, 2017
@haukepetersen
Copy link
Contributor Author

done.

Instead of using `weak` function definitions, this PR handles
default implementations using `PROVIDES_x` defines, allowing
for cpus/pm realted modules to use their own implementations.
@haukepetersen
Copy link
Contributor Author

rebased.

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

@miri64
Copy link
Member

miri64 commented Oct 16, 2017

Let's go and start this release!

@miri64 miri64 merged commit 28a6128 into RIOT-OS:master Oct 16, 2017
@haukepetersen haukepetersen deleted the opt_pm_fixweak branch October 16, 2017 12:49
@photonthunder photonthunder mentioned this pull request Oct 17, 2017
@roberthartung
Copy link
Member

@kaspar030 @haukepetersen I just tried to rebase my pm implementation for the atmega_common/atmega1284p and I am stuck at a point, where I select pm_layered im Makefile.include of my CPU. pm_layered is compiled correctly. However both pm.c from periph_common and pm_layered provide pm_set_lowest. Shouldn't we add

#ifndef PROVIDES_PM_SET_LOWEST
#define PROVIDES_PM_SET_LOWEST
#endif

to sys/include/pm_layered.h - at least until the default pm.c module is not build any more by accident?

@haukepetersen
Copy link
Contributor Author

sorry for the delayed reply. Just trying to get my head around this: in the case a CPU is using pm_layered, it always wants to use the pm_set_lowest() function as provided by the pm_layered module, right? So yes, I think you are right! Would you be so kind to open a PR?!

@roberthartung
Copy link
Member

@haukepetersen Just finished rebasing my atmega_common pm stuff on the latest master ... hooray! Will create a PR tomorrow.

@haukepetersen
Copy link
Contributor Author

Awesome, looking forward to it!

@roberthartung
Copy link
Member

@haukepetersen I just wonder why this isn't conflicting at the moment as well, as some CPUs also use pm_layered already?

@roberthartung
Copy link
Member

Confirmed. Does not happen with other boards. But why? Maybe it has something todo with _common. Will investigate.

@roberthartung
Copy link
Member

@haukepetersen ping #7863

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants