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/bench_timers: A comprehensive benchmark for periph_timer #8531

Merged
merged 1 commit into from
Jun 11, 2018

Conversation

jnohlgard
Copy link
Member

@jnohlgard jnohlgard commented Feb 7, 2018

Depends on #8733
(Excerpts from the README)

Benchmark test for periph_timer

This test is intended to collect statistics about the runtime delays in the
periph_timer implementation. This tool is mainly intended to detect problems in
the low level driver implementation which can be difficult to detect from
higher level systems such as xtimer.

Test outline

The basic idea of the test is to generate a wide variety of calls to the
periph/timer API, in order to detect problems with the software implementation.
The test consists of a single thread of execution which will set random
timeouts on a periph_timer device. A reference timer is used to measure the
time it takes until the callback is called. The difference between the expected
time and the measured time is computed, and the mean and variance of the
recorded values are calculated. The results are printed as a table on stdout
every 30 seconds. All of the test scenarios used in this application are
based on experience from real world bugs encountered during the development of
RIOT and other systems.

API functions tested

Both timer_set and timer_set_absolute calls are mixed in a random order, to
ensure that both functions are working correctly.

Rescheduling

Some bugs may occur only when the application attempts to replace an already
set timer by calling timer_set again while the timer is running. This is dubbed
"resched" in this application. The application will issue rescheduling timer
calls in the normal operation of the test to catch this class of problems.

Setting stopped timers

Another class of bugs is the kind where a timer is not behaving correctly if it
was stopped before setting a timer target. The timer should set the new target,
but not begin counting towards the target until timer_start is called. This is
covered by this application under the "stopped" category of test inputs.

Avoiding phase lock

The CPU time used for generation and setting of the next timer target in
software is approximately constant across iterations. When the application flow
is driven by the timer under test, via a mutex which is unlocked from the timer
callback, the application will be "phase locked" to the timer under test. This
peculiarity may hide certain implementation race conditions which only occur at
specific phases of the timer ticks. In the test application, this problem is
avoided by inserting random CPU delay loops at key locations:

  • After timer_stop
  • Before timer_set/timer_set_absolute
  • Before timer_start

Estimating benchmark CPU overhead

An estimation of the overhead resulting from the CPU processing delays inside
the benchmarking code is performed during benchmark initialization. The
estimation algorithm attempts to perform the exact same actions that the real
benchmark will perform, but without setting any timers. The measured delay is
assumed to originate in the benchmark code and will be subtracted when
computing the difference between expected and actual values. A warning is
printed when the variance of the estimated CPU overhead is too high, this can
be a sign that some other process is running on the CPU and disrupting the
estimation, or a sign of serious problems inside the timer_read function.

Results

When the test has run for a certain amount of time, the current results will be
presented as a table on stdout. To assist with finding the source of any
discrepancies, the results are split according to three parameters:

  • Function used: timer_set, timer_set_absolute
  • Rescheduled: yes/no
  • Stopped: yes/no

Interpreting timer_read statistics

A separate table is displayed for statistics on timer_read. This table compares
the expected timer under test time after a timer has triggered, against the
actual reported value from timer_read(TIM_TEST_DEV). A positive value means
that the TUT time has passed the timer target time. A negative value means
that, according to the timer under test, the alarm target time has not yet been
reached, even though the timer callback has been executed.

Example output

Below is a short sample of a test of a 32768 Hz timer with a 1 MHz reference:

------------- BEGIN STATISTICS --------------
Limits: mean: [-10, 41], variance: [58, 99]
Target error (actual trigger time - expected trigger time), in reference timer ticks
positive: timer is late, negative: timer is early
=== timer_set running ===
   interval    count       sum       sum_sq    min   max  mean  variance
   1 -    2:   25705    455646      2002373      2    35    17     77
   3 -    4:   25533    457326      1973191      2    35    17     77
   5 -    8:   25412    451046      1970014      2    35    17     77
   9 -   16:   25699    458563      2017198      2    36    17     78
  17 -   32:   25832    457768      2018909      1    35    17     78
  33 -   64:   25758    440454      1978830      1    35    17     76
  65 -  128:   25335    414320      1942196      0    34    16     76
 129 -  256:   25254    367689      1979616     -3    32    14     78
 257 -  512:   25677    285822      2020736     -7    31    11     78
      TOTAL   230205   3788634     18459378     -7    36    16     80

...

The statistics above show that the timer implementation introduces a small
delay on short timers. Note however that it is not clear whether this delay is
in timer_set, or timer_read, but the combined effect of all error sources make
the timer overshoot its target by on average 17 microseconds. The difference
between min and max is close to the expected difference of approximately
1/32768 s = 30.51 µs. The lower min and mean for the longer timer intervals are
most likely caused by a drift between the 1 MHz clock and the 32.768 kHz clocks
inside the CPU, and is expected when using two separate clock sources for the
timers being compared.

Below is a short sample of a test where there is something wrong with the timer
implementation, again a 32768 Hz timer tested with a 1 MHz reference:

=== timer_set_absolute resched ===
   interval    count       sum       sum_sq    min   max  mean  variance
   1 -    2:  152217  82324291  13339518497     38  1071   540  87635  <=== SIC!
   3 -    4:  152199  82254909  13301794832     38  1071   540  87397  <=== SIC!
   5 -    8:  152023  82085454  13264873203     38  1071   539  87256  <=== SIC!
   9 -   16:  152156  82236539  13265351119     38  1071   540  87183  <=== SIC!
  17 -   32:  152639  82606815  13267666812     38  1071   541  86922  <=== SIC!
  33 -   64:  151883  81836155  13268661551     37  1070   538  87361  <=== SIC!
  65 -  128:  152114  82151495  13228100922     36  1070   540  86962  <=== SIC!
 129 -  256:  152363  81806042  13278055359     34  1069   536  87148  <=== SIC!
 257 -  512:  152360  81235185  13303811951     29  1066   533  87318  <=== SIC!
      TOTAL  1369954 738536885 119197349719     29  1071   539  87008  <=== SIC!

We can see that the variance, the maximum error, and the mean are very large.
This particular timer implementation needs some work on its timer_set_absolute
implementation.

@jnohlgard jnohlgard added Area: tests Area: tests and testing framework Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: timers Area: timer subsystems labels Feb 7, 2018
@jnohlgard jnohlgard added this to the Release 2018.04 milestone Feb 7, 2018
@jnohlgard jnohlgard force-pushed the pr/periph-timer-stats branch 3 times, most recently from 1adb576 to 63ba28f Compare March 3, 2018 09:30
@jnohlgard jnohlgard force-pushed the pr/periph-timer-stats branch 2 times, most recently from cefa238 to c959c37 Compare March 5, 2018 15:10
@jnohlgard jnohlgard force-pushed the pr/periph-timer-stats branch 5 times, most recently from e0e34fe to bec4d17 Compare March 12, 2018 13:08
@jnohlgard jnohlgard force-pushed the pr/periph-timer-stats branch 2 times, most recently from 137c001 to a925203 Compare March 18, 2018 07:33
@jnohlgard jnohlgard changed the title tests: Add statistics test for periph_timer tests/bench_periph_timer: A comprehensive benchmark for periph_timer Mar 22, 2018
@jnohlgard
Copy link
Member Author

This is ready for review now.
The simple test it started out as has grown to a very powerful benchmark tool for testing the periph_timer implementation and has been invaluable in verifying the performance of the old and new timer implementation for Kinetis LPTMR in #8814

@jnohlgard jnohlgard added the State: waiting for other PR State: The PR requires another PR to be merged first label Mar 23, 2018
@kYc0o
Copy link
Contributor

kYc0o commented May 29, 2018

@gebart can you squash? I might have time to review this one this evening on Hack'n'ACK.

@jnohlgard
Copy link
Member Author

I won't be able to do it tonight. You may squash and push to my branch if you like

@jnohlgard jnohlgard changed the title tests/bench_periph_timer: A comprehensive benchmark for periph_timer tests/bench_timers: A comprehensive benchmark for periph_timer May 29, 2018
@jnohlgard
Copy link
Member Author

@kYc0o rebased ;)

@smlng
Copy link
Member

smlng commented May 30, 2018

on macOS the benchmark seems to hang, which isn't that surprising bc I regularly have problems with timers on RIOT native and macOS. Output so far, but nothing happening after long wait:

/RIOT/tests/bench_timers/bin/native/tests_bench_timers.elf  
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2018.07-devel-410-g857ea-mobi25.inet.haw-hamburg.de-HEAD)

Statistical benchmark for timers
Running timer test with seed 123 using Tiny Mersenne Twister PRNG.
TEST_MIN = 16
TEST_MAX = 128
TEST_MIN_REL = 0
TEST_MAX_REL = 112
TEST_NUM = 113
log2(TEST_NUM - 1) = 6
state vector elements per variant = 7
number of variants = 8
sizeof(state) = 32 bytes
state vector total memory usage = 1792 bytes
TIM_TEST_DEV = 0, TIM_TEST_FREQ = 1000000, TIM_TEST_CHAN = 0
TIM_REF_DEV  = 0, TIM_REF_FREQ  = 1000000
USE_REFERENCE = 1
TEST_PRINT_INTERVAL_TICKS = 30000000
Expected error variance due to truncation in tick conversion: 0
Calibrating spin delay...
spin_max = 12035
Estimating benchmark overhead...
overhead_target = 9 (s2 = 2)
overhead_read = 9 (s2 = 1)
exp_mask = 00000007
max interval = 255

no table with results, or is this expected?

@smlng
Copy link
Member

smlng commented May 30, 2018

tested on PhyNode, works! Output:

2018-05-30 08:56:27,190 - INFO # Elapsed time:
2018-05-30 08:56:27,192 - INFO #         Reference: 60
2018-05-30 08:56:27,194 - INFO #  Timer under test: 51
2018-05-30 08:56:27,196 - INFO #  Wall clock (RTT): 61
2018-05-30 08:56:27,200 - INFO # ------------- BEGIN STATISTICS --------------
2018-05-30 08:56:27,203 - INFO # ===== Reference timer statistics =====
2018-05-30 08:56:27,207 - INFO # Limits: mean: [-10, 10], variance: [0, 16]
2018-05-30 08:56:27,215 - INFO # Target error (actual trigger time - expected trigger time), in reference timer ticks
2018-05-30 08:56:27,221 - INFO # positive: timer under test is late, negative: timer under test is early
2018-05-30 08:56:27,223 - INFO # === timer_set running ===
2018-05-30 08:56:27,229 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,236 - INFO #    0 -    1:    12594     26036        10055      0     3     2      0
2018-05-30 08:56:27,242 - INFO #    2 -    3:    12664     28225        11251      0     4     2      0
2018-05-30 08:56:27,248 - INFO #    4 -    7:    12581     20359         9444      0     3     1      0
2018-05-30 08:56:27,254 - INFO #    8 -   15:    12575     18777         6201      1     2     1      0
2018-05-30 08:56:27,260 - INFO #   16 -   31:    12681     18986         6305      1     2     1      0
2018-05-30 08:56:27,266 - INFO #   32 -   63:    12549     18708         6156      1     2     1      0
2018-05-30 08:56:27,273 - INFO #   64 -  127:     9694     14469         4772      1     2     1      0
2018-05-30 08:56:27,279 - INFO #       TOTAL     85338    145560       108445      0     4     1      1
2018-05-30 08:56:27,281 - INFO # === timer_set resched ===
2018-05-30 08:56:27,287 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,294 - INFO #    0 -    1:    12679     25870        10132      0     3     2      0
2018-05-30 08:56:27,300 - INFO #    2 -    3:    12456     27365        11092      0     4     2      0
2018-05-30 08:56:27,306 - INFO #    4 -    7:    12818     20544         9534      0     3     1      0
2018-05-30 08:56:27,312 - INFO #    8 -   15:    12638     18626         5988      1     2     1      0
2018-05-30 08:56:27,318 - INFO #   16 -   31:    12600     18520         5920      1     2     1      0
2018-05-30 08:56:27,324 - INFO #   32 -   63:    12537     18475         5937      1     2     1      0
2018-05-30 08:56:27,331 - INFO #   64 -  127:     9477     13963         4486      1     2     1      0
2018-05-30 08:56:27,337 - INFO #       TOTAL     85205    143363       106324      0     4     1      1
2018-05-30 08:56:27,339 - INFO # === timer_set stopped ===
2018-05-30 08:56:27,345 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,352 - INFO #    0 -    1:    12486     11957        17613      0     2     0      1
2018-05-30 08:56:27,358 - INFO #    2 -    3:    12635     17326         6323      0     2     1      0
2018-05-30 08:56:27,364 - INFO #    4 -    7:    12565      1156         1934     -1     1     0      0
2018-05-30 08:56:27,370 - INFO #    8 -   15:    12830      2098         2098      0     1     0      0
2018-05-30 08:56:27,376 - INFO #   16 -   31:    12659      2108         2108      0     1     0      0
2018-05-30 08:56:27,382 - INFO #   32 -   63:    12536      2128         2127      0     1     0      0
2018-05-30 08:56:27,389 - INFO #   64 -  127:     9667      1697         1697      0     1     0      0
2018-05-30 08:56:27,395 - INFO #       TOTAL     85378     38470        51226     -1     2     0      0
2018-05-30 08:56:27,398 - INFO # === timer_set stopped, resched ===
2018-05-30 08:56:27,404 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,410 - INFO #    0 -    1:    12621     12085        17700      0     2     0      1
2018-05-30 08:56:27,416 - INFO #    2 -    3:    12583     17370         6283      0     2     1      0
2018-05-30 08:56:27,423 - INFO #    4 -    7:    12773      1217         1969     -1     1     0      0
2018-05-30 08:56:27,429 - INFO #    8 -   15:    12981      2215         2214      0     1     0      0
2018-05-30 08:56:27,435 - INFO #   16 -   31:    12563      2136         2135      0     1     0      0
2018-05-30 08:56:27,441 - INFO #   32 -   63:    12502      2089         2089      0     1     0      0
2018-05-30 08:56:27,447 - INFO #   64 -  127:     9662      1587         1587      0     1     0      0
2018-05-30 08:56:27,453 - INFO #       TOTAL     85685     38699        51347     -1     2     0      0
2018-05-30 08:56:27,456 - INFO # === timer_set_absolute running ===
2018-05-30 08:56:27,463 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,469 - INFO #   16 -   17:    12645       392         6230     -1     1     0      0
2018-05-30 08:56:27,475 - INFO #   18 -   19:    12672       681         6133     -1     1     0      0
2018-05-30 08:56:27,481 - INFO #   20 -   23:    12656       636         6181     -1     1     0      0
2018-05-30 08:56:27,488 - INFO #   24 -   31:    12697       812         6310     -1     1     0      0
2018-05-30 08:56:27,494 - INFO #   32 -   47:    12427       641         6115     -1     1     0      0
2018-05-30 08:56:27,500 - INFO #   48 -   79:    12498       647         6115     -1     1     0      0
2018-05-30 08:56:27,506 - INFO #   80 -  143:     9664       477         4709     -1     1     0      0
2018-05-30 08:56:27,512 - INFO #       TOTAL     85259      4286        41793     -1     1     0      0
2018-05-30 08:56:27,515 - INFO # === timer_set_absolute resched ===
2018-05-30 08:56:27,522 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,528 - INFO #   16 -   17:    12699       254         6279     -1     1     0      0
2018-05-30 08:56:27,534 - INFO #   18 -   19:    12771       164         6351     -1     1     0      0
2018-05-30 08:56:27,540 - INFO #   20 -   23:    12658        67         6201     -1     1     0      0
2018-05-30 08:56:27,546 - INFO #   24 -   31:    12699        52         6246     -1     1     0      0
2018-05-30 08:56:27,552 - INFO #   32 -   47:    12757       216         6289     -1     1     0      0
2018-05-30 08:56:27,559 - INFO #   48 -   79:    12629        54         6196     -1     1     0      0
2018-05-30 08:56:27,565 - INFO #   80 -  143:     9579        72         4805     -1     1     0      0
2018-05-30 08:56:27,571 - INFO #       TOTAL     85792       879        42367     -1     1     0      0
2018-05-30 08:56:27,574 - INFO # === timer_set_absolute stopped ===
2018-05-30 08:56:27,580 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,587 - INFO #   16 -   17:    12477      2147         2147      0     1     0      0
2018-05-30 08:56:27,593 - INFO #   18 -   19:    12579      2129         2129      0     1     0      0
2018-05-30 08:56:27,599 - INFO #   20 -   23:    12727      2146         2145      0     1     0      0
2018-05-30 08:56:27,605 - INFO #   24 -   31:    12627      2068         2068      0     1     0      0
2018-05-30 08:56:27,611 - INFO #   32 -   47:    12675      2144         2144      0     1     0      0
2018-05-30 08:56:27,617 - INFO #   48 -   79:    12662      2084         2084      0     1     0      0
2018-05-30 08:56:27,624 - INFO #   80 -  143:     9801      1672         1672      0     1     0      0
2018-05-30 08:56:27,630 - INFO #       TOTAL     85548     14390        14389      0     1     0      0
2018-05-30 08:56:27,633 - INFO # === timer_set_absolute stopped, resched ===
2018-05-30 08:56:27,640 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,646 - INFO #   16 -   17:    12623      2079         2079      0     1     0      0
2018-05-30 08:56:27,652 - INFO #   18 -   19:    12427      2064         2064      0     1     0      0
2018-05-30 08:56:27,658 - INFO #   20 -   23:    12704      2095         2095      0     1     0      0
2018-05-30 08:56:27,665 - INFO #   24 -   31:    12547      2107         2107      0     1     0      0
2018-05-30 08:56:27,671 - INFO #   32 -   47:    12665      2147         2147      0     1     0      0
2018-05-30 08:56:27,677 - INFO #   48 -   79:    12702      2052         2051      0     1     0      0
2018-05-30 08:56:27,683 - INFO #   80 -  143:     9670      1580         1580      0     1     0      0
2018-05-30 08:56:27,689 - INFO #       TOTAL     85338     14124        14123      0     1     0      0
2018-05-30 08:56:27,692 - INFO # ===== introspective statistics =====
2018-05-30 08:56:27,696 - INFO # Limits: mean: [-10, 10], variance: [0, 16]
2018-05-30 08:56:27,704 - INFO # self-referencing error (TUT time elapsed - expected TUT interval), in timer under test ticks
2018-05-30 08:56:27,713 - INFO # positive: timer target handling is slow, negative: TUT is dropping ticks or triggering callback early
2018-05-30 08:56:27,720 - INFO # function              count       sum       sum_sq    min   max  mean  variance
2018-05-30 08:56:27,720 - INFO # 
2018-05-30 08:56:27,727 - INFO #          timer_set   341606   -373512       250450     -3     2    -1      0
2018-05-30 08:56:27,733 - INFO #            running    85338    -28712        55857     -2     2     0      0
2018-05-30 08:56:27,740 - INFO #            resched    85205    -27993        55380     -2     2     0      0
2018-05-30 08:56:27,747 - INFO #            stopped    85378   -158001        97582     -3     0    -1      1
2018-05-30 08:56:27,753 - INFO #   stopped, resched    85685   -158806        98336     -3     0    -1      1
2018-05-30 08:56:27,754 - INFO # 
2018-05-30 08:56:27,760 - INFO # timer_set_absolute   341937   -683874            0     -2    -2    -2      0
2018-05-30 08:56:27,767 - INFO #            running    85259   -170518            0     -2    -2    -2      0
2018-05-30 08:56:27,774 - INFO #            resched    85792   -171584            0     -2    -2    -2      0
2018-05-30 08:56:27,780 - INFO #            stopped    85548   -171096            0     -2    -2    -2      0
2018-05-30 08:56:27,787 - INFO #   stopped, resched    85338   -170676            0     -2    -2    -2      0
2018-05-30 08:56:27,791 - INFO # -------------- END STATISTICS ---------------

sums and some values are negative, though - overflow or expected?

@jnohlgard
Copy link
Member Author

The negative values means that the timer fired too early and is an indication of an underlying timer problem. However, it may also be caused by the test runtime overhead being estimated too high (see the output you get when the application is starting)
Since it is only -1 usec i think it falls within the range of expected quantization errors, but it might be worth looking into if you see any timer problems in other applications

@smlng
Copy link
Member

smlng commented May 30, 2018

@gebart thanks for clearing things up!

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

besides the IMHO unrelated issues on macOS, tested ACK.

@smlng
Copy link
Member

smlng commented May 30, 2018

but it might be worth looking into if you see any timer problems in other applications

but then this problem is board specific and related to timer configuration there in, hence does not block this PR but rather shows the value and usefulness of this benchmark 😄

@smlng
Copy link
Member

smlng commented May 30, 2018

murdock is not completely happy, please fix and amend/squash directly

@jnohlgard
Copy link
Member Author

Probably due to the nucleo board renames. Will fix.
It would be interesting to see some result outputs from some non-kinetis boards.

@smlng
Copy link
Member

smlng commented May 30, 2018

mhm, benchmark hangs on remote-revb. I had to use TIMER_DEV(2) for reference, because due to board config and cc2538 features only 16bit timers have a prescaler and can run at any frequency.

Output is:

/RIOT/dist/tools/pyterm/pyterm -p "/dev/tty.SLAB_USBtoUART" -b "115200"
No handlers could be found for logger "root"
2018-05-30 10:09:06,526 - INFO # Connect to serial port /dev/tty.SLAB_USBtoUART
Welcome to pyterm!
Type '/exit' to exit.
2018-05-30 10:09:08,399 - INFO # main(): This is RIOT! (Version: 2018.07-devel-413-g6fb04c7-mobi25.inet.haw-hamburg.de-HEAD)
2018-05-30 10:09:08,405 - INFO # 
2018-05-30 10:09:08,405 - INFO # Statistical benchmark for timers
2018-05-30 10:09:08,406 - INFO # Running timer test with seed 123 using Tiny Mersenne Twister PRNG.
2018-05-30 10:09:08,407 - INFO # TEST_MIN = 16
2018-05-30 10:09:08,407 - INFO # TEST_MAX = 128
2018-05-30 10:09:08,407 - INFO # TEST_MIN_REL = 0
2018-05-30 10:09:08,407 - INFO # TEST_MAX_REL = 112
2018-05-30 10:09:08,408 - INFO # TEST_NUM = 113
2018-05-30 10:09:08,408 - INFO # log2(TEST_NUM - 1) = 6
2018-05-30 10:09:08,408 - INFO # state vector elements per variant = 7
2018-05-30 10:09:08,409 - INFO # number of variants = 8
2018-05-30 10:09:08,409 - INFO # sizeof(state) = 32 bytes
2018-05-30 10:09:08,410 - INFO # state vector total memory usage = 1792 bytes
2018-05-30 10:09:08,410 - INFO # TIM_TEST_DEV = 0, TIM_TEST_FREQ = 1000000, TIM_TEST_CHAN = 0
2018-05-30 10:09:08,411 - INFO # TIM_REF_DEV  = 2, TIM_REF_FREQ  = 1000000
2018-05-30 10:09:08,411 - INFO # USE_REFERENCE = 1
2018-05-30 10:09:08,412 - INFO # TEST_PRINT_INTERVAL_TICKS = 30000000
2018-05-30 10:09:08,413 - INFO # Expected error variance due to truncation in tick conversion: 0
2018-05-30 10:09:08,413 - INFO # Calibrating spin delay...
2018-05-30 10:09:08,413 - INFO # spin_max = 25
2018-05-30 10:09:08,414 - INFO # Estimating benchmark overhead...
2018-05-30 10:09:08,453 - INFO # cb: Warning! ref_state = NULL
2018-05-30 10:09:08,553 - INFO # overhead_target = 15 (s2 = 0)
2018-05-30 10:09:08,553 - INFO # overhead_read = 15 (s2 = 0)
2018-05-30 10:09:08,554 - INFO # exp_mask = 00000007
2018-05-30 10:09:08,554 - INFO # max interval = 255

Note the warning regarding the cb.

@smlng
Copy link
Member

smlng commented May 30, 2018

and here the output for Arduino-mega2560, gets stuck too - here I had to change the frequency to 250kHz for both timers

/RIOT/dist/tools/pyterm/pyterm -p "/dev/tty.wchusbserial14340" -b "9600"
No handlers could be found for logger "root"
2018-05-30 10:12:12,776 - INFO # Connect to serial port /dev/tty.wchusbserial14340
Welcome to pyterm!
Type '/exit' to exit.
2018-05-30 10:12:15,697 - INFO # 

2018-05-30 10:12:15,698 - INFO # random: NO SEED AVAILABLE!
2018-05-30 10:12:15,746 - INFO # main(): This is RIOT! (Version: 2018.07-devel-413-g6fb04c7-mobi25.inet.haw-hamburg.de-HEAD)
2018-05-30 10:12:15,746 - INFO # 
2018-05-30 10:12:15,779 - INFO # Statistical benchmark for timers
2018-05-30 10:12:15,846 - INFO # Running timer test with seed 123 using Tiny Mersenne Twister PRNG.
2018-05-30 10:12:15,880 - INFO # TEST_MIN = 16
2018-05-30 10:12:15,880 - INFO # TEST_MAX = 128
2018-05-30 10:12:15,913 - INFO # TEST_MIN_REL = 0
2018-05-30 10:12:15,914 - INFO # TEST_MAX_REL = 112
2018-05-30 10:12:15,947 - INFO # TEST_NUM = 113
2018-05-30 10:12:15,980 - INFO # log2(TEST_NUM - 1) = 6
2018-05-30 10:12:16,014 - INFO # state vector elements per variant = 7
2018-05-30 10:12:16,047 - INFO # number of variants = 8
2018-05-30 10:12:16,048 - INFO # sizeof(state) = 32 bytes
2018-05-30 10:12:16,114 - INFO # state vector total memory usage = 1792 bytes
2018-05-30 10:12:16,181 - INFO # TIM_TEST_DEV = 0, TIM_TEST_FREQ = 250000, TIM_TEST_CHAN = 0
2018-05-30 10:12:16,215 - INFO # TIM_REF_DEV  = 1, TIM_REF_FREQ  = 250000
2018-05-30 10:12:16,215 - INFO # USE_REFERENCE = 1
2018-05-30 10:12:16,282 - INFO # TEST_PRINT_INTERVAL_TICKS = 7500000
2018-05-30 10:12:16,349 - INFO # Expected error variance due to truncation in tick conversion: 0
2018-05-30 10:12:16,349 - INFO # Calibrating spin delay...
2018-05-30 10:12:16,383 - INFO # spin_max = 140
2018-05-30 10:12:16,418 - INFO # Estimating benchmark overhead...
2018-05-30 10:12:16,568 - INFO # cb: Warning! ref_state = NULL
2018-05-30 10:12:16,930 - INFO # overhead_target = 12 (s2 = 47503)
2018-05-30 10:12:16,964 - INFO # Warning: Variance in CPU estimation is too high
2018-05-30 10:12:16,997 - INFO # overhead_read = 6 (s2 = 0)
2018-05-30 10:12:17,040 - INFO # exp_mask = 00000007
2018-05-30 10:12:17,040 - INFO # max interval = 255

@smlng
Copy link
Member

smlng commented May 30, 2018

oops, sorry Arduino didn't get stuck - just took some time. Here the stats output:

2018-05-30 10:16:25,968 - INFO # Elapsed time:
2018-05-30 10:16:26,001 - INFO #         Reference: 17179
2018-05-30 10:16:26,002 - INFO #  Timer under test: 0
2018-05-30 10:16:26,069 - INFO # ------------- BEGIN STATISTICS --------------
2018-05-30 10:16:26,102 - INFO # ===== Reference timer statistics =====
2018-05-30 10:16:26,136 - INFO # Limits: mean: [-10, 10], variance: [0, 16]
2018-05-30 10:16:26,236 - INFO # Target error (actual trigger time - expected trigger time), in reference timer ticks
2018-05-30 10:16:26,303 - INFO # positive: timer under test is late, negative: timer under test is early
2018-05-30 10:16:26,337 - INFO # === timer_set running ===
2018-05-30 10:16:26,404 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:26,504 - INFO #    0 -    1:      655     -5420          238     -9    -7    -8      0
2018-05-30 10:16:26,571 - INFO #    2 -    3:      671     -3962          936     -9    -5    -5      1
2018-05-30 10:16:26,639 - INFO #    4 -    7:      632     -3130         4803     -9    -1    -4      7
2018-05-30 10:16:26,706 - INFO #    8 -   15:      620     -4234         2080     -9    -4    -6      3
2018-05-30 10:16:26,773 - INFO #   16 -   31:      645     -5412          252     -9    -8    -8      0
2018-05-30 10:16:26,873 - INFO #   32 -   63:      633     -5321          257     -9    -8    -8      0
2018-05-30 10:16:26,940 - INFO #   64 -  127:      506     -4256          208     -9    -8    -8      0
2018-05-30 10:16:27,007 - INFO #       TOTAL      4362    -31735         8965     -9    -1    -7      2
2018-05-30 10:16:27,041 - INFO # === timer_set resched ===
2018-05-30 10:16:27,108 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:27,175 - INFO #    0 -    1:      661     -5563          274     -9    -8    -8      0
2018-05-30 10:16:27,276 - INFO #    2 -    3:      670     -3977          989     -9    -5    -5      1
2018-05-30 10:16:27,343 - INFO #    4 -    7:      698     -3438         5618     -9    -1    -4      8
2018-05-30 10:16:27,410 - INFO #    8 -   15:      719     -4995         2149     -9    -4    -6      2
2018-05-30 10:16:27,477 - INFO #   16 -   31:      678     -5690          265     -9    -8    -8      0
2018-05-30 10:16:27,577 - INFO #   32 -   63:      628     -5265          241     -9    -8    -8      0
2018-05-30 10:16:27,644 - INFO #   64 -  127:      472     -3981          204     -9    -8    -8      0
2018-05-30 10:16:27,711 - INFO #       TOTAL      4526    -32909         8104     -9    -1    -7      1
2018-05-30 10:16:27,745 - INFO # === timer_set stopped ===
2018-05-30 10:16:27,812 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:27,879 - INFO #    0 -    1:      615     -4581         1615    -10    -5    -7      2
2018-05-30 10:16:27,980 - INFO #    2 -    3:      670     -5526          328     -9    -7    -8      0
2018-05-30 10:16:28,047 - INFO #    4 -    7:      655     -3016         2491    -10    -2    -4      3
2018-05-30 10:16:28,114 - INFO #    8 -   15:      691     -6061         1283    -10    -6    -8      1
2018-05-30 10:16:28,181 - INFO #   16 -   31:      675     -6303          227    -10    -9    -9      0
2018-05-30 10:16:28,248 - INFO #   32 -   63:      658     -6163          237    -10    -9    -9      0
2018-05-30 10:16:28,348 - INFO #   64 -  127:      497     -4649          176    -10    -9    -9      0
2018-05-30 10:16:28,415 - INFO #       TOTAL      4461    -36299         6827    -10    -2    -8      1
2018-05-30 10:16:28,449 - INFO # === timer_set stopped, resched ===
2018-05-30 10:16:28,516 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:28,616 - INFO #    0 -    1:      668     -4922         1638    -10    -5    -7      2
2018-05-30 10:16:28,684 - INFO #    2 -    3:      668     -5546          313     -9    -7    -8      0
2018-05-30 10:16:28,751 - INFO #    4 -    7:      602     -2746         2204    -10    -2    -4      3
2018-05-30 10:16:28,818 - INFO #    8 -   15:      674     -5898         1137    -10    -6    -8      1
2018-05-30 10:16:28,885 - INFO #   16 -   31:      661     -6180          231    -10    -9    -9      0
2018-05-30 10:16:28,985 - INFO #   32 -   63:      635     -5954          239    -10    -9    -9      0
2018-05-30 10:16:29,052 - INFO #   64 -  127:      512     -4800          190    -10    -9    -9      0
2018-05-30 10:16:29,120 - INFO #       TOTAL      4420    -36046         6980    -10    -2    -8      1
2018-05-30 10:16:29,153 - INFO # === timer_set_absolute running ===
2018-05-30 10:16:29,220 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:29,321 - INFO #   16 -   17:      664     -6274          297    -10    -9    -9      0
2018-05-30 10:16:29,388 - INFO #   18 -   19:      646     -6071          256    -10    -9    -9      0
2018-05-30 10:16:29,455 - INFO #   20 -   23:      670     -6331          299    -10    -9    -9      0
2018-05-30 10:16:29,522 - INFO #   24 -   31:      644     -6077          281    -10    -9    -9      0
2018-05-30 10:16:29,622 - INFO #   32 -   47:      646     -6093          279    -10    -9    -9      0
2018-05-30 10:16:29,689 - INFO #   48 -   79:      614     -5793          267    -10    -9    -9      0
2018-05-30 10:16:29,757 - INFO #   80 -  143:      503     -4752          223    -10    -9    -9      0
2018-05-30 10:16:29,824 - INFO #       TOTAL      4387    -41391         1902    -10    -9    -9      0
2018-05-30 10:16:29,857 - INFO # === timer_set_absolute resched ===
2018-05-30 10:16:29,957 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:30,025 - INFO #   16 -   17:      645     -6064          258    -10    -9    -9      0
2018-05-30 10:16:30,092 - INFO #   18 -   19:      646     -6101          286    -10    -9    -9      0
2018-05-30 10:16:30,159 - INFO #   20 -   23:      661     -6235          286    -10    -9    -9      0
2018-05-30 10:16:30,226 - INFO #   24 -   31:      657     -6197          283    -10    -9    -9      0
2018-05-30 10:16:30,326 - INFO #   32 -   47:      652     -6142          273    -10    -9    -9      0
2018-05-30 10:16:30,393 - INFO #   48 -   79:      695     -6547          290    -10    -9    -9      0
2018-05-30 10:16:30,461 - INFO #   80 -  143:      490     -4629          219    -10    -9    -9      0
2018-05-30 10:16:30,528 - INFO #       TOTAL      4446    -41915         1895    -10    -9    -9      0
2018-05-30 10:16:30,561 - INFO # === timer_set_absolute stopped ===
2018-05-30 10:16:30,662 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:30,729 - INFO #   16 -   17:      679     -6371          260    -10    -9    -9      0
2018-05-30 10:16:30,796 - INFO #   18 -   19:      657     -6157          244    -10    -9    -9      0
2018-05-30 10:16:30,863 - INFO #   20 -   23:      700     -6552          251    -10    -9    -9      0
2018-05-30 10:16:30,963 - INFO #   24 -   31:      648     -6058          226    -10    -9    -9      0
2018-05-30 10:16:31,030 - INFO #   32 -   47:      683     -6382          234    -10    -9    -9      0
2018-05-30 10:16:31,098 - INFO #   48 -   79:      649     -6075          234    -10    -9    -9      0
2018-05-30 10:16:31,165 - INFO #   80 -  143:      510     -4772          180    -10    -9    -9      0
2018-05-30 10:16:31,265 - INFO #       TOTAL      4526    -42367         1629    -10    -9    -9      0
2018-05-30 10:16:31,299 - INFO # === timer_set_absolute stopped, resched ===
2018-05-30 10:16:31,366 - INFO #    interval     count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:31,433 - INFO #   16 -   17:      641     -6011          242    -10    -9    -9      0
2018-05-30 10:16:31,533 - INFO #   18 -   19:      674     -6324          258    -10    -9    -9      0
2018-05-30 10:16:31,600 - INFO #   20 -   23:      626     -5859          225    -10    -9    -9      0
2018-05-30 10:16:31,667 - INFO #   24 -   31:      660     -6164          222    -10    -9    -9      0
2018-05-30 10:16:31,735 - INFO #   32 -   47:      689     -6455          253    -10    -9    -9      0
2018-05-30 10:16:31,835 - INFO #   48 -   79:      650     -6100          250    -10    -9    -9      0
2018-05-30 10:16:31,902 - INFO #   80 -  143:      518     -4853          191    -10    -9    -9      0
2018-05-30 10:16:31,969 - INFO #       TOTAL      4458    -41766         1641    -10    -9    -9      0
2018-05-30 10:16:32,003 - INFO # ===== introspective statistics =====
2018-05-30 10:16:32,036 - INFO # Limits: mean: [-10, 10], variance: [0, 16]
2018-05-30 10:16:32,137 - INFO # self-referencing error (TUT time elapsed - expected TUT interval), in timer under test ticks
2018-05-30 10:16:32,271 - INFO # positive: timer target handling is slow, negative: TUT is dropping ticks or triggering callback early
2018-05-30 10:16:32,338 - INFO # function              count       sum       sum_sq    min   max  mean  variance
2018-05-30 10:16:32,338 - INFO # 
2018-05-30 10:16:32,405 - INFO #          timer_set    17610    -44300        53004     -4     4    -2      3
2018-05-30 10:16:32,506 - INFO #            running     4409     -8974        12001     -3     4    -2      2
2018-05-30 10:16:32,573 - INFO #            resched     4439     -9138        12142     -3     4    -2      2
2018-05-30 10:16:32,673 - INFO #            stopped     4339    -12940        15643     -4     2    -2      3
2018-05-30 10:16:32,740 - INFO #   stopped, resched     4423    -13248        13218     -4     2    -2      2
2018-05-30 10:16:32,741 - INFO # 
2018-05-30 10:16:32,841 - INFO # timer_set_absolute    17663    -70652            0     -4    -4    -4      0
2018-05-30 10:16:32,908 - INFO #            running     4314    -17256            0     -4    -4    -4      0
2018-05-30 10:16:32,975 - INFO #            resched     4369    -17476            0     -4    -4    -4      0
2018-05-30 10:16:33,076 - INFO #            stopped     4511    -18044            0     -4    -4    -4      0
2018-05-30 10:16:33,143 - INFO #   stopped, resched     4469    -17876            0     -4    -4    -4      0
2018-05-30 10:16:33,202 - INFO # -------------- END STATISTICS ---------------

@jnohlgard
Copy link
Member Author

jnohlgard commented May 30, 2018

The cb warning comes up when the callback is called on the reference timer, which should not happen because we don't set a target for it.
The atmega timer implementation seem to have some troubles with the callback being run too soon

@kYc0o
Copy link
Contributor

kYc0o commented Jun 4, 2018

Apparently nucleo-f031k6 hasn't enough memory for this, @gebart can you add it to the blacklist to finally merge this? I think it's ready.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

The nucleo 32 boards involved in this PR needs to have their name updated. That's probably why Murdock is failing.

# CFLAGS configuration to build properly
SINGLE_TIMER_BOARDS = \
native \
nucleo32-f031 \
Copy link
Contributor

@aabadie aabadie Jun 4, 2018

Choose a reason for hiding this comment

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

This PR still uses the old nucleo board names. Here it should be nucleo-f031k8 nucleo-f031k6 and below nucleo-f042k8 nucleo-f042k6

# with the default settings of TEST_MIN and TEST_MAX, so DETAILED_STATS will be
# disabled by default for these boards unless explicitly enabled
SMALL_RAM_BOARDS = \
nucleo32-f031 \
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

This test is intended to collect statistics about the runtime delays in
the periph_timer implementation. This tool is mainly intended to detect
problems in the low level driver implementation which can be difficult
to detect from higher level systems such as xtimer.
@jnohlgard
Copy link
Member Author

@aabadie Corrected the names of the nucleo boards

@jnohlgard jnohlgard merged commit 2006937 into RIOT-OS:master Jun 11, 2018
@jnohlgard jnohlgard deleted the pr/periph-timer-stats branch June 11, 2018 11:19
@cladmi cladmi modified the milestone: Release 2018.07 Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: tests Area: tests and testing framework 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 Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants