sched: Hook SCHED_USAGE from existing tracing hook

On older architectures, we don't have the
architecture-independent/scheduler-internal hooks (which require
USE_SWITCH) but there is a hook shared by the tracing layer we can use.

This is sort of a layering violation (stat tracking is a core feature,
tracing is supposed to be optional), but simple and lightweight.  And
eventually it will go away as these architectures migrate.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2021-09-28 07:59:42 -07:00 committed by Anas Nashif
commit 4ae3250301
3 changed files with 14 additions and 1 deletions

View file

@ -379,7 +379,7 @@ config INSTRUMENT_THREAD_SWITCHING
config SCHED_THREAD_USAGE
bool "Collect thread runtime usage"
depends on USE_SWITCH
select INSTRUMENT_THREAD_SWITCHING if !USE_SWITCH
help
Alternate implementation of thread runtime cycle usage

View file

@ -1737,6 +1737,11 @@ int z_sched_wait(struct k_spinlock *lock, k_spinlock_key_t key,
#ifdef CONFIG_SCHED_THREAD_USAGE
/* Need one of these for this to work */
#if !defined(CONFIG_USE_SWITCH) && !defined(CONFIG_INSTRUMENT_THREAD_SWITCHING)
#error "No data backend configured for CONFIG_SCHED_THREAD_USAGE"
#endif
static struct k_spinlock usage_lock;
static uint32_t usage_now(void)

View file

@ -1006,6 +1006,10 @@ static inline k_ticks_t z_vrfy_k_thread_timeout_expires_ticks(
#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING
void z_thread_mark_switched_in(void)
{
#if defined(CONFIG_SCHED_THREAD_USAGE) && !defined(CONFIG_USE_SWITCH)
z_sched_usage_start(_current);
#endif
#ifdef CONFIG_TRACING
SYS_PORT_TRACING_FUNC(k_thread, switched_in);
#endif
@ -1025,6 +1029,10 @@ void z_thread_mark_switched_in(void)
void z_thread_mark_switched_out(void)
{
#if defined(CONFIG_SCHED_THREAD_USAGE) && !defined(CONFIG_USE_SWITCH)
z_sched_usage_stop();
#endif
#ifdef CONFIG_THREAD_RUNTIME_STATS
#ifdef CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS
timing_t now;