blob: f69a5199596bd4b7c1fe39118ee13616e51e2b56 [file] [log] [blame]
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001#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>
Steven Rostedt3928a8a2008-09-29 23:02:41 -04008#include <linux/ring_buffer.h>
Pekka Paalanenbd8ac682008-05-12 21:20:57 +02009#include <linux/mmiotrace.h>
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010010#include <linux/ftrace.h>
Frederic Weisbecker3f5ec132008-11-11 23:21:31 +010011#include <trace/boot.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020012
Thomas Gleixner72829bc2008-05-23 21:37:28 +020013enum trace_type {
14 __TRACE_FIRST_TYPE = 0,
15
16 TRACE_FN,
17 TRACE_CTX,
18 TRACE_WAKE,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040019 TRACE_CONT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020020 TRACE_STACK,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040021 TRACE_PRINT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020022 TRACE_SPECIAL,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020023 TRACE_MMIO_RW,
24 TRACE_MMIO_MAP,
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010025 TRACE_BOOT,
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010026 TRACE_FN_RET,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020027
28 __TRACE_LAST_TYPE
29};
30
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020031/*
Steven Rostedt777e2082008-09-29 23:02:42 -040032 * The trace entry - the most basic unit of tracing. This is what
33 * is printed in the end as a single line in the trace output, such as:
34 *
35 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
36 */
37struct trace_entry {
38 unsigned char type;
39 unsigned char cpu;
40 unsigned char flags;
41 unsigned char preempt_count;
42 int pid;
43};
44
45/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020046 * Function trace entry - function address and parent function addres:
47 */
48struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040049 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020050 unsigned long ip;
51 unsigned long parent_ip;
52};
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010053
54/* Function return entry */
55struct ftrace_ret_entry {
56 struct trace_entry ent;
57 unsigned long ip;
58 unsigned long parent_ip;
59 unsigned long long calltime;
60 unsigned long long rettime;
61};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010062extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020063
64/*
65 * Context switch trace entry - which task (and prio) we switched from/to:
66 */
67struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040068 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020069 unsigned int prev_pid;
70 unsigned char prev_prio;
71 unsigned char prev_state;
72 unsigned int next_pid;
73 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020074 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020075 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020076};
77
78/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020079 * Special (free-form) trace entry:
80 */
81struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040082 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020083 unsigned long arg1;
84 unsigned long arg2;
85 unsigned long arg3;
86};
87
88/*
Ingo Molnar86387f72008-05-12 21:20:51 +020089 * Stack-trace entry:
90 */
91
Ingo Molnar74f4e362008-05-12 21:21:15 +020092#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020093
94struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040095 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +020096 unsigned long caller[FTRACE_STACK_ENTRIES];
97};
98
99/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400100 * ftrace_printk entry:
101 */
102struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400103 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400104 unsigned long ip;
105 char buf[];
106};
107
Steven Rostedt777e2082008-09-29 23:02:42 -0400108#define TRACE_OLD_SIZE 88
109
110struct trace_field_cont {
111 unsigned char type;
112 /* Temporary till we get rid of this completely */
113 char buf[TRACE_OLD_SIZE - 1];
114};
115
116struct trace_mmiotrace_rw {
117 struct trace_entry ent;
118 struct mmiotrace_rw rw;
119};
120
121struct trace_mmiotrace_map {
122 struct trace_entry ent;
123 struct mmiotrace_map map;
124};
125
126struct trace_boot {
127 struct trace_entry ent;
128 struct boot_trace initcall;
129};
130
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400131/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300132 * trace_flag_type is an enumeration that holds different
133 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400134 * IRQS_OFF - interrupts were disabled
135 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
136 * NEED_RESCED - reschedule is requested
137 * HARDIRQ - inside an interrupt handler
138 * SOFTIRQ - inside a softirq handler
139 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300140 */
141enum trace_flag_type {
142 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400143 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
144 TRACE_FLAG_NEED_RESCHED = 0x04,
145 TRACE_FLAG_HARDIRQ = 0x08,
146 TRACE_FLAG_SOFTIRQ = 0x10,
147 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300148};
149
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300150#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200151
152/*
153 * The CPU trace array - it consists of thousands of trace entries
154 * plus some other descriptor data: (for example which task started
155 * the trace, etc.)
156 */
157struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200158 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200159
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200160 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200161 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200162 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200163 unsigned long saved_latency;
164 unsigned long critical_start;
165 unsigned long critical_end;
166 unsigned long critical_sequence;
167 unsigned long nice;
168 unsigned long policy;
169 unsigned long rt_priority;
170 cycle_t preempt_timestamp;
171 pid_t pid;
172 uid_t uid;
173 char comm[TASK_COMM_LEN];
174};
175
176struct trace_iterator;
177
178/*
179 * The trace array - an array of per-CPU trace arrays. This is the
180 * highest level data structure that individual tracers deal with.
181 * They have on/off state as well:
182 */
183struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400184 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200185 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200186 int cpu;
187 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200188 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200189 struct trace_array_cpu *data[NR_CPUS];
190};
191
Steven Rostedt7104f302008-10-01 10:52:51 -0400192#define FTRACE_CMP_TYPE(var, type) \
193 __builtin_types_compatible_p(typeof(var), type *)
194
195#undef IF_ASSIGN
196#define IF_ASSIGN(var, entry, etype, id) \
197 if (FTRACE_CMP_TYPE(var, etype)) { \
198 var = (typeof(var))(entry); \
199 WARN_ON(id && (entry)->type != id); \
200 break; \
201 }
202
203/* Will cause compile errors if type is not found. */
204extern void __ftrace_bad_type(void);
205
206/*
207 * The trace_assign_type is a verifier that the entry type is
208 * the same as the type being assigned. To add new types simply
209 * add a line with the following format:
210 *
211 * IF_ASSIGN(var, ent, type, id);
212 *
213 * Where "type" is the trace type that includes the trace_entry
214 * as the "ent" item. And "id" is the trace identifier that is
215 * used in the trace_type enum.
216 *
217 * If the type can have more than one id, then use zero.
218 */
219#define trace_assign_type(var, ent) \
220 do { \
221 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
222 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
223 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
224 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
225 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
226 IF_ASSIGN(var, ent, struct special_entry, 0); \
227 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
228 TRACE_MMIO_RW); \
229 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
230 TRACE_MMIO_MAP); \
231 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100232 IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET); \
Steven Rostedt7104f302008-10-01 10:52:51 -0400233 __ftrace_bad_type(); \
234 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200235
236/* Return values for print_line callback */
237enum print_line_t {
238 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
239 TRACE_TYPE_HANDLED = 1,
240 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
241};
242
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200243/*
244 * A specific tracer, represented by methods that operate on a trace array:
245 */
246struct tracer {
247 const char *name;
248 void (*init)(struct trace_array *tr);
249 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500250 void (*start)(struct trace_array *tr);
251 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200252 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200253 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200254 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200255 ssize_t (*read)(struct trace_iterator *iter,
256 struct file *filp, char __user *ubuf,
257 size_t cnt, loff_t *ppos);
Steven Rostedt60a11772008-05-12 21:20:44 +0200258#ifdef CONFIG_FTRACE_STARTUP_TEST
259 int (*selftest)(struct tracer *trace,
260 struct trace_array *tr);
261#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200262 enum print_line_t (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200263 struct tracer *next;
264 int print_max;
265};
266
Steven Rostedt214023c2008-05-12 21:20:46 +0200267struct trace_seq {
268 unsigned char buffer[PAGE_SIZE];
269 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200270 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200271};
272
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200273/*
274 * Trace iterator - used by printout routines who present trace
275 * results to users and which routines might sleep, etc:
276 */
277struct trace_iterator {
278 struct trace_array *tr;
279 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200280 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400281 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200282
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200283 /* The below is zeroed out in pipe_read */
284 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200285 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200286 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400287 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200288
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200289 unsigned long iter_flags;
290 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200291 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500292
293 cpumask_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200294};
295
Steven Rostedt90369902008-11-05 16:05:44 -0500296int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300297void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400298void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200299int tracing_open_generic(struct inode *inode, struct file *filp);
300struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200301void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
302
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300303struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
304 struct trace_array_cpu *data);
305void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400306 unsigned long flags,
307 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300308
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200309void ftrace(struct trace_array *tr,
310 struct trace_array_cpu *data,
311 unsigned long ip,
312 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400313 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200314void tracing_sched_switch_trace(struct trace_array *tr,
315 struct trace_array_cpu *data,
316 struct task_struct *prev,
317 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400318 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200319void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200320
321void tracing_sched_wakeup_trace(struct trace_array *tr,
322 struct trace_array_cpu *data,
323 struct task_struct *wakee,
324 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400325 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200326void trace_special(struct trace_array *tr,
327 struct trace_array_cpu *data,
328 unsigned long arg1,
329 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400330 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200331void trace_function(struct trace_array *tr,
332 struct trace_array_cpu *data,
333 unsigned long ip,
334 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400335 unsigned long flags, int pc);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100336void
337trace_function_return(struct ftrace_retfunc *trace);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200338
Steven Rostedt41bc8142008-05-22 11:49:22 -0400339void tracing_start_cmdline_record(void);
340void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500341void tracing_sched_switch_assign_trace(struct trace_array *tr);
342void tracing_stop_sched_switch_record(void);
343void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200344int register_tracer(struct tracer *type);
345void unregister_tracer(struct tracer *type);
346
347extern unsigned long nsecs_to_usecs(unsigned long nsecs);
348
349extern unsigned long tracing_max_latency;
350extern unsigned long tracing_thresh;
351
352void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
353void update_max_tr_single(struct trace_array *tr,
354 struct task_struct *tsk, int cpu);
355
Ingo Molnare309b412008-05-12 21:20:51 +0200356extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200357
Steven Rostedt606576c2008-10-06 19:06:12 -0400358#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400359void tracing_start_function_trace(void);
360void tracing_stop_function_trace(void);
361#else
362# define tracing_start_function_trace() do { } while (0)
363# define tracing_stop_function_trace() do { } while (0)
364#endif
365
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200366#ifdef CONFIG_CONTEXT_SWITCH_TRACER
367typedef void
368(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200369 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200370 struct task_struct *prev,
371 struct task_struct *next);
372
373struct tracer_switch_ops {
374 tracer_switch_func_t func;
375 void *private;
376 struct tracer_switch_ops *next;
377};
378
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200379#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
380
381#ifdef CONFIG_DYNAMIC_FTRACE
382extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200383#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
384extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200385#endif
386
Steven Rostedt60a11772008-05-12 21:20:44 +0200387#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200388extern int trace_selftest_startup_function(struct tracer *trace,
389 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200390extern int trace_selftest_startup_irqsoff(struct tracer *trace,
391 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200392extern int trace_selftest_startup_preemptoff(struct tracer *trace,
393 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200394extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
395 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200396extern int trace_selftest_startup_wakeup(struct tracer *trace,
397 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700398extern int trace_selftest_startup_nop(struct tracer *trace,
399 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200400extern int trace_selftest_startup_sched_switch(struct tracer *trace,
401 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200402extern int trace_selftest_startup_sysprof(struct tracer *trace,
403 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200404#endif /* CONFIG_FTRACE_STARTUP_TEST */
405
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200406extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200407extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300408extern void trace_seq_print_cont(struct trace_seq *s,
409 struct trace_iterator *iter);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100410
411extern int
412seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
413 unsigned long sym_flags);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200414extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
415 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200416extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300417extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200418
Ingo Molnar4e655512008-05-12 21:20:52 +0200419extern unsigned long trace_flags;
420
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100421/* Standard output formatting function used for function return traces */
422#ifdef CONFIG_FUNCTION_RET_TRACER
423extern enum print_line_t print_return_function(struct trace_iterator *iter);
424#else
425static inline enum print_line_t
426print_return_function(struct trace_iterator *iter)
427{
428 return TRACE_TYPE_UNHANDLED;
429}
430#endif
431
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200432/*
433 * trace_iterator_flags is an enumeration that defines bit
434 * positions into trace_flags that controls the output.
435 *
436 * NOTE: These bits must match the trace_options array in
437 * trace.c.
438 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200439enum trace_iterator_flags {
440 TRACE_ITER_PRINT_PARENT = 0x01,
441 TRACE_ITER_SYM_OFFSET = 0x02,
442 TRACE_ITER_SYM_ADDR = 0x04,
443 TRACE_ITER_VERBOSE = 0x08,
444 TRACE_ITER_RAW = 0x10,
445 TRACE_ITER_HEX = 0x20,
446 TRACE_ITER_BIN = 0x40,
447 TRACE_ITER_BLOCK = 0x80,
448 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200449 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200450 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500451 TRACE_ITER_PREEMPTONLY = 0x800,
Ingo Molnar4e655512008-05-12 21:20:52 +0200452};
453
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100454/*
455 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
456 * control the output of kernel symbols.
457 */
458#define TRACE_ITER_SYM_MASK \
459 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
460
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200461extern struct tracer nop_trace;
462
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500463/**
464 * ftrace_preempt_disable - disable preemption scheduler safe
465 *
466 * When tracing can happen inside the scheduler, there exists
467 * cases that the tracing might happen before the need_resched
468 * flag is checked. If this happens and the tracer calls
469 * preempt_enable (after a disable), a schedule might take place
470 * causing an infinite recursion.
471 *
472 * To prevent this, we read the need_recshed flag before
473 * disabling preemption. When we want to enable preemption we
474 * check the flag, if it is set, then we call preempt_enable_no_resched.
475 * Otherwise, we call preempt_enable.
476 *
477 * The rational for doing the above is that if need resched is set
478 * and we have yet to reschedule, we are either in an atomic location
479 * (where we do not need to check for scheduling) or we are inside
480 * the scheduler and do not want to resched.
481 */
482static inline int ftrace_preempt_disable(void)
483{
484 int resched;
485
486 resched = need_resched();
487 preempt_disable_notrace();
488
489 return resched;
490}
491
492/**
493 * ftrace_preempt_enable - enable preemption scheduler safe
494 * @resched: the return value from ftrace_preempt_disable
495 *
496 * This is a scheduler safe way to enable preemption and not miss
497 * any preemption checks. The disabled saved the state of preemption.
498 * If resched is set, then we were either inside an atomic or
499 * are inside the scheduler (we would have already scheduled
500 * otherwise). In this case, we do not want to call normal
501 * preempt_enable, but preempt_enable_no_resched instead.
502 */
503static inline void ftrace_preempt_enable(int resched)
504{
505 if (resched)
506 preempt_enable_no_resched_notrace();
507 else
508 preempt_enable_notrace();
509}
510
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200511#endif /* _LINUX_KERNEL_TRACE_H */