From 4b95459483cc36064d0840eaed6dfbaf07dafe24 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Tue, 16 Nov 2021 15:50:37 +0100 Subject: [PATCH] schedstatistics: Convert to ztimer --- sys/Makefile.dep | 2 +- sys/include/schedstatistics.h | 2 +- sys/ps/ps.c | 16 ++++++++-------- sys/schedstatistics/Kconfig | 2 +- sys/schedstatistics/schedstatistics.c | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 613062cc50..d0f856e88a 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -352,7 +352,7 @@ ifneq (,$(filter pthread,$(USEMODULE))) endif ifneq (,$(filter schedstatistics,$(USEMODULE))) - USEMODULE += xtimer + USEMODULE += ztimer_usec USEMODULE += sched_cb endif diff --git a/sys/include/schedstatistics.h b/sys/include/schedstatistics.h index 4e6352bf35..7d10735273 100644 --- a/sys/include/schedstatistics.h +++ b/sys/include/schedstatistics.h @@ -42,7 +42,7 @@ typedef struct { uint32_t laststart; /**< Time stamp of the last time this 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; /** diff --git a/sys/ps/ps.c b/sys/ps/ps.c index 6ebfc0765a..5dbaae1b78 100644 --- a/sys/ps/ps.c +++ b/sys/ps/ps.c @@ -26,7 +26,7 @@ #ifdef MODULE_SCHEDSTATISTICS #include "schedstatistics.h" -#include "xtimer.h" +#include "ztimer.h" #endif #ifdef MODULE_TLSF_MALLOC @@ -77,12 +77,12 @@ void ps(void) #ifdef MODULE_SCHEDSTATISTICS uint64_t rt_sum = 0; 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++) { thread_t *p = thread_get(i); if (p != NULL) { - rt_sum += sched_pidlist[i].runtime_ticks; + rt_sum += sched_pidlist[i].runtime_us; } } #endif /* MODULE_SCHEDSTATISTICS */ @@ -103,10 +103,10 @@ void ps(void) #endif #ifdef MODULE_SCHEDSTATISTICS /* multiply with 100 for percentage and to avoid floats/doubles */ - uint64_t runtime_ticks = sched_pidlist[i].runtime_ticks * 100; - xtimer_ticks32_t xtimer_ticks = {sched_pidlist[i].runtime_ticks}; - unsigned runtime_major = runtime_ticks / rt_sum; - unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum; + uint64_t runtime_us = sched_pidlist[i].runtime_us * 100; + uint32_t ztimer_us = {sched_pidlist[i].runtime_us}; + unsigned runtime_major = runtime_us / rt_sum; + unsigned runtime_minor = ((runtime_us % rt_sum) * 1000) / rt_sum; unsigned switches = sched_pidlist[i].schedules; #endif printf("\t%3" PRIkernel_pid @@ -131,7 +131,7 @@ void ps(void) thread_get_stackstart(p), thread_get_sp(p) #endif #ifdef MODULE_SCHEDSTATISTICS - , runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks) + , runtime_major, runtime_minor, switches, ztimer_us #endif ); } diff --git a/sys/schedstatistics/Kconfig b/sys/schedstatistics/Kconfig index e991199219..22bf74a0d6 100644 --- a/sys/schedstatistics/Kconfig +++ b/sys/schedstatistics/Kconfig @@ -7,6 +7,6 @@ config MODULE_SCHEDSTATISTICS bool "Scheduler statistics support" - depends on MODULE_XTIMER + select ZTIMER_USEC depends on TEST_KCONFIG select MODULE_SCHED_CB diff --git a/sys/schedstatistics/schedstatistics.c b/sys/schedstatistics/schedstatistics.c index 0d23881bf1..892466f4b1 100644 --- a/sys/schedstatistics/schedstatistics.c +++ b/sys/schedstatistics/schedstatistics.c @@ -24,7 +24,7 @@ #include "sched.h" #include "schedstatistics.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 @@ -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) { - uint32_t now = xtimer_now().ticks32; + uint32_t now = ztimer_now(ZTIMER_USEC); /* Update active thread stats */ if (!IS_USED(MODULE_CORE_IDLE_THREAD) || active_thread != KERNEL_PID_UNDEF) { 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 */ @@ -55,7 +55,7 @@ void init_schedstatistics(void) /* Init laststart for the thread starting schedstatistics since the callback wasn't registered when it was first scheduled */ 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; sched_register_cb(sched_statistics_cb); }