Skip to content

Commit f171443

Browse files
tleksell-penashif
authored andcommitted
Tracing: Thread tracing
Add thread tracing hooks, default hooks, and documentation. Signed-off-by: Torbjörn Leksell <[email protected]>
1 parent b93ff29 commit f171443

File tree

5 files changed

+304
-61
lines changed

5 files changed

+304
-61
lines changed

include/tracing/tracing.h

+217-46
Original file line numberDiff line numberDiff line change
@@ -35,112 +35,283 @@
3535
* @defgroup tracing_apis Tracing APIs
3636
* @{
3737
*/
38+
3839
/**
39-
* @brief Called before a thread has been selected to run
40+
* @brief Called when entering an ISR
4041
*/
41-
#define sys_trace_thread_switched_out()
42+
#define sys_trace_isr_enter()
4243

4344
/**
44-
* @brief Called after a thread has been selected to run
45+
* @brief Called when exiting an ISR
4546
*/
46-
#define sys_trace_thread_switched_in()
47+
#define sys_trace_isr_exit()
4748

4849
/**
49-
* @brief Called when setting priority of a thread
50-
* @param thread Thread structure
50+
* @brief Called when exiting an ISR and switching to scheduler
5151
*/
52-
#define sys_trace_thread_priority_set(thread)
52+
#define sys_trace_isr_exit_to_scheduler()
5353

5454
/**
55-
* @brief Called when a thread is being created
56-
* @param thread Thread structure
55+
* @brief Called when the cpu enters the idle state
5756
*/
58-
#define sys_trace_thread_create(thread)
57+
#define sys_trace_idle()
58+
/**
59+
* @}
60+
*/
61+
62+
63+
/**
64+
* @brief Tracing APIs
65+
* @defgroup tracing_apis Tracing APIs
66+
* @{
67+
*/
68+
69+
70+
/**
71+
* @brief Thread Tracing APIs
72+
* @defgroup thread_tracing_apis Thread Tracing APIs
73+
* @ingroup tracing_apis
74+
* @{
75+
*/
76+
77+
/**
78+
* @brief Called when entering a k_thread_foreach call
79+
*/
80+
#define sys_port_trace_k_thread_foreach_enter()
81+
82+
/**
83+
* @brief Called when exiting a k_thread_foreach call
84+
*/
85+
#define sys_port_trace_k_thread_foreach_exit()
86+
87+
/**
88+
* @brief Called when entering a k_thread_foreach_unlocked
89+
*/
90+
#define sys_port_trace_k_thread_foreach_unlocked_enter()
91+
92+
/**
93+
* @brief Called when exiting a k_thread_foreach_unlocked
94+
*/
95+
#define sys_port_trace_k_thread_foreach_unlocked_exit()
96+
97+
/**
98+
* @brief Trace creating a Thread
99+
* @param new_thread Thread object
100+
*/
101+
#define sys_port_trace_k_thread_create(new_thread)
102+
103+
/**
104+
* @brief Trace Thread entering user mode
105+
*/
106+
#define sys_port_trace_k_thread_user_mode_enter()
107+
108+
/**
109+
* @brief Called when entering a k_thread_join
110+
* @param thread Thread object
111+
* @param timeout Timeout period
112+
*/
113+
#define sys_port_trace_k_thread_join_enter(thread, timeout)
114+
115+
/**
116+
* @brief Called when k_thread_join blocks
117+
* @param thread Thread object
118+
* @param timeout Timeout period
119+
*/
120+
#define sys_port_trace_k_thread_join_blocking(thread, timeout)
121+
122+
/**
123+
* @brief Called when exiting k_thread_join
124+
* @param thread Thread object
125+
* @param timeout Timeout period
126+
* @param ret Return value
127+
*/
128+
#define sys_port_trace_k_thread_join_exit(thread, timeout, ret)
129+
130+
/**
131+
* @brief Called when entering k_thread_sleep
132+
* @param timeout Timeout period
133+
*/
134+
#define sys_port_trace_k_thread_sleep_enter(timeout)
135+
136+
/**
137+
* @brief Called when exiting k_thread_sleep
138+
* @param timeout Timeout period
139+
* @param ret Return value
140+
*/
141+
#define sys_port_trace_k_thread_sleep_exit(timeout, ret)
142+
143+
/**
144+
* @brief Called when entering k_thread_msleep
145+
* @param ms Duration in milliseconds
146+
*/
147+
#define sys_port_trace_k_thread_msleep_enter(ms)
148+
149+
/**
150+
* @brief Called when exiting k_thread_msleep
151+
* @param ms Duration in milliseconds
152+
* @param ret Return value
153+
*/
154+
#define sys_port_trace_k_thread_msleep_exit(ms, ret)
155+
156+
/**
157+
* @brief Called when entering k_thread_usleep
158+
* @param us Duration in microseconds
159+
*/
160+
#define sys_port_trace_k_thread_usleep_enter(us)
161+
162+
/**
163+
* @brief Called when exiting k_thread_usleep
164+
* @param us Duration in microseconds
165+
* @param ret Return value
166+
*/
167+
#define sys_port_trace_k_thread_usleep_exit(us, ret)
168+
169+
/**
170+
* @brief Called when entering k_thread_busy_wait
171+
* @param usec_to_wait Duration in microseconds
172+
*/
173+
#define sys_port_trace_k_thread_busy_wait_enter(usec_to_wait)
174+
175+
/**
176+
* @brief Called when exiting k_thread_busy_wait
177+
* @param usec_to_wait Duration in microseconds
178+
*/
179+
#define sys_port_trace_k_thread_busy_wait_exit(usec_to_wait)
180+
181+
/**
182+
* @brief Called when a thread yields
183+
*/
184+
#define sys_port_trace_k_thread_yield()
185+
186+
/**
187+
* @brief Called when a thread wakes up
188+
* @param thread Thread object
189+
*/
190+
#define sys_port_trace_k_thread_wakeup(thread)
191+
192+
/**
193+
* @brief Called when a thread is started
194+
* @param thread Thread object
195+
*/
196+
#define sys_port_trace_k_thread_start(thread)
59197

60198
/**
61199
* @brief Called when a thread is being aborted
62-
* @param thread Thread structure
63-
*
200+
* @param thread Thread object
201+
*/
202+
#define sys_port_trace_k_thread_abort(thread)
203+
204+
/**
205+
* @brief Called when setting priority of a thread
206+
* @param thread Thread object
64207
*/
65-
#define sys_trace_thread_abort(thread)
208+
#define sys_port_trace_k_thread_priority_set(thread)
66209

67210
/**
68211
* @brief Called when a thread is being suspended
69-
* @param thread Thread structure
212+
* @param thread Thread object
70213
*/
71-
#define sys_trace_thread_suspend(thread)
214+
#define sys_port_trace_k_thread_suspend(thread)
72215

73216
/**
74217
* @brief Called when a thread is being resumed from suspension
75-
* @param thread Thread structure
218+
* @param thread Thread object
219+
*/
220+
#define sys_port_trace_k_thread_resume(thread)
221+
222+
/**
223+
* @brief Called when the thread scheduler is locked
224+
*/
225+
#define sys_port_trace_k_thread_sched_lock()
226+
227+
/**
228+
* @brief Called when the thread sceduler is unlocked
229+
*/
230+
#define sys_port_trace_k_thread_sched_unlock()
231+
232+
/**
233+
* @brief Called when a thread name is set
234+
* @param thread Thread object
235+
* @param ret Return value
236+
*/
237+
#define sys_port_trace_k_thread_name_set(thread, ret)
238+
239+
/**
240+
* @brief Called before a thread has been selected to run
241+
*/
242+
#define sys_port_trace_k_thread_switched_out()
243+
244+
/**
245+
* @brief Called after a thread has been selected to run
76246
*/
77-
#define sys_trace_thread_resume(thread)
247+
#define sys_port_trace_k_thread_switched_in()
78248

79249
/**
80250
* @brief Called when a thread is ready to run
81-
* @param thread Thread structure
251+
* @param thread Thread object
82252
*/
83-
#define sys_trace_thread_ready(thread)
253+
#define sys_port_trace_k_thread_ready(thread)
84254

85255
/**
86256
* @brief Called when a thread is pending
87-
* @param thread Thread structure
257+
* @param thread Thread object
88258
*/
89-
#define sys_trace_thread_pend(thread)
259+
#define sys_port_trace_k_thread_pend(thread)
90260

91261
/**
92262
* @brief Provide information about specific thread
93-
* @param thread Thread structure
263+
* @param thread Thread object
94264
*/
95-
#define sys_trace_thread_info(thread)
265+
#define sys_port_trace_k_thread_info(thread)
96266

97267
/**
98-
* @brief Called when a thread name is set
99-
* @param thread Thread structure
268+
* @brief Trace implicit thread wakup invocation by the scheduler
269+
* @param thread Thread object
100270
*/
101-
#define sys_trace_thread_name_set(thread)
271+
#define sys_port_trace_k_thread_sched_wakeup(thread)
102272

103273
/**
104-
* @brief Called when entering an ISR
274+
* @brief Trace implicit thread abort invocation by the scheduler
275+
* @param thread Thread object
105276
*/
106-
#define sys_trace_isr_enter()
277+
#define sys_port_trace_k_thread_sched_abort(thread)
107278

108279
/**
109-
* @brief Called when exiting an ISR
280+
* @brief Trace implicit thread set priority invocation by the scheduler
281+
* @param thread Thread object
282+
* @param prio Thread priority
110283
*/
111-
#define sys_trace_isr_exit()
284+
#define sys_port_trace_k_thread_sched_priority_set(thread, prio)
112285

113286
/**
114-
* @brief Called when exiting an ISR and switching to scheduler
287+
* @brief Trace implicit thread ready invocation by the scheduler
288+
* @param thread Thread object
115289
*/
116-
#define sys_trace_isr_exit_to_scheduler()
290+
#define sys_port_trace_k_thread_sched_ready(thread)
117291

118292
/**
119-
* @brief Can be called with any id signifying a new call
120-
* @param id ID of the operation that was started
293+
* @brief Trace implicit thread pend invocation by the scheduler
294+
* @param thread Thread object
121295
*/
122-
#define sys_trace_void(id)
296+
#define sys_port_trace_k_thread_sched_pend(thread)
123297

124298
/**
125-
* @brief Can be called with any id signifying ending a call
126-
* @param id ID of the operation that was completed
299+
* @brief Trace implicit thread resume invocation by the scheduler
300+
* @param thread Thread object
127301
*/
128-
#define sys_trace_end_call(id)
302+
#define sys_port_trace_k_thread_sched_resume(thread)
129303

130304
/**
131-
* @brief Called when the cpu enters the idle state
305+
* @brief Trace implicit thread suspend invocation by the scheduler
306+
* @param thread Thread object
132307
*/
133-
#define sys_trace_idle()
308+
#define sys_port_trace_k_thread_sched_suspend(thread)
309+
134310
/**
135311
* @}
136-
*/
312+
*/ /* end of thread_tracing_apis */
137313

138314

139-
/**
140-
* @brief Tracing APIs
141-
* @defgroup tracing_apis Tracing APIs
142-
* @{
143-
*/
144315

145316

146317
/**

kernel/include/ksched.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ static inline bool z_is_thread_queued(struct k_thread *thread)
141141
static inline void z_mark_thread_as_suspended(struct k_thread *thread)
142142
{
143143
thread->base.thread_state |= _THREAD_SUSPENDED;
144-
sys_trace_thread_suspend(thread);
144+
145+
SYS_PORT_TRACING_FUNC(k_thread, sched_suspend, thread);
145146
}
146147

147148
static inline void z_mark_thread_as_not_suspended(struct k_thread *thread)
148149
{
149150
thread->base.thread_state &= ~_THREAD_SUSPENDED;
150-
sys_trace_thread_resume(thread);
151+
152+
SYS_PORT_TRACING_FUNC(k_thread, sched_resume, thread);
151153
}
152154

153155
static inline void z_mark_thread_as_started(struct k_thread *thread)

0 commit comments

Comments
 (0)