Skip to content

Commit 1267971

Browse files
committed
[nrf fromtree] 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 <[email protected]> (cherry picked from commit 4cbafc6)
1 parent 94e625a commit 1267971

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
@@ -2646,6 +2646,12 @@
26462646

26472647
#if defined(CONFIG_PERCEPIO_TRACERECORDER)
26482648
#include "tracing_tracerecorder.h"
2649+
2650+
/**
2651+
* @brief Called when the cpu exits the idle state
2652+
*/
2653+
void sys_trace_idle_exit(void);
2654+
26492655
#else
26502656
/**
26512657
* @brief Called when entering an ISR
@@ -2666,6 +2672,12 @@ void sys_trace_isr_exit_to_scheduler(void);
26662672
* @brief Called when the cpu enters the idle state
26672673
*/
26682674
void sys_trace_idle(void);
2675+
2676+
/**
2677+
* @brief Called when the cpu exits the idle state
2678+
*/
2679+
void sys_trace_idle_exit(void);
2680+
26692681
#endif /* CONFIG_PERCEPIO_TRACERECORDER */
26702682

26712683
/**

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
@@ -357,6 +357,7 @@ extern "C" {
357357
#define sys_trace_sys_init_exit(...)
358358

359359
void sys_trace_idle(void);
360+
void sys_trace_idle_exit(void);
360361
void sys_trace_isr_enter(void);
361362
void sys_trace_isr_exit(void);
362363

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
@@ -644,6 +644,7 @@ void sys_trace_thread_info(struct k_thread *thread);
644644
SEGGER_SYSVIEW_RecordEndCall(TID_SYSCALL)
645645

646646
void sys_trace_idle(void);
647+
void sys_trace_idle_exit(void);
647648

648649
void sys_trace_k_thread_create(struct k_thread *new_thread, size_t stack_size, int prio);
649650
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
@@ -465,6 +465,7 @@
465465
#define sys_port_trace_pm_device_runtime_disable_exit(dev, ret)
466466

467467
void sys_trace_idle(void);
468+
void sys_trace_idle_exit(void);
468469
void sys_trace_isr_enter(void);
469470
void sys_trace_isr_exit(void);
470471

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)