trace.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. * The trace field - the most basic unit of tracing. This is what
  64. * is printed in the end as a single line in the trace output, such as:
  65. *
  66. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  67. */
  68. struct trace_field {
  69. char cpu;
  70. char flags;
  71. char preempt_count;
  72. int pid;
  73. cycle_t t;
  74. union {
  75. struct ftrace_entry fn;
  76. struct ctx_switch_entry ctx;
  77. struct special_entry special;
  78. struct stack_entry stack;
  79. struct print_entry print;
  80. struct mmiotrace_rw mmiorw;
  81. struct mmiotrace_map mmiomap;
  82. };
  83. };
  84. struct trace_field_cont {
  85. char buf[sizeof(struct trace_field)];
  86. };
  87. struct trace_entry {
  88. char type;
  89. union {
  90. struct trace_field field;
  91. struct trace_field_cont cont;
  92. };
  93. };
  94. #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
  95. /*
  96. * The CPU trace array - it consists of thousands of trace entries
  97. * plus some other descriptor data: (for example which task started
  98. * the trace, etc.)
  99. */
  100. struct trace_array_cpu {
  101. struct list_head trace_pages;
  102. atomic_t disabled;
  103. raw_spinlock_t lock;
  104. struct lock_class_key lock_key;
  105. /* these fields get copied into max-trace: */
  106. unsigned trace_head_idx;
  107. unsigned trace_tail_idx;
  108. void *trace_head; /* producer */
  109. void *trace_tail; /* consumer */
  110. unsigned long trace_idx;
  111. unsigned long overrun;
  112. unsigned long saved_latency;
  113. unsigned long critical_start;
  114. unsigned long critical_end;
  115. unsigned long critical_sequence;
  116. unsigned long nice;
  117. unsigned long policy;
  118. unsigned long rt_priority;
  119. cycle_t preempt_timestamp;
  120. pid_t pid;
  121. uid_t uid;
  122. char comm[TASK_COMM_LEN];
  123. };
  124. struct trace_iterator;
  125. /*
  126. * The trace array - an array of per-CPU trace arrays. This is the
  127. * highest level data structure that individual tracers deal with.
  128. * They have on/off state as well:
  129. */
  130. struct trace_array {
  131. unsigned long entries;
  132. long ctrl;
  133. int cpu;
  134. cycle_t time_start;
  135. struct task_struct *waiter;
  136. struct trace_array_cpu *data[NR_CPUS];
  137. };
  138. /*
  139. * A specific tracer, represented by methods that operate on a trace array:
  140. */
  141. struct tracer {
  142. const char *name;
  143. void (*init)(struct trace_array *tr);
  144. void (*reset)(struct trace_array *tr);
  145. void (*open)(struct trace_iterator *iter);
  146. void (*pipe_open)(struct trace_iterator *iter);
  147. void (*close)(struct trace_iterator *iter);
  148. void (*start)(struct trace_iterator *iter);
  149. void (*stop)(struct trace_iterator *iter);
  150. ssize_t (*read)(struct trace_iterator *iter,
  151. struct file *filp, char __user *ubuf,
  152. size_t cnt, loff_t *ppos);
  153. void (*ctrl_update)(struct trace_array *tr);
  154. #ifdef CONFIG_FTRACE_STARTUP_TEST
  155. int (*selftest)(struct tracer *trace,
  156. struct trace_array *tr);
  157. #endif
  158. int (*print_line)(struct trace_iterator *iter);
  159. struct tracer *next;
  160. int print_max;
  161. };
  162. struct trace_seq {
  163. unsigned char buffer[PAGE_SIZE];
  164. unsigned int len;
  165. unsigned int readpos;
  166. };
  167. /*
  168. * Trace iterator - used by printout routines who present trace
  169. * results to users and which routines might sleep, etc:
  170. */
  171. struct trace_iterator {
  172. struct trace_array *tr;
  173. struct tracer *trace;
  174. void *private;
  175. long last_overrun[NR_CPUS];
  176. long overrun[NR_CPUS];
  177. /* The below is zeroed out in pipe_read */
  178. struct trace_seq seq;
  179. struct trace_entry *ent;
  180. int cpu;
  181. struct trace_entry *prev_ent;
  182. int prev_cpu;
  183. unsigned long iter_flags;
  184. loff_t pos;
  185. unsigned long next_idx[NR_CPUS];
  186. struct list_head *next_page[NR_CPUS];
  187. unsigned next_page_idx[NR_CPUS];
  188. long idx;
  189. };
  190. void tracing_reset(struct trace_array_cpu *data);
  191. int tracing_open_generic(struct inode *inode, struct file *filp);
  192. struct dentry *tracing_init_dentry(void);
  193. void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
  194. void ftrace(struct trace_array *tr,
  195. struct trace_array_cpu *data,
  196. unsigned long ip,
  197. unsigned long parent_ip,
  198. unsigned long flags);
  199. void tracing_sched_switch_trace(struct trace_array *tr,
  200. struct trace_array_cpu *data,
  201. struct task_struct *prev,
  202. struct task_struct *next,
  203. unsigned long flags);
  204. void tracing_record_cmdline(struct task_struct *tsk);
  205. void tracing_sched_wakeup_trace(struct trace_array *tr,
  206. struct trace_array_cpu *data,
  207. struct task_struct *wakee,
  208. struct task_struct *cur,
  209. unsigned long flags);
  210. void trace_special(struct trace_array *tr,
  211. struct trace_array_cpu *data,
  212. unsigned long arg1,
  213. unsigned long arg2,
  214. unsigned long arg3);
  215. void trace_function(struct trace_array *tr,
  216. struct trace_array_cpu *data,
  217. unsigned long ip,
  218. unsigned long parent_ip,
  219. unsigned long flags);
  220. void tracing_start_cmdline_record(void);
  221. void tracing_stop_cmdline_record(void);
  222. int register_tracer(struct tracer *type);
  223. void unregister_tracer(struct tracer *type);
  224. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  225. extern unsigned long tracing_max_latency;
  226. extern unsigned long tracing_thresh;
  227. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  228. void update_max_tr_single(struct trace_array *tr,
  229. struct task_struct *tsk, int cpu);
  230. extern cycle_t ftrace_now(int cpu);
  231. #ifdef CONFIG_FTRACE
  232. void tracing_start_function_trace(void);
  233. void tracing_stop_function_trace(void);
  234. #else
  235. # define tracing_start_function_trace() do { } while (0)
  236. # define tracing_stop_function_trace() do { } while (0)
  237. #endif
  238. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  239. typedef void
  240. (*tracer_switch_func_t)(void *private,
  241. void *__rq,
  242. struct task_struct *prev,
  243. struct task_struct *next);
  244. struct tracer_switch_ops {
  245. tracer_switch_func_t func;
  246. void *private;
  247. struct tracer_switch_ops *next;
  248. };
  249. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  250. #ifdef CONFIG_DYNAMIC_FTRACE
  251. extern unsigned long ftrace_update_tot_cnt;
  252. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  253. extern int DYN_FTRACE_TEST_NAME(void);
  254. #endif
  255. #ifdef CONFIG_MMIOTRACE
  256. extern void __trace_mmiotrace_rw(struct trace_array *tr,
  257. struct trace_array_cpu *data,
  258. struct mmiotrace_rw *rw);
  259. extern void __trace_mmiotrace_map(struct trace_array *tr,
  260. struct trace_array_cpu *data,
  261. struct mmiotrace_map *map);
  262. #endif
  263. #ifdef CONFIG_FTRACE_STARTUP_TEST
  264. #ifdef CONFIG_FTRACE
  265. extern int trace_selftest_startup_function(struct tracer *trace,
  266. struct trace_array *tr);
  267. #endif
  268. #ifdef CONFIG_IRQSOFF_TRACER
  269. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  270. struct trace_array *tr);
  271. #endif
  272. #ifdef CONFIG_PREEMPT_TRACER
  273. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  274. struct trace_array *tr);
  275. #endif
  276. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  277. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  278. struct trace_array *tr);
  279. #endif
  280. #ifdef CONFIG_SCHED_TRACER
  281. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  282. struct trace_array *tr);
  283. #endif
  284. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  285. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  286. struct trace_array *tr);
  287. #endif
  288. #ifdef CONFIG_SYSPROF_TRACER
  289. extern int trace_selftest_startup_sysprof(struct tracer *trace,
  290. struct trace_array *tr);
  291. #endif
  292. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  293. extern void *head_page(struct trace_array_cpu *data);
  294. extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
  295. extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  296. size_t cnt);
  297. extern long ns2usecs(cycle_t nsec);
  298. extern unsigned long trace_flags;
  299. /*
  300. * trace_iterator_flags is an enumeration that defines bit
  301. * positions into trace_flags that controls the output.
  302. *
  303. * NOTE: These bits must match the trace_options array in
  304. * trace.c.
  305. */
  306. enum trace_iterator_flags {
  307. TRACE_ITER_PRINT_PARENT = 0x01,
  308. TRACE_ITER_SYM_OFFSET = 0x02,
  309. TRACE_ITER_SYM_ADDR = 0x04,
  310. TRACE_ITER_VERBOSE = 0x08,
  311. TRACE_ITER_RAW = 0x10,
  312. TRACE_ITER_HEX = 0x20,
  313. TRACE_ITER_BIN = 0x40,
  314. TRACE_ITER_BLOCK = 0x80,
  315. TRACE_ITER_STACKTRACE = 0x100,
  316. TRACE_ITER_SCHED_TREE = 0x200,
  317. TRACE_ITER_PRINTK = 0x400,
  318. };
  319. #endif /* _LINUX_KERNEL_TRACE_H */