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

tests/periph_timer: Cleanup #14808

Closed
wants to merge 2 commits into from
Closed

Conversation

maribu
Copy link
Member

@maribu maribu commented Aug 20, 2020

Contribution description

  • (ab)use XTIMER_HZ instead of a manual list for timer frequencies
  • Use C11 atomics instead of incorrectly using volatile

Testing procedure

Test should still work as previously. In fact, the manual list of timer frequencies seems to be identical to the definition of XTIMER_HZ for every board.

Issues/PRs references

Split out of #14799

Abusing the volatile qualifier for synchronization doesn't work, instead
C11 atomics must be used.
@maribu maribu requested a review from aabadie August 20, 2020 12:29
@maribu maribu added Area: tests Area: tests and testing framework Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels Aug 20, 2020
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 20, 2020
static volatile uint32_t timeouts[MAX_CHANNELS];
static volatile unsigned args[MAX_CHANNELS];
#ifndef XTIMER_HZ
#define XTIMER_HZ MHZ(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor style improvement.

Suggested change
#define XTIMER_HZ MHZ(1)
#define XTIMER_HZ MHZ(1)

I can try on usb-kw41z, remote, hifive1b.

@aabadie
Copy link
Contributor

aabadie commented Aug 20, 2020

The test now fails on usb-kw41z (but works on master):

main(): This is RIOT! (Version: 2020.10-devel-874-g467996-review_tests_periph_timer)

Test for peripheral TIMERs

Available timers: 2

Testing TIMER_0:
TIMER_0: initialization successful
TIMER_0: stopped
TIMER_0: set channel 0 to 5000
TIMER_0: starting
TIMER_0: channel 0 fired at SW count     6858 - init:     6858

Testing TIMER_1:
TIMER_1: ERROR on initialization - skipping


TEST FAILED
Timeout in expect script at "child.expect_exact('TIMER_{}: initialization successful'.format(timer))" (tests/periph_timer/tests/01-run.py:18)

#include <stdlib.h>

#include "macros/units.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include "macros/units.h"
#include "board.h"
#include "macros/units.h"

This fixes the failing test on usb-kw41z (and probably on other boards)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I'll fix tonight. (Feel free to (force) push instead, of you want.)

@maribu maribu removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 20, 2020
@aabadie
Copy link
Contributor

aabadie commented Aug 20, 2020

It's also broken on remote (cc2538) based boards: they don't define XTIMER_HZ but requires CLOCK_CORECLOCK instead of MHZ(1). We can set XTIMER_HZ for them, but I'm not sure if that makes sense to enable it globally this way.

fix for usb-kw41z, hifive1b and remote
diff --git a/boards/common/remote/include/board_common.h b/boards/common/remote/include/board_common.h
index acb1d8a6fa..6eef086471 100644
--- a/boards/common/remote/include/board_common.h
+++ b/boards/common/remote/include/board_common.h
@@ -78,6 +78,7 @@
  * @name xtimer configuration
  * @{
  */
+#define XTIMER_HZ           (CLOCK_CORECLOCK)
 #define XTIMER_WIDTH        (16)
 #define XTIMER_BACKOFF      (50)
 #define XTIMER_ISR_BACKOFF  (40)
diff --git a/tests/periph_timer/main.c b/tests/periph_timer/main.c
index 806ea8dc30..660661f0b4 100644
--- a/tests/periph_timer/main.c
+++ b/tests/periph_timer/main.c
@@ -23,6 +23,8 @@
 #include <stdatomic.h>
 #include <stdlib.h>
 
+#include "board.h"
+
 #include "macros/units.h"
 #include "periph/timer.h"
 

@aabadie
Copy link
Contributor

aabadie commented Aug 20, 2020

@fjmolinas any opinion on #14808 (comment) ? (you know cc2538 boards quite well).

@fjmolinas
Copy link
Contributor

I don't think I like 752c6da:

  • using XTIMER_HZ in a test for timers is weird
  • XTIMER_HZ will probably be 1MHZ, there are boards with timers that run at 32Khz, but that timer is not used for XTIMER. This change will make the test break for those timers.

@maribu
Copy link
Member Author

maribu commented Aug 20, 2020

using XTIMER_HZ in a test for timers is weird

I agree. But that would be consistent with the other timer tests. Manually maintaining lists for each test is IMO not an option either; at least we should deduplicate this to only maintain one list for all tests.

@maribu
Copy link
Member Author

maribu commented Aug 20, 2020

I wonder if CLOCK_CORECLOCK would work for all boards, except those using 32.678 kHz. If so, maybe the easiest would be to modify the test to just always use CLOCK_CORECLOCK and fall back to 32.678 kHz when timer_init() fails.

@@ -2,42 +2,4 @@ include ../Makefile.tests_common

FEATURES_REQUIRED = periph_timer

BOARDS_TIMER_25kHz := \
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW this should have been 250kHz :)

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW this should have been 250kHz :)

Also noticed that and even opened a PR until I noticed that #14799 was removing it...

@fjmolinas
Copy link
Contributor

I wonder if CLOCK_CORECLOCK would work for all boards, except those using 32.678 kHz. If so, maybe the easiest would be to modify the test to just always use CLOCK_CORECLOCK and fall back to 32.678 kHz when timer_init() fails.

I'm unaware if for all platforms the timer speed can be the same as the core clock speed.

@fjmolinas
Copy link
Contributor

fjmolinas commented Aug 20, 2020

I'm unaware if for all platforms the timer speed can be the same as the core clock speed.

If you want to try it out I can run the test on a series of boards.

@aabadie
Copy link
Contributor

aabadie commented Sep 28, 2020

Needs rebase. What's the state of this PR btw ?

@maribu
Copy link
Member Author

maribu commented Sep 28, 2020

What's the state of this PR btw ?

I dislike the approach in this PR. I think it would be better to extend the API of periph_timer to allow querying supported frequencies. That might be useful for platform independent apps anyway, and would clean up this test quite a bit. (And without resorting to abuse XTIMER_HZ for selecting the test frequency.)

Most importantly however, this would allow to iterate over supported frequencies and verify that the timer implementation indeed works for every supported frequency. E.g. currently running periph_timer on CPU speed on the Nucleo-F767zi doesn't work at all, see #15072. Testing all frequencies would ease detecting those issues.

@maribu maribu closed this Sep 28, 2020
@maribu maribu deleted the periph_timer_xtimer_hz branch May 27, 2022 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework 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.

3 participants