tracing: remove cpu_stats in favor of thread runtime stats

Removing CONFIG_TRACING_CPU_STATS in favor of
CONFIG_THREAD_RUNTIME_STATS which provides per thread stats. The same
functionality is also available when Thread analyzer is enabled with the
runtime stats enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2021-04-13 16:08:41 -04:00
commit bc747e7167
9 changed files with 5 additions and 282 deletions

View file

@ -136,16 +136,6 @@ latest data from the internal RAM buffer can be loaded into SystemView::
.. _SEGGER SystemView: https://www.segger.com/products/development-tools/systemview/
CPU Stats
=========
A special tracing format which provides information about percentage of CPU
usage based on tracing hooks for threads switching in and out, interrupts enters
and exits (only distinguishes between idle thread, non idle thread and scheduler).
Enable this format with the :option:`CONFIG_TRACING_CPU_STATS` option.
Transport Backends
******************

View file

@ -309,6 +309,11 @@ Libraries / Subsystems
* Tracing
* ``CONFIG_TRACING_CPU_STATS`` was removed in favor of
``CONFIG_THREAD_RUNTIME_STATS`` which provides per thread statistics. The
same functionality is also available when Thread analyzer is enabled with
the runtime statistics enabled.
* Debug
HALs

View file

@ -22,9 +22,6 @@
#ifdef CONFIG_SEGGER_SYSTEMVIEW
#include "tracing_sysview.h"
#elif defined CONFIG_TRACING_CPU_STATS
#include "tracing_cpu_stats.h"
#elif defined CONFIG_TRACING_CTF
#include "tracing_ctf.h"

View file

@ -10,11 +10,6 @@ tests:
tracing.format.sysview:
platform_allow: nrf52840dk_nrf52840 mimxrt1050_evk mimxrt1064_evk
extra_args: CONF_FILE="prj_sysview.conf"
tracing.format.cpu_stats:
platform_allow: nrf52840dk_nrf52840
extra_configs:
- CONFIG_TRACING=y
- CONFIG_TRACING_CPU_STATS=y
tracing.osawareness.openocd:
extra_configs:
- CONFIG_MP_NUM_CPUS=1

View file

@ -21,7 +21,6 @@ OBJECT_TRACING,n
OVERRIDE_FRAME_POINTER_DEFAULT,y
DEBUG_INFO,n
DEBUG_THREAD_INFO,n
TRACING_CPU_STATS,n
TRACING_CTF,n
USE_SEGGER_RTT,n
LOG,n

1 HW_STACK_PROTECTION y
21 OVERRIDE_FRAME_POINTER_DEFAULT y
22 DEBUG_INFO n
23 DEBUG_THREAD_INFO n
TRACING_CPU_STATS n
24 TRACING_CTF n
25 USE_SEGGER_RTT n
26 LOG n

View file

@ -1,10 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_sources_ifdef(
CONFIG_TRACING_CPU_STATS
cpu_stats.c
)
zephyr_sources_ifdef(
CONFIG_TRACING_CORE
tracing_buffer.c

View file

@ -45,16 +45,6 @@ config TRACING_CTF
help
Enable tracing to a Common Trace Format stream.
config TRACING_CPU_STATS
bool "Enable CPU usage tracing"
select TRACING_CORE
help
Module provides information about percent of CPU usage based on
tracing hooks for threads switching in and out, interrupts enters
and exits (only distinguishes between idle thread, non idle thread
and scheduler). Use provided API or enable automatic logging to
get values.
config TRACING_TEST
bool "Tracing for test usage"
select TRACING_CORE
@ -73,20 +63,6 @@ config TRACING_CTF_TIMESTAMP
Timestamp prefix will be added to the beginning of CTF
event internally.
config TRACING_CPU_STATS_LOG
bool "Enable current CPU usage logging"
depends on TRACING_CPU_STATS
help
Periodically displays information about CPU usage.
config TRACING_CPU_STATS_INTERVAL
int "Logging interval for CPU measurements [ms]"
default 2000
depends on TRACING_CPU_STATS_LOG
help
Time period of displaying information about CPU usage.
choice
prompt "Tracing Method"
default TRACING_ASYNC

View file

@ -1,176 +0,0 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <tracing_cpu_stats.h>
#include <sys/printk.h>
#include <kernel_internal.h>
#include <ksched.h>
enum cpu_state {
CPU_STATE_IDLE,
CPU_STATE_NON_IDLE,
CPU_STATE_SCHEDULER
};
static enum cpu_state last_cpu_state = CPU_STATE_SCHEDULER;
static enum cpu_state cpu_state_before_interrupts;
static uint32_t last_time;
static struct cpu_stats stats_hw_tick;
static int nested_interrupts;
static struct k_thread *current_thread;
void update_counter(volatile uint64_t *cnt)
{
uint32_t time = k_cycle_get_32();
if (time >= last_time) {
(*cnt) += (time - last_time);
} else {
(*cnt) += (UINT32_MAX - last_time + 1 + time);
}
last_time = time;
}
static void cpu_stats_update_counters(void)
{
switch (last_cpu_state) {
case CPU_STATE_IDLE:
update_counter(&stats_hw_tick.idle);
break;
case CPU_STATE_NON_IDLE:
update_counter(&stats_hw_tick.non_idle);
break;
case CPU_STATE_SCHEDULER:
update_counter(&stats_hw_tick.sched);
break;
default:
/* Invalid CPU state */
__ASSERT_NO_MSG(false);
break;
}
}
void cpu_stats_get_ns(struct cpu_stats *cpu_stats_ns)
{
int key = irq_lock();
cpu_stats_update_counters();
cpu_stats_ns->idle = k_cyc_to_ns_floor64(stats_hw_tick.idle);
cpu_stats_ns->non_idle = k_cyc_to_ns_floor64(stats_hw_tick.non_idle);
cpu_stats_ns->sched = k_cyc_to_ns_floor64(stats_hw_tick.sched);
irq_unlock(key);
}
uint32_t cpu_stats_non_idle_and_sched_get_percent(void)
{
int key = irq_lock();
cpu_stats_update_counters();
irq_unlock(key);
return ((stats_hw_tick.non_idle + stats_hw_tick.sched) * 100) /
(stats_hw_tick.idle + stats_hw_tick.non_idle +
stats_hw_tick.sched);
}
void cpu_stats_reset_counters(void)
{
int key = irq_lock();
stats_hw_tick.idle = 0;
stats_hw_tick.non_idle = 0;
stats_hw_tick.sched = 0;
last_time = k_cycle_get_32();
irq_unlock(key);
}
void sys_trace_thread_switched_in(void)
{
int key = irq_lock();
__ASSERT_NO_MSG(nested_interrupts == 0);
cpu_stats_update_counters();
current_thread = k_current_get();
if (z_is_idle_thread_object(current_thread)) {
last_cpu_state = CPU_STATE_IDLE;
} else {
last_cpu_state = CPU_STATE_NON_IDLE;
}
irq_unlock(key);
}
void sys_trace_thread_switched_out(void)
{
int key = irq_lock();
__ASSERT_NO_MSG(nested_interrupts == 0);
__ASSERT_NO_MSG(!current_thread || (current_thread == k_current_get()));
cpu_stats_update_counters();
last_cpu_state = CPU_STATE_SCHEDULER;
irq_unlock(key);
}
void sys_trace_isr_enter(void)
{
int key = irq_lock();
if (nested_interrupts == 0) {
cpu_stats_update_counters();
cpu_state_before_interrupts = last_cpu_state;
last_cpu_state = CPU_STATE_NON_IDLE;
}
nested_interrupts++;
irq_unlock(key);
}
void sys_trace_isr_exit(void)
{
int key = irq_lock();
nested_interrupts--;
if (nested_interrupts == 0) {
cpu_stats_update_counters();
last_cpu_state = cpu_state_before_interrupts;
}
irq_unlock(key);
}
void sys_trace_idle(void)
{
}
#ifdef CONFIG_TRACING_CPU_STATS_LOG
static struct k_delayed_work cpu_stats_log;
static void cpu_stats_display(void)
{
printk("CPU usage: %u\n", cpu_stats_non_idle_and_sched_get_percent());
}
static void cpu_stats_log_fn(struct k_work *item)
{
cpu_stats_display();
cpu_stats_reset_counters();
k_delayed_work_submit(&cpu_stats_log,
K_MSEC(CONFIG_TRACING_CPU_STATS_INTERVAL));
}
static int cpu_stats_log_init(const struct device *dev)
{
k_delayed_work_init(&cpu_stats_log, cpu_stats_log_fn);
k_delayed_work_submit(&cpu_stats_log,
K_MSEC(CONFIG_TRACING_CPU_STATS_INTERVAL));
return 0;
}
SYS_INIT(cpu_stats_log_init, APPLICATION, 0);
#endif /* CONFIG_TRACING_CPU_STATS_LOG */

View file

@ -1,58 +0,0 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _TRACE_CPU_STATS_H
#define _TRACE_CPU_STATS_H
#include <kernel.h>
#include <kernel_structs.h>
#include <init.h>
#ifdef __cplusplus
extern "C" {
#endif
struct cpu_stats {
uint64_t idle;
uint64_t non_idle;
uint64_t sched;
};
void sys_trace_thread_switched_in(void);
void sys_trace_thread_switched_out(void);
void sys_trace_isr_enter(void);
void sys_trace_isr_exit(void);
void sys_trace_idle(void);
void cpu_stats_get_ns(struct cpu_stats *cpu_stats_ns);
uint32_t cpu_stats_non_idle_and_sched_get_percent(void);
void cpu_stats_reset_counters(void);
#define sys_trace_isr_exit_to_scheduler()
#define sys_trace_thread_priority_set(thread)
#define sys_trace_thread_info(thread)
#define sys_trace_thread_create(thread)
#define sys_trace_thread_abort(thread)
#define sys_trace_thread_suspend(thread)
#define sys_trace_thread_resume(thread)
#define sys_trace_thread_ready(thread)
#define sys_trace_thread_pend(thread)
#define sys_trace_thread_name_set(thread)
#define sys_trace_void(id)
#define sys_trace_end_call(id)
#define sys_trace_semaphore_init(sem)
#define sys_trace_semaphore_take(sem)
#define sys_trace_semaphore_give(sem)
#define sys_trace_mutex_init(mutex)
#define sys_trace_mutex_lock(mutex)
#define sys_trace_mutex_unlock(mutex)
#ifdef __cplusplus
}
#endif
#endif /* _TRACE_CPU_STATS_H */