trace.h 9.6 KB

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