1 #ifndef _LINUX_KERNEL_TRACE_H
2 #define _LINUX_KERNEL_TRACE_H
5 #include <asm/atomic.h>
6 #include <linux/sched.h>
7 #include <linux/clocksource.h>
8 #include <linux/ring_buffer.h>
9 #include <linux/mmiotrace.h>
10 #include <linux/ftrace.h>
13 __TRACE_FIRST_TYPE = 0,
30 * The trace entry - the most basic unit of tracing. This is what
31 * is printed in the end as a single line in the trace output, such as:
33 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
39 unsigned char preempt_count;
44 * Function trace entry - function address and parent function addres:
47 struct trace_entry ent;
49 unsigned long parent_ip;
51 extern struct tracer boot_tracer;
52 extern struct tracer sched_switch_trace; /* Used by the boot tracer */
55 * Context switch trace entry - which task (and prio) we switched from/to:
57 struct ctx_switch_entry {
58 struct trace_entry ent;
59 unsigned int prev_pid;
60 unsigned char prev_prio;
61 unsigned char prev_state;
62 unsigned int next_pid;
63 unsigned char next_prio;
64 unsigned char next_state;
65 unsigned int next_cpu;
69 * Special (free-form) trace entry:
71 struct special_entry {
72 struct trace_entry ent;
82 #define FTRACE_STACK_ENTRIES 8
85 struct trace_entry ent;
86 unsigned long caller[FTRACE_STACK_ENTRIES];
90 * ftrace_printk entry:
93 struct trace_entry ent;
98 #define TRACE_OLD_SIZE 88
100 struct trace_field_cont {
102 /* Temporary till we get rid of this completely */
103 char buf[TRACE_OLD_SIZE - 1];
106 struct trace_mmiotrace_rw {
107 struct trace_entry ent;
108 struct mmiotrace_rw rw;
111 struct trace_mmiotrace_map {
112 struct trace_entry ent;
113 struct mmiotrace_map map;
117 struct trace_entry ent;
118 struct boot_trace initcall;
122 * trace_flag_type is an enumeration that holds different
123 * states when a trace occurs. These are:
124 * IRQS_OFF - interrupts were disabled
125 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
126 * NEED_RESCED - reschedule is requested
127 * HARDIRQ - inside an interrupt handler
128 * SOFTIRQ - inside a softirq handler
129 * CONT - multiple entries hold the trace item
131 enum trace_flag_type {
132 TRACE_FLAG_IRQS_OFF = 0x01,
133 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
134 TRACE_FLAG_NEED_RESCHED = 0x04,
135 TRACE_FLAG_HARDIRQ = 0x08,
136 TRACE_FLAG_SOFTIRQ = 0x10,
137 TRACE_FLAG_CONT = 0x20,
140 #define TRACE_BUF_SIZE 1024
143 * The CPU trace array - it consists of thousands of trace entries
144 * plus some other descriptor data: (for example which task started
147 struct trace_array_cpu {
150 /* these fields get copied into max-trace: */
151 unsigned long trace_idx;
152 unsigned long overrun;
153 unsigned long saved_latency;
154 unsigned long critical_start;
155 unsigned long critical_end;
156 unsigned long critical_sequence;
158 unsigned long policy;
159 unsigned long rt_priority;
160 cycle_t preempt_timestamp;
163 char comm[TASK_COMM_LEN];
166 struct trace_iterator;
169 * The trace array - an array of per-CPU trace arrays. This is the
170 * highest level data structure that individual tracers deal with.
171 * They have on/off state as well:
174 struct ring_buffer *buffer;
175 unsigned long entries;
179 struct task_struct *waiter;
180 struct trace_array_cpu *data[NR_CPUS];
183 #define FTRACE_CMP_TYPE(var, type) \
184 __builtin_types_compatible_p(typeof(var), type *)
187 #define IF_ASSIGN(var, entry, etype, id) \
188 if (FTRACE_CMP_TYPE(var, etype)) { \
189 var = (typeof(var))(entry); \
190 WARN_ON(id && (entry)->type != id); \
194 /* Will cause compile errors if type is not found. */
195 extern void __ftrace_bad_type(void);
198 * The trace_assign_type is a verifier that the entry type is
199 * the same as the type being assigned. To add new types simply
200 * add a line with the following format:
202 * IF_ASSIGN(var, ent, type, id);
204 * Where "type" is the trace type that includes the trace_entry
205 * as the "ent" item. And "id" is the trace identifier that is
206 * used in the trace_type enum.
208 * If the type can have more than one id, then use zero.
210 #define trace_assign_type(var, ent) \
212 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
213 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
214 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
215 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
216 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
217 IF_ASSIGN(var, ent, struct special_entry, 0); \
218 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
220 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
222 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
223 __ftrace_bad_type(); \
226 /* Return values for print_line callback */
228 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
229 TRACE_TYPE_HANDLED = 1,
230 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
234 * A specific tracer, represented by methods that operate on a trace array:
238 void (*init)(struct trace_array *tr);
239 void (*reset)(struct trace_array *tr);
240 void (*start)(struct trace_array *tr);
241 void (*stop)(struct trace_array *tr);
242 void (*open)(struct trace_iterator *iter);
243 void (*pipe_open)(struct trace_iterator *iter);
244 void (*close)(struct trace_iterator *iter);
245 ssize_t (*read)(struct trace_iterator *iter,
246 struct file *filp, char __user *ubuf,
247 size_t cnt, loff_t *ppos);
248 void (*ctrl_update)(struct trace_array *tr);
249 #ifdef CONFIG_FTRACE_STARTUP_TEST
250 int (*selftest)(struct tracer *trace,
251 struct trace_array *tr);
253 enum print_line_t (*print_line)(struct trace_iterator *iter);
259 unsigned char buffer[PAGE_SIZE];
261 unsigned int readpos;
265 * Trace iterator - used by printout routines who present trace
266 * results to users and which routines might sleep, etc:
268 struct trace_iterator {
269 struct trace_array *tr;
270 struct tracer *trace;
272 struct ring_buffer_iter *buffer_iter[NR_CPUS];
274 /* The below is zeroed out in pipe_read */
275 struct trace_seq seq;
276 struct trace_entry *ent;
280 unsigned long iter_flags;
285 int tracing_is_enabled(void);
286 void trace_wake_up(void);
287 void tracing_reset(struct trace_array *tr, int cpu);
288 int tracing_open_generic(struct inode *inode, struct file *filp);
289 struct dentry *tracing_init_dentry(void);
290 void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
292 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
293 struct trace_array_cpu *data);
294 void tracing_generic_entry_update(struct trace_entry *entry,
298 void ftrace(struct trace_array *tr,
299 struct trace_array_cpu *data,
301 unsigned long parent_ip,
302 unsigned long flags, int pc);
303 void tracing_sched_switch_trace(struct trace_array *tr,
304 struct trace_array_cpu *data,
305 struct task_struct *prev,
306 struct task_struct *next,
307 unsigned long flags, int pc);
308 void tracing_record_cmdline(struct task_struct *tsk);
310 void tracing_sched_wakeup_trace(struct trace_array *tr,
311 struct trace_array_cpu *data,
312 struct task_struct *wakee,
313 struct task_struct *cur,
314 unsigned long flags, int pc);
315 void trace_special(struct trace_array *tr,
316 struct trace_array_cpu *data,
319 unsigned long arg3, int pc);
320 void trace_function(struct trace_array *tr,
321 struct trace_array_cpu *data,
323 unsigned long parent_ip,
324 unsigned long flags, int pc);
326 void tracing_start_cmdline_record(void);
327 void tracing_stop_cmdline_record(void);
328 int register_tracer(struct tracer *type);
329 void unregister_tracer(struct tracer *type);
331 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
333 extern unsigned long tracing_max_latency;
334 extern unsigned long tracing_thresh;
336 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
337 void update_max_tr_single(struct trace_array *tr,
338 struct task_struct *tsk, int cpu);
340 extern cycle_t ftrace_now(int cpu);
342 #ifdef CONFIG_FUNCTION_TRACER
343 void tracing_start_function_trace(void);
344 void tracing_stop_function_trace(void);
346 # define tracing_start_function_trace() do { } while (0)
347 # define tracing_stop_function_trace() do { } while (0)
350 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
352 (*tracer_switch_func_t)(void *private,
354 struct task_struct *prev,
355 struct task_struct *next);
357 struct tracer_switch_ops {
358 tracer_switch_func_t func;
360 struct tracer_switch_ops *next;
363 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
365 #ifdef CONFIG_DYNAMIC_FTRACE
366 extern unsigned long ftrace_update_tot_cnt;
367 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
368 extern int DYN_FTRACE_TEST_NAME(void);
371 #ifdef CONFIG_FTRACE_STARTUP_TEST
372 extern int trace_selftest_startup_function(struct tracer *trace,
373 struct trace_array *tr);
374 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
375 struct trace_array *tr);
376 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
377 struct trace_array *tr);
378 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
379 struct trace_array *tr);
380 extern int trace_selftest_startup_wakeup(struct tracer *trace,
381 struct trace_array *tr);
382 extern int trace_selftest_startup_nop(struct tracer *trace,
383 struct trace_array *tr);
384 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
385 struct trace_array *tr);
386 extern int trace_selftest_startup_sysprof(struct tracer *trace,
387 struct trace_array *tr);
388 #endif /* CONFIG_FTRACE_STARTUP_TEST */
390 extern void *head_page(struct trace_array_cpu *data);
391 extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
392 extern void trace_seq_print_cont(struct trace_seq *s,
393 struct trace_iterator *iter);
394 extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
396 extern long ns2usecs(cycle_t nsec);
397 extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
399 extern unsigned long trace_flags;
402 * trace_iterator_flags is an enumeration that defines bit
403 * positions into trace_flags that controls the output.
405 * NOTE: These bits must match the trace_options array in
408 enum trace_iterator_flags {
409 TRACE_ITER_PRINT_PARENT = 0x01,
410 TRACE_ITER_SYM_OFFSET = 0x02,
411 TRACE_ITER_SYM_ADDR = 0x04,
412 TRACE_ITER_VERBOSE = 0x08,
413 TRACE_ITER_RAW = 0x10,
414 TRACE_ITER_HEX = 0x20,
415 TRACE_ITER_BIN = 0x40,
416 TRACE_ITER_BLOCK = 0x80,
417 TRACE_ITER_STACKTRACE = 0x100,
418 TRACE_ITER_SCHED_TREE = 0x200,
419 TRACE_ITER_PRINTK = 0x400,
420 TRACE_ITER_PREEMPTONLY = 0x800,
423 extern struct tracer nop_trace;
426 * ftrace_preempt_disable - disable preemption scheduler safe
428 * When tracing can happen inside the scheduler, there exists
429 * cases that the tracing might happen before the need_resched
430 * flag is checked. If this happens and the tracer calls
431 * preempt_enable (after a disable), a schedule might take place
432 * causing an infinite recursion.
434 * To prevent this, we read the need_recshed flag before
435 * disabling preemption. When we want to enable preemption we
436 * check the flag, if it is set, then we call preempt_enable_no_resched.
437 * Otherwise, we call preempt_enable.
439 * The rational for doing the above is that if need resched is set
440 * and we have yet to reschedule, we are either in an atomic location
441 * (where we do not need to check for scheduling) or we are inside
442 * the scheduler and do not want to resched.
444 static inline int ftrace_preempt_disable(void)
448 resched = need_resched();
449 preempt_disable_notrace();
455 * ftrace_preempt_enable - enable preemption scheduler safe
456 * @resched: the return value from ftrace_preempt_disable
458 * This is a scheduler safe way to enable preemption and not miss
459 * any preemption checks. The disabled saved the state of preemption.
460 * If resched is set, then we were either inside an atomic or
461 * are inside the scheduler (we would have already scheduled
462 * otherwise). In this case, we do not want to call normal
463 * preempt_enable, but preempt_enable_no_resched instead.
465 static inline void ftrace_preempt_enable(int resched)
468 preempt_enable_no_resched_notrace();
470 preempt_enable_notrace();
473 #endif /* _LINUX_KERNEL_TRACE_H */