• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(cpu_frequency_limits,
152 
153 	TP_PROTO(unsigned int max_freq, unsigned int min_freq,
154 		unsigned int cpu_id),
155 
156 	TP_ARGS(max_freq, min_freq, cpu_id),
157 
158 	TP_STRUCT__entry(
159 		__field(	u32,		min_freq	)
160 		__field(	u32,		max_freq	)
161 		__field(	u32,		cpu_id		)
162 	),
163 
164 	TP_fast_assign(
165 		__entry->min_freq = min_freq;
166 		__entry->max_freq = max_freq;
167 		__entry->cpu_id = cpu_id;
168 	),
169 
170 	TP_printk("min=%lu max=%lu cpu_id=%lu",
171 		  (unsigned long)__entry->min_freq,
172 		  (unsigned long)__entry->max_freq,
173 		  (unsigned long)__entry->cpu_id)
174 );
175 
176 TRACE_EVENT(device_pm_callback_start,
177 
178 	TP_PROTO(struct device *dev, const char *pm_ops, int event),
179 
180 	TP_ARGS(dev, pm_ops, event),
181 
182 	TP_STRUCT__entry(
183 		__string(device, dev_name(dev))
184 		__string(driver, dev_driver_string(dev))
185 		__string(parent, dev->parent ? dev_name(dev->parent) : "none")
186 		__string(pm_ops, pm_ops ? pm_ops : "none ")
187 		__field(int, event)
188 	),
189 
190 	TP_fast_assign(
191 		__assign_str(device, dev_name(dev));
192 		__assign_str(driver, dev_driver_string(dev));
193 		__assign_str(parent,
194 			dev->parent ? dev_name(dev->parent) : "none");
195 		__assign_str(pm_ops, pm_ops ? pm_ops : "none ");
196 		__entry->event = event;
197 	),
198 
199 	TP_printk("%s %s, parent: %s, %s[%s]", __get_str(driver),
200 		__get_str(device), __get_str(parent), __get_str(pm_ops),
201 		pm_verb_symbolic(__entry->event))
202 );
203 
204 TRACE_EVENT(device_pm_callback_end,
205 
206 	TP_PROTO(struct device *dev, int error),
207 
208 	TP_ARGS(dev, error),
209 
210 	TP_STRUCT__entry(
211 		__string(device, dev_name(dev))
212 		__string(driver, dev_driver_string(dev))
213 		__field(int, error)
214 	),
215 
216 	TP_fast_assign(
217 		__assign_str(device, dev_name(dev));
218 		__assign_str(driver, dev_driver_string(dev));
219 		__entry->error = error;
220 	),
221 
222 	TP_printk("%s %s, err=%d",
223 		__get_str(driver), __get_str(device), __entry->error)
224 );
225 
226 TRACE_EVENT(suspend_resume,
227 
228 	TP_PROTO(const char *action, int val, bool start),
229 
230 	TP_ARGS(action, val, start),
231 
232 	TP_STRUCT__entry(
233 		__field(const char *, action)
234 		__field(int, val)
235 		__field(bool, start)
236 	),
237 
238 	TP_fast_assign(
239 		__entry->action = action;
240 		__entry->val = val;
241 		__entry->start = start;
242 	),
243 
244 	TP_printk("%s[%u] %s", __entry->action, (unsigned int)__entry->val,
245 		(__entry->start)?"begin":"end")
246 );
247 
248 DECLARE_EVENT_CLASS(wakeup_source,
249 
250 	TP_PROTO(const char *name, unsigned int state),
251 
252 	TP_ARGS(name, state),
253 
254 	TP_STRUCT__entry(
255 		__string(       name,           name            )
256 		__field(        u64,            state           )
257 	),
258 
259 	TP_fast_assign(
260 		__assign_str(name, name);
261 		__entry->state = state;
262 	),
263 
264 	TP_printk("%s state=0x%lx", __get_str(name),
265 		(unsigned long)__entry->state)
266 );
267 
268 DEFINE_EVENT(wakeup_source, wakeup_source_activate,
269 
270 	TP_PROTO(const char *name, unsigned int state),
271 
272 	TP_ARGS(name, state)
273 );
274 
275 DEFINE_EVENT(wakeup_source, wakeup_source_deactivate,
276 
277 	TP_PROTO(const char *name, unsigned int state),
278 
279 	TP_ARGS(name, state)
280 );
281 
282 /*
283  * The clock events are used for clock enable/disable and for
284  *  clock rate change
285  */
286 DECLARE_EVENT_CLASS(clock,
287 
288 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
289 
290 	TP_ARGS(name, state, cpu_id),
291 
292 	TP_STRUCT__entry(
293 		__string(       name,           name            )
294 		__field(        u64,            state           )
295 		__field(        u64,            cpu_id          )
296 	),
297 
298 	TP_fast_assign(
299 		__assign_str(name, name);
300 		__entry->state = state;
301 		__entry->cpu_id = cpu_id;
302 	),
303 
304 	TP_printk("%s state=%lu cpu_id=%lu", __get_str(name),
305 		(unsigned long)__entry->state, (unsigned long)__entry->cpu_id)
306 );
307 
308 DEFINE_EVENT(clock, clock_enable,
309 
310 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
311 
312 	TP_ARGS(name, state, cpu_id)
313 );
314 
315 DEFINE_EVENT(clock, clock_disable,
316 
317 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
318 
319 	TP_ARGS(name, state, cpu_id)
320 );
321 
322 DEFINE_EVENT(clock, clock_set_rate,
323 
324 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
325 
326 	TP_ARGS(name, state, cpu_id)
327 );
328 
329 TRACE_EVENT(clock_set_parent,
330 
331 	TP_PROTO(const char *name, const char *parent_name),
332 
333 	TP_ARGS(name, parent_name),
334 
335 	TP_STRUCT__entry(
336 		__string(       name,           name            )
337 		__string(       parent_name,    parent_name     )
338 	),
339 
340 	TP_fast_assign(
341 		__assign_str(name, name);
342 		__assign_str(parent_name, parent_name);
343 	),
344 
345 	TP_printk("%s parent=%s", __get_str(name), __get_str(parent_name))
346 );
347 
348 /*
349  * The power domain events are used for power domains transitions
350  */
351 DECLARE_EVENT_CLASS(power_domain,
352 
353 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
354 
355 	TP_ARGS(name, state, cpu_id),
356 
357 	TP_STRUCT__entry(
358 		__string(       name,           name            )
359 		__field(        u64,            state           )
360 		__field(        u64,            cpu_id          )
361 	),
362 
363 	TP_fast_assign(
364 		__assign_str(name, name);
365 		__entry->state = state;
366 		__entry->cpu_id = cpu_id;
367 ),
368 
369 	TP_printk("%s state=%lu cpu_id=%lu", __get_str(name),
370 		(unsigned long)__entry->state, (unsigned long)__entry->cpu_id)
371 );
372 
373 DEFINE_EVENT(power_domain, power_domain_target,
374 
375 	TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id),
376 
377 	TP_ARGS(name, state, cpu_id)
378 );
379 
380 /*
381  * The pm qos events are used for pm qos update
382  */
383 DECLARE_EVENT_CLASS(pm_qos_request,
384 
385 	TP_PROTO(int pm_qos_class, s32 value),
386 
387 	TP_ARGS(pm_qos_class, value),
388 
389 	TP_STRUCT__entry(
390 		__field( int,                    pm_qos_class   )
391 		__field( s32,                    value          )
392 	),
393 
394 	TP_fast_assign(
395 		__entry->pm_qos_class = pm_qos_class;
396 		__entry->value = value;
397 	),
398 
399 	TP_printk("pm_qos_class=%s value=%d",
400 		  __print_symbolic(__entry->pm_qos_class,
401 			{ PM_QOS_CPU_DMA_LATENCY,	"CPU_DMA_LATENCY" },
402 			{ PM_QOS_NETWORK_LATENCY,	"NETWORK_LATENCY" },
403 			{ PM_QOS_NETWORK_THROUGHPUT,	"NETWORK_THROUGHPUT" }),
404 		  __entry->value)
405 );
406 
407 DEFINE_EVENT(pm_qos_request, pm_qos_add_request,
408 
409 	TP_PROTO(int pm_qos_class, s32 value),
410 
411 	TP_ARGS(pm_qos_class, value)
412 );
413 
414 DEFINE_EVENT(pm_qos_request, pm_qos_update_request,
415 
416 	TP_PROTO(int pm_qos_class, s32 value),
417 
418 	TP_ARGS(pm_qos_class, value)
419 );
420 
421 DEFINE_EVENT(pm_qos_request, pm_qos_remove_request,
422 
423 	TP_PROTO(int pm_qos_class, s32 value),
424 
425 	TP_ARGS(pm_qos_class, value)
426 );
427 
428 TRACE_EVENT(pm_qos_update_request_timeout,
429 
430 	TP_PROTO(int pm_qos_class, s32 value, unsigned long timeout_us),
431 
432 	TP_ARGS(pm_qos_class, value, timeout_us),
433 
434 	TP_STRUCT__entry(
435 		__field( int,                    pm_qos_class   )
436 		__field( s32,                    value          )
437 		__field( unsigned long,          timeout_us     )
438 	),
439 
440 	TP_fast_assign(
441 		__entry->pm_qos_class = pm_qos_class;
442 		__entry->value = value;
443 		__entry->timeout_us = timeout_us;
444 	),
445 
446 	TP_printk("pm_qos_class=%s value=%d, timeout_us=%ld",
447 		  __print_symbolic(__entry->pm_qos_class,
448 			{ PM_QOS_CPU_DMA_LATENCY,	"CPU_DMA_LATENCY" },
449 			{ PM_QOS_NETWORK_LATENCY,	"NETWORK_LATENCY" },
450 			{ PM_QOS_NETWORK_THROUGHPUT,	"NETWORK_THROUGHPUT" }),
451 		  __entry->value, __entry->timeout_us)
452 );
453 
454 DECLARE_EVENT_CLASS(pm_qos_update,
455 
456 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
457 
458 	TP_ARGS(action, prev_value, curr_value),
459 
460 	TP_STRUCT__entry(
461 		__field( enum pm_qos_req_action, action         )
462 		__field( int,                    prev_value     )
463 		__field( int,                    curr_value     )
464 	),
465 
466 	TP_fast_assign(
467 		__entry->action = action;
468 		__entry->prev_value = prev_value;
469 		__entry->curr_value = curr_value;
470 	),
471 
472 	TP_printk("action=%s prev_value=%d curr_value=%d",
473 		  __print_symbolic(__entry->action,
474 			{ PM_QOS_ADD_REQ,	"ADD_REQ" },
475 			{ PM_QOS_UPDATE_REQ,	"UPDATE_REQ" },
476 			{ PM_QOS_REMOVE_REQ,	"REMOVE_REQ" }),
477 		  __entry->prev_value, __entry->curr_value)
478 );
479 
480 DEFINE_EVENT(pm_qos_update, pm_qos_update_target,
481 
482 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
483 
484 	TP_ARGS(action, prev_value, curr_value)
485 );
486 
487 DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags,
488 
489 	TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value),
490 
491 	TP_ARGS(action, prev_value, curr_value),
492 
493 	TP_printk("action=%s prev_value=0x%x curr_value=0x%x",
494 		  __print_symbolic(__entry->action,
495 			{ PM_QOS_ADD_REQ,	"ADD_REQ" },
496 			{ PM_QOS_UPDATE_REQ,	"UPDATE_REQ" },
497 			{ PM_QOS_REMOVE_REQ,	"REMOVE_REQ" }),
498 		  __entry->prev_value, __entry->curr_value)
499 );
500 
501 DECLARE_EVENT_CLASS(dev_pm_qos_request,
502 
503 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
504 		 s32 new_value),
505 
506 	TP_ARGS(name, type, new_value),
507 
508 	TP_STRUCT__entry(
509 		__string( name,                    name         )
510 		__field( enum dev_pm_qos_req_type, type         )
511 		__field( s32,                      new_value    )
512 	),
513 
514 	TP_fast_assign(
515 		__assign_str(name, name);
516 		__entry->type = type;
517 		__entry->new_value = new_value;
518 	),
519 
520 	TP_printk("device=%s type=%s new_value=%d",
521 		  __get_str(name),
522 		  __print_symbolic(__entry->type,
523 			{ DEV_PM_QOS_RESUME_LATENCY, "DEV_PM_QOS_RESUME_LATENCY" },
524 			{ DEV_PM_QOS_FLAGS, "DEV_PM_QOS_FLAGS" }),
525 		  __entry->new_value)
526 );
527 
528 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_add_request,
529 
530 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
531 		 s32 new_value),
532 
533 	TP_ARGS(name, type, new_value)
534 );
535 
536 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_update_request,
537 
538 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
539 		 s32 new_value),
540 
541 	TP_ARGS(name, type, new_value)
542 );
543 
544 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request,
545 
546 	TP_PROTO(const char *name, enum dev_pm_qos_req_type type,
547 		 s32 new_value),
548 
549 	TP_ARGS(name, type, new_value)
550 );
551 #endif /* _TRACE_POWER_H */
552 
553 /* This part must be outside protection */
554 #include <trace/define_trace.h>
555