trace_entries.h 8.2 KB

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