tests/periph_gpio: added benchmark capabilities#8040
tests/periph_gpio: added benchmark capabilities#8040kaspar030 merged 3 commits intoRIOT-OS:masterfrom
Conversation
tests/periph_gpio/main.c
Outdated
| #include "periph/gpio.h" | ||
| #include "xtimer.h" | ||
|
|
||
| #define BENCH_RUNS_DEFAULT (1000 * 1000UL) |
There was a problem hiding this comment.
I think this needs to be 1000UL * 1000
tests/periph_gpio/main.c
Outdated
| gpio_t pin = GPIO_PIN(atoi(argv[1]), atoi(argv[2])); | ||
| unsigned long runs = BENCH_RUNS_DEFAULT; | ||
| if (argc > 3) { | ||
| runs = (unsigned long)atoi(argv[3]); |
There was a problem hiding this comment.
The return value needs to be checked (for >0). Otherwise, later on, this can lead to div by zero. (atio() returns 0 for non-number strings...)
There was a problem hiding this comment.
And maybe use atol() or atoll() so 16bitter can do more than 2^15?
tests/periph_gpio/main.c
Outdated
| unsigned state = irq_disable(); | ||
| time = xtimer_now_usec(); | ||
| for (unsigned long i = 0; i < runs; i++) { | ||
| __asm("nop"); |
There was a problem hiding this comment.
__asm__, and maybe add volatile?
tests/periph_gpio/main.c
Outdated
| irq_restore(state); | ||
| bench_print_time(time, runs, "gpio_read"); | ||
|
|
||
|
|
tests/periph_gpio/main.c
Outdated
| state = irq_disable(); | ||
| time = xtimer_now_usec(); | ||
| for (unsigned long i = 0; i < runs; i++) { | ||
| int tmp = gpio_read(pin); |
There was a problem hiding this comment.
why save the return and then void it? does it prevent optimizing the function call away?
tests/periph_gpio/main.c
Outdated
| bench_print_time(time, runs, "gpio_write"); | ||
|
|
||
| /* gpio_read */ | ||
| state = irq_disable(); |
There was a problem hiding this comment.
would it, in this case, make sense to create a BENCHMARK(name, runs, command) macro?
4abcba6 to
d823ff1
Compare
|
Addressed comments and introduced an independent benchmark module for running this type of trivial function timing benchmarks. This makes the code much nicer to read, indeed. Making use of the benchmak modules in other tests (e.g. |
|
I have been thinking about something similar to this benchmark module using the Cortex-M systick timer to measure actual cycles. However, that would be a platform specific hack if I ever get around to implementing it. It could be useful to be able to measure the overhead in ISRs or other low level functionality. |
|
I think for the Cortex tick counter, it would make sense to write a (sub) module to the cortexm_common code, which allows to use this capability in an easy way. This would indeed be very useful thing! |
d823ff1 to
2bfdade
Compare
|
rebased. @kaspar030 what do you say? |
kaspar030
left a comment
There was a problem hiding this comment.
I think the benchmark print function needs to use stdint types. Other than that, looks good. will do a test run now.
sys/benchmark/benchmark.c
Outdated
| uint32_t div = (time - (full * runs)) / (runs / 1000); | ||
|
|
||
| printf("%11s: %9luus --- %2u.%03uus per call\n", name, | ||
| (unsigned long) time, (unsigned)full, (unsigned)div); |
There was a problem hiding this comment.
better use PRIu32 et al ...
| * @} | ||
| */ | ||
|
|
||
| #include <stdio.h> |
There was a problem hiding this comment.
here and below: usually we put a new line after system headers
There was a problem hiding this comment.
I usually do this, too, but in cases where there is only a small (roughly up to 2 or 3 ) includes in a file I tend to put them in a single block, as I think its quite ugly to have a single include per 'newline separated block'... But will fix this here to make you happy :-)
|
Tested, works flawlessly. Feel free to directly squash the printf fixes. |
2bfdade to
0262530
Compare
|
rebased, squashed, and fixed style and printf issues pointed out above. |
|
triggered Mudock (forgot earlier...) |
0262530 to
563002a
Compare
|
fixed style issues in the bench python script (as pointed out by the |
563002a to
542b4a9
Compare
|
fixed, should be all good now. |
|
nope, still not good: |
|
ups, missed that one. |
This commit enables the GPIO benchmark to be run automatically (through 'make bench') using pexpect.
542b4a9 to
9b557d2
Compare
|
next try (squashed fix right in) |
|
Let's go! |
|
I'll give travis another chance. Different cppcheck versions? |
Yeah, and it complains about timex.h, thus unrelated. |
alternative to #7478
Instead of adding a dedicated benchmark application this PR simply adds the same functionality as shell command to the existing
periph_gpiotest application (as done some time ago also for theperiph_spitest). For convenience and potentially more advanced improvements I added also amake benchtarget using pexpect. This way one can (semi-) automatically run the benchmark on any platform.I know there is a 1000 things that can be build upon this (and possible also improved), but I'd like to get this in in the current state for now and we can always improve this later. But it is quite useful already and I prefer this solution over #7478.