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