Merge pull request #14108 from benpicco/tests/periph_spi-enhance
tests/periph_spi: add benchmark for acquire / release
This commit is contained in:
commit
ba20272fb3
@ -94,6 +94,11 @@ static xtimer_ticks32_t _sched_ticks(void)
|
|||||||
return runtime_ticks;
|
return runtime_ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t _xtimer_diff_usec(xtimer_ticks32_t stop, xtimer_ticks32_t start)
|
||||||
|
{
|
||||||
|
return xtimer_usec_from_ticks(xtimer_diff(stop, start));
|
||||||
|
}
|
||||||
|
|
||||||
void print_bytes(char* title, uint8_t* data, size_t len)
|
void print_bytes(char* title, uint8_t* data, size_t len)
|
||||||
{
|
{
|
||||||
printf("%4s\n", title);
|
printf("%4s\n", title);
|
||||||
@ -306,8 +311,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 1 - write %i times %i byte:", BENCH_REDOS, 1);
|
printf(" 1 - write %i times %i byte:", BENCH_REDOS, 1);
|
||||||
printf("\t\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -322,8 +326,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 2 - write %i times %i byte:", BENCH_REDOS, BENCH_SMALL);
|
printf(" 2 - write %i times %i byte:", BENCH_REDOS, BENCH_SMALL);
|
||||||
printf("\t\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -338,8 +341,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 3 - write %i times %i byte:", BENCH_REDOS, BENCH_LARGE);
|
printf(" 3 - write %i times %i byte:", BENCH_REDOS, BENCH_LARGE);
|
||||||
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -354,8 +356,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 4 - write %i times %i byte to register:", BENCH_REDOS, 1);
|
printf(" 4 - write %i times %i byte to register:", BENCH_REDOS, 1);
|
||||||
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -370,8 +371,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 5 - write %i times %i byte to register:", BENCH_REDOS, BENCH_SMALL);
|
printf(" 5 - write %i times %i byte to register:", BENCH_REDOS, BENCH_SMALL);
|
||||||
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -386,8 +386,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 6 - write %i times %i byte to register:", BENCH_REDOS, BENCH_LARGE);
|
printf(" 6 - write %i times %i byte to register:", BENCH_REDOS, BENCH_LARGE);
|
||||||
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -402,8 +401,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 7 - read %i times %i byte:", BENCH_REDOS, BENCH_SMALL);
|
printf(" 7 - read %i times %i byte:", BENCH_REDOS, BENCH_SMALL);
|
||||||
printf("\t\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -418,8 +416,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 8 - read %i times %i byte:", BENCH_REDOS, BENCH_LARGE);
|
printf(" 8 - read %i times %i byte:", BENCH_REDOS, BENCH_LARGE);
|
||||||
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -434,8 +431,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf(" 9 - read %i times %i byte from register:", BENCH_REDOS, BENCH_SMALL);
|
printf(" 9 - read %i times %i byte from register:", BENCH_REDOS, BENCH_SMALL);
|
||||||
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -450,8 +446,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf("10 - read %i times %i byte from register:", BENCH_REDOS, BENCH_LARGE);
|
printf("10 - read %i times %i byte from register:", BENCH_REDOS, BENCH_LARGE);
|
||||||
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -466,8 +461,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf("11 - transfer %i times %i byte:", BENCH_REDOS, BENCH_SMALL);
|
printf("11 - transfer %i times %i byte:", BENCH_REDOS, BENCH_SMALL);
|
||||||
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -482,8 +476,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf("12 - transfer %i times %i byte:", BENCH_REDOS, BENCH_LARGE);
|
printf("12 - transfer %i times %i byte:", BENCH_REDOS, BENCH_LARGE);
|
||||||
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -498,8 +491,7 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf("13 - transfer %i times %i byte to register:", BENCH_REDOS, BENCH_SMALL);
|
printf("13 - transfer %i times %i byte to register:", BENCH_REDOS, BENCH_SMALL);
|
||||||
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("\t%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
@ -514,13 +506,31 @@ int cmd_bench(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
stop = xtimer_now_usec();
|
stop = xtimer_now_usec();
|
||||||
sched_stop = _sched_ticks();
|
sched_stop = _sched_ticks();
|
||||||
sched_diff_us = xtimer_usec_from_ticks(xtimer_diff(sched_stop,
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
sched_start));
|
|
||||||
printf("14 - transfer %i times %i byte to register:", BENCH_REDOS, BENCH_LARGE);
|
printf("14 - transfer %i times %i byte to register:", BENCH_REDOS, BENCH_LARGE);
|
||||||
printf("%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
printf("%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
sum += (stop - start);
|
sum += (stop - start);
|
||||||
sched_sum += sched_diff_us;
|
sched_sum += sched_diff_us;
|
||||||
|
|
||||||
|
/* 15 - release & acquire the bus 1000 times */
|
||||||
|
sched_start = _sched_ticks();
|
||||||
|
start = xtimer_now_usec();
|
||||||
|
for (int i = 0; i < BENCH_REDOS; i++) {
|
||||||
|
spi_release(spiconf.dev);
|
||||||
|
if (spi_acquire(spiconf.dev, spiconf.cs, spiconf.mode, spiconf.clk) != SPI_OK) {
|
||||||
|
puts("ERROR - spi_acquire() failed.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop = xtimer_now_usec();
|
||||||
|
sched_stop = _sched_ticks();
|
||||||
|
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start);
|
||||||
|
printf("15 - acquire/release %i times:\t\t", BENCH_REDOS);
|
||||||
|
printf("%"PRIu32"\t%"PRIu32"\n", (stop - start), sched_diff_us);
|
||||||
|
sum += (stop - start);
|
||||||
|
sched_sum += sched_diff_us;
|
||||||
|
|
||||||
|
|
||||||
xtimer_sleep(1);
|
xtimer_sleep(1);
|
||||||
|
|
||||||
printf("-- - SUM:\t\t\t\t\t%"PRIu32"\t%"PRIu32"\n", sum, sched_sum);
|
printf("-- - SUM:\t\t\t\t\t%"PRIu32"\t%"PRIu32"\n", sum, sched_sum);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user