blob: 28c15c2ebc2272dde5705fcd03c67c5c24c6e0ae [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,
Steven Rostedt9f029e82008-11-12 15:24:24 -050025 TRACE_BRANCH,
Frederic Weisbecker74239072008-11-11 23:24:42 +010026 TRACE_BOOT_CALL,
27 TRACE_BOOT_RET,
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010028 TRACE_FN_RET,
Török Edwin02b67512008-11-22 13:28:47 +020029 TRACE_USER_STACK,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020030
31 __TRACE_LAST_TYPE
32};
33
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020034/*
Steven Rostedt777e2082008-09-29 23:02:42 -040035 * The trace entry - the most basic unit of tracing. This is what
36 * is printed in the end as a single line in the trace output, such as:
37 *
38 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
39 */
40struct trace_entry {
41 unsigned char type;
42 unsigned char cpu;
43 unsigned char flags;
44 unsigned char preempt_count;
45 int pid;
Török Edwin02b67512008-11-22 13:28:47 +020046 int tgid;
Steven Rostedt777e2082008-09-29 23:02:42 -040047};
48
49/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020050 * Function trace entry - function address and parent function addres:
51 */
52struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040053 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020054 unsigned long ip;
55 unsigned long parent_ip;
56};
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010057
58/* Function return entry */
59struct ftrace_ret_entry {
60 struct trace_entry ent;
61 unsigned long ip;
62 unsigned long parent_ip;
63 unsigned long long calltime;
64 unsigned long long rettime;
Frederic Weisbecker02310222008-11-17 03:22:41 +010065 unsigned long overrun;
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010066};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010067extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020068
69/*
70 * Context switch trace entry - which task (and prio) we switched from/to:
71 */
72struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040073 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020074 unsigned int prev_pid;
75 unsigned char prev_prio;
76 unsigned char prev_state;
77 unsigned int next_pid;
78 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020079 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020080 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020081};
82
83/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020084 * Special (free-form) trace entry:
85 */
86struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040087 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020088 unsigned long arg1;
89 unsigned long arg2;
90 unsigned long arg3;
91};
92
93/*
Ingo Molnar86387f72008-05-12 21:20:51 +020094 * Stack-trace entry:
95 */
96
Ingo Molnar74f4e362008-05-12 21:21:15 +020097#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020098
99struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400100 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +0200101 unsigned long caller[FTRACE_STACK_ENTRIES];
102};
103
Török Edwin02b67512008-11-22 13:28:47 +0200104struct userstack_entry {
105 struct trace_entry ent;
106 unsigned long caller[FTRACE_STACK_ENTRIES];
107};
108
Ingo Molnar86387f72008-05-12 21:20:51 +0200109/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400110 * ftrace_printk entry:
111 */
112struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400113 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400114 unsigned long ip;
115 char buf[];
116};
117
Steven Rostedt777e2082008-09-29 23:02:42 -0400118#define TRACE_OLD_SIZE 88
119
120struct trace_field_cont {
121 unsigned char type;
122 /* Temporary till we get rid of this completely */
123 char buf[TRACE_OLD_SIZE - 1];
124};
125
126struct trace_mmiotrace_rw {
127 struct trace_entry ent;
128 struct mmiotrace_rw rw;
129};
130
131struct trace_mmiotrace_map {
132 struct trace_entry ent;
133 struct mmiotrace_map map;
134};
135
Frederic Weisbecker74239072008-11-11 23:24:42 +0100136struct trace_boot_call {
Steven Rostedt777e2082008-09-29 23:02:42 -0400137 struct trace_entry ent;
Frederic Weisbecker74239072008-11-11 23:24:42 +0100138 struct boot_trace_call boot_call;
139};
140
141struct trace_boot_ret {
142 struct trace_entry ent;
143 struct boot_trace_ret boot_ret;
Steven Rostedt777e2082008-09-29 23:02:42 -0400144};
145
Steven Rostedt52f232c2008-11-12 00:14:40 -0500146#define TRACE_FUNC_SIZE 30
147#define TRACE_FILE_SIZE 20
Steven Rostedt9f029e82008-11-12 15:24:24 -0500148struct trace_branch {
Steven Rostedt52f232c2008-11-12 00:14:40 -0500149 struct trace_entry ent;
150 unsigned line;
151 char func[TRACE_FUNC_SIZE+1];
152 char file[TRACE_FILE_SIZE+1];
153 char correct;
154};
155
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400156/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300157 * trace_flag_type is an enumeration that holds different
158 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400159 * IRQS_OFF - interrupts were disabled
160 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
161 * NEED_RESCED - reschedule is requested
162 * HARDIRQ - inside an interrupt handler
163 * SOFTIRQ - inside a softirq handler
164 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300165 */
166enum trace_flag_type {
167 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400168 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
169 TRACE_FLAG_NEED_RESCHED = 0x04,
170 TRACE_FLAG_HARDIRQ = 0x08,
171 TRACE_FLAG_SOFTIRQ = 0x10,
172 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300173};
174
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300175#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200176
177/*
178 * The CPU trace array - it consists of thousands of trace entries
179 * plus some other descriptor data: (for example which task started
180 * the trace, etc.)
181 */
182struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200183 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200184
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200185 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200186 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200187 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200188 unsigned long saved_latency;
189 unsigned long critical_start;
190 unsigned long critical_end;
191 unsigned long critical_sequence;
192 unsigned long nice;
193 unsigned long policy;
194 unsigned long rt_priority;
195 cycle_t preempt_timestamp;
196 pid_t pid;
197 uid_t uid;
198 char comm[TASK_COMM_LEN];
199};
200
201struct trace_iterator;
202
203/*
204 * The trace array - an array of per-CPU trace arrays. This is the
205 * highest level data structure that individual tracers deal with.
206 * They have on/off state as well:
207 */
208struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400209 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200210 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200211 int cpu;
212 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200213 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200214 struct trace_array_cpu *data[NR_CPUS];
215};
216
Steven Rostedt7104f302008-10-01 10:52:51 -0400217#define FTRACE_CMP_TYPE(var, type) \
218 __builtin_types_compatible_p(typeof(var), type *)
219
220#undef IF_ASSIGN
221#define IF_ASSIGN(var, entry, etype, id) \
222 if (FTRACE_CMP_TYPE(var, etype)) { \
223 var = (typeof(var))(entry); \
224 WARN_ON(id && (entry)->type != id); \
225 break; \
226 }
227
228/* Will cause compile errors if type is not found. */
229extern void __ftrace_bad_type(void);
230
231/*
232 * The trace_assign_type is a verifier that the entry type is
233 * the same as the type being assigned. To add new types simply
234 * add a line with the following format:
235 *
236 * IF_ASSIGN(var, ent, type, id);
237 *
238 * Where "type" is the trace type that includes the trace_entry
239 * as the "ent" item. And "id" is the trace identifier that is
240 * used in the trace_type enum.
241 *
242 * If the type can have more than one id, then use zero.
243 */
244#define trace_assign_type(var, ent) \
245 do { \
246 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
247 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
248 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
249 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
Török Edwin02b67512008-11-22 13:28:47 +0200250 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
Steven Rostedt7104f302008-10-01 10:52:51 -0400251 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
252 IF_ASSIGN(var, ent, struct special_entry, 0); \
253 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
254 TRACE_MMIO_RW); \
255 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
256 TRACE_MMIO_MAP); \
Frederic Weisbecker74239072008-11-11 23:24:42 +0100257 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
258 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
Steven Rostedt9f029e82008-11-12 15:24:24 -0500259 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
Frederic Weisbecker74239072008-11-11 23:24:42 +0100260 IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET);\
Steven Rostedt7104f302008-10-01 10:52:51 -0400261 __ftrace_bad_type(); \
262 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200263
264/* Return values for print_line callback */
265enum print_line_t {
266 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
267 TRACE_TYPE_HANDLED = 1,
268 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
269};
270
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100271
272/*
273 * An option specific to a tracer. This is a boolean value.
274 * The bit is the bit index that sets its value on the
275 * flags value in struct tracer_flags.
276 */
277struct tracer_opt {
278 const char *name; /* Will appear on the trace_options file */
279 u32 bit; /* Mask assigned in val field in tracer_flags */
280};
281
282/*
283 * The set of specific options for a tracer. Your tracer
284 * have to set the initial value of the flags val.
285 */
286struct tracer_flags {
287 u32 val;
288 struct tracer_opt *opts;
289};
290
291/* Makes more easy to define a tracer opt */
292#define TRACER_OPT(s, b) .name = #s, .bit = b
293
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200294/*
295 * A specific tracer, represented by methods that operate on a trace array:
296 */
297struct tracer {
298 const char *name;
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100299 /* Your tracer should raise a warning if init fails */
300 int (*init)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200301 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500302 void (*start)(struct trace_array *tr);
303 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200304 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200305 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200306 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200307 ssize_t (*read)(struct trace_iterator *iter,
308 struct file *filp, char __user *ubuf,
309 size_t cnt, loff_t *ppos);
Steven Rostedt60a11772008-05-12 21:20:44 +0200310#ifdef CONFIG_FTRACE_STARTUP_TEST
311 int (*selftest)(struct tracer *trace,
312 struct trace_array *tr);
313#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200314 enum print_line_t (*print_line)(struct trace_iterator *iter);
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100315 /* If you handled the flag setting, return 0 */
316 int (*set_flag)(u32 old_flags, u32 bit, int set);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200317 struct tracer *next;
318 int print_max;
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100319 struct tracer_flags *flags;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200320};
321
Steven Rostedt214023c2008-05-12 21:20:46 +0200322struct trace_seq {
323 unsigned char buffer[PAGE_SIZE];
324 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200325 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200326};
327
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200328/*
329 * Trace iterator - used by printout routines who present trace
330 * results to users and which routines might sleep, etc:
331 */
332struct trace_iterator {
333 struct trace_array *tr;
334 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200335 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400336 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200337
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200338 /* The below is zeroed out in pipe_read */
339 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200340 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200341 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400342 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200343
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200344 unsigned long iter_flags;
345 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200346 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500347
348 cpumask_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200349};
350
Steven Rostedt90369902008-11-05 16:05:44 -0500351int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300352void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400353void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200354int tracing_open_generic(struct inode *inode, struct file *filp);
355struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200356void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
357
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300358struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
359 struct trace_array_cpu *data);
360void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400361 unsigned long flags,
362 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300363
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200364void ftrace(struct trace_array *tr,
365 struct trace_array_cpu *data,
366 unsigned long ip,
367 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400368 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200369void tracing_sched_switch_trace(struct trace_array *tr,
370 struct trace_array_cpu *data,
371 struct task_struct *prev,
372 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400373 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200374void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200375
376void tracing_sched_wakeup_trace(struct trace_array *tr,
377 struct trace_array_cpu *data,
378 struct task_struct *wakee,
379 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400380 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200381void trace_special(struct trace_array *tr,
382 struct trace_array_cpu *data,
383 unsigned long arg1,
384 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400385 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200386void trace_function(struct trace_array *tr,
387 struct trace_array_cpu *data,
388 unsigned long ip,
389 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400390 unsigned long flags, int pc);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100391void
392trace_function_return(struct ftrace_retfunc *trace);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200393
Steven Rostedt41bc8142008-05-22 11:49:22 -0400394void tracing_start_cmdline_record(void);
395void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500396void tracing_sched_switch_assign_trace(struct trace_array *tr);
397void tracing_stop_sched_switch_record(void);
398void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200399int register_tracer(struct tracer *type);
400void unregister_tracer(struct tracer *type);
401
402extern unsigned long nsecs_to_usecs(unsigned long nsecs);
403
404extern unsigned long tracing_max_latency;
405extern unsigned long tracing_thresh;
406
407void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
408void update_max_tr_single(struct trace_array *tr,
409 struct task_struct *tsk, int cpu);
410
Ingo Molnare309b412008-05-12 21:20:51 +0200411extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200412
Steven Rostedt606576c2008-10-06 19:06:12 -0400413#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400414void tracing_start_function_trace(void);
415void tracing_stop_function_trace(void);
416#else
417# define tracing_start_function_trace() do { } while (0)
418# define tracing_stop_function_trace() do { } while (0)
419#endif
420
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200421#ifdef CONFIG_CONTEXT_SWITCH_TRACER
422typedef void
423(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200424 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200425 struct task_struct *prev,
426 struct task_struct *next);
427
428struct tracer_switch_ops {
429 tracer_switch_func_t func;
430 void *private;
431 struct tracer_switch_ops *next;
432};
433
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200434#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
435
436#ifdef CONFIG_DYNAMIC_FTRACE
437extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200438#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
439extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200440#endif
441
Steven Rostedt60a11772008-05-12 21:20:44 +0200442#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200443extern int trace_selftest_startup_function(struct tracer *trace,
444 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200445extern int trace_selftest_startup_irqsoff(struct tracer *trace,
446 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200447extern int trace_selftest_startup_preemptoff(struct tracer *trace,
448 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200449extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
450 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200451extern int trace_selftest_startup_wakeup(struct tracer *trace,
452 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700453extern int trace_selftest_startup_nop(struct tracer *trace,
454 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200455extern int trace_selftest_startup_sched_switch(struct tracer *trace,
456 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200457extern int trace_selftest_startup_sysprof(struct tracer *trace,
458 struct trace_array *tr);
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500459extern int trace_selftest_startup_branch(struct tracer *trace,
460 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200461#endif /* CONFIG_FTRACE_STARTUP_TEST */
462
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200463extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200464extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300465extern void trace_seq_print_cont(struct trace_seq *s,
466 struct trace_iterator *iter);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100467
468extern int
469seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
470 unsigned long sym_flags);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200471extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
472 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200473extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300474extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200475
Ingo Molnar4e655512008-05-12 21:20:52 +0200476extern unsigned long trace_flags;
477
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100478/* Standard output formatting function used for function return traces */
479#ifdef CONFIG_FUNCTION_RET_TRACER
480extern enum print_line_t print_return_function(struct trace_iterator *iter);
481#else
482static inline enum print_line_t
483print_return_function(struct trace_iterator *iter)
484{
485 return TRACE_TYPE_UNHANDLED;
486}
487#endif
488
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200489/*
490 * trace_iterator_flags is an enumeration that defines bit
491 * positions into trace_flags that controls the output.
492 *
493 * NOTE: These bits must match the trace_options array in
494 * trace.c.
495 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200496enum trace_iterator_flags {
497 TRACE_ITER_PRINT_PARENT = 0x01,
498 TRACE_ITER_SYM_OFFSET = 0x02,
499 TRACE_ITER_SYM_ADDR = 0x04,
500 TRACE_ITER_VERBOSE = 0x08,
501 TRACE_ITER_RAW = 0x10,
502 TRACE_ITER_HEX = 0x20,
503 TRACE_ITER_BIN = 0x40,
504 TRACE_ITER_BLOCK = 0x80,
505 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200506 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200507 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500508 TRACE_ITER_PREEMPTONLY = 0x800,
Steven Rostedt9f029e82008-11-12 15:24:24 -0500509 TRACE_ITER_BRANCH = 0x1000,
Steven Rostedt12ef7d42008-11-12 17:52:38 -0500510 TRACE_ITER_ANNOTATE = 0x2000,
Török Edwinb54d3de2008-11-22 13:28:48 +0200511 TRACE_ITER_USERSTACKTRACE = 0x4000,
512 TRACE_ITER_SYM_USEROBJ = 0x8000
Ingo Molnar4e655512008-05-12 21:20:52 +0200513};
514
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100515/*
516 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
517 * control the output of kernel symbols.
518 */
519#define TRACE_ITER_SYM_MASK \
520 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
521
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200522extern struct tracer nop_trace;
523
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500524/**
525 * ftrace_preempt_disable - disable preemption scheduler safe
526 *
527 * When tracing can happen inside the scheduler, there exists
528 * cases that the tracing might happen before the need_resched
529 * flag is checked. If this happens and the tracer calls
530 * preempt_enable (after a disable), a schedule might take place
531 * causing an infinite recursion.
532 *
533 * To prevent this, we read the need_recshed flag before
534 * disabling preemption. When we want to enable preemption we
535 * check the flag, if it is set, then we call preempt_enable_no_resched.
536 * Otherwise, we call preempt_enable.
537 *
538 * The rational for doing the above is that if need resched is set
539 * and we have yet to reschedule, we are either in an atomic location
540 * (where we do not need to check for scheduling) or we are inside
541 * the scheduler and do not want to resched.
542 */
543static inline int ftrace_preempt_disable(void)
544{
545 int resched;
546
547 resched = need_resched();
548 preempt_disable_notrace();
549
550 return resched;
551}
552
553/**
554 * ftrace_preempt_enable - enable preemption scheduler safe
555 * @resched: the return value from ftrace_preempt_disable
556 *
557 * This is a scheduler safe way to enable preemption and not miss
558 * any preemption checks. The disabled saved the state of preemption.
559 * If resched is set, then we were either inside an atomic or
560 * are inside the scheduler (we would have already scheduled
561 * otherwise). In this case, we do not want to call normal
562 * preempt_enable, but preempt_enable_no_resched instead.
563 */
564static inline void ftrace_preempt_enable(int resched)
565{
566 if (resched)
567 preempt_enable_no_resched_notrace();
568 else
569 preempt_enable_notrace();
570}
571
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500572#ifdef CONFIG_BRANCH_TRACER
Steven Rostedt9f029e82008-11-12 15:24:24 -0500573extern int enable_branch_tracing(struct trace_array *tr);
574extern void disable_branch_tracing(void);
575static inline int trace_branch_enable(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500576{
Steven Rostedt9f029e82008-11-12 15:24:24 -0500577 if (trace_flags & TRACE_ITER_BRANCH)
578 return enable_branch_tracing(tr);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500579 return 0;
580}
Steven Rostedt9f029e82008-11-12 15:24:24 -0500581static inline void trace_branch_disable(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500582{
583 /* due to races, always disable */
Steven Rostedt9f029e82008-11-12 15:24:24 -0500584 disable_branch_tracing();
Steven Rostedt52f232c2008-11-12 00:14:40 -0500585}
586#else
Steven Rostedt9f029e82008-11-12 15:24:24 -0500587static inline int trace_branch_enable(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500588{
589 return 0;
590}
Steven Rostedt9f029e82008-11-12 15:24:24 -0500591static inline void trace_branch_disable(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500592{
593}
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500594#endif /* CONFIG_BRANCH_TRACER */
Steven Rostedt52f232c2008-11-12 00:14:40 -0500595
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200596#endif /* _LINUX_KERNEL_TRACE_H */