blob: e40ce0c14690688c97413646c58acec18e08108b [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>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020011
Thomas Gleixner72829bc2008-05-23 21:37:28 +020012enum trace_type {
13 __TRACE_FIRST_TYPE = 0,
14
15 TRACE_FN,
16 TRACE_CTX,
17 TRACE_WAKE,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040018 TRACE_CONT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020019 TRACE_STACK,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040020 TRACE_PRINT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020021 TRACE_SPECIAL,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020022 TRACE_MMIO_RW,
23 TRACE_MMIO_MAP,
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010024 TRACE_BOOT,
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010025 TRACE_FN_RET,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020026
27 __TRACE_LAST_TYPE
28};
29
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020030/*
Steven Rostedt777e2082008-09-29 23:02:42 -040031 * The trace entry - the most basic unit of tracing. This is what
32 * is printed in the end as a single line in the trace output, such as:
33 *
34 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
35 */
36struct trace_entry {
37 unsigned char type;
38 unsigned char cpu;
39 unsigned char flags;
40 unsigned char preempt_count;
41 int pid;
42};
43
44/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020045 * Function trace entry - function address and parent function addres:
46 */
47struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040048 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020049 unsigned long ip;
50 unsigned long parent_ip;
51};
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010052
53/* Function return entry */
54struct ftrace_ret_entry {
55 struct trace_entry ent;
56 unsigned long ip;
57 unsigned long parent_ip;
58 unsigned long long calltime;
59 unsigned long long rettime;
60};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010061extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020062
63/*
64 * Context switch trace entry - which task (and prio) we switched from/to:
65 */
66struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040067 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020068 unsigned int prev_pid;
69 unsigned char prev_prio;
70 unsigned char prev_state;
71 unsigned int next_pid;
72 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020073 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020074 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020075};
76
77/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020078 * Special (free-form) trace entry:
79 */
80struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040081 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020082 unsigned long arg1;
83 unsigned long arg2;
84 unsigned long arg3;
85};
86
87/*
Ingo Molnar86387f72008-05-12 21:20:51 +020088 * Stack-trace entry:
89 */
90
Ingo Molnar74f4e362008-05-12 21:21:15 +020091#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020092
93struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040094 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +020095 unsigned long caller[FTRACE_STACK_ENTRIES];
96};
97
98/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -040099 * ftrace_printk entry:
100 */
101struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400102 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400103 unsigned long ip;
104 char buf[];
105};
106
Steven Rostedt777e2082008-09-29 23:02:42 -0400107#define TRACE_OLD_SIZE 88
108
109struct trace_field_cont {
110 unsigned char type;
111 /* Temporary till we get rid of this completely */
112 char buf[TRACE_OLD_SIZE - 1];
113};
114
115struct trace_mmiotrace_rw {
116 struct trace_entry ent;
117 struct mmiotrace_rw rw;
118};
119
120struct trace_mmiotrace_map {
121 struct trace_entry ent;
122 struct mmiotrace_map map;
123};
124
125struct trace_boot {
126 struct trace_entry ent;
127 struct boot_trace initcall;
128};
129
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400130/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300131 * trace_flag_type is an enumeration that holds different
132 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400133 * IRQS_OFF - interrupts were disabled
134 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
135 * NEED_RESCED - reschedule is requested
136 * HARDIRQ - inside an interrupt handler
137 * SOFTIRQ - inside a softirq handler
138 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300139 */
140enum trace_flag_type {
141 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400142 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
143 TRACE_FLAG_NEED_RESCHED = 0x04,
144 TRACE_FLAG_HARDIRQ = 0x08,
145 TRACE_FLAG_SOFTIRQ = 0x10,
146 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300147};
148
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300149#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200150
151/*
152 * The CPU trace array - it consists of thousands of trace entries
153 * plus some other descriptor data: (for example which task started
154 * the trace, etc.)
155 */
156struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200157 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200158
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200159 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200160 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200161 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200162 unsigned long saved_latency;
163 unsigned long critical_start;
164 unsigned long critical_end;
165 unsigned long critical_sequence;
166 unsigned long nice;
167 unsigned long policy;
168 unsigned long rt_priority;
169 cycle_t preempt_timestamp;
170 pid_t pid;
171 uid_t uid;
172 char comm[TASK_COMM_LEN];
173};
174
175struct trace_iterator;
176
177/*
178 * The trace array - an array of per-CPU trace arrays. This is the
179 * highest level data structure that individual tracers deal with.
180 * They have on/off state as well:
181 */
182struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400183 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200184 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200185 int cpu;
186 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200187 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200188 struct trace_array_cpu *data[NR_CPUS];
189};
190
Steven Rostedt7104f302008-10-01 10:52:51 -0400191#define FTRACE_CMP_TYPE(var, type) \
192 __builtin_types_compatible_p(typeof(var), type *)
193
194#undef IF_ASSIGN
195#define IF_ASSIGN(var, entry, etype, id) \
196 if (FTRACE_CMP_TYPE(var, etype)) { \
197 var = (typeof(var))(entry); \
198 WARN_ON(id && (entry)->type != id); \
199 break; \
200 }
201
202/* Will cause compile errors if type is not found. */
203extern void __ftrace_bad_type(void);
204
205/*
206 * The trace_assign_type is a verifier that the entry type is
207 * the same as the type being assigned. To add new types simply
208 * add a line with the following format:
209 *
210 * IF_ASSIGN(var, ent, type, id);
211 *
212 * Where "type" is the trace type that includes the trace_entry
213 * as the "ent" item. And "id" is the trace identifier that is
214 * used in the trace_type enum.
215 *
216 * If the type can have more than one id, then use zero.
217 */
218#define trace_assign_type(var, ent) \
219 do { \
220 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
221 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
222 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
223 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
224 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
225 IF_ASSIGN(var, ent, struct special_entry, 0); \
226 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
227 TRACE_MMIO_RW); \
228 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
229 TRACE_MMIO_MAP); \
230 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100231 IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET); \
Steven Rostedt7104f302008-10-01 10:52:51 -0400232 __ftrace_bad_type(); \
233 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200234
235/* Return values for print_line callback */
236enum print_line_t {
237 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
238 TRACE_TYPE_HANDLED = 1,
239 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
240};
241
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200242/*
243 * A specific tracer, represented by methods that operate on a trace array:
244 */
245struct tracer {
246 const char *name;
247 void (*init)(struct trace_array *tr);
248 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500249 void (*start)(struct trace_array *tr);
250 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200251 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200252 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200253 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200254 ssize_t (*read)(struct trace_iterator *iter,
255 struct file *filp, char __user *ubuf,
256 size_t cnt, loff_t *ppos);
Steven Rostedt60a11772008-05-12 21:20:44 +0200257#ifdef CONFIG_FTRACE_STARTUP_TEST
258 int (*selftest)(struct tracer *trace,
259 struct trace_array *tr);
260#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200261 enum print_line_t (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200262 struct tracer *next;
263 int print_max;
264};
265
Steven Rostedt214023c2008-05-12 21:20:46 +0200266struct trace_seq {
267 unsigned char buffer[PAGE_SIZE];
268 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200269 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200270};
271
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200272/*
273 * Trace iterator - used by printout routines who present trace
274 * results to users and which routines might sleep, etc:
275 */
276struct trace_iterator {
277 struct trace_array *tr;
278 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200279 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400280 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200281
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200282 /* The below is zeroed out in pipe_read */
283 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200284 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200285 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400286 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200287
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200288 unsigned long iter_flags;
289 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200290 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500291
292 cpumask_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200293};
294
Steven Rostedt90369902008-11-05 16:05:44 -0500295int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300296void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400297void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200298int tracing_open_generic(struct inode *inode, struct file *filp);
299struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200300void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
301
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300302struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
303 struct trace_array_cpu *data);
304void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400305 unsigned long flags,
306 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300307
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200308void ftrace(struct trace_array *tr,
309 struct trace_array_cpu *data,
310 unsigned long ip,
311 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400312 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200313void tracing_sched_switch_trace(struct trace_array *tr,
314 struct trace_array_cpu *data,
315 struct task_struct *prev,
316 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400317 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200318void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200319
320void tracing_sched_wakeup_trace(struct trace_array *tr,
321 struct trace_array_cpu *data,
322 struct task_struct *wakee,
323 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400324 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200325void trace_special(struct trace_array *tr,
326 struct trace_array_cpu *data,
327 unsigned long arg1,
328 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400329 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200330void trace_function(struct trace_array *tr,
331 struct trace_array_cpu *data,
332 unsigned long ip,
333 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400334 unsigned long flags, int pc);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100335void
336trace_function_return(struct ftrace_retfunc *trace);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200337
Steven Rostedt41bc8142008-05-22 11:49:22 -0400338void tracing_start_cmdline_record(void);
339void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500340void tracing_sched_switch_assign_trace(struct trace_array *tr);
341void tracing_stop_sched_switch_record(void);
342void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200343int register_tracer(struct tracer *type);
344void unregister_tracer(struct tracer *type);
345
346extern unsigned long nsecs_to_usecs(unsigned long nsecs);
347
348extern unsigned long tracing_max_latency;
349extern unsigned long tracing_thresh;
350
351void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
352void update_max_tr_single(struct trace_array *tr,
353 struct task_struct *tsk, int cpu);
354
Ingo Molnare309b412008-05-12 21:20:51 +0200355extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200356
Steven Rostedt606576c2008-10-06 19:06:12 -0400357#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400358void tracing_start_function_trace(void);
359void tracing_stop_function_trace(void);
360#else
361# define tracing_start_function_trace() do { } while (0)
362# define tracing_stop_function_trace() do { } while (0)
363#endif
364
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200365#ifdef CONFIG_CONTEXT_SWITCH_TRACER
366typedef void
367(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200368 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200369 struct task_struct *prev,
370 struct task_struct *next);
371
372struct tracer_switch_ops {
373 tracer_switch_func_t func;
374 void *private;
375 struct tracer_switch_ops *next;
376};
377
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200378#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
379
380#ifdef CONFIG_DYNAMIC_FTRACE
381extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200382#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
383extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200384#endif
385
Steven Rostedt60a11772008-05-12 21:20:44 +0200386#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200387extern int trace_selftest_startup_function(struct tracer *trace,
388 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200389extern int trace_selftest_startup_irqsoff(struct tracer *trace,
390 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200391extern int trace_selftest_startup_preemptoff(struct tracer *trace,
392 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200393extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
394 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200395extern int trace_selftest_startup_wakeup(struct tracer *trace,
396 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700397extern int trace_selftest_startup_nop(struct tracer *trace,
398 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200399extern int trace_selftest_startup_sched_switch(struct tracer *trace,
400 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200401extern int trace_selftest_startup_sysprof(struct tracer *trace,
402 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200403#endif /* CONFIG_FTRACE_STARTUP_TEST */
404
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200405extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200406extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300407extern void trace_seq_print_cont(struct trace_seq *s,
408 struct trace_iterator *iter);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100409
410extern int
411seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
412 unsigned long sym_flags);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200413extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
414 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200415extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300416extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200417
Ingo Molnar4e655512008-05-12 21:20:52 +0200418extern unsigned long trace_flags;
419
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100420/* Standard output formatting function used for function return traces */
421#ifdef CONFIG_FUNCTION_RET_TRACER
422extern enum print_line_t print_return_function(struct trace_iterator *iter);
423#else
424static inline enum print_line_t
425print_return_function(struct trace_iterator *iter)
426{
427 return TRACE_TYPE_UNHANDLED;
428}
429#endif
430
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200431/*
432 * trace_iterator_flags is an enumeration that defines bit
433 * positions into trace_flags that controls the output.
434 *
435 * NOTE: These bits must match the trace_options array in
436 * trace.c.
437 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200438enum trace_iterator_flags {
439 TRACE_ITER_PRINT_PARENT = 0x01,
440 TRACE_ITER_SYM_OFFSET = 0x02,
441 TRACE_ITER_SYM_ADDR = 0x04,
442 TRACE_ITER_VERBOSE = 0x08,
443 TRACE_ITER_RAW = 0x10,
444 TRACE_ITER_HEX = 0x20,
445 TRACE_ITER_BIN = 0x40,
446 TRACE_ITER_BLOCK = 0x80,
447 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200448 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200449 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500450 TRACE_ITER_PREEMPTONLY = 0x800,
Ingo Molnar4e655512008-05-12 21:20:52 +0200451};
452
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100453/*
454 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
455 * control the output of kernel symbols.
456 */
457#define TRACE_ITER_SYM_MASK \
458 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
459
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200460extern struct tracer nop_trace;
461
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500462/**
463 * ftrace_preempt_disable - disable preemption scheduler safe
464 *
465 * When tracing can happen inside the scheduler, there exists
466 * cases that the tracing might happen before the need_resched
467 * flag is checked. If this happens and the tracer calls
468 * preempt_enable (after a disable), a schedule might take place
469 * causing an infinite recursion.
470 *
471 * To prevent this, we read the need_recshed flag before
472 * disabling preemption. When we want to enable preemption we
473 * check the flag, if it is set, then we call preempt_enable_no_resched.
474 * Otherwise, we call preempt_enable.
475 *
476 * The rational for doing the above is that if need resched is set
477 * and we have yet to reschedule, we are either in an atomic location
478 * (where we do not need to check for scheduling) or we are inside
479 * the scheduler and do not want to resched.
480 */
481static inline int ftrace_preempt_disable(void)
482{
483 int resched;
484
485 resched = need_resched();
486 preempt_disable_notrace();
487
488 return resched;
489}
490
491/**
492 * ftrace_preempt_enable - enable preemption scheduler safe
493 * @resched: the return value from ftrace_preempt_disable
494 *
495 * This is a scheduler safe way to enable preemption and not miss
496 * any preemption checks. The disabled saved the state of preemption.
497 * If resched is set, then we were either inside an atomic or
498 * are inside the scheduler (we would have already scheduled
499 * otherwise). In this case, we do not want to call normal
500 * preempt_enable, but preempt_enable_no_resched instead.
501 */
502static inline void ftrace_preempt_enable(int resched)
503{
504 if (resched)
505 preempt_enable_no_resched_notrace();
506 else
507 preempt_enable_notrace();
508}
509
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200510#endif /* _LINUX_KERNEL_TRACE_H */