trace.h 9.7 KB

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