xref: /openbmc/linux/include/trace/events/power.h (revision 4f3db074)
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM power
3 
4 #if !defined(_TRACE_POWER_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_POWER_H
6 
7 #include <linux/ktime.h>
8 #include <linux/pm_qos.h>
9 #include <linux/tracepoint.h>
10 #include <linux/ftrace_event.h>
11 
12 #define TPS(x)  tracepoint_string(x)
13 
14 DECLARE_EVENT_CLASS(cpu,
15 
16 	TP_PROTO(unsigned int state, unsigned int cpu_id),
17 
18 	TP_ARGS(state, cpu_id),
19 
20 	TP_STRUCT__entry(
21 		__field(	u32,		state		)
22 		__field(	u32,		cpu_id		)
23 	),
24 
25 	TP_fast_assign(
26 		__entry->state = state;
27 		__entry->cpu_id = cpu_id;
28 	),
29 
30 	TP_printk("state=%lu cpu_id=%lu", (unsigned long)__entry->state,
31 		  (unsigned long)__entry->cpu_id)
32 );
33 
34 DEFINE_EVENT(cpu, cpu_idle,
35 
36 	TP_PROTO(unsigned int state, unsigned int cpu_id),
37 
38 	TP_ARGS(state, cpu_id)
39 );
40 
41 TRACE_EVENT(pstate_sample,
42 
43 	TP_PROTO(u32 core_busy,
44 		u32 scaled_busy,
45 		u32 state,
46 		u64 mperf,
47 		u64 aperf,
48 		u32 freq
49 		),
50 
51 	TP_ARGS(core_busy,
52 		scaled_busy,
53 		state,
54 		mperf,
55 		aperf,
56 		freq
57 		),
58 
59 	TP_STRUCT__entry(
60 		__field(u32, core_busy)
61 		__field(u32, scaled_busy)
62 		__field(u32, state)
63 		__field(u64, mperf)
64 		__field(u64, aperf)
65 		__field(u32, freq)
66 
67 	),
68 
69 	TP_fast_assign(
70 		__entry->core_busy = core_busy;
71 		__entry->scaled_busy = scaled_busy;
72 		__entry->state = state;
73 		__entry->mperf = mperf;
74 		__entry->aperf = aperf;
75 		__entry->freq = freq;
76 		),
77 
78 	TP_printk("core_busy=%lu scaled=%lu state=%lu mperf=%llu aperf=%llu freq=%lu ",
79 		(unsigned long)__entry->core_busy,
80 		(unsigned long)__entry->scaled_busy,
81 		(unsigned long)__entry->state,
82 		(unsigned long long)__entry->mperf,
83 		(unsigned long long)__entry->aperf,
84 		(unsigned long)__entry->freq
85 		)
86 
87 );
88 
89 /* This file can get included multiple times, TRACE_HEADER_MULTI_READ at top */
90 #ifndef _PWR_EVENT_AVOID_DOUBLE_DEFINING
91 #define _PWR_EVENT_AVOID_DOUBLE_DEFINING
92 
93 #define PWR_EVENT_EXIT -1
94 #endif
95 
96 #define pm_verb_symbolic(event) \
97 	__print_symbolic(event, \
98 		{ PM_EVENT_SUSPEND, "suspend" }, \
99 		{ PM_EVENT_RESUME, "resume" }, \
100 		{ PM_EVENT_FREEZE, "freeze" }, \
101 		{ PM_EVENT_QUIESCE, "quiesce" }, \
102 		{ PM_EVENT_HIBERNATE, "hibernate" }, \
103 		{ PM_EVENT_THAW, "thaw" }, \
104 		{ PM_EVENT_RESTORE, "restore" }, \
105 		{ PM_EVENT_RECOVER, "recover" })
106 
107 DEFINE_EVENT(cpu, cpu_frequency,
108 
109 	TP_PROTO(unsigned int frequency, unsigned int cpu_id),
110 
111 	TP_ARGS(frequency, cpu_id)
112 );
113 
114 TRACE_EVENT(device_pm_callback_start,
115 
116 	TP_PROTO(struct device *dev, const char *pm_ops, int event),
117 
118 	TP_ARGS(dev, pm_ops, event),
119 
120 	TP_STRUCT__entry(
121 		__string(device, dev_name(dev))
122 		__string(driver, dev_driver_string(dev))
123 		__string(parent, dev->parent ? dev_name(dev->parent) : "none")
124 		__string(pm_ops, pm_ops ? pm_ops : "none ")
125 		__field(int, event)
126 	),
127 
128 	TP_fast_assign(
129 		__assign_str(device, dev_name(dev));
130 		__assign_str(driver, dev_driver_string(dev));
131 		__assign_str(parent,
132 			dev->parent ? dev_name(dev->parent) : "none");
133 		__assign_str(pm_ops, pm_ops ? pm_ops : "none ");
134 		__entry->event = event;
135 	),
136 
137 	TP_printk("%s %s, parent: %s, %s[%s]", __get_str(driver),
138 		__get_str(device), __get_str(parent), __get_str(pm_ops),
139 		pm_verb_symbolic(__entry->event))
140 );
141 
142 TRACE_EVENT(device_pm_callback_end,
143 
144 	TP_PROTO(struct device *dev, int error),
145 
146 	TP_ARGS(dev, error),
147 
148 	TP_STRUCT__entry(
149 		__string(device, dev_name(dev))
150 		__string(driver, dev_driver_string(dev))
151 		__field(int, error)
152 	),
153 
154 	TP_fast_assign(
155 		__assign_str(device, dev_name(dev));
156 		__assign_str(driver, dev_driver_string(dev));
157 		__entry->error = error;
158 	),
159 
160 	TP_printk("%s %s, err=%d",
161 		__get_str(driver), __get_str(device), __entry->error)
162 );
163 
164 TRACE_EVENT(suspend_resume,
165 
166 	TP_PROTO(const char *action, int val, bool start),
167 
168 	TP_ARGS(action, val, start),
169 
170 	TP_STRUCT__entry(
171 		__field(const char *, action)
172 		__field(int, val)
173 		__field(bool, start)
174 	),
175 
176 	TP_fast_assign(
177 		__entry->action = action;
178 		__entry->val = val;
179 		__entry->start = start;
180 	),
181 
182 	TP_printk("%s[%u] %s", __entry->action, (unsigned int)__entry->val,
183 		(__entry->start)?"begin":"end")
184 );
185 
186 DECLARE_EVENT_CLASS(wakeup_source,
187 
188 	TP_PROTO(const char *name, unsigned int state),
189 
190 	TP_ARGS(name, state),
191 
192 	TP_STRUCT__entry(
193 		__string(       name,           name            )
194 		__field(        u64,            state           )
195 	),
196 
197 	TP_fast_assign(
198 		__assign_str(name, name);
199 		__entry->state = state;
200 	),
201 
202 	TP_printk("%s state=0x%lx", __get_str(name),
203 		(unsigned long)__entry->state)
204 );
205 
206 DEFINE_EVENT(wakeup_source, wakeup_source_activate,
207 
208 	TP_PROTO(const char *name, unsigned int state),
209 
210 	TP_ARGS(name, state)
211 );
212 
213 DEFINE_EVENT(wakeup_source, wakeup_source_deactivate,
214 
215 	TP_PROTO(const char *name, unsigned int state),
216 
217 	TP_ARGS(name, state)
218 );
219 
220 /*
221  * The clock events are used for clock enable/disable and for
222  *  clock rate change
223  */
224 DECLARE_EVENT_CLASS(clock,
225 
226 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
227 
228 	TP_ARGS(name, state, cpu_id),
229 
230 	TP_STRUCT__entry(
231 		__string(       name,           name            )
232 		__field(        u64,            state           )
233 		__field(        u64,            cpu_id          )
234 	),
235 
236 	TP_fast_assign(
237 		__assign_str(name, name);
238 		__entry->state = state;
239 		__entry->cpu_id = cpu_id;
240 	),
241 
242 	TP_printk("%s state=%lu cpu_id=%lu", __get_str(name),
243 		(unsigned long)__entry->state, (unsigned long)__entry->cpu_id)
244 );
245 
246 DEFINE_EVENT(clock, clock_enable,
247 
248 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
249 
250 	TP_ARGS(name, state, cpu_id)
251 );
252 
253 DEFINE_EVENT(clock, clock_disable,
254 
255 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
256 
257 	TP_ARGS(name, state, cpu_id)
258 );
259 
260 DEFINE_EVENT(clock, clock_set_rate,
261 
262 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
263 
264 	TP_ARGS(name, state, cpu_id)
265 );
266 
267 /*
268  * The power domain events are used for power domains transitions
269  */
270 DECLARE_EVENT_CLASS(power_domain,
271 
272 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
273 
274 	TP_ARGS(name, state, cpu_id),
275 
276 	TP_STRUCT__entry(
277 		__string(       name,           name            )
278 		__field(        u64,            state           )
279 		__field(        u64,            cpu_id          )
280 	),
281 
282 	TP_fast_assign(
283 		__assign_str(name, name);
284 		__entry->state = state;
285 		__entry->cpu_id = cpu_id;
286 ),
287 
288 	TP_printk("%s state=%lu cpu_id=%lu", __get_str(name),
289 		(unsigned long)__entry->state, (unsigned long)__entry->cpu_id)
290 );
291 
292 DEFINE_EVENT(power_domain, power_domain_target,
293 
294 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
295 
296 	TP_ARGS(name, state, cpu_id)
297 );
298 
299 /*
300  * The pm qos events are used for pm qos update
301  */
302 DECLARE_EVENT_CLASS(pm_qos_request,
303 
304 	TP_PROTO(int pm_qos_class, s32 value),
305 
306 	TP_ARGS(pm_qos_class, value),
307 
308 	TP_STRUCT__entry(
309 		__field( int,                    pm_qos_class   )
310 		__field( s32,                    value          )
311 	),
312 
313 	TP_fast_assign(
314 		__entry->pm_qos_class = pm_qos_class;
315 		__entry->value = value;
316 	),
317 
318 	TP_printk("pm_qos_class=%s value=%d",
319 		  __print_symbolic(__entry->pm_qos_class,
320 			{ PM_QOS_CPU_DMA_LATENCY,	"CPU_DMA_LATENCY" },
321 			{ PM_QOS_NETWORK_LATENCY,	"NETWORK_LATENCY" },
322 			{ PM_QOS_NETWORK_THROUGHPUT,	"NETWORK_THROUGHPUT" }),
323 		  __entry->value)
324 );
325 
326 DEFINE_EVENT(pm_qos_request, pm_qos_add_request,
327 
328 	TP_PROTO(int pm_qos_class, s32 value),
329 
330 	TP_ARGS(pm_qos_class, value)
331 );
332 
333 DEFINE_EVENT(pm_qos_request, pm_qos_update_request,
334 
335 	TP_PROTO(int pm_qos_class, s32 value),
336 
337 	TP_ARGS(pm_qos_class, value)
338 );
339 
340 DEFINE_EVENT(pm_qos_request, pm_qos_remove_request,
341 
342 	TP_PROTO(int pm_qos_class, s32 value),
343 
344 	TP_ARGS(pm_qos_class, value)
345 );
346 
347 TRACE_EVENT(pm_qos_update_request_timeout,
348 
349 	TP_PROTO(int pm_qos_class, s32 value, unsigned long timeout_us),
350 
351 	TP_ARGS(pm_qos_class, value, timeout_us),
352 
353 	TP_STRUCT__entry(
354 		__field( int,                    pm_qos_class   )
355 		__field( s32,                    value          )
356 		__field( unsigned long,          timeout_us     )
357 	),
358 
359 	TP_fast_assign(
360 		__entry->pm_qos_class = pm_qos_class;
361 		__entry->value = value;
362 		__entry->timeout_us = timeout_us;
363 	),
364 
365 	TP_printk("pm_qos_class=%s value=%d, timeout_us=%ld",
366 		  __print_symbolic(__entry->pm_qos_class,
367 			{ PM_QOS_CPU_DMA_LATENCY,	"CPU_DMA_LATENCY" },
368 			{ PM_QOS_NETWORK_LATENCY,	"NETWORK_LATENCY" },
369 			{ PM_QOS_NETWORK_THROUGHPUT,	"NETWORK_THROUGHPUT" }),
370 		  __entry->value, __entry->timeout_us)
371 );
372 
373 DECLARE_EVENT_CLASS(pm_qos_update,
374 
375 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
376 
377 	TP_ARGS(action, prev_value, curr_value),
378 
379 	TP_STRUCT__entry(
380 		__field( enum pm_qos_req_action, action         )
381 		__field( int,                    prev_value     )
382 		__field( int,                    curr_value     )
383 	),
384 
385 	TP_fast_assign(
386 		__entry->action = action;
387 		__entry->prev_value = prev_value;
388 		__entry->curr_value = curr_value;
389 	),
390 
391 	TP_printk("action=%s prev_value=%d curr_value=%d",
392 		  __print_symbolic(__entry->action,
393 			{ PM_QOS_ADD_REQ,	"ADD_REQ" },
394 			{ PM_QOS_UPDATE_REQ,	"UPDATE_REQ" },
395 			{ PM_QOS_REMOVE_REQ,	"REMOVE_REQ" }),
396 		  __entry->prev_value, __entry->curr_value)
397 );
398 
399 DEFINE_EVENT(pm_qos_update, pm_qos_update_target,
400 
401 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
402 
403 	TP_ARGS(action, prev_value, curr_value)
404 );
405 
406 DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags,
407 
408 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
409 
410 	TP_ARGS(action, prev_value, curr_value),
411 
412 	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
413 		  __print_symbolic(__entry->action,
414 			{ PM_QOS_ADD_REQ,	"ADD_REQ" },
415 			{ PM_QOS_UPDATE_REQ,	"UPDATE_REQ" },
416 			{ PM_QOS_REMOVE_REQ,	"REMOVE_REQ" }),
417 		  __entry->prev_value, __entry->curr_value)
418 );
419 
420 DECLARE_EVENT_CLASS(dev_pm_qos_request,
421 
422 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
423 		 s32 new_value),
424 
425 	TP_ARGS(name, type, new_value),
426 
427 	TP_STRUCT__entry(
428 		__string( name,                    name         )
429 		__field( enum dev_pm_qos_req_type, type         )
430 		__field( s32,                      new_value    )
431 	),
432 
433 	TP_fast_assign(
434 		__assign_str(name, name);
435 		__entry->type = type;
436 		__entry->new_value = new_value;
437 	),
438 
439 	TP_printk("device=%s type=%s new_value=%d",
440 		  __get_str(name),
441 		  __print_symbolic(__entry->type,
442 			{ DEV_PM_QOS_RESUME_LATENCY, "DEV_PM_QOS_RESUME_LATENCY" },
443 			{ DEV_PM_QOS_FLAGS, "DEV_PM_QOS_FLAGS" }),
444 		  __entry->new_value)
445 );
446 
447 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_add_request,
448 
449 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
450 		 s32 new_value),
451 
452 	TP_ARGS(name, type, new_value)
453 );
454 
455 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_update_request,
456 
457 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
458 		 s32 new_value),
459 
460 	TP_ARGS(name, type, new_value)
461 );
462 
463 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request,
464 
465 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
466 		 s32 new_value),
467 
468 	TP_ARGS(name, type, new_value)
469 );
470 #endif /* _TRACE_POWER_H */
471 
472 /* This part must be outside protection */
473 #include <trace/define_trace.h>
474