| 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 | #ifdef CONFIG_ARM_PSCI_CPUIDLE |
| 66 | DECLARE_EVENT_CLASS(psci_domain_idle, |
| 67 | |
| 68 | TP_PROTO(unsigned int cpu_id, unsigned int state, bool s2idle), |
| 69 | |
| 70 | TP_ARGS(cpu_id, state, s2idle), |
| 71 | |
| 72 | TP_STRUCT__entry( |
| 73 | __field(u32, cpu_id) |
| 74 | __field(u32, state) |
| 75 | __field(bool, s2idle) |
| 76 | ), |
| 77 | |
| 78 | TP_fast_assign( |
| 79 | __entry->cpu_id = cpu_id; |
| 80 | __entry->state = state; |
| 81 | __entry->s2idle = s2idle; |
| 82 | ), |
| 83 | |
| 84 | TP_printk("cpu_id=%lu state=0x%lx is_s2idle=%s" , |
| 85 | (unsigned long)__entry->cpu_id, (unsigned long)__entry->state, |
| 86 | (__entry->s2idle)?"yes" :"no" ) |
| 87 | ); |
| 88 | |
| 89 | DEFINE_EVENT(psci_domain_idle, psci_domain_idle_enter, |
| 90 | |
| 91 | TP_PROTO(unsigned int cpu_id, unsigned int state, bool s2idle), |
| 92 | |
| 93 | TP_ARGS(cpu_id, state, s2idle) |
| 94 | ); |
| 95 | |
| 96 | DEFINE_EVENT(psci_domain_idle, psci_domain_idle_exit, |
| 97 | |
| 98 | TP_PROTO(unsigned int cpu_id, unsigned int state, bool s2idle), |
| 99 | |
| 100 | TP_ARGS(cpu_id, state, s2idle) |
| 101 | ); |
| 102 | #endif |
| 103 | |
| 104 | TRACE_EVENT(pstate_sample, |
| 105 | |
| 106 | TP_PROTO(u32 core_busy, |
| 107 | u32 scaled_busy, |
| 108 | u32 from, |
| 109 | u32 to, |
| 110 | u64 mperf, |
| 111 | u64 aperf, |
| 112 | u64 tsc, |
| 113 | u32 freq, |
| 114 | u32 io_boost |
| 115 | ), |
| 116 | |
| 117 | TP_ARGS(core_busy, |
| 118 | scaled_busy, |
| 119 | from, |
| 120 | to, |
| 121 | mperf, |
| 122 | aperf, |
| 123 | tsc, |
| 124 | freq, |
| 125 | io_boost |
| 126 | ), |
| 127 | |
| 128 | TP_STRUCT__entry( |
| 129 | __field(u32, core_busy) |
| 130 | __field(u32, scaled_busy) |
| 131 | __field(u32, from) |
| 132 | __field(u32, to) |
| 133 | __field(u64, mperf) |
| 134 | __field(u64, aperf) |
| 135 | __field(u64, tsc) |
| 136 | __field(u32, freq) |
| 137 | __field(u32, io_boost) |
| 138 | ), |
| 139 | |
| 140 | TP_fast_assign( |
| 141 | __entry->core_busy = core_busy; |
| 142 | __entry->scaled_busy = scaled_busy; |
| 143 | __entry->from = from; |
| 144 | __entry->to = to; |
| 145 | __entry->mperf = mperf; |
| 146 | __entry->aperf = aperf; |
| 147 | __entry->tsc = tsc; |
| 148 | __entry->freq = freq; |
| 149 | __entry->io_boost = io_boost; |
| 150 | ), |
| 151 | |
| 152 | TP_printk("core_busy=%lu scaled=%lu from=%lu to=%lu mperf=%llu aperf=%llu tsc=%llu freq=%lu io_boost=%lu" , |
| 153 | (unsigned long)__entry->core_busy, |
| 154 | (unsigned long)__entry->scaled_busy, |
| 155 | (unsigned long)__entry->from, |
| 156 | (unsigned long)__entry->to, |
| 157 | (unsigned long long)__entry->mperf, |
| 158 | (unsigned long long)__entry->aperf, |
| 159 | (unsigned long long)__entry->tsc, |
| 160 | (unsigned long)__entry->freq, |
| 161 | (unsigned long)__entry->io_boost |
| 162 | ) |
| 163 | |
| 164 | ); |
| 165 | |
| 166 | /* This file can get included multiple times, TRACE_HEADER_MULTI_READ at top */ |
| 167 | #ifndef _PWR_EVENT_AVOID_DOUBLE_DEFINING |
| 168 | #define _PWR_EVENT_AVOID_DOUBLE_DEFINING |
| 169 | |
| 170 | #define PWR_EVENT_EXIT -1 |
| 171 | #endif |
| 172 | |
| 173 | #define pm_verb_symbolic(event) \ |
| 174 | __print_symbolic(event, \ |
| 175 | { PM_EVENT_SUSPEND, "suspend" }, \ |
| 176 | { PM_EVENT_RESUME, "resume" }, \ |
| 177 | { PM_EVENT_FREEZE, "freeze" }, \ |
| 178 | { PM_EVENT_QUIESCE, "quiesce" }, \ |
| 179 | { PM_EVENT_HIBERNATE, "hibernate" }, \ |
| 180 | { PM_EVENT_THAW, "thaw" }, \ |
| 181 | { PM_EVENT_RESTORE, "restore" }, \ |
| 182 | { PM_EVENT_RECOVER, "recover" }, \ |
| 183 | { PM_EVENT_POWEROFF, "poweroff" }) |
| 184 | |
| 185 | DEFINE_EVENT(cpu, cpu_frequency, |
| 186 | |
| 187 | TP_PROTO(unsigned int frequency, unsigned int cpu_id), |
| 188 | |
| 189 | TP_ARGS(frequency, cpu_id) |
| 190 | ); |
| 191 | |
| 192 | TRACE_EVENT(cpu_frequency_limits, |
| 193 | |
| 194 | TP_PROTO(struct cpufreq_policy *policy), |
| 195 | |
| 196 | TP_ARGS(policy), |
| 197 | |
| 198 | TP_STRUCT__entry( |
| 199 | __field(u32, min_freq) |
| 200 | __field(u32, max_freq) |
| 201 | __field(u32, cpu_id) |
| 202 | ), |
| 203 | |
| 204 | TP_fast_assign( |
| 205 | __entry->min_freq = policy->min; |
| 206 | __entry->max_freq = policy->max; |
| 207 | __entry->cpu_id = policy->cpu; |
| 208 | ), |
| 209 | |
| 210 | TP_printk("min=%lu max=%lu cpu_id=%lu" , |
| 211 | (unsigned long)__entry->min_freq, |
| 212 | (unsigned long)__entry->max_freq, |
| 213 | (unsigned long)__entry->cpu_id) |
| 214 | ); |
| 215 | |
| 216 | #ifdef CONFIG_PM_SLEEP |
| 217 | TRACE_EVENT(device_pm_callback_start, |
| 218 | |
| 219 | TP_PROTO(struct device *dev, const char *pm_ops, int event), |
| 220 | |
| 221 | TP_ARGS(dev, pm_ops, event), |
| 222 | |
| 223 | TP_STRUCT__entry( |
| 224 | __string(device, dev_name(dev)) |
| 225 | __string(driver, dev_driver_string(dev)) |
| 226 | __string(parent, dev->parent ? dev_name(dev->parent) : "none" ) |
| 227 | __string(pm_ops, pm_ops ? pm_ops : "none " ) |
| 228 | __field(int, event) |
| 229 | ), |
| 230 | |
| 231 | TP_fast_assign( |
| 232 | __assign_str(device); |
| 233 | __assign_str(driver); |
| 234 | __assign_str(parent); |
| 235 | __assign_str(pm_ops); |
| 236 | __entry->event = event; |
| 237 | ), |
| 238 | |
| 239 | TP_printk("%s %s, parent: %s, %s[%s]" , __get_str(driver), |
| 240 | __get_str(device), __get_str(parent), __get_str(pm_ops), |
| 241 | pm_verb_symbolic(__entry->event)) |
| 242 | ); |
| 243 | |
| 244 | TRACE_EVENT(device_pm_callback_end, |
| 245 | |
| 246 | TP_PROTO(struct device *dev, int error), |
| 247 | |
| 248 | TP_ARGS(dev, error), |
| 249 | |
| 250 | TP_STRUCT__entry( |
| 251 | __string(device, dev_name(dev)) |
| 252 | __string(driver, dev_driver_string(dev)) |
| 253 | __field(int, error) |
| 254 | ), |
| 255 | |
| 256 | TP_fast_assign( |
| 257 | __assign_str(device); |
| 258 | __assign_str(driver); |
| 259 | __entry->error = error; |
| 260 | ), |
| 261 | |
| 262 | TP_printk("%s %s, err=%d" , |
| 263 | __get_str(driver), __get_str(device), __entry->error) |
| 264 | ); |
| 265 | #endif |
| 266 | |
| 267 | TRACE_EVENT(suspend_resume, |
| 268 | |
| 269 | TP_PROTO(const char *action, int val, bool start), |
| 270 | |
| 271 | TP_ARGS(action, val, start), |
| 272 | |
| 273 | TP_STRUCT__entry( |
| 274 | __field(const char *, action) |
| 275 | __field(int, val) |
| 276 | __field(bool, start) |
| 277 | ), |
| 278 | |
| 279 | TP_fast_assign( |
| 280 | __entry->action = action; |
| 281 | __entry->val = val; |
| 282 | __entry->start = start; |
| 283 | ), |
| 284 | |
| 285 | TP_printk("%s[%u] %s" , __entry->action, (unsigned int)__entry->val, |
| 286 | (__entry->start)?"begin" :"end" ) |
| 287 | ); |
| 288 | |
| 289 | DECLARE_EVENT_CLASS(wakeup_source, |
| 290 | |
| 291 | TP_PROTO(const char *name, unsigned int state), |
| 292 | |
| 293 | TP_ARGS(name, state), |
| 294 | |
| 295 | TP_STRUCT__entry( |
| 296 | __string( name, name ) |
| 297 | __field( u64, state ) |
| 298 | ), |
| 299 | |
| 300 | TP_fast_assign( |
| 301 | __assign_str(name); |
| 302 | __entry->state = state; |
| 303 | ), |
| 304 | |
| 305 | TP_printk("%s state=0x%lx" , __get_str(name), |
| 306 | (unsigned long)__entry->state) |
| 307 | ); |
| 308 | |
| 309 | DEFINE_EVENT(wakeup_source, wakeup_source_activate, |
| 310 | |
| 311 | TP_PROTO(const char *name, unsigned int state), |
| 312 | |
| 313 | TP_ARGS(name, state) |
| 314 | ); |
| 315 | |
| 316 | DEFINE_EVENT(wakeup_source, wakeup_source_deactivate, |
| 317 | |
| 318 | TP_PROTO(const char *name, unsigned int state), |
| 319 | |
| 320 | TP_ARGS(name, state) |
| 321 | ); |
| 322 | |
| 323 | #ifdef CONFIG_ARCH_OMAP2PLUS |
| 324 | /* |
| 325 | * The power domain events are used for power domains transitions |
| 326 | */ |
| 327 | DECLARE_EVENT_CLASS(power_domain, |
| 328 | |
| 329 | TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id), |
| 330 | |
| 331 | TP_ARGS(name, state, cpu_id), |
| 332 | |
| 333 | TP_STRUCT__entry( |
| 334 | __string( name, name ) |
| 335 | __field( u64, state ) |
| 336 | __field( u64, cpu_id ) |
| 337 | ), |
| 338 | |
| 339 | TP_fast_assign( |
| 340 | __assign_str(name); |
| 341 | __entry->state = state; |
| 342 | __entry->cpu_id = cpu_id; |
| 343 | ), |
| 344 | |
| 345 | TP_printk("%s state=%lu cpu_id=%lu" , __get_str(name), |
| 346 | (unsigned long)__entry->state, (unsigned long)__entry->cpu_id) |
| 347 | ); |
| 348 | |
| 349 | DEFINE_EVENT(power_domain, power_domain_target, |
| 350 | |
| 351 | TP_PROTO(const char *name, unsigned int state, unsigned int cpu_id), |
| 352 | |
| 353 | TP_ARGS(name, state, cpu_id) |
| 354 | ); |
| 355 | #endif |
| 356 | |
| 357 | /* |
| 358 | * CPU latency QoS events used for global CPU latency QoS list updates |
| 359 | */ |
| 360 | DECLARE_EVENT_CLASS(cpu_latency_qos_request, |
| 361 | |
| 362 | TP_PROTO(s32 value), |
| 363 | |
| 364 | TP_ARGS(value), |
| 365 | |
| 366 | TP_STRUCT__entry( |
| 367 | __field( s32, value ) |
| 368 | ), |
| 369 | |
| 370 | TP_fast_assign( |
| 371 | __entry->value = value; |
| 372 | ), |
| 373 | |
| 374 | TP_printk("CPU_DMA_LATENCY value=%d" , |
| 375 | __entry->value) |
| 376 | ); |
| 377 | |
| 378 | DEFINE_EVENT(cpu_latency_qos_request, pm_qos_add_request, |
| 379 | |
| 380 | TP_PROTO(s32 value), |
| 381 | |
| 382 | TP_ARGS(value) |
| 383 | ); |
| 384 | |
| 385 | DEFINE_EVENT(cpu_latency_qos_request, pm_qos_update_request, |
| 386 | |
| 387 | TP_PROTO(s32 value), |
| 388 | |
| 389 | TP_ARGS(value) |
| 390 | ); |
| 391 | |
| 392 | DEFINE_EVENT(cpu_latency_qos_request, pm_qos_remove_request, |
| 393 | |
| 394 | TP_PROTO(s32 value), |
| 395 | |
| 396 | TP_ARGS(value) |
| 397 | ); |
| 398 | |
| 399 | /* |
| 400 | * General PM QoS events used for updates of PM QoS request lists |
| 401 | */ |
| 402 | DECLARE_EVENT_CLASS(pm_qos_update, |
| 403 | |
| 404 | TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value), |
| 405 | |
| 406 | TP_ARGS(action, prev_value, curr_value), |
| 407 | |
| 408 | TP_STRUCT__entry( |
| 409 | __field( enum pm_qos_req_action, action ) |
| 410 | __field( int, prev_value ) |
| 411 | __field( int, curr_value ) |
| 412 | ), |
| 413 | |
| 414 | TP_fast_assign( |
| 415 | __entry->action = action; |
| 416 | __entry->prev_value = prev_value; |
| 417 | __entry->curr_value = curr_value; |
| 418 | ), |
| 419 | |
| 420 | TP_printk("action=%s prev_value=%d curr_value=%d" , |
| 421 | __print_symbolic(__entry->action, |
| 422 | { PM_QOS_ADD_REQ, "ADD_REQ" }, |
| 423 | { PM_QOS_UPDATE_REQ, "UPDATE_REQ" }, |
| 424 | { PM_QOS_REMOVE_REQ, "REMOVE_REQ" }), |
| 425 | __entry->prev_value, __entry->curr_value) |
| 426 | ); |
| 427 | |
| 428 | DEFINE_EVENT(pm_qos_update, pm_qos_update_target, |
| 429 | |
| 430 | TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value), |
| 431 | |
| 432 | TP_ARGS(action, prev_value, curr_value) |
| 433 | ); |
| 434 | |
| 435 | DEFINE_EVENT_PRINT(pm_qos_update, pm_qos_update_flags, |
| 436 | |
| 437 | TP_PROTO(enum pm_qos_req_action action, int prev_value, int curr_value), |
| 438 | |
| 439 | TP_ARGS(action, prev_value, curr_value), |
| 440 | |
| 441 | TP_printk("action=%s prev_value=0x%x curr_value=0x%x" , |
| 442 | __print_symbolic(__entry->action, |
| 443 | { PM_QOS_ADD_REQ, "ADD_REQ" }, |
| 444 | { PM_QOS_UPDATE_REQ, "UPDATE_REQ" }, |
| 445 | { PM_QOS_REMOVE_REQ, "REMOVE_REQ" }), |
| 446 | __entry->prev_value, __entry->curr_value) |
| 447 | ); |
| 448 | |
| 449 | DECLARE_EVENT_CLASS(dev_pm_qos_request, |
| 450 | |
| 451 | TP_PROTO(const char *name, enum dev_pm_qos_req_type type, |
| 452 | s32 new_value), |
| 453 | |
| 454 | TP_ARGS(name, type, new_value), |
| 455 | |
| 456 | TP_STRUCT__entry( |
| 457 | __string( name, name ) |
| 458 | __field( enum dev_pm_qos_req_type, type ) |
| 459 | __field( s32, new_value ) |
| 460 | ), |
| 461 | |
| 462 | TP_fast_assign( |
| 463 | __assign_str(name); |
| 464 | __entry->type = type; |
| 465 | __entry->new_value = new_value; |
| 466 | ), |
| 467 | |
| 468 | TP_printk("device=%s type=%s new_value=%d" , |
| 469 | __get_str(name), |
| 470 | __print_symbolic(__entry->type, |
| 471 | { DEV_PM_QOS_RESUME_LATENCY, "DEV_PM_QOS_RESUME_LATENCY" }, |
| 472 | { DEV_PM_QOS_FLAGS, "DEV_PM_QOS_FLAGS" }), |
| 473 | __entry->new_value) |
| 474 | ); |
| 475 | |
| 476 | DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_add_request, |
| 477 | |
| 478 | TP_PROTO(const char *name, enum dev_pm_qos_req_type type, |
| 479 | s32 new_value), |
| 480 | |
| 481 | TP_ARGS(name, type, new_value) |
| 482 | ); |
| 483 | |
| 484 | DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_update_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_remove_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 | TRACE_EVENT(guest_halt_poll_ns, |
| 501 | |
| 502 | TP_PROTO(bool grow, unsigned int new, unsigned int old), |
| 503 | |
| 504 | TP_ARGS(grow, new, old), |
| 505 | |
| 506 | TP_STRUCT__entry( |
| 507 | __field(bool, grow) |
| 508 | __field(unsigned int, new) |
| 509 | __field(unsigned int, old) |
| 510 | ), |
| 511 | |
| 512 | TP_fast_assign( |
| 513 | __entry->grow = grow; |
| 514 | __entry->new = new; |
| 515 | __entry->old = old; |
| 516 | ), |
| 517 | |
| 518 | TP_printk("halt_poll_ns %u (%s %u)" , |
| 519 | __entry->new, |
| 520 | __entry->grow ? "grow" : "shrink" , |
| 521 | __entry->old) |
| 522 | ); |
| 523 | |
| 524 | #define trace_guest_halt_poll_ns_grow(new, old) \ |
| 525 | trace_guest_halt_poll_ns(true, new, old) |
| 526 | #define trace_guest_halt_poll_ns_shrink(new, old) \ |
| 527 | trace_guest_halt_poll_ns(false, new, old) |
| 528 | #endif /* _TRACE_POWER_H */ |
| 529 | |
| 530 | /* This part must be outside protection */ |
| 531 | #include <trace/define_trace.h> |
| 532 | |