-
Notifications
You must be signed in to change notification settings - Fork 2k
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: WIP for power management that uses submodules #7597
pm: WIP for power management that uses submodules #7597
Conversation
It seems to me that you didn't reduce the number of duplicate implementations. How about using submodules in the pm_fallback module, which can be independently selected? |
Hi @kaspar030 , the idea was not to reduce duplication, but to resolve some issues with the current selection of pm functions/implementations and to allow the actual cpu to use the implementation it needs. Submodules sound the way to go for me! Which would you suggest? One for each of pm_off, pm_reboot and pm_set_lowest? So the cpu would e.g. do the following:
Like this? That also looks like a lot of overhead? |
Yes! Can we apply this to the cpu fallbacks, too? |
@kaspar030 check out my updated comment! |
@kaspar030 That's the question how it would work with the most used CPUs (atmega_common, stm32_common, cortexm_common and nrf5x_common). Let's try to figure it out from my proposal. |
Hm, it does, but we do want this fine-grained selection. The alternatives are ifdefs with global defines, weak defaults, ... Let's try! |
Yes, overhead is relative though, because we can just select fine-grained implementations. The main problem is that some CPUs use both stm32_common AND cortexm_common. And we have to review the current pm implementation and see if we can merge it to one of them IMO. I would really like to avoid any ifdefs/weak defaults if possible. |
@kaspar030 Can you help me with enabling a simple submodule? What do I need? Let's say I want to change pm_fallback to have three submodules: pm_fallback_off, pm_fallback_set_lowest and pm_fallback_reboot. Do I need to cherry-pick / get anything from #7241 ? |
The steps should be
See how it is done in core/Makefile.
That should be independent. I'll be rebasing it on this one once we're done here. ;) |
@kaspar030 Okay, had a little typo :/ Only problem now is that I have to add
Is there a smarter way to tell the build system that it should include it automatically? How do we do it if we mix it up. I would like to have it like this:
but for now we would have to write the following:
|
Ah, I forgot: add "pm_fallback" as dependency of "pm_falback_%" (e.g., in Makefile.dep):
|
Additionally: is there a smart way to select all submodues automatically? e.g. pm_fallback will select _off, _set_lowest and _reboot? |
If the module is in drivers, drivers/Makefile.dep, otherwise ./Makefile.dep. The module is shared by all (or most) boards, right?
nope. ;) |
Almost finished. One thing we really have to look at before merging: Can all CPUs that are based on cortexm_common by default use the pm implementation that is present in cortexm_common? That would be great! |
@kaspar030 Pushed a submodule-based version. You can have a look now! |
cpu/atmega1281/Makefile.include
Outdated
@@ -3,6 +3,9 @@ export CFLAGS += -DCOREIF_NG=1 | |||
|
|||
# tell the build system that the CPU depends on the atmega common files | |||
USEMODULE += atmega_common | |||
USEMODULE += pm_fallback_set_lowest |
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.
can these be moved to atmega_common?
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.
@kaspar030 No, the idea is that the final CPU will always select everything it needs. In particular my implementation of the pm is specific to atmega1284p, as registers and modes and peripheral levels are individual per CPU.
The only thing would be to create a pm_fallback.mk.inc in atmega_common that will be included in Makefile.include of the CPU?
cpu/atmega_common/pm/pm.c
Outdated
@@ -26,6 +26,14 @@ | |||
#include "irq.h" | |||
#include "periph/pm.h" | |||
|
|||
void pm_set_lowest(void) {} |
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.
shouldn't this be in the common pm_fallback_set_lowest?
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.
ACK
cpu/atmega_common/pm/pm.c
Outdated
@@ -26,6 +26,14 @@ | |||
#include "irq.h" | |||
#include "periph/pm.h" | |||
|
|||
void pm_set_lowest(void) {} | |||
|
|||
void pm_off(void) |
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.
dito
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.
ACK
cpu/cortexm_common/Makefile.include
Outdated
@@ -3,5 +3,6 @@ INCLUDES += -I$(RIOTCPU)/cortexm_common/include | |||
INCLUDES += -I$(RIOTCPU)/cortexm_common/include/vendor | |||
|
|||
USEMODULE += cortexm_common_periph | |||
include $(RIOTCPU)/cortexm_common/Makefile.dep |
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.
cannot include Makefile.dep from a different makefile
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.
I think it didn't work without, but I will check again
cpu/ezr32wg/Makefile.include
Outdated
@@ -1,3 +1,7 @@ | |||
export CPU_ARCH = cortex-m4f | |||
|
|||
USEMODULE += pm_cortexm_common_set_lowest | |||
USEMODULE += pm_cortexm_common_off |
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.
don't all cortexm boards use the cortexm_common off and reboot?
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.
I think so
cpu/lm4f120/Makefile.include
Outdated
# use common periph functions | ||
USEMODULE += periph_common | ||
USEMODULE += pm_cortexm_common_set_lowest |
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.
IMO we can generalize this for all cortexm boards:
if not (feature_provided(periph/pm)) -> use ...._common_set_lowest
of make it dependend on whether pm_layered is used.
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.
Sounds good. As mentioned above we have to check if all boards based on cortexm_common AND stm32_common can still use the pm implementation of cortexm_common!
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.
well, pm_reboot()
will definitely be the same for all cortexm. "pm_off()" will be cpu dependent. "pm_set_lowest()" will be the same for all cortexm not implementing periph/pm.
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.
where would we implemented such a check to select all cortexm_common fallback if the feature is not provided by the cpu itself?
cpu/nrf5x_common/pm/pm.c
Outdated
@@ -23,6 +23,14 @@ | |||
|
|||
#include "cpu.h" | |||
|
|||
void pm_set_lowest(void) { |
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.
use pm_fallback_coretexm_common_
#define ENABLE_DEBUG (0) | ||
#include "debug.h" | ||
|
||
void pm_set_lowest(void) {} |
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.
I don't like this file much... ;)
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.
Me neither, but that's the fallback and it was before as well. Any suggestions?
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.
Not with using submodules and without using ifdefs. Let's keep it for now.
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.
pm_set_lowest is only used in core/kernel_init.c
and sys/pm_layered/pm.c
, maybe we can omit the file and only call pm_set_lowest in kernel_init.c
if the CPU/board defines something like #define HAS_PM_SET_LOWEST
or something?
From what I can see, all boards that are based on stm32_common, are also based on cortexm_common. Therefore, as stm32_common provides a pm_layered implementation, all boards based on stm32_common can select the pm_set method from stm32_common and off/reboot from cortexm_common. find . -name "Makefile.include" | xargs grep -A2 stm32_common |
@kaspar030 Can |
Kinetis has 4 power modes which can be used with RIOT without any big intrusive changes. I have a WIP branch for adding them, but I have not yet posted a PR. Please leave the Kinetis specific implementation of pm_set in place to make merging my future PR easier, don't remove it right now. |
@gebart Thanks! The function has been moved to its own module for now to comply with the other implementations. Might change that depending on the feedback receivedhere. I dont like that I have to use USEMODULE += in Makefile.features, but this was the only possibility to check if the feature exists. |
I also updated the wiki page on the new power management API and the ideas behind it: https://github.com/RIOT-OS/RIOT/wiki/Power-Management#architecture |
I would prefer the version with submodules, because, the required code and the dependencies are explicit. For me, the problem here, is the current possibility to express dependencies to interfaces which is a build system issue and not a source file issue. |
Closed in favor of #7726. @roberthartung Again, thanks a lot for the work you've put in this! |
This commit resolves issues with the power management and prepares the PM architecture to be selected by the actual CPU.