Skip to content

sys/trickle: migrate from xtimer to ZTIMER_MSEC#16322

Merged
cgundogan merged 3 commits intoRIOT-OS:masterfrom
haukepetersen:opt_trickle_ztimer
Jun 14, 2021
Merged

sys/trickle: migrate from xtimer to ZTIMER_MSEC#16322
cgundogan merged 3 commits intoRIOT-OS:masterfrom
haukepetersen:opt_trickle_ztimer

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

Contribution description

This PR migrates trickle from xtimer to ZTIMER_MSEC. This allows for a) slightly simpler code, and b) for potential energy savings as xtimer can (at one point) be left out of a GNRC build.

The acutal changes are pretty straight forward, no surprises here :-)

Testing procedure

Running the test/trickle test should suffice.

Issues/PRs references

none

@haukepetersen haukepetersen added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 13, 2021
@jue89
Copy link
Copy Markdown
Contributor

jue89 commented Apr 14, 2021

All in all a valid change. But your PR shows up a problem, if just ztimer_msec is required. It tries to back its time by ztimer_periph_timer - but that module is missing. This must be fixed before merging this PR.

@haukepetersen haukepetersen added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 15, 2021
@haukepetersen
Copy link
Copy Markdown
Contributor Author

Yap, but this is IMHO more a generic problem with the ztimer deps. I proposed a generic fix in #16334, lets see if it gets in :-)

@haukepetersen haukepetersen removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 15, 2021
@haukepetersen
Copy link
Copy Markdown
Contributor Author

On top there is a problem in the rpl shell command, as it accesses internals of the trickle data structure directly, very good coding style :-)

But as it seems the calculation of the remaining trickle time is based on a xtimer function that does not exist for ztimer, so there is no easy drop-in replacement. Will need to think of a viable approach to migrate that piece of code.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

After thinking about it, I will adapt this PR as well to be 'dual-timer', so to use ztimer only if its included in the build anyway and fallback to xtimer in any other case...

@kfessel
Copy link
Copy Markdown
Contributor

kfessel commented Apr 15, 2021

#13667

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Adapted this PR to follow the same style as #16340 and #16339: ztimer_msec is now used only if available, whereas the default dependencies are not changed - despite including xtimer as dep only in the case ztimer_msec is not present in the build.

@jue89 This should also rule out the dependency problem we discussed.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

rebased

@github-actions github-actions bot added Area: sys Area: System Area: tests Area: tests and testing framework and removed Area: network Area: Networking labels Jun 11, 2021
@haukepetersen
Copy link
Copy Markdown
Contributor Author

rebased

@cgundogan
Copy link
Copy Markdown
Member

The code changes look reasonable. Just a quick question on how to test this .. I wanted to run the trickle test in tests/ and modified the Makefile to include USEMODULE += ztimer_msec. But I get an error from the linker:

RIOT/sys/ztimer/auto_init.c:224: undefined reference to `ztimer_periph_timer_init'

I was testing with native; is this expected because of missing adaptations?

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jun 11, 2021

RIOT/sys/ztimer/auto_init.c:224: undefined reference to `ztimer_periph_timer_init'

I was testing with native; is this expected because of missing adaptations?

For native you need to also manually include ztimer_usec at the moment.

@cgundogan
Copy link
Copy Markdown
Member

RIOT/sys/ztimer/auto_init.c:224: undefined reference to `ztimer_periph_timer_init'

I was testing with native; is this expected because of missing adaptations?

For native you need to also manually include ztimer_usec at the moment.

mhh, okay. Works with the following diff:

diff --git a/tests/trickle/Makefile b/tests/trickle/Makefile
index 72efd754bc..5512f1cb0d 100644
--- a/tests/trickle/Makefile
+++ b/tests/trickle/Makefile
@@ -1,5 +1,7 @@
 include ../Makefile.tests_common
 
 USEMODULE += trickle
+USEMODULE += ztimer_usec
+USEMODULE += ztimer_msec
 
 include $(RIOTBASE)/Makefile.include

The print output of the test also looks correct. I'd be fine with merging if there are no unresolved discussions (from above).

Copy link
Copy Markdown
Member

@cgundogan cgundogan left a comment

Choose a reason for hiding this comment

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

Reasonable code changes and the tests/trickle test shows expected results.

@cgundogan cgundogan added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Jun 11, 2021
@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Jun 11, 2021
@miri64
Copy link
Copy Markdown
Member

miri64 commented Jun 11, 2021

The Github action figured out just fine that the PR needs squashing. No need to set the label and possibly waste valuable CI time as such ;-).

@haukepetersen
Copy link
Copy Markdown
Contributor Author

squashed.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Some gnrc_networking example builds failed due to sc_gnrc_rpl using the timer member of the trickle timer directly, which lead to conflicts between ztimer and xtimer. I fixed this by pulling in the sc_gnrc_rpl fixes already included in #16339.

gnrc_rpl_instances[i].mop, gnrc_rpl_instances[i].of->ocp,
gnrc_rpl_instances[i].min_hop_rank_inc, gnrc_rpl_instances[i].max_rank_inc);

#if !IS_USED(MODULE_XTIMER)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, if there is no better way to access the current time-to-fire of the timer, then we should probably remove the TC print in both cases. It was there for debugging purposes and is not very important to have that around.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, to my knowledge there is not really a decent way with ztimer to get the TC. Removing all-together sounds good to me, will adapt.

@cgundogan
Copy link
Copy Markdown
Member

The changes still look good after the amendments.

@cgundogan cgundogan merged commit d4997d7 into RIOT-OS:master Jun 14, 2021
@cgundogan cgundogan deleted the opt_trickle_ztimer branch June 14, 2021 11:13
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines 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.

7 participants