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;
54 * Context switch trace entry - which task (and prio) we switched from/to:
56 struct ctx_switch_entry {
57 struct trace_entry ent;
58 unsigned int prev_pid;
59 unsigned char prev_prio;
60 unsigned char prev_state;
61 unsigned int next_pid;
62 unsigned char next_prio;
63 unsigned char next_state;
64 unsigned int next_cpu;
68 * Special (free-form) trace entry:
70 struct special_entry {
71 struct trace_entry ent;
81 #define FTRACE_STACK_ENTRIES 8
84 struct trace_entry ent;
85 unsigned long caller[FTRACE_STACK_ENTRIES];
89 * ftrace_printk entry:
92 struct trace_entry ent;
97 #define TRACE_OLD_SIZE 88
99 struct trace_field_cont {
101 /* Temporary till we get rid of this completely */
102 char buf[TRACE_OLD_SIZE - 1];
105 struct trace_mmiotrace_rw {
106 struct trace_entry ent;
107 struct mmiotrace_rw rw;
110 struct trace_mmiotrace_map {
111 struct trace_entry ent;
112 struct mmiotrace_map map;
116 struct trace_entry ent;
117 struct boot_trace initcall;
121 * trace_flag_type is an enumeration that holds different
122 * states when a trace occurs. These are:
123 * IRQS_OFF - interrupts were disabled
124 * NEED_RESCED - reschedule is requested
125 * HARDIRQ - inside an interrupt handler
126 * SOFTIRQ - inside a softirq handler
127 * CONT - multiple entries hold the trace item
129 enum trace_flag_type {
130 TRACE_FLAG_IRQS_OFF = 0x01,
131 TRACE_FLAG_NEED_RESCHED = 0x02,
132 TRACE_FLAG_HARDIRQ = 0x04,
133 TRACE_FLAG_SOFTIRQ = 0x08,
134 TRACE_FLAG_CONT = 0x10,
137 #define TRACE_BUF_SIZE 1024
140 * The CPU trace array - it consists of thousands of trace entries
141 * plus some other descriptor data: (for example which task started
144 struct trace_array_cpu {
147 /* these fields get copied into max-trace: */
148 unsigned long trace_idx;
149 unsigned long overrun;
150 unsigned long saved_latency;
151 unsigned long critical_start;
152 unsigned long critical_end;
153 unsigned long critical_sequence;
155 unsigned long policy;
156 unsigned long rt_priority;
157 cycle_t preempt_timestamp;
160 char comm[TASK_COMM_LEN];
163 struct trace_iterator;
166 * The trace array - an array of per-CPU trace arrays. This is the
167 * highest level data structure that individual tracers deal with.
168 * They have on/off state as well:
171 struct ring_buffer *buffer;
172 unsigned long entries;
176 struct task_struct *waiter;
177 struct trace_array_cpu *data[NR_CPUS];
181 /* Return values for print_line callback */
183 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
184 TRACE_TYPE_HANDLED = 1,
185 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
189 * A specific tracer, represented by methods that operate on a trace array:
193 void (*init)(struct trace_array *tr);
194 void (*reset)(struct trace_array *tr);
195 void (*open)(struct trace_iterator *iter);
196 void (*pipe_open)(struct trace_iterator *iter);
197 void (*close)(struct trace_iterator *iter);
198 void (*start)(struct trace_iterator *iter);
199 void (*stop)(struct trace_iterator *iter);
200 ssize_t (*read)(struct trace_iterator *iter,
201 struct file *filp, char __user *ubuf,
202 size_t cnt, loff_t *ppos);
203 void (*ctrl_update)(struct trace_array *tr);
204 #ifdef CONFIG_FTRACE_STARTUP_TEST
205 int (*selftest)(struct tracer *trace,
206 struct trace_array *tr);
208 enum print_line_t (*print_line)(struct trace_iterator *iter);
214 unsigned char buffer[PAGE_SIZE];
216 unsigned int readpos;
220 * Trace iterator - used by printout routines who present trace
221 * results to users and which routines might sleep, etc:
223 struct trace_iterator {
224 struct trace_array *tr;
225 struct tracer *trace;
227 struct ring_buffer_iter *buffer_iter[NR_CPUS];
229 /* The below is zeroed out in pipe_read */
230 struct trace_seq seq;
231 struct trace_entry *ent;
235 unsigned long iter_flags;
240 void trace_wake_up(void);
241 void tracing_reset(struct trace_array *tr, int cpu);
242 int tracing_open_generic(struct inode *inode, struct file *filp);
243 struct dentry *tracing_init_dentry(void);
244 void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
246 struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
247 struct trace_array_cpu *data);
248 void tracing_generic_entry_update(struct trace_entry *entry,
249 unsigned long flags);
251 void ftrace(struct trace_array *tr,
252 struct trace_array_cpu *data,
254 unsigned long parent_ip,
255 unsigned long flags);
256 void tracing_sched_switch_trace(struct trace_array *tr,
257 struct trace_array_cpu *data,
258 struct task_struct *prev,
259 struct task_struct *next,
260 unsigned long flags);
261 void tracing_record_cmdline(struct task_struct *tsk);
263 void tracing_sched_wakeup_trace(struct trace_array *tr,
264 struct trace_array_cpu *data,
265 struct task_struct *wakee,
266 struct task_struct *cur,
267 unsigned long flags);
268 void trace_special(struct trace_array *tr,
269 struct trace_array_cpu *data,
273 void trace_function(struct trace_array *tr,
274 struct trace_array_cpu *data,
276 unsigned long parent_ip,
277 unsigned long flags);
279 void tracing_start_cmdline_record(void);
280 void tracing_stop_cmdline_record(void);
281 int register_tracer(struct tracer *type);
282 void unregister_tracer(struct tracer *type);
284 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
286 extern unsigned long tracing_max_latency;
287 extern unsigned long tracing_thresh;
289 void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
290 void update_max_tr_single(struct trace_array *tr,
291 struct task_struct *tsk, int cpu);
293 extern cycle_t ftrace_now(int cpu);
296 void tracing_start_function_trace(void);
297 void tracing_stop_function_trace(void);
299 # define tracing_start_function_trace() do { } while (0)
300 # define tracing_stop_function_trace() do { } while (0)
303 #ifdef CONFIG_CONTEXT_SWITCH_TRACER
305 (*tracer_switch_func_t)(void *private,
307 struct task_struct *prev,
308 struct task_struct *next);
310 struct tracer_switch_ops {
311 tracer_switch_func_t func;
313 struct tracer_switch_ops *next;
316 #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
318 #ifdef CONFIG_DYNAMIC_FTRACE
319 extern unsigned long ftrace_update_tot_cnt;
320 #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
321 extern int DYN_FTRACE_TEST_NAME(void);
324 #ifdef CONFIG_FTRACE_STARTUP_TEST
325 extern int trace_selftest_startup_function(struct tracer *trace,
326 struct trace_array *tr);
327 extern int trace_selftest_startup_irqsoff(struct tracer *trace,
328 struct trace_array *tr);
329 extern int trace_selftest_startup_preemptoff(struct tracer *trace,
330 struct trace_array *tr);
331 extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
332 struct trace_array *tr);
333 extern int trace_selftest_startup_wakeup(struct tracer *trace,
334 struct trace_array *tr);
335 extern int trace_selftest_startup_nop(struct tracer *trace,
336 struct trace_array *tr);
337 extern int trace_selftest_startup_sched_switch(struct tracer *trace,
338 struct trace_array *tr);
339 extern int trace_selftest_startup_sysprof(struct tracer *trace,
340 struct trace_array *tr);
341 #endif /* CONFIG_FTRACE_STARTUP_TEST */
343 extern void *head_page(struct trace_array_cpu *data);
344 extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
345 extern void trace_seq_print_cont(struct trace_seq *s,
346 struct trace_iterator *iter);
347 extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
349 extern long ns2usecs(cycle_t nsec);
350 extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
352 extern unsigned long trace_flags;
355 * trace_iterator_flags is an enumeration that defines bit
356 * positions into trace_flags that controls the output.
358 * NOTE: These bits must match the trace_options array in
361 enum trace_iterator_flags {
362 TRACE_ITER_PRINT_PARENT = 0x01,
363 TRACE_ITER_SYM_OFFSET = 0x02,
364 TRACE_ITER_SYM_ADDR = 0x04,
365 TRACE_ITER_VERBOSE = 0x08,
366 TRACE_ITER_RAW = 0x10,
367 TRACE_ITER_HEX = 0x20,
368 TRACE_ITER_BIN = 0x40,
369 TRACE_ITER_BLOCK = 0x80,
370 TRACE_ITER_STACKTRACE = 0x100,
371 TRACE_ITER_SCHED_TREE = 0x200,
372 TRACE_ITER_PRINTK = 0x400,
375 extern struct tracer nop_trace;
377 #endif /* _LINUX_KERNEL_TRACE_H */