trace_entries.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * This file defines the trace event structures that go into the ring
  4. * buffer directly. They are created via macros so that changes for them
  5. * appear in the format file. Using macros will automate this process.
  6. *
  7. * The macro used to create a ftrace data structure is:
  8. *
  9. * FTRACE_ENTRY( name, struct_name, id, structure, print )
  10. *
  11. * @name: the name used the event name, as well as the name of
  12. * the directory that holds the format file.
  13. *
  14. * @struct_name: the name of the structure that is created.
  15. *
  16. * @id: The event identifier that is used to detect what event
  17. * this is from the ring buffer.
  18. *
  19. * @structure: the structure layout
  20. *
  21. * - __field( type, item )
  22. * This is equivalent to declaring
  23. * type item;
  24. * in the structure.
  25. * - __array( type, item, size )
  26. * This is equivalent to declaring
  27. * type item[size];
  28. * in the structure.
  29. *
  30. * * for structures within structures, the format of the internal
  31. * structure is laid out. This allows the internal structure
  32. * to be deciphered for the format file. Although these macros
  33. * may become out of sync with the internal structure, they
  34. * will create a compile error if it happens. Since the
  35. * internal structures are just tracing helpers, this is not
  36. * an issue.
  37. *
  38. * When an internal structure is used, it should use:
  39. *
  40. * __field_struct( type, item )
  41. *
  42. * instead of __field. This will prevent it from being shown in
  43. * the output file. The fields in the structure should use.
  44. *
  45. * __field_desc( type, container, item )
  46. * __array_desc( type, container, item, len )
  47. *
  48. * type, item and len are the same as __field and __array, but
  49. * container is added. This is the name of the item in
  50. * __field_struct that this is describing.
  51. *
  52. *
  53. * @print: the print format shown to users in the format file.
  54. */
  55. /*
  56. * Function trace entry - function address and parent function address:
  57. */
  58. FTRACE_ENTRY_REG(function, ftrace_entry,
  59. TRACE_FN,
  60. F_STRUCT(
  61. __field_fn( unsigned long, ip )
  62. __field_fn( unsigned long, parent_ip )
  63. ),
  64. F_printk(" %ps <-- %ps",
  65. (void *)__entry->ip, (void *)__entry->parent_ip),
  66. perf_ftrace_event_register
  67. );
  68. /* Function call entry */
  69. FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry,
  70. TRACE_GRAPH_ENT,
  71. F_STRUCT(
  72. __field_struct( struct ftrace_graph_ent, graph_ent )
  73. __field_packed( unsigned long, graph_ent, func )
  74. __field_packed( int, graph_ent, depth )
  75. ),
  76. F_printk("--> %ps (%d)", (void *)__entry->func, __entry->depth)
  77. );
  78. /* Function return entry */
  79. #ifdef CONFIG_FUNCTION_GRAPH_RETVAL
  80. FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
  81. TRACE_GRAPH_RET,
  82. F_STRUCT(
  83. __field_struct( struct ftrace_graph_ret, ret )
  84. __field_packed( unsigned long, ret, func )
  85. __field_packed( unsigned long, ret, retval )
  86. __field_packed( int, ret, depth )
  87. __field_packed( unsigned int, ret, overrun )
  88. __field_packed( unsigned long long, ret, calltime)
  89. __field_packed( unsigned long long, ret, rettime )
  90. ),
  91. F_printk("<-- %ps (%d) (start: %llx end: %llx) over: %d retval: %lx",
  92. (void *)__entry->func, __entry->depth,
  93. __entry->calltime, __entry->rettime,
  94. __entry->depth, __entry->retval)
  95. );
  96. #else
  97. FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
  98. TRACE_GRAPH_RET,
  99. F_STRUCT(
  100. __field_struct( struct ftrace_graph_ret, ret )
  101. __field_packed( unsigned long, ret, func )
  102. __field_packed( int, ret, depth )
  103. __field_packed( unsigned int, ret, overrun )
  104. __field_packed( unsigned long long, ret, calltime)
  105. __field_packed( unsigned long long, ret, rettime )
  106. ),
  107. F_printk("<-- %ps (%d) (start: %llx end: %llx) over: %d",
  108. (void *)__entry->func, __entry->depth,
  109. __entry->calltime, __entry->rettime,
  110. __entry->depth)
  111. );
  112. #endif
  113. /*
  114. * Context switch trace entry - which task (and prio) we switched from/to:
  115. *
  116. * This is used for both wakeup and context switches. We only want
  117. * to create one structure, but we need two outputs for it.
  118. */
  119. #define FTRACE_CTX_FIELDS \
  120. __field( unsigned int, prev_pid ) \
  121. __field( unsigned int, next_pid ) \
  122. __field( unsigned int, next_cpu ) \
  123. __field( unsigned char, prev_prio ) \
  124. __field( unsigned char, prev_state ) \
  125. __field( unsigned char, next_prio ) \
  126. __field( unsigned char, next_state )
  127. FTRACE_ENTRY(context_switch, ctx_switch_entry,
  128. TRACE_CTX,
  129. F_STRUCT(
  130. FTRACE_CTX_FIELDS
  131. ),
  132. F_printk("%u:%u:%u ==> %u:%u:%u [%03u]",
  133. __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
  134. __entry->next_pid, __entry->next_prio, __entry->next_state,
  135. __entry->next_cpu)
  136. );
  137. /*
  138. * FTRACE_ENTRY_DUP only creates the format file, it will not
  139. * create another structure.
  140. */
  141. FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry,
  142. TRACE_WAKE,
  143. F_STRUCT(
  144. FTRACE_CTX_FIELDS
  145. ),
  146. F_printk("%u:%u:%u ==+ %u:%u:%u [%03u]",
  147. __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
  148. __entry->next_pid, __entry->next_prio, __entry->next_state,
  149. __entry->next_cpu)
  150. );
  151. /*
  152. * Stack-trace entry:
  153. */
  154. #define FTRACE_STACK_ENTRIES 8
  155. FTRACE_ENTRY(kernel_stack, stack_entry,
  156. TRACE_STACK,
  157. F_STRUCT(
  158. __field( int, size )
  159. __stack_array( unsigned long, caller, FTRACE_STACK_ENTRIES, size)
  160. ),
  161. F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
  162. "\t=> %ps\n\t=> %ps\n\t=> %ps\n"
  163. "\t=> %ps\n\t=> %ps\n",
  164. (void *)__entry->caller[0], (void *)__entry->caller[1],
  165. (void *)__entry->caller[2], (void *)__entry->caller[3],
  166. (void *)__entry->caller[4], (void *)__entry->caller[5],
  167. (void *)__entry->caller[6], (void *)__entry->caller[7])
  168. );
  169. FTRACE_ENTRY(user_stack, userstack_entry,
  170. TRACE_USER_STACK,
  171. F_STRUCT(
  172. __field( unsigned int, tgid )
  173. __array( unsigned long, caller, FTRACE_STACK_ENTRIES )
  174. ),
  175. F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
  176. "\t=> %ps\n\t=> %ps\n\t=> %ps\n"
  177. "\t=> %ps\n\t=> %ps\n",
  178. (void *)__entry->caller[0], (void *)__entry->caller[1],
  179. (void *)__entry->caller[2], (void *)__entry->caller[3],
  180. (void *)__entry->caller[4], (void *)__entry->caller[5],
  181. (void *)__entry->caller[6], (void *)__entry->caller[7])
  182. );
  183. /*
  184. * trace_printk entry:
  185. */
  186. FTRACE_ENTRY(bprint, bprint_entry,
  187. TRACE_BPRINT,
  188. F_STRUCT(
  189. __field( unsigned long, ip )
  190. __field( const char *, fmt )
  191. __dynamic_array( u32, buf )
  192. ),
  193. F_printk("%ps: %s",
  194. (void *)__entry->ip, __entry->fmt)
  195. );
  196. FTRACE_ENTRY_REG(print, print_entry,
  197. TRACE_PRINT,
  198. F_STRUCT(
  199. __field( unsigned long, ip )
  200. __dynamic_array( char, buf )
  201. ),
  202. F_printk("%ps: %s",
  203. (void *)__entry->ip, __entry->buf),
  204. ftrace_event_register
  205. );
  206. FTRACE_ENTRY(raw_data, raw_data_entry,
  207. TRACE_RAW_DATA,
  208. F_STRUCT(
  209. __field( unsigned int, id )
  210. __dynamic_array( char, buf )
  211. ),
  212. F_printk("id:%04x %08x",
  213. __entry->id, (int)__entry->buf[0])
  214. );
  215. FTRACE_ENTRY(bputs, bputs_entry,
  216. TRACE_BPUTS,
  217. F_STRUCT(
  218. __field( unsigned long, ip )
  219. __field( const char *, str )
  220. ),
  221. F_printk("%ps: %s",
  222. (void *)__entry->ip, __entry->str)
  223. );
  224. FTRACE_ENTRY(mmiotrace_rw, trace_mmiotrace_rw,
  225. TRACE_MMIO_RW,
  226. F_STRUCT(
  227. __field_struct( struct mmiotrace_rw, rw )
  228. __field_desc( resource_size_t, rw, phys )
  229. __field_desc( unsigned long, rw, value )
  230. __field_desc( unsigned long, rw, pc )
  231. __field_desc( int, rw, map_id )
  232. __field_desc( unsigned char, rw, opcode )
  233. __field_desc( unsigned char, rw, width )
  234. ),
  235. F_printk("%lx %lx %lx %d %x %x",
  236. (unsigned long)__entry->phys, __entry->value, __entry->pc,
  237. __entry->map_id, __entry->opcode, __entry->width)
  238. );
  239. FTRACE_ENTRY(mmiotrace_map, trace_mmiotrace_map,
  240. TRACE_MMIO_MAP,
  241. F_STRUCT(
  242. __field_struct( struct mmiotrace_map, map )
  243. __field_desc( resource_size_t, map, phys )
  244. __field_desc( unsigned long, map, virt )
  245. __field_desc( unsigned long, map, len )
  246. __field_desc( int, map, map_id )
  247. __field_desc( unsigned char, map, opcode )
  248. ),
  249. F_printk("%lx %lx %lx %d %x",
  250. (unsigned long)__entry->phys, __entry->virt, __entry->len,
  251. __entry->map_id, __entry->opcode)
  252. );
  253. #define TRACE_FUNC_SIZE 30
  254. #define TRACE_FILE_SIZE 20
  255. FTRACE_ENTRY(branch, trace_branch,
  256. TRACE_BRANCH,
  257. F_STRUCT(
  258. __field( unsigned int, line )
  259. __array( char, func, TRACE_FUNC_SIZE+1 )
  260. __array( char, file, TRACE_FILE_SIZE+1 )
  261. __field( char, correct )
  262. __field( char, constant )
  263. ),
  264. F_printk("%u:%s:%s (%u)%s",
  265. __entry->line,
  266. __entry->func, __entry->file, __entry->correct,
  267. __entry->constant ? " CONSTANT" : "")
  268. );
  269. FTRACE_ENTRY(hwlat, hwlat_entry,
  270. TRACE_HWLAT,
  271. F_STRUCT(
  272. __field( u64, duration )
  273. __field( u64, outer_duration )
  274. __field( u64, nmi_total_ts )
  275. __field_struct( struct timespec64, timestamp )
  276. __field_desc( s64, timestamp, tv_sec )
  277. __field_desc( long, timestamp, tv_nsec )
  278. __field( unsigned int, nmi_count )
  279. __field( unsigned int, seqnum )
  280. __field( unsigned int, count )
  281. ),
  282. F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llu\tcount:%d\tnmi-ts:%llu\tnmi-count:%u\n",
  283. __entry->seqnum,
  284. __entry->tv_sec,
  285. __entry->tv_nsec,
  286. __entry->duration,
  287. __entry->outer_duration,
  288. __entry->count,
  289. __entry->nmi_total_ts,
  290. __entry->nmi_count)
  291. );
  292. #define FUNC_REPEATS_GET_DELTA_TS(entry) \
  293. (((u64)(entry)->top_delta_ts << 32) | (entry)->bottom_delta_ts) \
  294. FTRACE_ENTRY(func_repeats, func_repeats_entry,
  295. TRACE_FUNC_REPEATS,
  296. F_STRUCT(
  297. __field( unsigned long, ip )
  298. __field( unsigned long, parent_ip )
  299. __field( u16 , count )
  300. __field( u16 , top_delta_ts )
  301. __field( u32 , bottom_delta_ts )
  302. ),
  303. F_printk(" %ps <-%ps\t(repeats:%u delta: -%llu)",
  304. (void *)__entry->ip,
  305. (void *)__entry->parent_ip,
  306. __entry->count,
  307. FUNC_REPEATS_GET_DELTA_TS(__entry))
  308. );
  309. FTRACE_ENTRY(osnoise, osnoise_entry,
  310. TRACE_OSNOISE,
  311. F_STRUCT(
  312. __field( u64, noise )
  313. __field( u64, runtime )
  314. __field( u64, max_sample )
  315. __field( unsigned int, hw_count )
  316. __field( unsigned int, nmi_count )
  317. __field( unsigned int, irq_count )
  318. __field( unsigned int, softirq_count )
  319. __field( unsigned int, thread_count )
  320. ),
  321. F_printk("noise:%llu\tmax_sample:%llu\thw:%u\tnmi:%u\tirq:%u\tsoftirq:%u\tthread:%u\n",
  322. __entry->noise,
  323. __entry->max_sample,
  324. __entry->hw_count,
  325. __entry->nmi_count,
  326. __entry->irq_count,
  327. __entry->softirq_count,
  328. __entry->thread_count)
  329. );
  330. FTRACE_ENTRY(timerlat, timerlat_entry,
  331. TRACE_TIMERLAT,
  332. F_STRUCT(
  333. __field( unsigned int, seqnum )
  334. __field( int, context )
  335. __field( u64, timer_latency )
  336. ),
  337. F_printk("seq:%u\tcontext:%d\ttimer_latency:%llu\n",
  338. __entry->seqnum,
  339. __entry->context,
  340. __entry->timer_latency)
  341. );