Browse Source

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>
pull/76156/head
Jyri Sarha 1 year ago committed by Fabio Baltieri
parent
commit
28215fc788
  1. 9
      include/zephyr/kernel.h
  2. 21
      kernel/thread.c

9
include/zephyr/kernel.h

@ -6193,6 +6193,15 @@ int k_thread_runtime_stats_get(k_tid_t thread, @@ -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
*

21
kernel/thread.c

@ -998,6 +998,27 @@ int k_thread_runtime_stats_all_get(k_thread_runtime_stats_t *stats) @@ -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;

Loading…
Cancel
Save