trace_entries.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. * internel 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( unsigned long, ip )
  62. __field( unsigned long, parent_ip )
  63. ),
  64. F_printk(" %lx <-- %lx", __entry->ip, __entry->parent_ip),
  65. FILTER_TRACE_FN,
  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_desc( unsigned long, graph_ent, func )
  74. __field_desc( int, graph_ent, depth )
  75. ),
  76. F_printk("--> %lx (%d)", __entry->func, __entry->depth),
  77. FILTER_OTHER
  78. );
  79. /* Function return entry */
  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_desc( unsigned long, ret, func )
  85. __field_desc( unsigned long long, ret, calltime)
  86. __field_desc( unsigned long long, ret, rettime )
  87. __field_desc( unsigned long, ret, overrun )
  88. __field_desc( int, ret, depth )
  89. ),
  90. F_printk("<-- %lx (%d) (start: %llx end: %llx) over: %d",
  91. __entry->func, __entry->depth,
  92. __entry->calltime, __entry->rettime,
  93. __entry->depth),
  94. FILTER_OTHER
  95. );
  96. /*
  97. * Context switch trace entry - which task (and prio) we switched from/to:
  98. *
  99. * This is used for both wakeup and context switches. We only want
  100. * to create one structure, but we need two outputs for it.
  101. */
  102. #define FTRACE_CTX_FIELDS \
  103. __field( unsigned int, prev_pid ) \
  104. __field( unsigned int, next_pid ) \
  105. __field( unsigned int, next_cpu ) \
  106. __field( unsigned char, prev_prio ) \
  107. __field( unsigned char, prev_state ) \
  108. __field( unsigned char, next_prio ) \
  109. __field( unsigned char, next_state )
  110. FTRACE_ENTRY(context_switch, ctx_switch_entry,
  111. TRACE_CTX,
  112. F_STRUCT(
  113. FTRACE_CTX_FIELDS
  114. ),
  115. F_printk("%u:%u:%u ==> %u:%u:%u [%03u]",
  116. __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
  117. __entry->next_pid, __entry->next_prio, __entry->next_state,
  118. __entry->next_cpu),
  119. FILTER_OTHER
  120. );
  121. /*
  122. * FTRACE_ENTRY_DUP only creates the format file, it will not
  123. * create another structure.
  124. */
  125. FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry,
  126. TRACE_WAKE,
  127. F_STRUCT(
  128. FTRACE_CTX_FIELDS
  129. ),
  130. F_printk("%u:%u:%u ==+ %u:%u:%u [%03u]",
  131. __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
  132. __entry->next_pid, __entry->next_prio, __entry->next_state,
  133. __entry->next_cpu),
  134. FILTER_OTHER
  135. );
  136. /*
  137. * Stack-trace entry:
  138. */
  139. #define FTRACE_STACK_ENTRIES 8
  140. #ifndef CONFIG_64BIT
  141. # define IP_FMT "%08lx"
  142. #else
  143. # define IP_FMT "%016lx"
  144. #endif
  145. FTRACE_ENTRY(kernel_stack, stack_entry,
  146. TRACE_STACK,
  147. F_STRUCT(
  148. __field( int, size )
  149. __dynamic_array(unsigned long, caller )
  150. ),
  151. F_printk("\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
  152. "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
  153. "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n",
  154. __entry->caller[0], __entry->caller[1], __entry->caller[2],
  155. __entry->caller[3], __entry->caller[4], __entry->caller[5],
  156. __entry->caller[6], __entry->caller[7]),
  157. FILTER_OTHER
  158. );
  159. FTRACE_ENTRY(user_stack, userstack_entry,
  160. TRACE_USER_STACK,
  161. F_STRUCT(
  162. __field( unsigned int, tgid )
  163. __array( unsigned long, caller, FTRACE_STACK_ENTRIES )
  164. ),
  165. F_printk("\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
  166. "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n"
  167. "\t=> (" IP_FMT ")\n\t=> (" IP_FMT ")\n",
  168. __entry->caller[0], __entry->caller[1], __entry->caller[2],
  169. __entry->caller[3], __entry->caller[4], __entry->caller[5],
  170. __entry->caller[6], __entry->caller[7]),
  171. FILTER_OTHER
  172. );
  173. /*
  174. * trace_printk entry:
  175. */
  176. FTRACE_ENTRY(bprint, bprint_entry,
  177. TRACE_BPRINT,
  178. F_STRUCT(
  179. __field( unsigned long, ip )
  180. __field( const char *, fmt )
  181. __dynamic_array( u32, buf )
  182. ),
  183. F_printk("%ps: %s",
  184. (void *)__entry->ip, __entry->fmt),
  185. FILTER_OTHER
  186. );
  187. FTRACE_ENTRY_REG(print, print_entry,
  188. TRACE_PRINT,
  189. F_STRUCT(
  190. __field( unsigned long, ip )
  191. __dynamic_array( char, buf )
  192. ),
  193. F_printk("%ps: %s",
  194. (void *)__entry->ip, __entry->buf),
  195. FILTER_OTHER,
  196. ftrace_event_register
  197. );
  198. FTRACE_ENTRY(raw_data, raw_data_entry,
  199. TRACE_RAW_DATA,
  200. F_STRUCT(
  201. __field( unsigned int, id )
  202. __dynamic_array( char, buf )
  203. ),
  204. F_printk("id:%04x %08x",
  205. __entry->id, (int)__entry->buf[0]),
  206. FILTER_OTHER
  207. );
  208. FTRACE_ENTRY(bputs, bputs_entry,
  209. TRACE_BPUTS,
  210. F_STRUCT(
  211. __field( unsigned long, ip )
  212. __field( const char *, str )
  213. ),
  214. F_printk("%ps: %s",
  215. (void *)__entry->ip, __entry->str),
  216. FILTER_OTHER
  217. );
  218. FTRACE_ENTRY(mmiotrace_rw, trace_mmiotrace_rw,
  219. TRACE_MMIO_RW,
  220. F_STRUCT(
  221. __field_struct( struct mmiotrace_rw, rw )
  222. __field_desc( resource_size_t, rw, phys )
  223. __field_desc( unsigned long, rw, value )
  224. __field_desc( unsigned long, rw, pc )
  225. __field_desc( int, rw, map_id )
  226. __field_desc( unsigned char, rw, opcode )
  227. __field_desc( unsigned char, rw, width )
  228. ),
  229. F_printk("%lx %lx %lx %d %x %x",
  230. (unsigned long)__entry->phys, __entry->value, __entry->pc,
  231. __entry->map_id, __entry->opcode, __entry->width),
  232. FILTER_OTHER
  233. );
  234. FTRACE_ENTRY(mmiotrace_map, trace_mmiotrace_map,
  235. TRACE_MMIO_MAP,
  236. F_STRUCT(
  237. __field_struct( struct mmiotrace_map, map )
  238. __field_desc( resource_size_t, map, phys )
  239. __field_desc( unsigned long, map, virt )
  240. __field_desc( unsigned long, map, len )
  241. __field_desc( int, map, map_id )
  242. __field_desc( unsigned char, map, opcode )
  243. ),
  244. F_printk("%lx %lx %lx %d %x",
  245. (unsigned long)__entry->phys, __entry->virt, __entry->len,
  246. __entry->map_id, __entry->opcode),
  247. FILTER_OTHER
  248. );
  249. #define TRACE_FUNC_SIZE 30
  250. #define TRACE_FILE_SIZE 20
  251. FTRACE_ENTRY(branch, trace_branch,
  252. TRACE_BRANCH,
  253. F_STRUCT(
  254. __field( unsigned int, line )
  255. __array( char, func, TRACE_FUNC_SIZE+1 )
  256. __array( char, file, TRACE_FILE_SIZE+1 )
  257. __field( char, correct )
  258. __field( char, constant )
  259. ),
  260. F_printk("%u:%s:%s (%u)%s",
  261. __entry->line,
  262. __entry->func, __entry->file, __entry->correct,
  263. __entry->constant ? " CONSTANT" : ""),
  264. FILTER_OTHER
  265. );
  266. FTRACE_ENTRY(hwlat, hwlat_entry,
  267. TRACE_HWLAT,
  268. F_STRUCT(
  269. __field( u64, duration )
  270. __field( u64, outer_duration )
  271. __field( u64, nmi_total_ts )
  272. __field_struct( struct timespec64, timestamp )
  273. __field_desc( s64, timestamp, tv_sec )
  274. __field_desc( long, timestamp, tv_nsec )
  275. __field( unsigned int, nmi_count )
  276. __field( unsigned int, seqnum )
  277. ),
  278. F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llu\tnmi-ts:%llu\tnmi-count:%u\n",
  279. __entry->seqnum,
  280. __entry->tv_sec,
  281. __entry->tv_nsec,
  282. __entry->duration,
  283. __entry->outer_duration,
  284. __entry->nmi_total_ts,
  285. __entry->nmi_count),
  286. FILTER_OTHER
  287. );