From bc747e716750fa5ef2e301890c7e3ac9c8eeb03a Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 13 Apr 2021 16:08:41 -0400 Subject: [PATCH] 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 --- doc/guides/tracing/index.rst | 10 -- doc/releases/release-notes-2.6.rst | 5 + include/tracing/tracing.h | 3 - samples/subsys/tracing/sample.yaml | 5 - scripts/kconfig/hardened.csv | 1 - subsys/tracing/CMakeLists.txt | 5 - subsys/tracing/Kconfig | 24 --- subsys/tracing/cpu_stats.c | 176 --------------------- subsys/tracing/include/tracing_cpu_stats.h | 58 ------- 9 files changed, 5 insertions(+), 282 deletions(-) delete mode 100644 subsys/tracing/cpu_stats.c delete mode 100644 subsys/tracing/include/tracing_cpu_stats.h diff --git a/doc/guides/tracing/index.rst b/doc/guides/tracing/index.rst index 4baba702743..942b67992f6 100644 --- a/doc/guides/tracing/index.rst +++ b/doc/guides/tracing/index.rst @@ -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 ****************** diff --git a/doc/releases/release-notes-2.6.rst b/doc/releases/release-notes-2.6.rst index 65770493a7d..319c3021e62 100644 --- a/doc/releases/release-notes-2.6.rst +++ b/doc/releases/release-notes-2.6.rst @@ -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 diff --git a/include/tracing/tracing.h b/include/tracing/tracing.h index 4b6522111ef..d58e631b401 100644 --- a/include/tracing/tracing.h +++ b/include/tracing/tracing.h @@ -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" diff --git a/samples/subsys/tracing/sample.yaml b/samples/subsys/tracing/sample.yaml index ef92547f861..ad1a38ef647 100644 --- a/samples/subsys/tracing/sample.yaml +++ b/samples/subsys/tracing/sample.yaml @@ -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 diff --git a/scripts/kconfig/hardened.csv b/scripts/kconfig/hardened.csv index f62cae137a6..e1fe65dff24 100644 --- a/scripts/kconfig/hardened.csv +++ b/scripts/kconfig/hardened.csv @@ -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 diff --git a/subsys/tracing/CMakeLists.txt b/subsys/tracing/CMakeLists.txt index dbe9988f041..8face71b093 100644 --- a/subsys/tracing/CMakeLists.txt +++ b/subsys/tracing/CMakeLists.txt @@ -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 diff --git a/subsys/tracing/Kconfig b/subsys/tracing/Kconfig index b9cc0c0a23d..e8c80d5c582 100644 --- a/subsys/tracing/Kconfig +++ b/subsys/tracing/Kconfig @@ -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 diff --git a/subsys/tracing/cpu_stats.c b/subsys/tracing/cpu_stats.c deleted file mode 100644 index dc01d02e049..00000000000 --- a/subsys/tracing/cpu_stats.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2018 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -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 */ diff --git a/subsys/tracing/include/tracing_cpu_stats.h b/subsys/tracing/include/tracing_cpu_stats.h deleted file mode 100644 index feeb7707ceb..00000000000 --- a/subsys/tracing/include/tracing_cpu_stats.h +++ /dev/null @@ -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 -#include -#include - -#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 */