kernel/sched: Add an optional "all" counter for thread_usage
Tally the runtime of all non-idle threads. Make it optional via kconfig to avoid overhead. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
4ae3250301
commit
b62d6e17a4
3 changed files with 27 additions and 2 deletions
|
@ -172,6 +172,10 @@ struct z_kernel {
|
|||
#if defined(CONFIG_THREAD_MONITOR)
|
||||
struct k_thread *threads; /* singly linked list of ALL threads */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
|
||||
uint64_t all_thread_usage;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct z_kernel _kernel_t;
|
||||
|
|
|
@ -383,6 +383,12 @@ config SCHED_THREAD_USAGE
|
|||
help
|
||||
Alternate implementation of thread runtime cycle usage
|
||||
|
||||
config SCHED_THREAD_USAGE_ALL
|
||||
bool "Collect total system runtime usage"
|
||||
default y if SCHED_THREAD_USAGE
|
||||
help
|
||||
Maintain a sum of all non-idle thread cycle usage.
|
||||
|
||||
menuconfig THREAD_RUNTIME_STATS
|
||||
bool "Thread runtime statistics"
|
||||
select INSTRUMENT_THREAD_SWITCHING
|
||||
|
|
|
@ -1767,7 +1767,14 @@ void z_sched_usage_stop(void)
|
|||
uint32_t u0 = _current_cpu->usage0;
|
||||
|
||||
if (u0 != 0) {
|
||||
_current->base.usage += usage_now() - u0;
|
||||
uint32_t dt = usage_now() - u0;
|
||||
|
||||
#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
|
||||
if (!z_is_idle_thread_object(_current)) {
|
||||
_kernel.all_thread_usage += dt;
|
||||
}
|
||||
#endif
|
||||
_current->base.usage += dt;
|
||||
}
|
||||
|
||||
_current_cpu->usage0 = 0;
|
||||
|
@ -1781,7 +1788,15 @@ uint64_t z_sched_thread_usage(struct k_thread *thread)
|
|||
uint64_t ret = thread->base.usage;
|
||||
|
||||
if (u0 != 0) {
|
||||
ret += now - u0;
|
||||
uint32_t dt = now - u0;
|
||||
|
||||
#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
|
||||
if (!z_is_idle_thread_object(thread)) {
|
||||
_kernel.all_thread_usage += dt;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret += dt;
|
||||
thread->base.usage = ret;
|
||||
_current_cpu->usage0 = now;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue