kernel: thread: Add k_thread_runtime_stats_cpu_get()

Add k_thread_runtime_stats_cpu_get() to get runtime statistics of
the specified core.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
This commit is contained in:
Jyri Sarha 2024-02-20 21:42:06 +02:00 committed by Fabio Baltieri
commit 28215fc788
2 changed files with 30 additions and 0 deletions

View file

@ -6193,6 +6193,15 @@ int k_thread_runtime_stats_get(k_tid_t thread,
*/
int k_thread_runtime_stats_all_get(k_thread_runtime_stats_t *stats);
/**
* @brief Get the runtime statistics of all threads on specified cpu
*
* @param cpu The cpu number
* @param stats Pointer to struct to copy statistics into.
* @return -EINVAL if null pointers, otherwise 0
*/
int k_thread_runtime_stats_cpu_get(int cpu, k_thread_runtime_stats_t *stats);
/**
* @brief Enable gathering of runtime statistics for specified thread
*

View file

@ -998,6 +998,27 @@ int k_thread_runtime_stats_all_get(k_thread_runtime_stats_t *stats)
return 0;
}
int k_thread_runtime_stats_cpu_get(int cpu, k_thread_runtime_stats_t *stats)
{
if (stats == NULL) {
return -EINVAL;
}
*stats = (k_thread_runtime_stats_t) {};
#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
#ifdef CONFIG_SMP
z_sched_cpu_usage(cpu, stats);
#else
__ASSERT(cpu == 0, "cpu filter out of bounds");
ARG_UNUSED(cpu);
z_sched_cpu_usage(0, stats);
#endif
#endif
return 0;
}
#ifdef CONFIG_THREAD_ABORT_NEED_CLEANUP
/** Pointer to thread which needs to be cleaned up. */
static struct k_thread *thread_to_cleanup;