kernel/sched: Add timing.h support to thread_usage

The runtime stats feature has always supported this, so use the same
kconfig to indirect the timing source in the same way.

(Personally I'm not a fan of the "timing" API, which really doesn't do
anything that the existing core "cycles" API does not except add a
bunch of code due to the separate implementation of frequency
management and conversion routines.  It comes from an era where
"cycles" were fixed to a MHz frequency clock on platforms like x86 yet
we had benchmarks that wanted to use the TSC.  Those days are behind
us and "cycles" can be fast everywhere.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2021-09-28 09:38:43 -07:00 committed by Anas Nashif
commit 52351458f4

View file

@ -17,6 +17,8 @@
#include <logging/log.h>
#include <sys/atomic.h>
#include <sys/math_extras.h>
#include <timing/timing.h>
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
#if defined(CONFIG_SCHED_DUMB)
@ -1746,7 +1748,13 @@ static struct k_spinlock usage_lock;
static uint32_t usage_now(void)
{
uint32_t now = k_cycle_get_32();
uint32_t now;
#ifdef CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS
now = (uint32_t)timing_counter_get();
#else
now = k_cycle_get_32();
#endif
/* Edge case: we use a zero as a null ("stop() already called") */
return (now == 0) ? 1 : now;