1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #17216 from bergzand/pr/ps_schedstatistics/ztimer

schedstatistics: Convert to ztimer
This commit is contained in:
Francisco 2021-12-07 20:22:58 +01:00 committed by GitHub
commit 97b4dd3a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 117 additions and 111 deletions

View File

@ -353,7 +353,7 @@ ifneq (,$(filter pthread,$(USEMODULE)))
endif endif
ifneq (,$(filter schedstatistics,$(USEMODULE))) ifneq (,$(filter schedstatistics,$(USEMODULE)))
USEMODULE += xtimer USEMODULE += ztimer_usec
USEMODULE += sched_cb USEMODULE += sched_cb
endif endif

View File

@ -42,7 +42,7 @@ typedef struct {
uint32_t laststart; /**< Time stamp of the last time this thread was uint32_t laststart; /**< Time stamp of the last time this thread was
scheduled to run */ scheduled to run */
unsigned int schedules; /**< How often the thread was scheduled to run */ unsigned int schedules; /**< How often the thread was scheduled to run */
uint64_t runtime_ticks; /**< The total runtime of this thread in ticks */ uint64_t runtime_us; /**< The total runtime of this thread in microseconds */
} schedstat_t; } schedstat_t;
/** /**

View File

@ -26,7 +26,7 @@
#ifdef MODULE_SCHEDSTATISTICS #ifdef MODULE_SCHEDSTATISTICS
#include "schedstatistics.h" #include "schedstatistics.h"
#include "xtimer.h" #include "ztimer.h"
#endif #endif
#ifdef MODULE_TLSF_MALLOC #ifdef MODULE_TLSF_MALLOC
@ -77,12 +77,12 @@ void ps(void)
#ifdef MODULE_SCHEDSTATISTICS #ifdef MODULE_SCHEDSTATISTICS
uint64_t rt_sum = 0; uint64_t rt_sum = 0;
if (!IS_ACTIVE(MODULE_CORE_IDLE_THREAD)) { if (!IS_ACTIVE(MODULE_CORE_IDLE_THREAD)) {
rt_sum = sched_pidlist[KERNEL_PID_UNDEF].runtime_ticks; rt_sum = sched_pidlist[KERNEL_PID_UNDEF].runtime_us;
} }
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) { for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
thread_t *p = thread_get(i); thread_t *p = thread_get(i);
if (p != NULL) { if (p != NULL) {
rt_sum += sched_pidlist[i].runtime_ticks; rt_sum += sched_pidlist[i].runtime_us;
} }
} }
#endif /* MODULE_SCHEDSTATISTICS */ #endif /* MODULE_SCHEDSTATISTICS */
@ -103,10 +103,10 @@ void ps(void)
#endif #endif
#ifdef MODULE_SCHEDSTATISTICS #ifdef MODULE_SCHEDSTATISTICS
/* multiply with 100 for percentage and to avoid floats/doubles */ /* multiply with 100 for percentage and to avoid floats/doubles */
uint64_t runtime_ticks = sched_pidlist[i].runtime_ticks * 100; uint64_t runtime_us = sched_pidlist[i].runtime_us * 100;
xtimer_ticks32_t xtimer_ticks = {sched_pidlist[i].runtime_ticks}; uint32_t ztimer_us = {sched_pidlist[i].runtime_us};
unsigned runtime_major = runtime_ticks / rt_sum; unsigned runtime_major = runtime_us / rt_sum;
unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum; unsigned runtime_minor = ((runtime_us % rt_sum) * 1000) / rt_sum;
unsigned switches = sched_pidlist[i].schedules; unsigned switches = sched_pidlist[i].schedules;
#endif #endif
printf("\t%3" PRIkernel_pid printf("\t%3" PRIkernel_pid
@ -131,7 +131,7 @@ void ps(void)
thread_get_stackstart(p), thread_get_sp(p) thread_get_stackstart(p), thread_get_sp(p)
#endif #endif
#ifdef MODULE_SCHEDSTATISTICS #ifdef MODULE_SCHEDSTATISTICS
, runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks) , runtime_major, runtime_minor, switches, ztimer_us
#endif #endif
); );
} }

View File

@ -7,6 +7,6 @@
config MODULE_SCHEDSTATISTICS config MODULE_SCHEDSTATISTICS
bool "Scheduler statistics support" bool "Scheduler statistics support"
depends on MODULE_XTIMER select ZTIMER_USEC
depends on TEST_KCONFIG depends on TEST_KCONFIG
select MODULE_SCHED_CB select MODULE_SCHED_CB

View File

@ -24,7 +24,7 @@
#include "sched.h" #include "sched.h"
#include "schedstatistics.h" #include "schedstatistics.h"
#include "thread.h" #include "thread.h"
#include "xtimer.h" #include "ztimer.h"
/** /**
* When core_idle_thread is not active, the KERNEL_PID_UNDEF is used to track * When core_idle_thread is not active, the KERNEL_PID_UNDEF is used to track
@ -34,12 +34,12 @@ schedstat_t sched_pidlist[KERNEL_PID_LAST + 1];
void sched_statistics_cb(kernel_pid_t active_thread, kernel_pid_t next_thread) void sched_statistics_cb(kernel_pid_t active_thread, kernel_pid_t next_thread)
{ {
uint32_t now = xtimer_now().ticks32; uint32_t now = ztimer_now(ZTIMER_USEC);
/* Update active thread stats */ /* Update active thread stats */
if (!IS_USED(MODULE_CORE_IDLE_THREAD) || active_thread != KERNEL_PID_UNDEF) { if (!IS_USED(MODULE_CORE_IDLE_THREAD) || active_thread != KERNEL_PID_UNDEF) {
schedstat_t *active_stat = &sched_pidlist[active_thread]; schedstat_t *active_stat = &sched_pidlist[active_thread];
active_stat->runtime_ticks += now - active_stat->laststart; active_stat->runtime_us += now - active_stat->laststart;
} }
/* Update next_thread stats */ /* Update next_thread stats */
@ -55,7 +55,7 @@ void init_schedstatistics(void)
/* Init laststart for the thread starting schedstatistics since the callback /* Init laststart for the thread starting schedstatistics since the callback
wasn't registered when it was first scheduled */ wasn't registered when it was first scheduled */
schedstat_t *active_stat = &sched_pidlist[thread_getpid()]; schedstat_t *active_stat = &sched_pidlist[thread_getpid()];
active_stat->laststart = xtimer_now().ticks32; active_stat->laststart = ztimer_now(ZTIMER_USEC);
active_stat->schedules = 1; active_stat->schedules = 1;
sched_register_cb(sched_statistics_cb); sched_register_cb(sched_statistics_cb);
} }

View File

@ -10,7 +10,8 @@ ifeq (,$(filter $(BOARD),$(LOW_MEMORY_BOARDS)))
FEATURES_OPTIONAL += periph_spi_reconfigure FEATURES_OPTIONAL += periph_spi_reconfigure
endif endif
USEMODULE += xtimer USEMODULE += ztimer_usec
USEMODULE += ztimer_sec
USEMODULE += shell USEMODULE += shell
USEMODULE += shell_commands USEMODULE += shell_commands
USEMODULE += schedstatistics USEMODULE += schedstatistics

View File

@ -6,5 +6,6 @@ BOARD_INSUFFICIENT_MEMORY := \
atmega328p \ atmega328p \
atmega328p-xplained-mini \ atmega328p-xplained-mini \
nucleo-l011k4 \ nucleo-l011k4 \
samd10-xmini \
stm32f030f4-demo \ stm32f030f4-demo \
# #

View File

@ -5,4 +5,6 @@ CONFIG_MODULE_PERIPH_SPI=y
CONFIG_MODULE_SHELL=y CONFIG_MODULE_SHELL=y
CONFIG_MODULE_SHELL_COMMANDS=y CONFIG_MODULE_SHELL_COMMANDS=y
CONFIG_MODULE_SCHEDSTATISTICS=y CONFIG_MODULE_SCHEDSTATISTICS=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_SEC=y
CONFIG_ZTIMER_USEC=y

View File

@ -24,7 +24,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "xtimer.h" #include "ztimer.h"
#include "shell.h" #include "shell.h"
#include "periph/spi.h" #include "periph/spi.h"
#include "schedstatistics.h" #include "schedstatistics.h"
@ -85,18 +85,15 @@ static void _sched_statistics_trigger(void)
sched_statistics_cb(thread_getpid(), thread_getpid()); sched_statistics_cb(thread_getpid(), thread_getpid());
} }
static xtimer_ticks32_t _sched_ticks(void) static uint32_t _sched_us(void)
{ {
_sched_statistics_trigger(); _sched_statistics_trigger();
xtimer_ticks32_t runtime_ticks = { return sched_pidlist[thread_getpid()].runtime_us;
.ticks32 = sched_pidlist[thread_getpid()].runtime_ticks
};
return runtime_ticks;
} }
static uint32_t _xtimer_diff_usec(xtimer_ticks32_t stop, xtimer_ticks32_t start) static uint32_t _ztimer_diff_usec(uint32_t stop, uint32_t start)
{ {
return xtimer_usec_from_ticks(xtimer_diff(stop, start)); return stop - start;
} }
void print_bytes(char* title, uint8_t* data, size_t len) void print_bytes(char* title, uint8_t* data, size_t len)
@ -266,7 +263,7 @@ int cmd_bench(int argc, char **argv)
(void)argv; (void)argv;
uint32_t start, stop; uint32_t start, stop;
xtimer_ticks32_t sched_start, sched_stop; uint32_t sched_start, sched_stop;
uint32_t sched_diff_us; uint32_t sched_diff_us;
uint32_t sum = 0; uint32_t sum = 0;
uint32_t sched_sum = 0; uint32_t sched_sum = 0;
@ -288,231 +285,231 @@ int cmd_bench(int argc, char **argv)
puts("### Test\t\t\t\tTransfer time\tuser time\n"); puts("### Test\t\t\t\tTransfer time\tuser time\n");
/* 1 - write 1000 times 1 byte */ /* 1 - write 1000 times 1 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
in = spi_transfer_byte(spiconf.dev, spiconf.cs, false, out); in = spi_transfer_byte(spiconf.dev, spiconf.cs, false, out);
(void)in; (void)in;
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 2 - write 1000 times 2 byte */ /* 2 - write 1000 times 2 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_bytes(spiconf.dev, spiconf.cs, false, spi_transfer_bytes(spiconf.dev, spiconf.cs, false,
bench_wbuf, NULL, BENCH_SMALL); bench_wbuf, NULL, BENCH_SMALL);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 3 - write 1000 times 100 byte */ /* 3 - write 1000 times 100 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_bytes(spiconf.dev, spiconf.cs, false, spi_transfer_bytes(spiconf.dev, spiconf.cs, false,
bench_wbuf, NULL, BENCH_LARGE); bench_wbuf, NULL, BENCH_LARGE);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 4 - write 1000 times 1 byte to register */ /* 4 - write 1000 times 1 byte to register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
in = spi_transfer_reg(spiconf.dev, spiconf.cs, BENCH_REGADDR, out); in = spi_transfer_reg(spiconf.dev, spiconf.cs, BENCH_REGADDR, out);
(void)in; (void)in;
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 5 - write 1000 times 2 byte to register */ /* 5 - write 1000 times 2 byte to register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR, spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR,
bench_wbuf, NULL, BENCH_SMALL); bench_wbuf, NULL, BENCH_SMALL);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 6 - write 1000 times 100 byte to register */ /* 6 - write 1000 times 100 byte to register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR, spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR,
bench_wbuf, NULL, BENCH_LARGE); bench_wbuf, NULL, BENCH_LARGE);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 7 - read 1000 times 2 byte */ /* 7 - read 1000 times 2 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_bytes(spiconf.dev, spiconf.cs, false, spi_transfer_bytes(spiconf.dev, spiconf.cs, false,
NULL, bench_rbuf, BENCH_SMALL); NULL, bench_rbuf, BENCH_SMALL);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 8 - read 1000 times 100 byte */ /* 8 - read 1000 times 100 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_bytes(spiconf.dev, spiconf.cs, false, spi_transfer_bytes(spiconf.dev, spiconf.cs, false,
NULL, bench_rbuf, BENCH_LARGE); NULL, bench_rbuf, BENCH_LARGE);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 9 - read 1000 times 2 byte from register */ /* 9 - read 1000 times 2 byte from register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR, spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR,
NULL, bench_rbuf, BENCH_SMALL); NULL, bench_rbuf, BENCH_SMALL);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 10 - read 1000 times 100 byte from register */ /* 10 - read 1000 times 100 byte from register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR, spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR,
NULL, bench_rbuf, BENCH_LARGE); NULL, bench_rbuf, BENCH_LARGE);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 11 - transfer 1000 times 2 byte */ /* 11 - transfer 1000 times 2 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_bytes(spiconf.dev, spiconf.cs, false, spi_transfer_bytes(spiconf.dev, spiconf.cs, false,
bench_wbuf, bench_rbuf, BENCH_SMALL); bench_wbuf, bench_rbuf, BENCH_SMALL);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 12 - transfer 1000 times 100 byte */ /* 12 - transfer 1000 times 100 byte */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_bytes(spiconf.dev, spiconf.cs, false, spi_transfer_bytes(spiconf.dev, spiconf.cs, false,
bench_wbuf, bench_rbuf, BENCH_LARGE); bench_wbuf, bench_rbuf, BENCH_LARGE);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 13 - transfer 1000 times 2 byte from/to register */ /* 13 - transfer 1000 times 2 byte from/to register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR, spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR,
bench_wbuf, bench_rbuf, BENCH_SMALL); bench_wbuf, bench_rbuf, BENCH_SMALL);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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);
sched_sum += sched_diff_us; sched_sum += sched_diff_us;
/* 14 - transfer 1000 times 100 byte from/to register */ /* 14 - transfer 1000 times 100 byte from/to register */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR, spi_transfer_regs(spiconf.dev, spiconf.cs, BENCH_REGADDR,
bench_wbuf, bench_rbuf, BENCH_LARGE); bench_wbuf, bench_rbuf, BENCH_LARGE);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, 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 */ /* 15 - release & acquire the bus 1000 times */
sched_start = _sched_ticks(); sched_start = _sched_us();
start = xtimer_now_usec(); start = ztimer_now(ZTIMER_USEC);
for (int i = 0; i < BENCH_REDOS; i++) { for (int i = 0; i < BENCH_REDOS; i++) {
spi_release(spiconf.dev); spi_release(spiconf.dev);
spi_acquire(spiconf.dev, spiconf.cs, spiconf.mode, spiconf.clk); spi_acquire(spiconf.dev, spiconf.cs, spiconf.mode, spiconf.clk);
} }
stop = xtimer_now_usec(); stop = ztimer_now(ZTIMER_USEC);
sched_stop = _sched_ticks(); sched_stop = _sched_us();
sched_diff_us = _xtimer_diff_usec(sched_stop, sched_start); sched_diff_us = _ztimer_diff_usec(sched_stop, sched_start);
printf("15 - acquire/release %i times:\t\t", BENCH_REDOS); printf("15 - acquire/release %i times:\t\t", BENCH_REDOS);
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;
xtimer_sleep(1); ztimer_sleep(ZTIMER_SEC, 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);
@ -546,19 +543,19 @@ int cmd_spi_gpio(int argc, char **argv)
gpio_init(miso_pin, GPIO_OUT); gpio_init(miso_pin, GPIO_OUT);
gpio_init(mosi_pin, GPIO_OUT); gpio_init(mosi_pin, GPIO_OUT);
xtimer_sleep(1); ztimer_sleep(ZTIMER_SEC, 1);
printf("Command: gpio_set()\n"); printf("Command: gpio_set()\n");
gpio_set(miso_pin); gpio_set(miso_pin);
gpio_set(mosi_pin); gpio_set(mosi_pin);
xtimer_sleep(1); ztimer_sleep(ZTIMER_SEC, 1);
printf("Command: gpio_clear()\n"); printf("Command: gpio_clear()\n");
gpio_clear(miso_pin); gpio_clear(miso_pin);
gpio_clear(mosi_pin); gpio_clear(mosi_pin);
xtimer_sleep(1); ztimer_sleep(ZTIMER_SEC, 1);
printf("Command: spi_init_pins(%i)\n", dev); printf("Command: spi_init_pins(%i)\n", dev);
spi_init_pins(dev); spi_init_pins(dev);

View File

@ -6,4 +6,6 @@ CONFIG_MODULE_PERIPH_SPI=y
CONFIG_MODULE_SHELL=y CONFIG_MODULE_SHELL=y
CONFIG_MODULE_SHELL_COMMANDS=y CONFIG_MODULE_SHELL_COMMANDS=y
CONFIG_MODULE_SCHEDSTATISTICS=y CONFIG_MODULE_SCHEDSTATISTICS=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_SEC=y
CONFIG_ZTIMER_USEC=y

View File

@ -5,6 +5,8 @@ USEMODULE += shell_commands
USEMODULE += ps USEMODULE += ps
USEMODULE += schedstatistics USEMODULE += schedstatistics
USEMODULE += printf_float USEMODULE += printf_float
USEMODULE += ztimer_usec
USEMODULE += ztimer_sec
# For this test we don't want to use the shell version of # For this test we don't want to use the shell version of
# test_utils_interactive_sync, since we want to synchronize before # test_utils_interactive_sync, since we want to synchronize before

View File

@ -25,7 +25,7 @@
#include <shell.h> #include <shell.h>
#include <thread.h> #include <thread.h>
#include <xtimer.h> #include <ztimer.h>
#include "test_utils/interactive_sync.h" #include "test_utils/interactive_sync.h"
@ -44,10 +44,11 @@ static void *_thread_fn(void *arg)
msg_t m1, m2; msg_t m1, m2;
msg_receive(&m1); msg_receive(&m1);
/* generate different loads per thead */ /* generate different loads per thead */
for (int i = 0; i < (10 * (next + 1)); ++i) { for (int i = 0; i < (100 * (next + 1)); ++i) {
_xtimer_now64(); volatile uint32_t now = ztimer_now(ZTIMER_USEC);
(void)now;
} }
xtimer_usleep(XTIMER_BACKOFF * 10); ztimer_sleep(ZTIMER_USEC, 100); /* Sleep for a bit */
msg_send(&m2, pids[next]); msg_send(&m2, pids[next]);
} }
@ -65,7 +66,7 @@ int main(void)
_thread_fn, (void *)i, "thread"); _thread_fn, (void *)i, "thread");
} }
/* sleep for a second, so that `ps` shows some % on idle at the beginning */ /* sleep for a second, so that `ps` shows some % on idle at the beginning */
xtimer_sleep(1); ztimer_sleep(ZTIMER_SEC, 1);
msg_t msg; msg_t msg;
msg_send(&msg, pids[0]); msg_send(&msg, pids[0]);