Skip to content

ztimer: relocate PSEUDOMODULES definitions #14123

Merged
fjmolinas merged 3 commits intoRIOT-OS:masterfrom
jue89:fix/ztimer_pseudomodules
Jun 24, 2020
Merged

ztimer: relocate PSEUDOMODULES definitions #14123
fjmolinas merged 3 commits intoRIOT-OS:masterfrom
jue89:fix/ztimer_pseudomodules

Conversation

@jue89
Copy link
Copy Markdown
Contributor

@jue89 jue89 commented May 23, 2020

Contribution description

The discussion in #13661 pointed out that ztimer is the only module touching PSEUDOMUDLES within its Makefile.dep. To be aligned to the current dependency resolution system of RIOT, this PR relocates these definitions.

Testing procedure

  1. env USEMODULE="ztimer xtimer_on_ztimer" make -C tests/xtimer_msg clean all test
  2. env USEMODULE="ztimer ztimer_xtimer_compat" make -C tests/xtimer_msg clean all test
  3. ./dist/tools/buildsystem_sanity_check/check.sh

Issues/PRs references

#13661

@jue89 jue89 requested review from bergzand and kaspar030 as code owners May 23, 2020 14:51
@benpicco benpicco added Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels May 23, 2020
@jue89
Copy link
Copy Markdown
Contributor Author

jue89 commented May 25, 2020

I think @maribu may also should have a look, as he proposed the build system's sanity-check.

@maribu
Copy link
Copy Markdown
Member

maribu commented May 25, 2020

I wonder if it wouldn't be simpler to move the include of pseudomodules.inc.mk from here:

RIOT/Makefile.include

Lines 367 to 369 in 4adb8ab

# mandatory includes!
include $(RIOTMAKE)/pseudomodules.inc.mk
include $(RIOTMAKE)/defaultmodules.inc.mk

below here:

RIOT/Makefile.include

Lines 396 to 397 in 4adb8ab

# process dependencies
include $(RIOTMAKE)/dependency_resolution.inc.mk

The PSEUDOMODULES should not be relevant for the dependency resolution anyway, so we could just process them after and do within pseudomodules.inc.mk stuff like:

ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE))
  # Don't link in xtimer when ztimer_xtimer_compat is used
  PSEUDOMOUDLES += xtimer
endif

@maribu
Copy link
Copy Markdown
Member

maribu commented May 25, 2020

@leandrolanzieri and @fjmolinas, care to share your thoughts on this?

@fjmolinas
Copy link
Copy Markdown
Contributor

@leandrolanzieri and @fjmolinas, care to share your thoughts on this?

Up to recently pseudo-module where declarative I preferred that, so I lean more to what I suggested in #13661 (comment), but its not something I would insist on.

PSEUDOMODULES are already defined in Makefile.includes so I think it makes makes sense to keep these conditional definitions in Makefile.include instead of in pseudomodules.inc.mk. But the problem is that Makefile.include is not included after Makefile.dep for CPUs and BOARDs. So the problem is that now that it is not declarative we care about inclusion order, because of that until this inclusion order is fixed I would have them in pseudomodules.inc.mk as @maribu suggested.

But for me this is just an argument in favor of keeping them declarative.

@fjmolinas
Copy link
Copy Markdown
Contributor

But for me this is just an argument in favor of keeping them declarative.

Declarative IMO is easier to maintain.

Other than that, +1 for the sanity check.

@aabadie aabadie changed the title ztimer: relocate PSEUDOMULDES definitions ztimer: relocate PSEUDOMODULES definitions Jun 23, 2020
@fjmolinas
Copy link
Copy Markdown
Contributor

Seem that my comment unintentionally blocked this one, that was not my intention. I don't really mind either way. We are targeting changing inclusion order pretty soon, I think we can watch out to not to add the conditional PSEUDOMODULES inclusion in BOARD or CPU Makefile.include. And keep this PR as is, @maribu any comments?

@fjmolinas
Copy link
Copy Markdown
Contributor

Seem that my comment unintentionally blocked this one, that was not my intention. I don't really mind either way. We are targeting changing inclusion order pretty soon, I think we can watch out to not to add the conditional PSEUDOMODULES inclusion in BOARD or CPU Makefile.include. And keep this PR as is, @maribu any comments?

@jue89 if you want to take the approach suggested by @maribu I fine as well.

@maribu
Copy link
Copy Markdown
Member

maribu commented Jun 24, 2020

I think there might be something to learn in this for the Kconfig migration. It would be good if one module could "provide" another module. Specifically, ztimer_xtimer_compat would "provide" xtimer. There are more instances of this. E.g. sock_udp could be provided by the GNRC sock API implementation, or by the lwIP sock implementation, or any other network stack implementing the sock API. (Maybe Kconfig does so anyway. But if not, this would likely be a feature we could now implement with little additional effort.)


Update: Fixed typo (no --> now), which changes the meaning of the last sentence

@fjmolinas
Copy link
Copy Markdown
Contributor

I think there might be something to learn in this for the Kconfig migration. It would be good if one module could "provide" another module. Specifically, ztimer_xtimer_compat would "provide" xtimer. There are more instances of this. E.g. sock_udp could be provided by the GNRC sock API implementation, or by the lwIP sock implementation, or any other network stack implementing the sock API. (Maybe Kconfig does so anyway. But if not, this would likely be a feature we could no implement with little additional effort.)

From what I understand what you are referring too will be easy to model in Kconfig, in our current structure what it needs it a module that just represents the api. In the example above that could be xtimer that could be provided by xtimer_on_xtimer or xtimer_on_ztimer. Same for sock_udp. You would have the api and the choice of implementation, that would require having PSEUDOMODULES for those api modules. My suggestion in #13661 (comment) went a little bit in that direction but not quite that.

Anyway, this might be something we will need to address eventually when trying to migrate dependency resolution or otherwise it might be difficult to compare with kconfig. I kconfig terms I could see this as (ping @leandrolanzieri on this :) ):

config MOD_XTIMER
    bool
    depends on MOD_XTIMER_ON_ZTIMER || MOD_XTIMER_ON_XTIMER

@fjmolinas
Copy link
Copy Markdown
Contributor

An the USEMODULE equivalent:

ifneq (,$(filter xtimer,$(USEMODULE)))
  ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
    USEMODULE += xtimer_on_xtimer
  endif
endif

xtimer_on_xtimer would currently still need to do the inclusion of the SRC, or be its own module and xtimer a PSEUDOMODULE.

@fjmolinas
Copy link
Copy Markdown
Contributor

Anyway, my two last comments, are addressing a broader subject than this PR. I still like this PR in the sense that the exception is contained, and a static check is added to avoid it being added in Makefile.dep. The broader subject can be addressed in another PR.

So ACK, on my side @maribu, I take your thumbs up as you being OK with the PR as well. I'll merge tomorrow in case you want to add something else :)

@maribu
Copy link
Copy Markdown
Member

maribu commented Jun 24, 2020

Hmm, I wonder if it might make sense to tread modules and APIs completely independent. So that a module is no longer allowed to depend on a module, but rather on an API. And the xtimer module would just be one implementation of the xtimer API, with the ztimer_xtimer_compat being another implementation of the xtimer API.

This distinction would allow adding alternative implementations of an API later on quite easily. It should also allow detecting conflicts easier. E.g. if two modules provide the same API, they implicitly conflict.

Regarding the PR: I'm fine with merging :-)

Copy link
Copy Markdown
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK.

@fjmolinas fjmolinas merged commit a665fcc into RIOT-OS:master Jun 24, 2020
@fjmolinas
Copy link
Copy Markdown
Contributor

Hmm, I wonder if it might make sense to tread modules and APIs completely independent. So that a module is no longer allowed to depend on a module, but rather on an API. And the xtimer module would just be one implementation of the xtimer API, with the ztimer_xtimer_compat being another implementation of the xtimer API.

This distinction would allow adding alternative implementations of an API later on quite easily. It should also allow detecting conflicts easier. E.g. if two modules provide the same API, they implicitly conflict.

Would be nice to have @leandrolanzieri point of view on this.

@miri64 miri64 added this to the Release 2020.07 milestone Jun 25, 2020
@leandrolanzieri
Copy link
Copy Markdown
Contributor

Hmm, I wonder if it might make sense to tread modules and APIs completely independent. So that a module is no longer allowed to depend on a module, but rather on an API. And the xtimer module would just be one implementation of the xtimer API, with the ztimer_xtimer_compat being another implementation of the xtimer API.
This distinction would allow adding alternative implementations of an API later on quite easily. It should also allow detecting conflicts easier. E.g. if two modules provide the same API, they implicitly conflict.

Yes. I think in Kconfig this can be modelled as features provided by modules. Module A uses the B API in its code, so Module A depends on the feature HAS_B. If Module C and Module D implement the API they provide the feature when included. To make them mutually exclusive though, the symbols should be modelled inside a choice.

config MOD_A
    bool "A support"
    depends on HAS_B

config HAS_B
    bool
    help
        Indicates that B API is implemented.

choice
    bool "B implementation"

config MOD_C
    bool "C"
    select HAS_B

config MOD_D
    bool "D"
    select HAS_B

endchoice

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

Labels

Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants