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 power domain events are used for power domains transitions 342 */ 343 DECLARE_EVENT_CLASS(power_domain, 344 345 TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id), 346 347 TP_ARGS(name, state, cpu_id), 348 349 TP_STRUCT__entry( 350 __string( name, name ) 351 __field( u64, state ) 352 __field( u64, cpu_id ) 353 ), 354 355 TP_fast_assign( 356 __assign_str(name); 357 __entry->state = state; 358 __entry->cpu_id = cpu_id; 359 ), 360 361 TP_printk("%s state=%lu cpu_id=%lu", __get_str(name), 362 (unsigned long)__entry->state, (unsigned long)__entry->cpu_id) 363 ); 364 365 DEFINE_EVENT(power_domain, power_domain_target, 366 367 TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id), 368 369 TP_ARGS(name, state, cpu_id) 370 ); 371 372 /* 373 * CPU latency QoS events used for global CPU latency QoS list updates 374 */ 375 DECLARE_EVENT_CLASS(cpu_latency_qos_request, 376 377 TP_PROTO(s32 value), 378 379 TP_ARGS(value), 380 381 TP_STRUCT__entry( 382 __field( s32, value ) 383 ), 384 385 TP_fast_assign( 386 __entry->value = value; 387 ), 388 389 TP_printk("CPU_DMA_LATENCY value=%d", 390 __entry->value) 391 ); 392 393 DEFINE_EVENT(cpu_latency_qos_request, pm_qos_add_request, 394 395 TP_PROTO(s32 value), 396 397 TP_ARGS(value) 398 ); 399 400 DEFINE_EVENT(cpu_latency_qos_request, pm_qos_update_request, 401 402 TP_PROTO(s32 value), 403 404 TP_ARGS(value) 405 ); 406 407 DEFINE_EVENT(cpu_latency_qos_request, pm_qos_remove_request, 408 409 TP_PROTO(s32 value), 410 411 TP_ARGS(value) 412 ); 413 414 /* 415 * General PM QoS events used for updates of PM QoS request lists 416 */ 417 DECLARE_EVENT_CLASS(pm_qos_update, 418 419 TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value), 420 421 TP_ARGS(action, prev_value, curr_value), 422 423 TP_STRUCT__entry( 424 __field( enum pm_qos_req_action, action ) 425 __field( int, prev_value ) 426 __field( int, curr_value ) 427 ), 428 429 TP_fast_assign( 430 __entry->action = action; 431 __entry->prev_value = prev_value; 432 __entry->curr_value = curr_value; 433 ), 434 435 TP_printk("action=%s prev_value=%d curr_value=%d", 436 __print_symbolic(__entry->action, 437 { PM_QOS_ADD_REQ, "ADD_REQ" }, 438 { PM_QOS_UPDATE_REQ, "UPDATE_REQ" }, 439 { PM_QOS_REMOVE_REQ, "REMOVE_REQ" }), 440 __entry->prev_value, __entry->curr_value) 441 ); 442 443 DEFINE_EVENT(pm_qos_update, pm_qos_update_target, 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 450 DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags, 451 452 TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value), 453 454 TP_ARGS(action, prev_value, curr_value), 455 456 TP_printk("action=%s prev_value=0x%x curr_value=0x%x", 457 __print_symbolic(__entry->action, 458 { PM_QOS_ADD_REQ, "ADD_REQ" }, 459 { PM_QOS_UPDATE_REQ, "UPDATE_REQ" }, 460 { PM_QOS_REMOVE_REQ, "REMOVE_REQ" }), 461 __entry->prev_value, __entry->curr_value) 462 ); 463 464 DECLARE_EVENT_CLASS(dev_pm_qos_request, 465 466 TP_PROTO(const char *name, enum dev_pm_qos_req_type type, 467 s32 new_value), 468 469 TP_ARGS(name, type, new_value), 470 471 TP_STRUCT__entry( 472 __string( name, name ) 473 __field( enum dev_pm_qos_req_type, type ) 474 __field( s32, new_value ) 475 ), 476 477 TP_fast_assign( 478 __assign_str(name); 479 __entry->type = type; 480 __entry->new_value = new_value; 481 ), 482 483 TP_printk("device=%s type=%s new_value=%d", 484 __get_str(name), 485 __print_symbolic(__entry->type, 486 { DEV_PM_QOS_RESUME_LATENCY, "DEV_PM_QOS_RESUME_LATENCY" }, 487 { DEV_PM_QOS_FLAGS, "DEV_PM_QOS_FLAGS" }), 488 __entry->new_value) 489 ); 490 491 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_add_request, 492 493 TP_PROTO(const char *name, enum dev_pm_qos_req_type type, 494 s32 new_value), 495 496 TP_ARGS(name, type, new_value) 497 ); 498 499 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_update_request, 500 501 TP_PROTO(const char *name, enum dev_pm_qos_req_type type, 502 s32 new_value), 503 504 TP_ARGS(name, type, new_value) 505 ); 506 507 DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request, 508 509 TP_PROTO(const char *name, enum dev_pm_qos_req_type type, 510 s32 new_value), 511 512 TP_ARGS(name, type, new_value) 513 ); 514 515 TRACE_EVENT(guest_halt_poll_ns, 516 517 TP_PROTO(bool grow, unsigned int new, unsigned int old), 518 519 TP_ARGS(grow, new, old), 520 521 TP_STRUCT__entry( 522 __field(bool, grow) 523 __field(unsigned int, new) 524 __field(unsigned int, old) 525 ), 526 527 TP_fast_assign( 528 __entry->grow = grow; 529 __entry->new = new; 530 __entry->old = old; 531 ), 532 533 TP_printk("halt_poll_ns %u (%s %u)", 534 __entry->new, 535 __entry->grow ? "grow" : "shrink", 536 __entry->old) 537 ); 538 539 #define trace_guest_halt_poll_ns_grow(new, old) \ 540 trace_guest_halt_poll_ns(true, new, old) 541 #define trace_guest_halt_poll_ns_shrink(new, old) \ 542 trace_guest_halt_poll_ns(false, new, old) 543 #endif /* _TRACE_POWER_H */ 544 545 /* This part must be outside protection */ 546 #include <trace/define_trace.h> 547