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

sys/ztimer: add ZTIMER_SEC #15715

Closed
wants to merge 10 commits into from
Closed

sys/ztimer: add ZTIMER_SEC #15715

wants to merge 10 commits into from

Conversation

maribu
Copy link
Member

@maribu maribu commented Jan 7, 2021

Contribution description

Wired up ZTIMER_SEC to the existing RTC backend, or RTT backend, or periph_timer backend (in this order of preference).

Testing procedure

  • tests/ztimer_msg has been updated to allow testing ZTIMER_SEC. Note: Uncomment a line in the Makefile as documented there
  • tests/ztimer_underflow has been updated to allow testing ZTIMER_SEC
    • Run make TEST_ZTIMER_CLOCK=ZTIMER_SEC -C tests/ztimer_underflow flash test
    • This fails for me, which proves two things: a) wiring up the RTC worked, and b) there is a preexisting bug in master unrelated to the PR that needs fixing.

Issues/PRs references

None

@maribu maribu added Area: sys Area: System Area: timers Area: timer subsystems labels Jan 7, 2021
@maribu
Copy link
Member Author

maribu commented Jan 7, 2021

@kfessel might want to have a look at this

static ztimer_convert_frac_t _ztimer_convert_frac_sec;
ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super;
ztimer_clock_t *const ZTIMER_SEC_BASE = &_ztimer_periph_timer_msec.super;
# define ZTIMER_SEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok to use this symbol here? doesn't it need the rtt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I changed the preprocessor conditional to only uses this if both ztimer_msec and ztimer_periph_rtt are used.

Maybe it makes sense to decouple this from ztimer_msec to also profit from the power savings when ztimer_sec but not ztimer_msec is used. I'll fix this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. RTT is now used for ZTIMER_SEC when available regardless of ZTIMER_MSEC, unless the application/user explicitly pulled in ztimer_periph_rtc.

@kaspar030
Copy link
Contributor

Long overdue! But I think we should try to not use RTC. On most platforms, it shares the same hardware with RTT anyways (requiring to chose one). Also the RTC interface is clumsy to use if only a seconds granularity counter is desired (like in this case).

So, please change to use RTT as preference (possibly a converted ZTIMER_MSEC), and only fall back to RTC if no RTT is available.

@kaspar030
Copy link
Contributor

kaspar030 commented Jan 7, 2021

This fails for me, which proves two things: a) wiring up the RTC worked, and b) there is a preexisting bug in master unrelated to the PR that needs fixing.

Yeah, the RTC backend probably doesn't yet deal with setting 0 or 1 properly. It would need to set at least +2 to be safe.

@maribu
Copy link
Member Author

maribu commented Jan 7, 2021

So, please change to use RTT as preference (possibly a converted ZTIMER_MSEC), and only fall back to RTC if no RTT is available.

Hmm, if one pulls in ztimer_periph_rtc, IMO we really should use this for ZTIMER_SEC. So far there is no logic that every pulls in ztimer_periph_rtc, so it is up to the user to add this module. And for the reasons you provided against using the RTC, I don't think we should automatically pull it in.

Btw.: Shouldn't we (unrelated of this PR) use FEATURES_OPTIONAL += periph_rtt for ztimer_msec and ztimer_sec and automatically use ztimer_periph_rtt if periph_rtt is used?

@maribu
Copy link
Member Author

maribu commented Jan 7, 2021

Oh, I chose the wrong commit with --fixup=. I hope I remember to manually squash to fix this :-D

@kaspar030
Copy link
Contributor

Btw.: Shouldn't we (unrelated of this PR) use FEATURES_OPTIONAL += periph_rtt for ztimer_msec and ztimer_sec and automatically use ztimer_periph_rtt if periph_rtt is used?

That's an FAQ by now. The issue is that if ztimer_periph_rtt is used, it'll be used for ztimer_msec. But not all periph_rtt can actually do 1000 or 1024 Hz (or are configured that way). I think we need to add more fine-grained rtt capabilities as features.

@maribu maribu requested a review from vincent-d January 12, 2021 15:42
@maribu
Copy link
Member Author

maribu commented Jan 12, 2021

I think we need to add more fine-grained rtt capabilities as features.

👍

Copy link
Contributor

@kfessel kfessel left a comment

Choose a reason for hiding this comment

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

I did not want to respond without measuring. Yesterday i found my nucleo-l073rz having a IDD bride. I tested different configuration (non extra, rtt, rtc, rtt and rtc). Not every configuration could be built first I fixed that, patch attached an added the pm_layerd configuration for ZTIMER_SEC

i will add the patch later

@maribu
Copy link
Member Author

maribu commented Feb 5, 2021

@kfessel: Care to also squash when rebasing?

@kfessel kfessel force-pushed the ztimer_sec branch 2 times, most recently from 75b1781 to 13cbca8 Compare February 5, 2021 14:33
# ifdef MODULE_PM_LAYERED
LOG_DEBUG("ztimer_init(): ZTIMER_SEC setting required_pm_mode to %i\n",
CONFIG_ZTIMER_SEC_REQUIRED_PM_MODE);
ZTIMER_SEC->required_pm_mode = CONFIG_ZTIMER_SEC_REQUIRED_PM_MODE;
Copy link
Member Author

Choose a reason for hiding this comment

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

@kfessel: Can you take a look at #15911 I think this needs to be applied to the hardware clock. In case of the RTC, this is already the hardware clock, but in case of RTT, it should be applied to the RTT clock sitting below the convert frac clock.

Copy link
Contributor

@kfessel kfessel Feb 5, 2021

Choose a reason for hiding this comment

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

you are right and while writing that lines i thought this is wrong but its the current way to go and i was already searching if there is an issue or PR in this direction.
so these PRs are in "conflict". one has to merged the other has to follow

@kfessel
Copy link
Contributor

kfessel commented Feb 5, 2021

my Test Example

IDD on nucleo-l073rz waitfor rtc or rtt 1.5µA (30€ Multimeter)

ztimer_pm.zip

@kfessel
Copy link
Contributor

kfessel commented Feb 9, 2021

with restructure for flexibility i also fixed the issue of #15911

@kfessel
Copy link
Contributor

kfessel commented Feb 9, 2021

uncrustify keeps calling out:
sys/include/ztimer.h#L295
it thinks the * is an operation but it is a pointer-marker (i like the space after the * but it is to my understanding against the uncrustify rules)

@kfessel
Copy link
Contributor

kfessel commented Mar 4, 2021

the fixup also adds the comments
@fjmolinas: you are right the "rename reorder uncrustify" is a fixup but i also think its title is better matching (and much easyser to see in qgit fixup can be anything

@kfessel
Copy link
Contributor

kfessel commented Mar 4, 2021

uncrustfy is just plain wrong wrong about sys/include/ztimer.h#L297 and sys/include/ztimer.h#L309 its against the riot uncrustfy rules

and no one in their right mind would consider to do that

--- a/sys/include/ztimer/config.h
+++ b/sys/include/ztimer/config.h
@@ -109,10 +109,10 @@ extern "C" {
 #ifndef CONFIG_ZTIMER_TIMER_REQUIRED_PM_MODE
 #  ifdef CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE
 #    define CONFIG_ZTIMER_TIMER_REQUIRED_PM_MODE \
-            CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE
+    CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE
 #  else
 #    define CONFIG_ZTIMER_TIMER_REQUIRED_PM_MODE \
-            ZTIMER_CLOCK_NO_REQUIRED_PM_MODE
+    ZTIMER_CLOCK_NO_REQUIRED_PM_MODE
 #  endif
 #endif

it kills the last bit of readablity that was left (after a line breake that it sugested there for 2-5 chars

@kaspar030
Copy link
Contributor

uncrustfy is just plain wrong wrong about sys/include/ztimer.h#L297 and sys/include/ztimer.h#L309 its against the riot uncrustfy rules

uncrustify is currently only warning. just use up-to-date uncrustify and ignore the warnings.

it kills the last bit of readablity that was left (after a line breake that it sugested there for 2-5 chars

main reason to use uncrustify is to not deal with formatting anymore but still have consistent looks. right now, that might be at the cost of some readability sometimes.

@maribu
Copy link
Member Author

maribu commented Mar 4, 2021

Maybe we could configure uncrustify to never ever suggest a line break. We have other tools already complaining about long lines and I agree that uncrustify really does a poor job at breaking lines.

@kaspar030
Copy link
Contributor

Maybe we could configure uncrustify to never ever suggest a line break. We have other tools already complaining about long lines and I agree that uncrustify really does a poor job at breaking lines.

I do like being able to do "strg-f" (my shortcut for uncrustify) and be done with it, and enjoy not going through a CI static-test fail/look at/manually fix cycle...

We should definitely update the uncrustify on CI. if it takes too long to go to 2020.04 LTS, maybe self-compile the latest version.

@kfessel
Copy link
Contributor

kfessel commented Mar 4, 2021

but even the version that comes with 2020.10 wants to make that define less readable

ATM i think changing CONFIG_ZTIMER_TIMER_REQUIRED_PM_MODE to CONFIG_ZTIMER_TIM_REQ_PM_MODE to cicumvent that uncrustify problem

for the gcc warning you can state don't do that here, is there something that does it for uncrustify

@maribu
Copy link
Member Author

maribu commented Mar 4, 2021

I do like being able to do "strg-f" (my shortcut for uncrustify) and be done with it, and enjoy not going through a CI static-test fail/look at/manually fix cycle...

Add set cc=101 to your .vimrc / init.vim and you'll never accidentally surpass the limit.

Also: uncrustify still is at 80 chars (not 100). Fixing this would solve the issue at hand.

But generally: The coding convention only recommends to keep lines shorter than up to 100 chars - as otherwise this sets and insensitive to use short but unreadable names.

@kfessel
Copy link
Contributor

kfessel commented Mar 4, 2021

I do like being able to do "strg-f" (my shortcut for uncrustify) and be done with it, and enjoy not going through a CI static-test fail/look at/manually fix cycle...

Add set cc=101 to your .vimrc / init.vim and you'll never accidentally surpass the limit.

Also: uncrustify still is at 80 chars (not 100). Fixing this would solve the issue at hand.

But generally: The coding convention only recommends to keep lines shorter than up to 100 chars - as otherwise this sets and insensitive to use short but unreadable names.

so i remove the linebreakes and ignore the uncrustify?

@kaspar030
Copy link
Contributor

ATM i think changing CONFIG_ZTIMER_TIMER_REQUIRED_PM_MODE to CONFIG_ZTIMER_TIM_REQ_PM_MODE to cicumvent that uncrustify problem

you can also use code-style-ignore comments.

@maribu
Copy link
Member Author

maribu commented Mar 4, 2021

so i remove the linebreakes and ignore the uncrustify?

Let's wait a bit. I'll PR a change to 100 chars. That should go in without discussion, as our coding convention was updated to allow this and we just forgot to also touch uncrustify. Maybe the issue is gone with that already.

@kfessel
Copy link
Contributor

kfessel commented Mar 5, 2021

#16149 will update riot-uncrustify to 100 chars (riot-coding convention)

@kfessel
Copy link
Contributor

kfessel commented Mar 5, 2021

just checked the complains by uncrustify:
-it is wrong about wrong about sys/include/ztimer.h#L297 and sys/include/ztimer.h#L309 , changing to suggestion breaks the rule written in config (there is no multipication in that line)
-sys/include/ztimer/config.h#L108 #L119 #L130 are complient with riot coding convention of upto 100 chars in a line
breaking them hinders readability (especially if the uncrustify indention-suggestion is used)

maribu and others added 10 commits March 8, 2021 15:11
wire up ZTIMER_SEC to the existing RTC backend, or RTT backend, or periph_timer
backend (in this order of preference).

Update sys/ztimer/auto_init.c

Co-authored-by: Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
rename ztimer_periph_timer_rtt for readability
fix debugmessage
reorder defines
MSEC and SEC are now usable on TIMER(0) without having USEC
pm is configured by used hardware
    OLD configuration values are translated for backward compatibility
better go for readybility and convention than uncrustify
@kfessel
Copy link
Contributor

kfessel commented Mar 8, 2021

rebased for uncrustify config update

@maribu
Copy link
Member Author

maribu commented Mar 9, 2021

At this point I'm still formally author of this PR, but haven't really authored much of the changes. IMO it would make sense if I close the PR and @kfessel opens a new one with the current state (which references this one). This would IMO better document the development history and authorship.

@kfessel
Copy link
Contributor

kfessel commented Mar 17, 2021

Please continue the review in #16172

@maribu maribu deleted the ztimer_sec branch March 31, 2021 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants