Skip to content

Commit b6304e6

Browse files
committed
tracing: support generic tracing hooks
Define generic interface and hooks for tracing to replace kernel_event_logger and existing tracing facilities with something more common. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 9038416 commit b6304e6

File tree

17 files changed

+206
-25
lines changed

17 files changed

+206
-25
lines changed

arch/arm/core/cpu_idle.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ SECTION_FUNC(TEXT, _NanoIdleValClear)
113113
*/
114114

115115
SECTION_FUNC(TEXT, k_cpu_idle)
116-
#ifdef CONFIG_KERNEL_EVENT_LOGGER_SLEEP
116+
#ifdef CONFIG_TRACING
117117
push {lr}
118-
bl _sys_k_event_logger_enter_sleep
118+
bl sys_trace_idle
119119
pop {r0}
120120
mov lr, r0
121121
#endif
@@ -157,9 +157,9 @@ SECTION_FUNC(TEXT, k_cpu_idle)
157157
*/
158158

159159
SECTION_FUNC(TEXT, k_cpu_atomic_idle)
160-
#ifdef CONFIG_KERNEL_EVENT_LOGGER_SLEEP
160+
#ifdef CONFIG_TRACING
161161
push {lr}
162-
bl _sys_k_event_logger_enter_sleep
162+
bl sys_trace_idle
163163
pop {r1}
164164
mov lr, r1
165165
#endif

arch/arm/core/irq_manage.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <sw_isr_table.h>
2424
#include <irq.h>
2525
#include <kernel_structs.h>
26-
#include <logging/kernel_event_logger.h>
26+
#include <tracing.h>
2727

2828
extern void __reserved(void);
2929

@@ -137,7 +137,6 @@ void _irq_spurious(void *unused)
137137
* arch/cpu.h and kernel_structs.h; the inline functions typically need to
138138
* perform operations on _kernel. For now, leave as regular functions, a
139139
* future iteration will resolve this.
140-
* We have a similar issue with the k_event_logger functions.
141140
*
142141
* See https://github.com/zephyrproject-rtos/zephyr/issues/3056
143142
*/
@@ -178,14 +177,10 @@ void _arch_isr_direct_pm(void)
178177
}
179178
#endif
180179

181-
#if defined(CONFIG_KERNEL_EVENT_LOGGER_SLEEP) || \
182-
defined(CONFIG_KERNEL_EVENT_LOGGER_INTERRUPT)
183180
void _arch_isr_direct_header(void)
184181
{
185-
_sys_k_event_logger_interrupt();
186-
_sys_k_event_logger_exit_sleep();
182+
sys_trace_isr_enter();
187183
}
188-
#endif
189184

190185
#if defined(CONFIG_ARM_SECURE_FIRMWARE)
191186
/**

arch/arm/core/isr_wrapper.S

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ SECTION_FUNC(TEXT, _isr_wrapper)
4747
bl read_timer_start_of_isr
4848
#endif
4949

50-
#ifdef CONFIG_KERNEL_EVENT_LOGGER_INTERRUPT
51-
bl _sys_k_event_logger_interrupt
52-
#endif
53-
54-
#ifdef CONFIG_KERNEL_EVENT_LOGGER_SLEEP
55-
bl _sys_k_event_logger_exit_sleep
50+
#ifdef CONFIG_TRACING
51+
bl sys_trace_isr_enter
5652
#endif
5753

5854
#ifdef CONFIG_SYS_POWER_MANAGEMENT

arch/arm/core/swap_helper.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ GDATA(_kernel)
4343

4444
SECTION_FUNC(TEXT, __pendsv)
4545

46-
#ifdef CONFIG_KERNEL_EVENT_LOGGER_CONTEXT_SWITCH
46+
#ifdef CONFIG_TRACING
4747
/* Register the context switch */
4848
push {lr}
49-
bl _sys_k_event_logger_context_switch
49+
bl sys_trace_thread_switched_in
5050
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
5151
pop {r0}
5252
mov lr, r0

arch/x86/core/irq_manage.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void _arch_irq_direct_pm(void)
6363
void _arch_isr_direct_header(void)
6464
{
6565
_int_latency_start();
66+
sys_trace_isr_enter();
6667
_sys_k_event_logger_interrupt();
6768
_sys_k_event_logger_exit_sleep();
6869

@@ -76,6 +77,7 @@ void _arch_isr_direct_footer(int swap)
7677
{
7778
_irq_controller_eoi();
7879
_int_latency_stop();
80+
sys_trace_isr_exit();
7981
--_kernel.nested;
8082

8183
/* Call swap if all the following is true:

drivers/timer/cortex_m_systick.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ void _timer_int_handler(void *unused)
224224
extern void _sys_k_event_logger_interrupt(void);
225225
_sys_k_event_logger_interrupt();
226226
#endif
227+
sys_trace_isr_enter();
227228

228229
#ifdef CONFIG_SYS_POWER_MANAGEMENT
229230
s32_t numIdleTicks;

drivers/timer/nrf_rtc_timer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ void rtc1_nrf5_isr(void *arg)
472472
extern void read_timer_start_of_tick_handler(void);
473473
read_timer_start_of_tick_handler();
474474
#endif
475+
sys_trace_isr_enter();
475476

476477
#ifdef CONFIG_TICKLESS_KERNEL
477478
if (!expected_sys_ticks) {
@@ -500,6 +501,7 @@ void rtc1_nrf5_isr(void *arg)
500501
extern void read_timer_end_of_tick_handler(void);
501502
read_timer_end_of_tick_handler();
502503
#endif
504+
sys_trace_isr_exit();
503505

504506
}
505507

include/arch/arm/cortex_m/irq.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,25 @@ extern void _arch_isr_direct_pm(void);
107107
#define _ARCH_ISR_DIRECT_PM() do { } while (0)
108108
#endif
109109

110-
#if defined(CONFIG_KERNEL_EVENT_LOGGER_SLEEP) || \
111-
defined(CONFIG_KERNEL_EVENT_LOGGER_INTERRUPT)
112110
#define _ARCH_ISR_DIRECT_HEADER() _arch_isr_direct_header()
113111
extern void _arch_isr_direct_header(void);
114-
#else
115-
#define _ARCH_ISR_DIRECT_HEADER() do { } while (0)
116-
#endif
117112

118113
#define _ARCH_ISR_DIRECT_FOOTER(swap) _arch_isr_direct_footer(swap)
119114

120115
/* arch/arm/core/exc_exit.S */
121116
extern void _IntExit(void);
122117

118+
#ifdef CONFIG_TRACING
119+
extern void sys_trace_isr_exit_to_scheduler(void);
120+
#endif
121+
123122
static inline void _arch_isr_direct_footer(int maybe_swap)
124123
{
125124
if (maybe_swap) {
125+
126+
#ifdef CONFIG_TRACING
127+
sys_trace_isr_exit_to_scheduler();
128+
#endif
126129
_IntExit();
127130
}
128131
}

include/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,6 +4967,7 @@ inline void *operator new[](size_t size, void *ptr)
49674967

49684968
#endif /* defined(CONFIG_CPLUSPLUS) && defined(__cplusplus) */
49694969

4970+
#include <tracing.h>
49704971
#include <syscalls/kernel.h>
49714972

49724973
#endif /* !_ASMLANGUAGE */

include/tracing.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef _KERNEL_TRACE_H
7+
#define _KERNEL_TRACE_H
8+
9+
#include <kernel.h>
10+
11+
/* Below IDs are used with systemview, not final to the zephyr tracing API */
12+
#define SYS_TRACE_ID_OFFSET (32u)
13+
14+
#define SYS_TRACE_ID_MUTEX_INIT (1u + SYS_TRACE_ID_OFFSET)
15+
#define SYS_TRACE_ID_MUTEX_UNLOCK (2u + SYS_TRACE_ID_OFFSET)
16+
#define SYS_TRACE_ID_MUTEX_LOCK (3u + SYS_TRACE_ID_OFFSET)
17+
#define SYS_TRACE_ID_SEMA_INIT (4u + SYS_TRACE_ID_OFFSET)
18+
#define SYS_TRACE_ID_SEMA_GIVE (5u + SYS_TRACE_ID_OFFSET)
19+
#define SYS_TRACE_ID_SEMA_TAKE (6u + SYS_TRACE_ID_OFFSET)
20+
21+
#if CONFIG_TRACING
22+
void z_sys_trace_idle(void);
23+
void z_sys_trace_isr_enter(void);
24+
void z_sys_trace_isr_exit_to_scheduler(void);
25+
void z_sys_trace_thread_switched_in(void);
26+
#endif
27+
28+
/**
29+
* @brief Called before a thread has been selected to run
30+
*/
31+
#define sys_trace_thread_switched_out()
32+
33+
/**
34+
* @brief Called after a thread has been selected to run
35+
*/
36+
#define sys_trace_thread_switched_in()
37+
38+
/**
39+
* @brief Called when setting priority of a thread
40+
*/
41+
#define sys_trace_thread_priority_set(thread)
42+
43+
/**
44+
* @brief Called when a thread is being created
45+
*/
46+
#define sys_trace_thread_create(thread)
47+
48+
/**
49+
* @brief Called when a thread is being aborted
50+
*
51+
*/
52+
#define sys_trace_thread_abort(thread)
53+
54+
/**
55+
* @brief Called when a thread is being suspended
56+
* @param thread Thread structure
57+
*/
58+
#define sys_trace_thread_suspend(thread)
59+
60+
/**
61+
* @brief Called when a thread is being resumed from suspension
62+
* @param thread Thread structure
63+
*/
64+
#define sys_trace_thread_resume(thread)
65+
66+
/**
67+
* @brief Called when a thread is ready to run
68+
* @param thread Thread structure
69+
*/
70+
#define sys_trace_thread_ready(thread)
71+
72+
/**
73+
* @brief Called when a thread is pending
74+
* @param thread Thread structure
75+
*/
76+
#define sys_trace_thread_pend(thread)
77+
78+
/**
79+
* @brief Provide information about specific thread
80+
* @param thread Thread structure
81+
*/
82+
#define sys_trace_thread_info(thread)
83+
84+
/**
85+
* @brief Called when entering an ISR
86+
*/
87+
#define sys_trace_isr_enter()
88+
89+
/**
90+
* @brief Called when exiting an ISR
91+
*/
92+
#define sys_trace_isr_exit()
93+
94+
/**
95+
* @brief Called when exiting an ISR and switching to scheduler
96+
*/
97+
#define sys_trace_isr_exit_to_scheduler()
98+
99+
/**
100+
* @brief Can be called with any id signifying a new call
101+
* @param id ID of the operation that was started
102+
*/
103+
#define sys_trace_void(id)
104+
105+
/**
106+
* @brief Can be called with any id signifying ending a call
107+
* @param id ID of the operation that was completed
108+
*/
109+
#define sys_trace_end_call(id)
110+
111+
112+
113+
#define z_sys_trace_idle()
114+
115+
#define z_sys_trace_isr_enter()
116+
117+
#define z_sys_trace_isr_exit_to_scheduler()
118+
119+
#define z_sys_trace_thread_switched_in()
120+
121+
#endif

0 commit comments

Comments
 (0)