trace.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #ifndef _LINUX_KERNEL_TRACE_H
  2. #define _LINUX_KERNEL_TRACE_H
  3. #include <linux/fs.h>
  4. #include <asm/atomic.h>
  5. #include <linux/sched.h>
  6. #include <linux/clocksource.h>
  7. #include <linux/mmiotrace.h>
  8. enum trace_type {
  9. __TRACE_FIRST_TYPE = 0,
  10. TRACE_FN,
  11. TRACE_CTX,
  12. TRACE_WAKE,
  13. TRACE_CONT,
  14. TRACE_STACK,
  15. TRACE_PRINT,
  16. TRACE_SPECIAL,
  17. TRACE_MMIO_RW,
  18. TRACE_MMIO_MAP,
  19. __TRACE_LAST_TYPE
  20. };
  21. /*
  22. * Function trace entry - function address and parent function addres:
  23. */
  24. struct ftrace_entry {
  25. unsigned long ip;
  26. unsigned long parent_ip;
  27. };
  28. /*
  29. * Context switch trace entry - which task (and prio) we switched from/to:
  30. */
  31. struct ctx_switch_entry {
  32. unsigned int prev_pid;
  33. unsigned char prev_prio;
  34. unsigned char prev_state;
  35. unsigned int next_pid;
  36. unsigned char next_prio;
  37. unsigned char next_state;
  38. unsigned int next_cpu;
  39. };
  40. /*
  41. * Special (free-form) trace entry:
  42. */
  43. struct special_entry {
  44. unsigned long arg1;
  45. unsigned long arg2;
  46. unsigned long arg3;
  47. };
  48. /*
  49. * Stack-trace entry:
  50. */
  51. #define FTRACE_STACK_ENTRIES 8
  52. struct stack_entry {
  53. unsigned long caller[FTRACE_STACK_ENTRIES];
  54. };
  55. /*
  56. * ftrace_printk entry:
  57. */
  58. struct print_entry {
  59. unsigned long ip;
  60. char buf[];
  61. };
  62. /*
  63. * trace_flag_type is an enumeration that holds different
  64. * states when a trace occurs. These are:
  65. * IRQS_OFF - interrupts were disabled
  66. * NEED_RESCED - reschedule is requested
  67. * HARDIRQ - inside an interrupt handler
  68. * SOFTIRQ - inside a softirq handler
  69. * CONT - multiple entries hold the trace item
  70. */
  71. enum trace_flag_type {
  72. TRACE_FLAG_IRQS_OFF = 0x01,
  73. TRACE_FLAG_NEED_RESCHED = 0x02,
  74. TRACE_FLAG_HARDIRQ = 0x04,
  75. TRACE_FLAG_SOFTIRQ = 0x08,
  76. TRACE_FLAG_CONT = 0x10,
  77. };
  78. /*
  79. * The trace field - the most basic unit of tracing. This is what
  80. * is printed in the end as a single line in the trace output, such as:
  81. *
  82. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  83. */
  84. struct trace_field {
  85. char cpu;
  86. char flags;
  87. char preempt_count;
  88. int pid;
  89. cycle_t t;
  90. union {
  91. struct ftrace_entry fn;
  92. struct ctx_switch_entry ctx;
  93. struct special_entry special;
  94. struct stack_entry stack;
  95. struct print_entry print;
  96. struct mmiotrace_rw mmiorw;
  97. struct mmiotrace_map mmiomap;
  98. };
  99. };
  100. struct trace_field_cont {
  101. char buf[sizeof(struct trace_field)];
  102. };
  103. struct trace_entry {
  104. char type;
  105. union {
  106. struct trace_field field;
  107. struct trace_field_cont cont;
  108. };
  109. };
  110. #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
  111. #define TRACE_BUF_SIZE 1024
  112. #define TRACE_PRINT_BUF_SIZE \
  113. (sizeof(struct trace_field) - offsetof(struct trace_field, print.buf))
  114. #define TRACE_CONT_BUF_SIZE sizeof(struct trace_field)
  115. /*
  116. * The CPU trace array - it consists of thousands of trace entries
  117. * plus some other descriptor data: (for example which task started
  118. * the trace, etc.)
  119. */
  120. struct trace_array_cpu {
  121. struct list_head trace_pages;
  122. atomic_t disabled;
  123. raw_spinlock_t lock;
  124. struct lock_class_key lock_key;
  125. /* these fields get copied into max-trace: */
  126. unsigned trace_head_idx;
  127. unsigned trace_tail_idx;
  128. void *trace_head; /* producer */
  129. void *trace_tail; /* consumer */
  130. unsigned long trace_idx;
  131. unsigned long overrun;
  132. unsigned long saved_latency;
  133. unsigned long critical_start;
  134. unsigned long critical_end;
  135. unsigned long critical_sequence;
  136. unsigned long nice;
  137. unsigned long policy;
  138. unsigned long rt_priority;
  139. cycle_t preempt_timestamp;
  140. pid_t pid;
  141. uid_t uid;
  142. char comm[TASK_COMM_LEN];
  143. };
  144. struct trace_iterator;
  145. /*
  146. * The trace array - an array of per-CPU trace arrays. This is the
  147. * highest level data structure that individual tracers deal with.
  148. * They have on/off state as well:
  149. */
  150. struct trace_array {
  151. unsigned long entries;
  152. long ctrl;
  153. int cpu;
  154. cycle_t time_start;
  155. struct task_struct *waiter;
  156. struct trace_array_cpu *data[NR_CPUS];
  157. };
  158. /*
  159. * A specific tracer, represented by methods that operate on a trace array:
  160. */
  161. struct tracer {
  162. const char *name;
  163. void (*init)(struct trace_array *tr);
  164. void (*reset)(struct trace_array *tr);
  165. void (*open)(struct trace_iterator *iter);
  166. void (*pipe_open)(struct trace_iterator *iter);
  167. void (*close)(struct trace_iterator *iter);
  168. void (*start)(struct trace_iterator *iter);
  169. void (*stop)(struct trace_iterator *iter);
  170. ssize_t (*read)(struct trace_iterator *iter,
  171. struct file *filp, char __user *ubuf,
  172. size_t cnt, loff_t *ppos);
  173. void (*ctrl_update)(struct trace_array *tr);
  174. #ifdef CONFIG_FTRACE_STARTUP_TEST
  175. int (*selftest)(struct tracer *trace,
  176. struct trace_array *tr);
  177. #endif
  178. int (*print_line)(struct trace_iterator *iter);
  179. struct tracer *next;
  180. int print_max;
  181. };
  182. struct trace_seq {
  183. unsigned char buffer[PAGE_SIZE];
  184. unsigned int len;
  185. unsigned int readpos;
  186. };
  187. /*
  188. * Trace iterator - used by printout routines who present trace
  189. * results to users and which routines might sleep, etc:
  190. */
  191. struct trace_iterator {
  192. struct trace_array *tr;
  193. struct tracer *trace;
  194. void *private;
  195. long last_overrun[NR_CPUS];
  196. long overrun[NR_CPUS];
  197. /* The below is zeroed out in pipe_read */
  198. struct trace_seq seq;
  199. struct trace_entry *ent;
  200. int cpu;
  201. struct trace_entry *prev_ent;
  202. int prev_cpu;
  203. unsigned long iter_flags;
  204. loff_t pos;
  205. unsigned long next_idx[NR_CPUS];
  206. struct list_head *next_page[NR_CPUS];
  207. unsigned next_page_idx[NR_CPUS];
  208. long idx;
  209. };
  210. void trace_wake_up(void);
  211. void tracing_reset(struct trace_array_cpu *data);
  212. int tracing_open_generic(struct inode *inode, struct file *filp);
  213. struct dentry *tracing_init_dentry(void);
  214. void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
  215. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  216. struct trace_array_cpu *data);
  217. void tracing_generic_entry_update(struct trace_entry *entry,
  218. unsigned long flags);
  219. void ftrace(struct trace_array *tr,
  220. struct trace_array_cpu *data,
  221. unsigned long ip,
  222. unsigned long parent_ip,
  223. unsigned long flags);
  224. void tracing_sched_switch_trace(struct trace_array *tr,
  225. struct trace_array_cpu *data,
  226. struct task_struct *prev,
  227. struct task_struct *next,
  228. unsigned long flags);
  229. void tracing_record_cmdline(struct task_struct *tsk);
  230. void tracing_sched_wakeup_trace(struct trace_array *tr,
  231. struct trace_array_cpu *data,
  232. struct task_struct *wakee,
  233. struct task_struct *cur,
  234. unsigned long flags);
  235. void trace_special(struct trace_array *tr,
  236. struct trace_array_cpu *data,
  237. unsigned long arg1,
  238. unsigned long arg2,
  239. unsigned long arg3);
  240. void trace_function(struct trace_array *tr,
  241. struct trace_array_cpu *data,
  242. unsigned long ip,
  243. unsigned long parent_ip,
  244. unsigned long flags);
  245. void tracing_start_cmdline_record(void);
  246. void tracing_stop_cmdline_record(void);
  247. int register_tracer(struct tracer *type);
  248. void unregister_tracer(struct tracer *type);
  249. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  250. extern unsigned long tracing_max_latency;
  251. extern unsigned long tracing_thresh;
  252. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  253. void update_max_tr_single(struct trace_array *tr,
  254. struct task_struct *tsk, int cpu);
  255. extern cycle_t ftrace_now(int cpu);
  256. #ifdef CONFIG_FTRACE
  257. void tracing_start_function_trace(void);
  258. void tracing_stop_function_trace(void);
  259. #else
  260. # define tracing_start_function_trace() do { } while (0)
  261. # define tracing_stop_function_trace() do { } while (0)
  262. #endif
  263. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  264. typedef void
  265. (*tracer_switch_func_t)(void *private,
  266. void *__rq,
  267. struct task_struct *prev,
  268. struct task_struct *next);
  269. struct tracer_switch_ops {
  270. tracer_switch_func_t func;
  271. void *private;
  272. struct tracer_switch_ops *next;
  273. };
  274. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  275. #ifdef CONFIG_DYNAMIC_FTRACE
  276. extern unsigned long ftrace_update_tot_cnt;
  277. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  278. extern int DYN_FTRACE_TEST_NAME(void);
  279. #endif
  280. #ifdef CONFIG_FTRACE_STARTUP_TEST
  281. #ifdef CONFIG_FTRACE
  282. extern int trace_selftest_startup_function(struct tracer *trace,
  283. struct trace_array *tr);
  284. #endif
  285. #ifdef CONFIG_IRQSOFF_TRACER
  286. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  287. struct trace_array *tr);
  288. #endif
  289. #ifdef CONFIG_PREEMPT_TRACER
  290. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  291. struct trace_array *tr);
  292. #endif
  293. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  294. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  295. struct trace_array *tr);
  296. #endif
  297. #ifdef CONFIG_SCHED_TRACER
  298. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  299. struct trace_array *tr);
  300. #endif
  301. #ifdef CONFIG_NOP_TRACER
  302. extern int trace_selftest_startup_nop(struct tracer *trace,
  303. struct trace_array *tr);
  304. #endif
  305. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  306. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  307. struct trace_array *tr);
  308. #endif
  309. #ifdef CONFIG_SYSPROF_TRACER
  310. extern int trace_selftest_startup_sysprof(struct tracer *trace,
  311. struct trace_array *tr);
  312. #endif
  313. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  314. extern void *head_page(struct trace_array_cpu *data);
  315. extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
  316. extern void trace_seq_print_cont(struct trace_seq *s,
  317. struct trace_iterator *iter);
  318. extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  319. size_t cnt);
  320. extern long ns2usecs(cycle_t nsec);
  321. extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  322. extern unsigned long trace_flags;
  323. /*
  324. * trace_iterator_flags is an enumeration that defines bit
  325. * positions into trace_flags that controls the output.
  326. *
  327. * NOTE: These bits must match the trace_options array in
  328. * trace.c.
  329. */
  330. enum trace_iterator_flags {
  331. TRACE_ITER_PRINT_PARENT = 0x01,
  332. TRACE_ITER_SYM_OFFSET = 0x02,
  333. TRACE_ITER_SYM_ADDR = 0x04,
  334. TRACE_ITER_VERBOSE = 0x08,
  335. TRACE_ITER_RAW = 0x10,
  336. TRACE_ITER_HEX = 0x20,
  337. TRACE_ITER_BIN = 0x40,
  338. TRACE_ITER_BLOCK = 0x80,
  339. TRACE_ITER_STACKTRACE = 0x100,
  340. TRACE_ITER_SCHED_TREE = 0x200,
  341. TRACE_ITER_PRINTK = 0x400,
  342. };
  343. #endif /* _LINUX_KERNEL_TRACE_H */