Skip to content

Commit 4cbafc6

Browse files
nordic-krchfabiobaltieri
authored andcommitted
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>
1 parent c7d7aac commit 4cbafc6

File tree

11 files changed

+76
-9
lines changed

11 files changed

+76
-9
lines changed

include/zephyr/tracing/tracing.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,12 @@
27182718

27192719
#if defined(CONFIG_PERCEPIO_TRACERECORDER)
27202720
#include "tracing_tracerecorder.h"
2721+
2722+
/**
2723+
* @brief Called when the cpu exits the idle state
2724+
*/
2725+
void sys_trace_idle_exit(void);
2726+
27212727
#else
27222728
/**
27232729
* @brief Called when entering an ISR
@@ -2738,6 +2744,12 @@ void sys_trace_isr_exit_to_scheduler(void);
27382744
* @brief Called when the cpu enters the idle state
27392745
*/
27402746
void sys_trace_idle(void);
2747+
2748+
/**
2749+
* @brief Called when the cpu exits the idle state
2750+
*/
2751+
void sys_trace_idle_exit(void);
2752+
27412753
#endif /* CONFIG_PERCEPIO_TRACERECORDER */
27422754

27432755
/**

subsys/tracing/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ zephyr_sources_ifdef(
4848

4949
endif()
5050

51-
if(NOT CONFIG_PERCEPIO_TRACERECORDER AND NOT CONFIG_TRACING_CTF
52-
AND NOT CONFIG_SEGGER_SYSTEMVIEW AND NOT CONFIG_TRACING_TEST
53-
AND NOT CONFIG_TRACING_USER)
54-
zephyr_sources(tracing_none.c)
55-
endif()
51+
zephyr_sources(
52+
tracing_none.c
53+
)
5654

5755
zephyr_sources_ifdef(
5856
CONFIG_TRACING_OBJECT_TRACKING

subsys/tracing/ctf/ctf_top.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/net/socket_poll.h>
1414
#include <zephyr/net/net_if.h>
1515
#include <zephyr/net/net_pkt.h>
16+
#include <zephyr/debug/cpu_load.h>
1617

1718
static void _get_thread_name(struct k_thread *thread,
1819
ctf_bounded_string_t *name)
@@ -189,6 +190,16 @@ void sys_trace_isr_exit_to_scheduler(void)
189190
void sys_trace_idle(void)
190191
{
191192
ctf_top_idle();
193+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
194+
cpu_load_on_enter_idle();
195+
}
196+
}
197+
198+
void sys_trace_idle_exit(void)
199+
{
200+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
201+
cpu_load_on_exit_idle();
202+
}
192203
}
193204

194205
/* Semaphore */

subsys/tracing/ctf/tracing_ctf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ extern "C" {
368368
#define sys_trace_sys_init_exit(...)
369369

370370
void sys_trace_idle(void);
371+
void sys_trace_idle_exit(void);
371372
void sys_trace_isr_enter(void);
372373
void sys_trace_isr_exit(void);
373374

subsys/tracing/sysview/sysview.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <zephyr/kernel.h>
77
#include <zephyr/kernel_structs.h>
88
#include <zephyr/init.h>
9+
#include <zephyr/debug/cpu_load.h>
910
#include <ksched.h>
1011

1112
#include <SEGGER_SYSVIEW.h>
@@ -64,6 +65,17 @@ void sys_trace_isr_exit_to_scheduler(void)
6465
void sys_trace_idle(void)
6566
{
6667
SEGGER_SYSVIEW_OnIdle();
68+
69+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
70+
cpu_load_on_enter_idle();
71+
}
72+
}
73+
74+
void sys_trace_idle_exit(void)
75+
{
76+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
77+
cpu_load_on_exit_idle();
78+
}
6779
}
6880

6981
void sys_trace_named_event(const char *name, uint32_t arg0, uint32_t arg1)

subsys/tracing/sysview/tracing_sysview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ void sys_trace_thread_info(struct k_thread *thread);
655655
SEGGER_SYSVIEW_RecordEndCall(TID_SYSCALL)
656656

657657
void sys_trace_idle(void);
658+
void sys_trace_idle_exit(void);
658659

659660
void sys_trace_k_thread_create(struct k_thread *new_thread, size_t stack_size, int prio);
660661
void sys_trace_k_thread_user_mode_enter(k_thread_entry_t entry, void *p1, void *p2, void *p3);

subsys/tracing/test/tracing_string_format_test.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ void sys_trace_idle(void)
204204
TRACING_STRING("%s\n", __func__);
205205
}
206206

207+
void sys_trace_idle_exit(void)
208+
{
209+
TRACING_STRING("%s\n", __func__);
210+
}
211+
207212
void sys_trace_k_condvar_broadcast_enter(struct k_condvar *condvar)
208213
{
209214
TRACING_STRING("%s: %p\n", __func__, condvar);

subsys/tracing/test/tracing_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@
480480
#define sys_port_trace_pm_device_runtime_disable_exit(dev, ret)
481481

482482
void sys_trace_idle(void);
483+
void sys_trace_idle_exit(void);
483484
void sys_trace_isr_enter(void);
484485
void sys_trace_isr_exit(void);
485486

subsys/tracing/tracing_none.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
#include <zephyr/tracing/tracing.h>
7+
#include <zephyr/debug/cpu_load.h>
68

9+
__weak void sys_trace_isr_enter(void) {}
710

8-
void sys_trace_isr_enter(void) {}
11+
__weak void sys_trace_isr_exit(void) {}
912

10-
void sys_trace_isr_exit(void) {}
13+
__weak void sys_trace_isr_exit_to_scheduler(void) {}
1114

12-
void sys_trace_isr_exit_to_scheduler(void) {}
15+
__weak void sys_trace_idle(void)
16+
{
17+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
18+
cpu_load_on_enter_idle();
19+
}
20+
}
1321

14-
void sys_trace_idle(void) {}
22+
__weak void sys_trace_idle_exit(void)
23+
{
24+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
25+
cpu_load_on_exit_idle();
26+
}
27+
}

subsys/tracing/user/tracing_user.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <tracing_user.h>
99
#include <zephyr/kernel.h>
10+
#include <zephyr/debug/cpu_load.h>
1011
#include <zephyr/init.h>
1112

1213
void __weak sys_trace_thread_create_user(struct k_thread *thread) {}
@@ -143,6 +144,17 @@ void sys_trace_isr_exit(void)
143144
void sys_trace_idle(void)
144145
{
145146
sys_trace_idle_user();
147+
148+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
149+
cpu_load_on_enter_idle();
150+
}
151+
}
152+
153+
void sys_trace_idle_exit(void)
154+
{
155+
if (IS_ENABLED(CONFIG_CPU_LOAD)) {
156+
cpu_load_on_exit_idle();
157+
}
146158
}
147159

148160
void sys_trace_sys_init_enter(const struct init_entry *entry, int level)

0 commit comments

Comments
 (0)