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