tracing: Add sys_trace_idle_exit call

Add new tracing API which is called when core is exiting from idle.
Current implementation is using it to track CPU load. Implementation
in tracing_none is now weak so it can be used if given backend does
not support new API call.

When CONFIG_CPU_LOAD is enabled then sys_trace_idle also calls a
hook which stores the timing information when CPU entered idle.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2025-02-04 10:40:53 +01:00 committed by Fabio Baltieri
commit 4cbafc6bd4
11 changed files with 76 additions and 9 deletions

View file

@ -2718,6 +2718,12 @@
#if defined(CONFIG_PERCEPIO_TRACERECORDER)
#include "tracing_tracerecorder.h"
/**
* @brief Called when the cpu exits the idle state
*/
void sys_trace_idle_exit(void);
#else
/**
* @brief Called when entering an ISR
@ -2738,6 +2744,12 @@ void sys_trace_isr_exit_to_scheduler(void);
* @brief Called when the cpu enters the idle state
*/
void sys_trace_idle(void);
/**
* @brief Called when the cpu exits the idle state
*/
void sys_trace_idle_exit(void);
#endif /* CONFIG_PERCEPIO_TRACERECORDER */
/**

View file

@ -48,11 +48,9 @@ zephyr_sources_ifdef(
endif()
if(NOT CONFIG_PERCEPIO_TRACERECORDER AND NOT CONFIG_TRACING_CTF
AND NOT CONFIG_SEGGER_SYSTEMVIEW AND NOT CONFIG_TRACING_TEST
AND NOT CONFIG_TRACING_USER)
zephyr_sources(tracing_none.c)
endif()
zephyr_sources(
tracing_none.c
)
zephyr_sources_ifdef(
CONFIG_TRACING_OBJECT_TRACKING

View file

@ -13,6 +13,7 @@
#include <zephyr/net/socket_poll.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/debug/cpu_load.h>
static void _get_thread_name(struct k_thread *thread,
ctf_bounded_string_t *name)
@ -189,6 +190,16 @@ void sys_trace_isr_exit_to_scheduler(void)
void sys_trace_idle(void)
{
ctf_top_idle();
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_enter_idle();
}
}
void sys_trace_idle_exit(void)
{
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_exit_idle();
}
}
/* Semaphore */

View file

@ -368,6 +368,7 @@ extern "C" {
#define sys_trace_sys_init_exit(...)
void sys_trace_idle(void);
void sys_trace_idle_exit(void);
void sys_trace_isr_enter(void);
void sys_trace_isr_exit(void);

View file

@ -6,6 +6,7 @@
#include <zephyr/kernel.h>
#include <zephyr/kernel_structs.h>
#include <zephyr/init.h>
#include <zephyr/debug/cpu_load.h>
#include <ksched.h>
#include <SEGGER_SYSVIEW.h>
@ -64,6 +65,17 @@ void sys_trace_isr_exit_to_scheduler(void)
void sys_trace_idle(void)
{
SEGGER_SYSVIEW_OnIdle();
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_enter_idle();
}
}
void sys_trace_idle_exit(void)
{
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_exit_idle();
}
}
void sys_trace_named_event(const char *name, uint32_t arg0, uint32_t arg1)

View file

@ -655,6 +655,7 @@ void sys_trace_thread_info(struct k_thread *thread);
SEGGER_SYSVIEW_RecordEndCall(TID_SYSCALL)
void sys_trace_idle(void);
void sys_trace_idle_exit(void);
void sys_trace_k_thread_create(struct k_thread *new_thread, size_t stack_size, int prio);
void sys_trace_k_thread_user_mode_enter(k_thread_entry_t entry, void *p1, void *p2, void *p3);

View file

@ -204,6 +204,11 @@ void sys_trace_idle(void)
TRACING_STRING("%s\n", __func__);
}
void sys_trace_idle_exit(void)
{
TRACING_STRING("%s\n", __func__);
}
void sys_trace_k_condvar_broadcast_enter(struct k_condvar *condvar)
{
TRACING_STRING("%s: %p\n", __func__, condvar);

View file

@ -480,6 +480,7 @@
#define sys_port_trace_pm_device_runtime_disable_exit(dev, ret)
void sys_trace_idle(void);
void sys_trace_idle_exit(void);
void sys_trace_isr_enter(void);
void sys_trace_isr_exit(void);

View file

@ -3,12 +3,25 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/tracing/tracing.h>
#include <zephyr/debug/cpu_load.h>
__weak void sys_trace_isr_enter(void) {}
void sys_trace_isr_enter(void) {}
__weak void sys_trace_isr_exit(void) {}
void sys_trace_isr_exit(void) {}
__weak void sys_trace_isr_exit_to_scheduler(void) {}
void sys_trace_isr_exit_to_scheduler(void) {}
__weak void sys_trace_idle(void)
{
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_enter_idle();
}
}
void sys_trace_idle(void) {}
__weak void sys_trace_idle_exit(void)
{
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_exit_idle();
}
}

View file

@ -7,6 +7,7 @@
#include <tracing_user.h>
#include <zephyr/kernel.h>
#include <zephyr/debug/cpu_load.h>
#include <zephyr/init.h>
void __weak sys_trace_thread_create_user(struct k_thread *thread) {}
@ -143,6 +144,17 @@ void sys_trace_isr_exit(void)
void sys_trace_idle(void)
{
sys_trace_idle_user();
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_enter_idle();
}
}
void sys_trace_idle_exit(void)
{
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
cpu_load_on_exit_idle();
}
}
void sys_trace_sys_init_enter(const struct init_entry *entry, int level)

View file

@ -46,6 +46,7 @@ void sys_trace_thread_pend(struct k_thread *thread);
void sys_trace_isr_enter(void);
void sys_trace_isr_exit(void);
void sys_trace_idle(void);
void sys_trace_idle_exit(void);
void sys_trace_sys_init_enter(const struct init_entry *entry, int level);
void sys_trace_sys_init_exit(const struct init_entry *entry, int level, int result);