1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-28 22:49:47 +01:00

schedstatistics: Convert to ztimer

This commit is contained in:
Koen Zandberg 2021-11-16 15:50:37 +01:00
parent 76215adef1
commit 4b95459483
No known key found for this signature in database
GPG Key ID: BA1718B37D79F51C
5 changed files with 15 additions and 15 deletions

View File

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

View File

@ -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;
/**

View File

@ -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
);
}

View File

@ -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

View File

@ -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);
}