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: WIP for power management that uses submodules #7597

Conversation

roberthartung
Copy link
Member

This commit resolves issues with the power management and prepares the PM architecture to be selected by the actual CPU.

@kaspar030
Copy link
Contributor

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?

@roberthartung
Copy link
Member Author

roberthartung commented Sep 14, 2017

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:

USEMODULE += pm_fallback_pm_set_lowest
USEMODULE += pm_stm32_common_pm_off
USEMODULE += pm_stm32_common_pm_reboot

Like this? That also looks like a lot of overhead?

@kaspar030
Copy link
Contributor

Submodules sound the way to go for me! Which would you suggest? One for each of pm_off, pm_reboot and pm_set_lowest?

Yes! Can we apply this to the cpu fallbacks, too?

@roberthartung
Copy link
Member Author

@kaspar030 check out my updated comment!

@roberthartung
Copy link
Member Author

@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.

@kaspar030
Copy link
Contributor

Like this? That also looks like a lot of overhead?

Hm, it does, but we do want this fine-grained selection. The alternatives are ifdefs with global defines, weak defaults, ...

Let's try!

@roberthartung
Copy link
Member Author

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.

@roberthartung
Copy link
Member Author

@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 ?

@kaspar030
Copy link
Contributor

@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.

The steps should be

  • add SUBMODULES := 1 to the pm_fallback Makefile
  • move the implementations to "off.c", "set_lowest.c", "reboot.c"
  • add "pm_fallback_%" to makefiles/pseudomodules.mk (or pm_fallback% if there are no always compiled .c files).

See how it is done in core/Makefile.

Do I need to cherry-pick / get anything from #7241 ?

That should be independent. I'll be rebasing it on this one once we're done here. ;)

@roberthartung
Copy link
Member Author

@kaspar030 Okay, had a little typo :/

Only problem now is that I have to add USEMODULE += pm_fallback to be able to do the following:

USEMODULE += pm_fallback_off
USEMODULE += pm_fallback_set_lowest
USEMODULE += pm_fallback_reboot

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:

USEMODULE += pm_fallback_set_lowest
USEMODULE += pm_stm32_common_off
USEMODULE += pm_cortexm_common_reboot

but for now we would have to write the following:

USEMODULE += pm_fallback
USEMODULE += pm_fallback_set_lowest

USEMODULE += pm_stm32_common
USEMODULE += pm_stm32_common_off

USEMODULE += pm_cortexm_common
USEMODULE += pm_cortexm_common_reboot

@kaspar030
Copy link
Contributor

Is there a smarter way to tell the build system that it should include it automatically?

Ah, I forgot: add "pm_fallback" as dependency of "pm_falback_%" (e.g., in Makefile.dep):

ifneq (,$(filter pm_fallback_%,$(USEMODULE)))
  USEMODULE += pm_fallback
endif

@roberthartung
Copy link
Member Author

Additionally: is there a smart way to select all submodues automatically? e.g. pm_fallback will select _off, _set_lowest and _reboot?

@kaspar030
Copy link
Contributor

Where do add it? In each board, cpu, RIOT's Makefile.dep?

If the module is in drivers, drivers/Makefile.dep, otherwise ./Makefile.dep. The module is shared by all (or most) boards, right?

Additionally: is there a smart way to select all submodues automatically? e.g. pm_fallback will select _off, _set_lowest and _reboot?

nope. ;)

@roberthartung
Copy link
Member Author

roberthartung commented Sep 14, 2017

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!

@roberthartung
Copy link
Member Author

@kaspar030 Pushed a submodule-based version. You can have a look now!

@roberthartung roberthartung changed the title Power Management: Proposal for an implementation that uses separate modules pm: WIP for power management that uses submodules Sep 14, 2017
@@ -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
Copy link
Contributor

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?

Copy link
Member Author

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?

@@ -26,6 +26,14 @@
#include "irq.h"
#include "periph/pm.h"

void pm_set_lowest(void) {}
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

ACK

@@ -26,6 +26,14 @@
#include "irq.h"
#include "periph/pm.h"

void pm_set_lowest(void) {}

void pm_off(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

dito

Copy link
Member Author

Choose a reason for hiding this comment

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

ACK

@@ -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
Copy link
Contributor

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

Copy link
Member Author

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

@@ -1,3 +1,7 @@
export CPU_ARCH = cortex-m4f

USEMODULE += pm_cortexm_common_set_lowest
USEMODULE += pm_cortexm_common_off
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so

# use common periph functions
USEMODULE += periph_common
USEMODULE += pm_cortexm_common_set_lowest
Copy link
Contributor

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.

Copy link
Member Author

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!

Copy link
Contributor

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.

Copy link
Member Author

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?

@@ -23,6 +23,14 @@

#include "cpu.h"

void pm_set_lowest(void) {
Copy link
Contributor

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) {}
Copy link
Contributor

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... ;)

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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?

@roberthartung
Copy link
Member Author

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

@roberthartung
Copy link
Member Author

@kaspar030 Can kinetis_common just use the default cortem_common pm implementation? You defined a single power mode here, which will in the end do the same as pm_set_lowest of pm_layered will call pm_set which calls cortexm_sleep(0), but in the end, this is the same as pm_set_lowest from cortexm_common.

@jnohlgard
Copy link
Member

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.

@roberthartung
Copy link
Member Author

roberthartung commented Sep 25, 2017

@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.
@kaspar030 I just committed all the changes requested.

I dont like that I have to use USEMODULE += in Makefile.features, but this was the only possibility to check if the feature exists.

@roberthartung
Copy link
Member Author

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

@cladmi
Copy link
Contributor

cladmi commented Oct 6, 2017

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.

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: pm Area: (Low) power management State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Oct 28, 2017
@kaspar030
Copy link
Contributor

Closed in favor of #7726.

@roberthartung Again, thanks a lot for the work you've put in this!

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 State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants