]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/trace/trace.h
ftrace: soft tracing stop and start
[net-next-2.6.git] / kernel / trace / trace.h
CommitLineData
bc0c38d1
SR
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>
3928a8a2 8#include <linux/ring_buffer.h>
bd8ac686 9#include <linux/mmiotrace.h>
d13744cd 10#include <linux/ftrace.h>
bc0c38d1 11
72829bc3
TG
12enum trace_type {
13 __TRACE_FIRST_TYPE = 0,
14
15 TRACE_FN,
16 TRACE_CTX,
17 TRACE_WAKE,
dd0e545f 18 TRACE_CONT,
72829bc3 19 TRACE_STACK,
dd0e545f 20 TRACE_PRINT,
72829bc3 21 TRACE_SPECIAL,
bd8ac686
PP
22 TRACE_MMIO_RW,
23 TRACE_MMIO_MAP,
d13744cd 24 TRACE_BOOT,
72829bc3
TG
25
26 __TRACE_LAST_TYPE
27};
28
777e208d
SR
29/*
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:
32 *
33 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
34 */
35struct trace_entry {
36 unsigned char type;
37 unsigned char cpu;
38 unsigned char flags;
39 unsigned char preempt_count;
40 int pid;
41};
42
bc0c38d1
SR
43/*
44 * Function trace entry - function address and parent function addres:
45 */
46struct ftrace_entry {
777e208d 47 struct trace_entry ent;
bc0c38d1
SR
48 unsigned long ip;
49 unsigned long parent_ip;
50};
d13744cd 51extern struct tracer boot_tracer;
d7ad44b6 52extern struct tracer sched_switch_trace; /* Used by the boot tracer */
bc0c38d1
SR
53
54/*
55 * Context switch trace entry - which task (and prio) we switched from/to:
56 */
57struct ctx_switch_entry {
777e208d 58 struct trace_entry ent;
bc0c38d1
SR
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;
bac524d3 64 unsigned char next_state;
80b5e940 65 unsigned int next_cpu;
bc0c38d1
SR
66};
67
f0a920d5
IM
68/*
69 * Special (free-form) trace entry:
70 */
71struct special_entry {
777e208d 72 struct trace_entry ent;
f0a920d5
IM
73 unsigned long arg1;
74 unsigned long arg2;
75 unsigned long arg3;
76};
77
86387f7e
IM
78/*
79 * Stack-trace entry:
80 */
81
74f4e369 82#define FTRACE_STACK_ENTRIES 8
86387f7e
IM
83
84struct stack_entry {
777e208d 85 struct trace_entry ent;
86387f7e
IM
86 unsigned long caller[FTRACE_STACK_ENTRIES];
87};
88
dd0e545f
SR
89/*
90 * ftrace_printk entry:
91 */
92struct print_entry {
777e208d 93 struct trace_entry ent;
dd0e545f
SR
94 unsigned long ip;
95 char buf[];
96};
97
777e208d
SR
98#define TRACE_OLD_SIZE 88
99
100struct trace_field_cont {
101 unsigned char type;
102 /* Temporary till we get rid of this completely */
103 char buf[TRACE_OLD_SIZE - 1];
104};
105
106struct trace_mmiotrace_rw {
107 struct trace_entry ent;
108 struct mmiotrace_rw rw;
109};
110
111struct trace_mmiotrace_map {
112 struct trace_entry ent;
113 struct mmiotrace_map map;
114};
115
116struct trace_boot {
117 struct trace_entry ent;
118 struct boot_trace initcall;
119};
120
fc5e27ae
PP
121/*
122 * trace_flag_type is an enumeration that holds different
123 * states when a trace occurs. These are:
9244489a
SR
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
fc5e27ae
PP
130 */
131enum trace_flag_type {
132 TRACE_FLAG_IRQS_OFF = 0x01,
9244489a
SR
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,
fc5e27ae
PP
138};
139
5bf9a1ee 140#define TRACE_BUF_SIZE 1024
bc0c38d1
SR
141
142/*
143 * The CPU trace array - it consists of thousands of trace entries
144 * plus some other descriptor data: (for example which task started
145 * the trace, etc.)
146 */
147struct trace_array_cpu {
bc0c38d1 148 atomic_t disabled;
4e3c3333 149
c7aafc54 150 /* these fields get copied into max-trace: */
c7aafc54 151 unsigned long trace_idx;
53d0aa77 152 unsigned long overrun;
bc0c38d1
SR
153 unsigned long saved_latency;
154 unsigned long critical_start;
155 unsigned long critical_end;
156 unsigned long critical_sequence;
157 unsigned long nice;
158 unsigned long policy;
159 unsigned long rt_priority;
160 cycle_t preempt_timestamp;
161 pid_t pid;
162 uid_t uid;
163 char comm[TASK_COMM_LEN];
164};
165
166struct trace_iterator;
167
168/*
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:
172 */
173struct trace_array {
3928a8a2 174 struct ring_buffer *buffer;
bc0c38d1
SR
175 unsigned long entries;
176 long ctrl;
177 int cpu;
178 cycle_t time_start;
b3806b43 179 struct task_struct *waiter;
bc0c38d1
SR
180 struct trace_array_cpu *data[NR_CPUS];
181};
182
7104f300
SR
183#define FTRACE_CMP_TYPE(var, type) \
184 __builtin_types_compatible_p(typeof(var), type *)
185
186#undef IF_ASSIGN
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); \
191 break; \
192 }
193
194/* Will cause compile errors if type is not found. */
195extern void __ftrace_bad_type(void);
196
197/*
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:
201 *
202 * IF_ASSIGN(var, ent, type, id);
203 *
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.
207 *
208 * If the type can have more than one id, then use zero.
209 */
210#define trace_assign_type(var, ent) \
211 do { \
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, \
219 TRACE_MMIO_RW); \
220 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
221 TRACE_MMIO_MAP); \
222 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
223 __ftrace_bad_type(); \
224 } while (0)
2c4f035f
FW
225
226/* Return values for print_line callback */
227enum print_line_t {
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 */
231};
232
bc0c38d1
SR
233/*
234 * A specific tracer, represented by methods that operate on a trace array:
235 */
236struct tracer {
237 const char *name;
238 void (*init)(struct trace_array *tr);
239 void (*reset)(struct trace_array *tr);
240 void (*open)(struct trace_iterator *iter);
107bad8b 241 void (*pipe_open)(struct trace_iterator *iter);
bc0c38d1
SR
242 void (*close)(struct trace_iterator *iter);
243 void (*start)(struct trace_iterator *iter);
244 void (*stop)(struct trace_iterator *iter);
107bad8b
SR
245 ssize_t (*read)(struct trace_iterator *iter,
246 struct file *filp, char __user *ubuf,
247 size_t cnt, loff_t *ppos);
bc0c38d1 248 void (*ctrl_update)(struct trace_array *tr);
60a11774
SR
249#ifdef CONFIG_FTRACE_STARTUP_TEST
250 int (*selftest)(struct tracer *trace,
251 struct trace_array *tr);
252#endif
2c4f035f 253 enum print_line_t (*print_line)(struct trace_iterator *iter);
bc0c38d1
SR
254 struct tracer *next;
255 int print_max;
256};
257
214023c3
SR
258struct trace_seq {
259 unsigned char buffer[PAGE_SIZE];
260 unsigned int len;
6c6c2796 261 unsigned int readpos;
214023c3
SR
262};
263
bc0c38d1
SR
264/*
265 * Trace iterator - used by printout routines who present trace
266 * results to users and which routines might sleep, etc:
267 */
268struct trace_iterator {
269 struct trace_array *tr;
270 struct tracer *trace;
107bad8b 271 void *private;
3928a8a2 272 struct ring_buffer_iter *buffer_iter[NR_CPUS];
4e3c3333 273
53d0aa77
SR
274 /* The below is zeroed out in pipe_read */
275 struct trace_seq seq;
bc0c38d1 276 struct trace_entry *ent;
4e3c3333 277 int cpu;
3928a8a2 278 u64 ts;
4e3c3333 279
bc0c38d1
SR
280 unsigned long iter_flags;
281 loff_t pos;
4c11d7ae 282 long idx;
bc0c38d1
SR
283};
284
45dcd8b8 285void trace_wake_up(void);
3928a8a2 286void tracing_reset(struct trace_array *tr, int cpu);
bc0c38d1
SR
287int tracing_open_generic(struct inode *inode, struct file *filp);
288struct dentry *tracing_init_dentry(void);
d618b3e6
IM
289void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
290
45dcd8b8
PP
291struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
292 struct trace_array_cpu *data);
293void tracing_generic_entry_update(struct trace_entry *entry,
38697053
SR
294 unsigned long flags,
295 int pc);
45dcd8b8 296
bc0c38d1
SR
297void ftrace(struct trace_array *tr,
298 struct trace_array_cpu *data,
299 unsigned long ip,
300 unsigned long parent_ip,
38697053 301 unsigned long flags, int pc);
bc0c38d1
SR
302void tracing_sched_switch_trace(struct trace_array *tr,
303 struct trace_array_cpu *data,
304 struct task_struct *prev,
305 struct task_struct *next,
38697053 306 unsigned long flags, int pc);
bc0c38d1 307void tracing_record_cmdline(struct task_struct *tsk);
57422797
IM
308
309void tracing_sched_wakeup_trace(struct trace_array *tr,
310 struct trace_array_cpu *data,
311 struct task_struct *wakee,
312 struct task_struct *cur,
38697053 313 unsigned long flags, int pc);
f0a920d5
IM
314void trace_special(struct trace_array *tr,
315 struct trace_array_cpu *data,
316 unsigned long arg1,
317 unsigned long arg2,
38697053 318 unsigned long arg3, int pc);
6fb44b71
SR
319void trace_function(struct trace_array *tr,
320 struct trace_array_cpu *data,
321 unsigned long ip,
322 unsigned long parent_ip,
38697053 323 unsigned long flags, int pc);
bc0c38d1 324
41bc8144
SR
325void tracing_start_cmdline_record(void);
326void tracing_stop_cmdline_record(void);
bc0c38d1
SR
327int register_tracer(struct tracer *type);
328void unregister_tracer(struct tracer *type);
329
330extern unsigned long nsecs_to_usecs(unsigned long nsecs);
331
332extern unsigned long tracing_max_latency;
333extern unsigned long tracing_thresh;
334
335void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
336void update_max_tr_single(struct trace_array *tr,
337 struct task_struct *tsk, int cpu);
338
e309b41d 339extern cycle_t ftrace_now(int cpu);
bc0c38d1 340
606576ce 341#ifdef CONFIG_FUNCTION_TRACER
001b6767
SR
342void tracing_start_function_trace(void);
343void tracing_stop_function_trace(void);
344#else
345# define tracing_start_function_trace() do { } while (0)
346# define tracing_stop_function_trace() do { } while (0)
347#endif
348
bc0c38d1
SR
349#ifdef CONFIG_CONTEXT_SWITCH_TRACER
350typedef void
351(*tracer_switch_func_t)(void *private,
5b82a1b0 352 void *__rq,
bc0c38d1
SR
353 struct task_struct *prev,
354 struct task_struct *next);
355
356struct tracer_switch_ops {
357 tracer_switch_func_t func;
358 void *private;
359 struct tracer_switch_ops *next;
360};
361
bc0c38d1
SR
362#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
363
364#ifdef CONFIG_DYNAMIC_FTRACE
365extern unsigned long ftrace_update_tot_cnt;
d05cdb25
SR
366#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
367extern int DYN_FTRACE_TEST_NAME(void);
bc0c38d1
SR
368#endif
369
60a11774 370#ifdef CONFIG_FTRACE_STARTUP_TEST
60a11774
SR
371extern int trace_selftest_startup_function(struct tracer *trace,
372 struct trace_array *tr);
60a11774
SR
373extern int trace_selftest_startup_irqsoff(struct tracer *trace,
374 struct trace_array *tr);
60a11774
SR
375extern int trace_selftest_startup_preemptoff(struct tracer *trace,
376 struct trace_array *tr);
60a11774
SR
377extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
378 struct trace_array *tr);
60a11774
SR
379extern int trace_selftest_startup_wakeup(struct tracer *trace,
380 struct trace_array *tr);
fb1b6d8b
SN
381extern int trace_selftest_startup_nop(struct tracer *trace,
382 struct trace_array *tr);
60a11774
SR
383extern int trace_selftest_startup_sched_switch(struct tracer *trace,
384 struct trace_array *tr);
a6dd24f8
IM
385extern int trace_selftest_startup_sysprof(struct tracer *trace,
386 struct trace_array *tr);
60a11774
SR
387#endif /* CONFIG_FTRACE_STARTUP_TEST */
388
c7aafc54 389extern void *head_page(struct trace_array_cpu *data);
72829bc3 390extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
fc5e27ae
PP
391extern void trace_seq_print_cont(struct trace_seq *s,
392 struct trace_iterator *iter);
6c6c2796
PP
393extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
394 size_t cnt);
72829bc3 395extern long ns2usecs(cycle_t nsec);
801fe400 396extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
c7aafc54 397
4e655519
IM
398extern unsigned long trace_flags;
399
4fcdae83
SR
400/*
401 * trace_iterator_flags is an enumeration that defines bit
402 * positions into trace_flags that controls the output.
403 *
404 * NOTE: These bits must match the trace_options array in
405 * trace.c.
406 */
4e655519
IM
407enum trace_iterator_flags {
408 TRACE_ITER_PRINT_PARENT = 0x01,
409 TRACE_ITER_SYM_OFFSET = 0x02,
410 TRACE_ITER_SYM_ADDR = 0x04,
411 TRACE_ITER_VERBOSE = 0x08,
412 TRACE_ITER_RAW = 0x10,
413 TRACE_ITER_HEX = 0x20,
414 TRACE_ITER_BIN = 0x40,
415 TRACE_ITER_BLOCK = 0x80,
416 TRACE_ITER_STACKTRACE = 0x100,
4ac3ba41 417 TRACE_ITER_SCHED_TREE = 0x200,
f09ce573 418 TRACE_ITER_PRINTK = 0x400,
b2a866f9 419 TRACE_ITER_PREEMPTONLY = 0x800,
4e655519
IM
420};
421
43a15386
FW
422extern struct tracer nop_trace;
423
8f0a056f
SR
424/**
425 * ftrace_preempt_disable - disable preemption scheduler safe
426 *
427 * When tracing can happen inside the scheduler, there exists
428 * cases that the tracing might happen before the need_resched
429 * flag is checked. If this happens and the tracer calls
430 * preempt_enable (after a disable), a schedule might take place
431 * causing an infinite recursion.
432 *
433 * To prevent this, we read the need_recshed flag before
434 * disabling preemption. When we want to enable preemption we
435 * check the flag, if it is set, then we call preempt_enable_no_resched.
436 * Otherwise, we call preempt_enable.
437 *
438 * The rational for doing the above is that if need resched is set
439 * and we have yet to reschedule, we are either in an atomic location
440 * (where we do not need to check for scheduling) or we are inside
441 * the scheduler and do not want to resched.
442 */
443static inline int ftrace_preempt_disable(void)
444{
445 int resched;
446
447 resched = need_resched();
448 preempt_disable_notrace();
449
450 return resched;
451}
452
453/**
454 * ftrace_preempt_enable - enable preemption scheduler safe
455 * @resched: the return value from ftrace_preempt_disable
456 *
457 * This is a scheduler safe way to enable preemption and not miss
458 * any preemption checks. The disabled saved the state of preemption.
459 * If resched is set, then we were either inside an atomic or
460 * are inside the scheduler (we would have already scheduled
461 * otherwise). In this case, we do not want to call normal
462 * preempt_enable, but preempt_enable_no_resched instead.
463 */
464static inline void ftrace_preempt_enable(int resched)
465{
466 if (resched)
467 preempt_enable_no_resched_notrace();
468 else
469 preempt_enable_notrace();
470}
471
bc0c38d1 472#endif /* _LINUX_KERNEL_TRACE_H */