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