blob: b5f91f198fd46f8c11c6d3a66964a08a6c17243c [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,
Frederic Weisbecker74239072008-11-11 23:24:42 +010025 TRACE_BOOT_CALL,
26 TRACE_BOOT_RET,
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010027 TRACE_FN_RET,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020028
29 __TRACE_LAST_TYPE
30};
31
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020032/*
Steven Rostedt777e2082008-09-29 23:02:42 -040033 * The trace entry - the most basic unit of tracing. This is what
34 * is printed in the end as a single line in the trace output, such as:
35 *
36 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
37 */
38struct trace_entry {
39 unsigned char type;
40 unsigned char cpu;
41 unsigned char flags;
42 unsigned char preempt_count;
43 int pid;
44};
45
46/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020047 * Function trace entry - function address and parent function addres:
48 */
49struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040050 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020051 unsigned long ip;
52 unsigned long parent_ip;
53};
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010054
55/* Function return entry */
56struct ftrace_ret_entry {
57 struct trace_entry ent;
58 unsigned long ip;
59 unsigned long parent_ip;
60 unsigned long long calltime;
61 unsigned long long rettime;
62};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010063extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020064
65/*
66 * Context switch trace entry - which task (and prio) we switched from/to:
67 */
68struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040069 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020070 unsigned int prev_pid;
71 unsigned char prev_prio;
72 unsigned char prev_state;
73 unsigned int next_pid;
74 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020075 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020076 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020077};
78
79/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020080 * Special (free-form) trace entry:
81 */
82struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040083 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020084 unsigned long arg1;
85 unsigned long arg2;
86 unsigned long arg3;
87};
88
89/*
Ingo Molnar86387f72008-05-12 21:20:51 +020090 * Stack-trace entry:
91 */
92
Ingo Molnar74f4e362008-05-12 21:21:15 +020093#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020094
95struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040096 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +020097 unsigned long caller[FTRACE_STACK_ENTRIES];
98};
99
100/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400101 * ftrace_printk entry:
102 */
103struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400104 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400105 unsigned long ip;
106 char buf[];
107};
108
Steven Rostedt777e2082008-09-29 23:02:42 -0400109#define TRACE_OLD_SIZE 88
110
111struct trace_field_cont {
112 unsigned char type;
113 /* Temporary till we get rid of this completely */
114 char buf[TRACE_OLD_SIZE - 1];
115};
116
117struct trace_mmiotrace_rw {
118 struct trace_entry ent;
119 struct mmiotrace_rw rw;
120};
121
122struct trace_mmiotrace_map {
123 struct trace_entry ent;
124 struct mmiotrace_map map;
125};
126
Frederic Weisbecker74239072008-11-11 23:24:42 +0100127struct trace_boot_call {
Steven Rostedt777e2082008-09-29 23:02:42 -0400128 struct trace_entry ent;
Frederic Weisbecker74239072008-11-11 23:24:42 +0100129 struct boot_trace_call boot_call;
130};
131
132struct trace_boot_ret {
133 struct trace_entry ent;
134 struct boot_trace_ret boot_ret;
Steven Rostedt777e2082008-09-29 23:02:42 -0400135};
136
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400137/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300138 * trace_flag_type is an enumeration that holds different
139 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400140 * IRQS_OFF - interrupts were disabled
141 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
142 * NEED_RESCED - reschedule is requested
143 * HARDIRQ - inside an interrupt handler
144 * SOFTIRQ - inside a softirq handler
145 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300146 */
147enum trace_flag_type {
148 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400149 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
150 TRACE_FLAG_NEED_RESCHED = 0x04,
151 TRACE_FLAG_HARDIRQ = 0x08,
152 TRACE_FLAG_SOFTIRQ = 0x10,
153 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300154};
155
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300156#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200157
158/*
159 * The CPU trace array - it consists of thousands of trace entries
160 * plus some other descriptor data: (for example which task started
161 * the trace, etc.)
162 */
163struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200164 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200165
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200166 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200167 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200168 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200169 unsigned long saved_latency;
170 unsigned long critical_start;
171 unsigned long critical_end;
172 unsigned long critical_sequence;
173 unsigned long nice;
174 unsigned long policy;
175 unsigned long rt_priority;
176 cycle_t preempt_timestamp;
177 pid_t pid;
178 uid_t uid;
179 char comm[TASK_COMM_LEN];
180};
181
182struct trace_iterator;
183
184/*
185 * The trace array - an array of per-CPU trace arrays. This is the
186 * highest level data structure that individual tracers deal with.
187 * They have on/off state as well:
188 */
189struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400190 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200191 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200192 int cpu;
193 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200194 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200195 struct trace_array_cpu *data[NR_CPUS];
196};
197
Steven Rostedt7104f302008-10-01 10:52:51 -0400198#define FTRACE_CMP_TYPE(var, type) \
199 __builtin_types_compatible_p(typeof(var), type *)
200
201#undef IF_ASSIGN
202#define IF_ASSIGN(var, entry, etype, id) \
203 if (FTRACE_CMP_TYPE(var, etype)) { \
204 var = (typeof(var))(entry); \
205 WARN_ON(id && (entry)->type != id); \
206 break; \
207 }
208
209/* Will cause compile errors if type is not found. */
210extern void __ftrace_bad_type(void);
211
212/*
213 * The trace_assign_type is a verifier that the entry type is
214 * the same as the type being assigned. To add new types simply
215 * add a line with the following format:
216 *
217 * IF_ASSIGN(var, ent, type, id);
218 *
219 * Where "type" is the trace type that includes the trace_entry
220 * as the "ent" item. And "id" is the trace identifier that is
221 * used in the trace_type enum.
222 *
223 * If the type can have more than one id, then use zero.
224 */
225#define trace_assign_type(var, ent) \
226 do { \
227 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
228 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
229 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
230 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
231 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
232 IF_ASSIGN(var, ent, struct special_entry, 0); \
233 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
234 TRACE_MMIO_RW); \
235 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
236 TRACE_MMIO_MAP); \
Frederic Weisbecker74239072008-11-11 23:24:42 +0100237 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
238 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
239 IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET);\
Steven Rostedt7104f302008-10-01 10:52:51 -0400240 __ftrace_bad_type(); \
241 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200242
243/* Return values for print_line callback */
244enum print_line_t {
245 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
246 TRACE_TYPE_HANDLED = 1,
247 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
248};
249
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200250/*
251 * A specific tracer, represented by methods that operate on a trace array:
252 */
253struct tracer {
254 const char *name;
255 void (*init)(struct trace_array *tr);
256 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500257 void (*start)(struct trace_array *tr);
258 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200259 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200260 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200261 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200262 ssize_t (*read)(struct trace_iterator *iter,
263 struct file *filp, char __user *ubuf,
264 size_t cnt, loff_t *ppos);
Steven Rostedt60a11772008-05-12 21:20:44 +0200265#ifdef CONFIG_FTRACE_STARTUP_TEST
266 int (*selftest)(struct tracer *trace,
267 struct trace_array *tr);
268#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200269 enum print_line_t (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200270 struct tracer *next;
271 int print_max;
272};
273
Steven Rostedt214023c2008-05-12 21:20:46 +0200274struct trace_seq {
275 unsigned char buffer[PAGE_SIZE];
276 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200277 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200278};
279
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200280/*
281 * Trace iterator - used by printout routines who present trace
282 * results to users and which routines might sleep, etc:
283 */
284struct trace_iterator {
285 struct trace_array *tr;
286 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200287 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400288 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200289
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200290 /* The below is zeroed out in pipe_read */
291 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200292 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200293 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400294 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200295
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200296 unsigned long iter_flags;
297 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200298 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500299
300 cpumask_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200301};
302
Steven Rostedt90369902008-11-05 16:05:44 -0500303int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300304void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400305void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200306int tracing_open_generic(struct inode *inode, struct file *filp);
307struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200308void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
309
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300310struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
311 struct trace_array_cpu *data);
312void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400313 unsigned long flags,
314 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300315
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200316void ftrace(struct trace_array *tr,
317 struct trace_array_cpu *data,
318 unsigned long ip,
319 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400320 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200321void tracing_sched_switch_trace(struct trace_array *tr,
322 struct trace_array_cpu *data,
323 struct task_struct *prev,
324 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400325 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200326void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200327
328void tracing_sched_wakeup_trace(struct trace_array *tr,
329 struct trace_array_cpu *data,
330 struct task_struct *wakee,
331 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400332 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200333void trace_special(struct trace_array *tr,
334 struct trace_array_cpu *data,
335 unsigned long arg1,
336 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400337 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200338void trace_function(struct trace_array *tr,
339 struct trace_array_cpu *data,
340 unsigned long ip,
341 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400342 unsigned long flags, int pc);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100343void
344trace_function_return(struct ftrace_retfunc *trace);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200345
Steven Rostedt41bc8142008-05-22 11:49:22 -0400346void tracing_start_cmdline_record(void);
347void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500348void tracing_sched_switch_assign_trace(struct trace_array *tr);
349void tracing_stop_sched_switch_record(void);
350void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200351int register_tracer(struct tracer *type);
352void unregister_tracer(struct tracer *type);
353
354extern unsigned long nsecs_to_usecs(unsigned long nsecs);
355
356extern unsigned long tracing_max_latency;
357extern unsigned long tracing_thresh;
358
359void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
360void update_max_tr_single(struct trace_array *tr,
361 struct task_struct *tsk, int cpu);
362
Ingo Molnare309b412008-05-12 21:20:51 +0200363extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200364
Steven Rostedt606576c2008-10-06 19:06:12 -0400365#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400366void tracing_start_function_trace(void);
367void tracing_stop_function_trace(void);
368#else
369# define tracing_start_function_trace() do { } while (0)
370# define tracing_stop_function_trace() do { } while (0)
371#endif
372
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200373#ifdef CONFIG_CONTEXT_SWITCH_TRACER
374typedef void
375(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200376 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200377 struct task_struct *prev,
378 struct task_struct *next);
379
380struct tracer_switch_ops {
381 tracer_switch_func_t func;
382 void *private;
383 struct tracer_switch_ops *next;
384};
385
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200386#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
387
388#ifdef CONFIG_DYNAMIC_FTRACE
389extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200390#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
391extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200392#endif
393
Steven Rostedt60a11772008-05-12 21:20:44 +0200394#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200395extern int trace_selftest_startup_function(struct tracer *trace,
396 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200397extern int trace_selftest_startup_irqsoff(struct tracer *trace,
398 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200399extern int trace_selftest_startup_preemptoff(struct tracer *trace,
400 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200401extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
402 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200403extern int trace_selftest_startup_wakeup(struct tracer *trace,
404 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700405extern int trace_selftest_startup_nop(struct tracer *trace,
406 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200407extern int trace_selftest_startup_sched_switch(struct tracer *trace,
408 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200409extern int trace_selftest_startup_sysprof(struct tracer *trace,
410 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200411#endif /* CONFIG_FTRACE_STARTUP_TEST */
412
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200413extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200414extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300415extern void trace_seq_print_cont(struct trace_seq *s,
416 struct trace_iterator *iter);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100417
418extern int
419seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
420 unsigned long sym_flags);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200421extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
422 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200423extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300424extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200425
Ingo Molnar4e655512008-05-12 21:20:52 +0200426extern unsigned long trace_flags;
427
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100428/* Standard output formatting function used for function return traces */
429#ifdef CONFIG_FUNCTION_RET_TRACER
430extern enum print_line_t print_return_function(struct trace_iterator *iter);
431#else
432static inline enum print_line_t
433print_return_function(struct trace_iterator *iter)
434{
435 return TRACE_TYPE_UNHANDLED;
436}
437#endif
438
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200439/*
440 * trace_iterator_flags is an enumeration that defines bit
441 * positions into trace_flags that controls the output.
442 *
443 * NOTE: These bits must match the trace_options array in
444 * trace.c.
445 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200446enum trace_iterator_flags {
447 TRACE_ITER_PRINT_PARENT = 0x01,
448 TRACE_ITER_SYM_OFFSET = 0x02,
449 TRACE_ITER_SYM_ADDR = 0x04,
450 TRACE_ITER_VERBOSE = 0x08,
451 TRACE_ITER_RAW = 0x10,
452 TRACE_ITER_HEX = 0x20,
453 TRACE_ITER_BIN = 0x40,
454 TRACE_ITER_BLOCK = 0x80,
455 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200456 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200457 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500458 TRACE_ITER_PREEMPTONLY = 0x800,
Ingo Molnar4e655512008-05-12 21:20:52 +0200459};
460
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100461/*
462 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
463 * control the output of kernel symbols.
464 */
465#define TRACE_ITER_SYM_MASK \
466 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
467
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200468extern struct tracer nop_trace;
469
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500470/**
471 * ftrace_preempt_disable - disable preemption scheduler safe
472 *
473 * When tracing can happen inside the scheduler, there exists
474 * cases that the tracing might happen before the need_resched
475 * flag is checked. If this happens and the tracer calls
476 * preempt_enable (after a disable), a schedule might take place
477 * causing an infinite recursion.
478 *
479 * To prevent this, we read the need_recshed flag before
480 * disabling preemption. When we want to enable preemption we
481 * check the flag, if it is set, then we call preempt_enable_no_resched.
482 * Otherwise, we call preempt_enable.
483 *
484 * The rational for doing the above is that if need resched is set
485 * and we have yet to reschedule, we are either in an atomic location
486 * (where we do not need to check for scheduling) or we are inside
487 * the scheduler and do not want to resched.
488 */
489static inline int ftrace_preempt_disable(void)
490{
491 int resched;
492
493 resched = need_resched();
494 preempt_disable_notrace();
495
496 return resched;
497}
498
499/**
500 * ftrace_preempt_enable - enable preemption scheduler safe
501 * @resched: the return value from ftrace_preempt_disable
502 *
503 * This is a scheduler safe way to enable preemption and not miss
504 * any preemption checks. The disabled saved the state of preemption.
505 * If resched is set, then we were either inside an atomic or
506 * are inside the scheduler (we would have already scheduled
507 * otherwise). In this case, we do not want to call normal
508 * preempt_enable, but preempt_enable_no_resched instead.
509 */
510static inline void ftrace_preempt_enable(int resched)
511{
512 if (resched)
513 preempt_enable_no_resched_notrace();
514 else
515 preempt_enable_notrace();
516}
517
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200518#endif /* _LINUX_KERNEL_TRACE_H */