power.h 12 KB

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