Skip to content

pm: adds a c/file-based power management configuration to select required implementations#7648

Closed
roberthartung wants to merge 113 commits intoRIOT-OS:masterfrom
roberthartung:pm-c-header-conf
Closed

pm: adds a c/file-based power management configuration to select required implementations#7648
roberthartung wants to merge 113 commits intoRIOT-OS:masterfrom
roberthartung:pm-c-header-conf

Conversation

@roberthartung
Copy link
Copy Markdown
Member

@roberthartung roberthartung commented Sep 26, 2017

Supersedes #7597 and porposes an alternative for the submodule/buildsystem-based version.
I just ran the buildtest by now, but didnt test any hardware yet!

@kaspar030 @MichelRottleuthner @haukepetersen Feedback appreciated!

@kaspar030
Copy link
Copy Markdown
Contributor

This might be nicer than the submodule version.
Some thoughts:

  1. There are a lot of "pm_conf.h" which just include "pm_conf_common.h". If I'm not mistaken, "pm_conf.h" either does that or defines all needed values. I think we should be able to rely on the include path order here (first cpu/specific/include, then cpu/family_common/include, ...), and just rename all "pm_conf_common.h" to "pm_conf.h". If the order is not deterministic, we should fix that (in another PR) anyways.

  2. the defines get veeery long. IMO we can shorten them. Maybe drop "PERIPH_PM" prefix, and drop "COMMON", which should turn into sufficiently unique names. E.g.: "PERIPH_PM_NEEDS_ARM7_COMMON_FALLBACK_REBOOT" -> "NEEDS_ARM7_PM_REBOOT".

  3. Some functions are guarded by both general and specific defines, e.g., "NEEDS_PM_FALLBACK | NEEDS_PM_FALBACK_OFF". Please, if possible, bundle the generic selection into one ifdef block (at the top of the file?), and keep only one condition at the function definition:

#ifdef NEEDS_PM_FALLBACK
#define NEEDS_PM_OFF_FALLBACK
#define NEEDS_PM_SET_LOWEST_FALLBACK
...
#endif

@roberthartung
Copy link
Copy Markdown
Member Author

@kaspar030 sounds nice. Will make the changes once I am back from vacation!

@miri64 miri64 added the Area: pm Area: (Low) power management label Oct 4, 2017
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Oct 6, 2017

@kaspar030
Is there other places in the codebase right now where some similar configuration is done ?
Like a cpu/board header changing which functions are actually built in another module.

And same for using include path order to resolve header files include.

@kaspar030
Copy link
Copy Markdown
Contributor

Is there other places in the codebase right now where some similar configuration is done ?

periph_spi_common is doing something similar. grep PERIPH_SPI_NEEDS_.

@roberthartung
Copy link
Copy Markdown
Member Author

roberthartung commented Oct 12, 2017

@kaspar030 Almost finished. If I provide my own configuration for pm, the pm_conf.h will be empty. Is there a better way? Or should we just place an empty pm_conf.h in that case with according comments?

Additionally, I cannot build for native:

make BUILD_IN_DOCKER=1 BOARD=native
...
cc1: fatal error: /data/riotbuild/riotproject/examples/default/bin/native/riotbuild/riotbuild.h: No such file or directory

EDIT: Nevermind, can build native now .. for some reason..

@roberthartung
Copy link
Copy Markdown
Member Author

@kaspar030 @cladmi I just pushed a shortened version. I really like this one!

Copy link
Copy Markdown
Contributor

@haukepetersen haukepetersen left a comment

Choose a reason for hiding this comment

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

Sorry for jumping the ship so late and being quiet so far. I very much like the direction of this PR, but there are still things I don't like and which can be further simplified.

For one, I am not too much a fan of introducing all these pm specific pm_conf.h header files. I actually think we can do without, by switching the paradigm of the config parameters from NEEDS to PROVIDE.

For pm_off and pm_reboot this would simplify things -> the fallback implementation (pm_reboot() in cpu/ARCH/pm.c and pm_off() in drivers/periph_common/pm.c) are simply guarded with:

#ifndef PROVIDES_PM_OFF
...
#endif

This define should simply reside in periph_cpu.h (or any shared file like periph_cpu_common.h if valid for a complete family of CPUs).

Next, the pm_off() in sys/pm_layered/pm.c is guarded with

#ifndef PROVIDES_PM_LAYERED_OFF
...
#endif

Now a CPU that does not use pm_layered simply does nothing if it wants to use the default implementation in periph_common.

Next, the pm_layered module does define PROVIDES_PM_OFF, so if a CPU uses pm_layered, it would automatically use the pm_off function provided by pm_layered.

The only 'hack' that has to be done here, is to conditionally include the pm_layered.h header in pm.h.

Does this make sense? I could draft a quick branch if it would be easier to understand, should I proceed here?

* Select the required implementations from the common CPUs or fallbacks
* @{
*/
#define NEEDS_ARM7_PM_REBOOT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might be nitpicky, but I would definitely prefer NEEDS_PM_ARM7_REBOOT to keep pm as prefix and make clear that this is a pm specific option

}
#endif

#if defined(NEEDS_CORTEXM_PM_REBOOT)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: why is pm_reboot guarded, if it is always used anyway? There is no case in the source tree, where the pm_reboot function provided by the architecture is not used... So isn't this a case of 'add the guard once we encounter a case where its needed' instead of 'adding it now because sometime in the future it might be needed'?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because one could define their own implementation. For all *_common CPUs I added guards around their implementations.

#ifndef FEATURES_PERIPH_PM
#ifdef NEEDS_MIPS32R2_PM_FALLBACK
#define NEEDS_MIPS32R2_PM_OFF
#define NEEDS_MIPS32R2_PM_OFF
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

duplicate line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes. it's a typo.

@roberthartung
Copy link
Copy Markdown
Member Author

Does this make sense? I could draft a quick branch if it would be easier to understand, should I proceed here?

@haukepetersen I know what you mean but can we cover the same functionality? Especially when mixing different fallback implementations? e.g. can we cover the cases in cpu/nrf5x_common/include/pm_conf.h and cpu/stm32_common/include/pm_conf.h.

@haukepetersen
Copy link
Copy Markdown
Contributor

Couldn't resist to try it out: #7726

@haukepetersen
Copy link
Copy Markdown
Contributor

Especially when mixing different fallback implementations?

Yes, just tried it in #7726. The nrf5x falls back to the pm_set_lowest() as provided in cortexm/periph/pm.c, while the stm32 uses the pm_set_lowest() provided in sys/pm_layered/pm.c. At least as far as I have seen in my quick tests -> please correct me if I **ucked up :-)

@roberthartung
Copy link
Copy Markdown
Member Author

Have you tried to run buildtest on the default example?

@haukepetersen
Copy link
Copy Markdown
Contributor

I did just Murdock do that job for me -> fails all the way :-) Looking into it now.

miri64 and others added 27 commits October 20, 2017 12:43
@kaspar030
Copy link
Copy Markdown
Contributor

Closed in favor of #7726. @roberthartung Thanks a lot for trying this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: pm Area: (Low) power management

Projects

None yet

Development

Successfully merging this pull request may close these issues.