blob: 4c453778a6abc2f290a16702fb557ef33e7a3c3e [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,
Markus Metzger1e9b51c2008-11-25 09:24:15 +010030 TRACE_BTS,
Arjan van de Venf3f47a62008-11-23 16:49:58 -080031 TRACE_POWER,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020032
33 __TRACE_LAST_TYPE
34};
35
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020036/*
Steven Rostedt777e2082008-09-29 23:02:42 -040037 * The trace entry - the most basic unit of tracing. This is what
38 * is printed in the end as a single line in the trace output, such as:
39 *
40 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
41 */
42struct trace_entry {
43 unsigned char type;
44 unsigned char cpu;
45 unsigned char flags;
46 unsigned char preempt_count;
47 int pid;
Török Edwin02b67512008-11-22 13:28:47 +020048 int tgid;
Steven Rostedt777e2082008-09-29 23:02:42 -040049};
50
51/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020052 * Function trace entry - function address and parent function addres:
53 */
54struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040055 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020056 unsigned long ip;
57 unsigned long parent_ip;
58};
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010059
60/* Function return entry */
61struct ftrace_ret_entry {
62 struct trace_entry ent;
63 unsigned long ip;
64 unsigned long parent_ip;
65 unsigned long long calltime;
66 unsigned long long rettime;
Frederic Weisbecker02310222008-11-17 03:22:41 +010067 unsigned long overrun;
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010068};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010069extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020070
71/*
72 * Context switch trace entry - which task (and prio) we switched from/to:
73 */
74struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040075 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020076 unsigned int prev_pid;
77 unsigned char prev_prio;
78 unsigned char prev_state;
79 unsigned int next_pid;
80 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020081 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020082 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020083};
84
85/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020086 * Special (free-form) trace entry:
87 */
88struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040089 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020090 unsigned long arg1;
91 unsigned long arg2;
92 unsigned long arg3;
93};
94
95/*
Ingo Molnar86387f72008-05-12 21:20:51 +020096 * Stack-trace entry:
97 */
98
Ingo Molnar74f4e362008-05-12 21:21:15 +020099#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +0200100
101struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400102 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +0200103 unsigned long caller[FTRACE_STACK_ENTRIES];
104};
105
Török Edwin02b67512008-11-22 13:28:47 +0200106struct userstack_entry {
107 struct trace_entry ent;
108 unsigned long caller[FTRACE_STACK_ENTRIES];
109};
110
Ingo Molnar86387f72008-05-12 21:20:51 +0200111/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400112 * ftrace_printk entry:
113 */
114struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400115 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400116 unsigned long ip;
117 char buf[];
118};
119
Steven Rostedt777e2082008-09-29 23:02:42 -0400120#define TRACE_OLD_SIZE 88
121
122struct trace_field_cont {
123 unsigned char type;
124 /* Temporary till we get rid of this completely */
125 char buf[TRACE_OLD_SIZE - 1];
126};
127
128struct trace_mmiotrace_rw {
129 struct trace_entry ent;
130 struct mmiotrace_rw rw;
131};
132
133struct trace_mmiotrace_map {
134 struct trace_entry ent;
135 struct mmiotrace_map map;
136};
137
Frederic Weisbecker74239072008-11-11 23:24:42 +0100138struct trace_boot_call {
Steven Rostedt777e2082008-09-29 23:02:42 -0400139 struct trace_entry ent;
Frederic Weisbecker74239072008-11-11 23:24:42 +0100140 struct boot_trace_call boot_call;
141};
142
143struct trace_boot_ret {
144 struct trace_entry ent;
145 struct boot_trace_ret boot_ret;
Steven Rostedt777e2082008-09-29 23:02:42 -0400146};
147
Steven Rostedt52f232c2008-11-12 00:14:40 -0500148#define TRACE_FUNC_SIZE 30
149#define TRACE_FILE_SIZE 20
Steven Rostedt9f029e82008-11-12 15:24:24 -0500150struct trace_branch {
Steven Rostedt52f232c2008-11-12 00:14:40 -0500151 struct trace_entry ent;
152 unsigned line;
153 char func[TRACE_FUNC_SIZE+1];
154 char file[TRACE_FILE_SIZE+1];
155 char correct;
156};
157
Markus Metzger1e9b51c2008-11-25 09:24:15 +0100158struct bts_entry {
159 struct trace_entry ent;
160 unsigned long from;
161 unsigned long to;
162};
163
Arjan van de Venf3f47a62008-11-23 16:49:58 -0800164struct trace_power {
165 struct trace_entry ent;
166 struct power_trace state_data;
167};
168
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400169/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300170 * trace_flag_type is an enumeration that holds different
171 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400172 * IRQS_OFF - interrupts were disabled
173 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
174 * NEED_RESCED - reschedule is requested
175 * HARDIRQ - inside an interrupt handler
176 * SOFTIRQ - inside a softirq handler
177 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300178 */
179enum trace_flag_type {
180 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400181 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
182 TRACE_FLAG_NEED_RESCHED = 0x04,
183 TRACE_FLAG_HARDIRQ = 0x08,
184 TRACE_FLAG_SOFTIRQ = 0x10,
185 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300186};
187
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300188#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200189
190/*
191 * The CPU trace array - it consists of thousands of trace entries
192 * plus some other descriptor data: (for example which task started
193 * the trace, etc.)
194 */
195struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200196 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200197
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200198 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200199 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200200 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200201 unsigned long saved_latency;
202 unsigned long critical_start;
203 unsigned long critical_end;
204 unsigned long critical_sequence;
205 unsigned long nice;
206 unsigned long policy;
207 unsigned long rt_priority;
208 cycle_t preempt_timestamp;
209 pid_t pid;
210 uid_t uid;
211 char comm[TASK_COMM_LEN];
212};
213
214struct trace_iterator;
215
216/*
217 * The trace array - an array of per-CPU trace arrays. This is the
218 * highest level data structure that individual tracers deal with.
219 * They have on/off state as well:
220 */
221struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400222 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200223 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200224 int cpu;
225 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200226 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200227 struct trace_array_cpu *data[NR_CPUS];
228};
229
Steven Rostedt7104f302008-10-01 10:52:51 -0400230#define FTRACE_CMP_TYPE(var, type) \
231 __builtin_types_compatible_p(typeof(var), type *)
232
233#undef IF_ASSIGN
234#define IF_ASSIGN(var, entry, etype, id) \
235 if (FTRACE_CMP_TYPE(var, etype)) { \
236 var = (typeof(var))(entry); \
237 WARN_ON(id && (entry)->type != id); \
238 break; \
239 }
240
241/* Will cause compile errors if type is not found. */
242extern void __ftrace_bad_type(void);
243
244/*
245 * The trace_assign_type is a verifier that the entry type is
246 * the same as the type being assigned. To add new types simply
247 * add a line with the following format:
248 *
249 * IF_ASSIGN(var, ent, type, id);
250 *
251 * Where "type" is the trace type that includes the trace_entry
252 * as the "ent" item. And "id" is the trace identifier that is
253 * used in the trace_type enum.
254 *
255 * If the type can have more than one id, then use zero.
256 */
257#define trace_assign_type(var, ent) \
258 do { \
259 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
260 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
261 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
262 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
Török Edwin02b67512008-11-22 13:28:47 +0200263 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
Steven Rostedt7104f302008-10-01 10:52:51 -0400264 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
265 IF_ASSIGN(var, ent, struct special_entry, 0); \
266 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
267 TRACE_MMIO_RW); \
268 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
269 TRACE_MMIO_MAP); \
Frederic Weisbecker74239072008-11-11 23:24:42 +0100270 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
271 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
Steven Rostedt9f029e82008-11-12 15:24:24 -0500272 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
Frederic Weisbecker74239072008-11-11 23:24:42 +0100273 IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET);\
Markus Metzger1e9b51c2008-11-25 09:24:15 +0100274 IF_ASSIGN(var, ent, struct bts_entry, TRACE_BTS);\
Arjan van de Venf3f47a62008-11-23 16:49:58 -0800275 IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
Steven Rostedt7104f302008-10-01 10:52:51 -0400276 __ftrace_bad_type(); \
277 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200278
279/* Return values for print_line callback */
280enum print_line_t {
281 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
282 TRACE_TYPE_HANDLED = 1,
283 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
284};
285
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100286
287/*
288 * An option specific to a tracer. This is a boolean value.
289 * The bit is the bit index that sets its value on the
290 * flags value in struct tracer_flags.
291 */
292struct tracer_opt {
293 const char *name; /* Will appear on the trace_options file */
294 u32 bit; /* Mask assigned in val field in tracer_flags */
295};
296
297/*
298 * The set of specific options for a tracer. Your tracer
299 * have to set the initial value of the flags val.
300 */
301struct tracer_flags {
302 u32 val;
303 struct tracer_opt *opts;
304};
305
306/* Makes more easy to define a tracer opt */
307#define TRACER_OPT(s, b) .name = #s, .bit = b
308
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200309/*
310 * A specific tracer, represented by methods that operate on a trace array:
311 */
312struct tracer {
313 const char *name;
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100314 /* Your tracer should raise a warning if init fails */
315 int (*init)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200316 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500317 void (*start)(struct trace_array *tr);
318 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200319 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200320 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200321 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200322 ssize_t (*read)(struct trace_iterator *iter,
323 struct file *filp, char __user *ubuf,
324 size_t cnt, loff_t *ppos);
Steven Rostedt60a11772008-05-12 21:20:44 +0200325#ifdef CONFIG_FTRACE_STARTUP_TEST
326 int (*selftest)(struct tracer *trace,
327 struct trace_array *tr);
328#endif
Markus Metzger8bba1bf2008-11-25 09:12:31 +0100329 void (*print_header)(struct seq_file *m);
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200330 enum print_line_t (*print_line)(struct trace_iterator *iter);
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100331 /* If you handled the flag setting, return 0 */
332 int (*set_flag)(u32 old_flags, u32 bit, int set);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200333 struct tracer *next;
334 int print_max;
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100335 struct tracer_flags *flags;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200336};
337
Steven Rostedt214023c2008-05-12 21:20:46 +0200338struct trace_seq {
339 unsigned char buffer[PAGE_SIZE];
340 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200341 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200342};
343
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200344/*
345 * Trace iterator - used by printout routines who present trace
346 * results to users and which routines might sleep, etc:
347 */
348struct trace_iterator {
349 struct trace_array *tr;
350 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200351 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400352 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200353
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200354 /* The below is zeroed out in pipe_read */
355 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200356 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200357 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400358 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200359
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200360 unsigned long iter_flags;
361 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200362 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500363
364 cpumask_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200365};
366
Steven Rostedt90369902008-11-05 16:05:44 -0500367int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300368void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400369void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200370int tracing_open_generic(struct inode *inode, struct file *filp);
371struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200372void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
373
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300374struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
375 struct trace_array_cpu *data);
376void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400377 unsigned long flags,
378 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300379
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200380void ftrace(struct trace_array *tr,
381 struct trace_array_cpu *data,
382 unsigned long ip,
383 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400384 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200385void tracing_sched_switch_trace(struct trace_array *tr,
386 struct trace_array_cpu *data,
387 struct task_struct *prev,
388 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400389 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200390void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200391
392void tracing_sched_wakeup_trace(struct trace_array *tr,
393 struct trace_array_cpu *data,
394 struct task_struct *wakee,
395 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400396 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200397void trace_special(struct trace_array *tr,
398 struct trace_array_cpu *data,
399 unsigned long arg1,
400 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400401 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200402void trace_function(struct trace_array *tr,
403 struct trace_array_cpu *data,
404 unsigned long ip,
405 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400406 unsigned long flags, int pc);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100407void
408trace_function_return(struct ftrace_retfunc *trace);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200409
Markus Metzger1e9b51c2008-11-25 09:24:15 +0100410void trace_bts(struct trace_array *tr,
411 unsigned long from,
412 unsigned long to);
413
Steven Rostedt41bc8142008-05-22 11:49:22 -0400414void tracing_start_cmdline_record(void);
415void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500416void tracing_sched_switch_assign_trace(struct trace_array *tr);
417void tracing_stop_sched_switch_record(void);
418void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200419int register_tracer(struct tracer *type);
420void unregister_tracer(struct tracer *type);
421
422extern unsigned long nsecs_to_usecs(unsigned long nsecs);
423
424extern unsigned long tracing_max_latency;
425extern unsigned long tracing_thresh;
426
427void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
428void update_max_tr_single(struct trace_array *tr,
429 struct task_struct *tsk, int cpu);
430
Ingo Molnare309b412008-05-12 21:20:51 +0200431extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200432
Steven Rostedt606576c2008-10-06 19:06:12 -0400433#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400434void tracing_start_function_trace(void);
435void tracing_stop_function_trace(void);
436#else
437# define tracing_start_function_trace() do { } while (0)
438# define tracing_stop_function_trace() do { } while (0)
439#endif
440
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200441#ifdef CONFIG_CONTEXT_SWITCH_TRACER
442typedef void
443(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200444 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200445 struct task_struct *prev,
446 struct task_struct *next);
447
448struct tracer_switch_ops {
449 tracer_switch_func_t func;
450 void *private;
451 struct tracer_switch_ops *next;
452};
453
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200454#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
455
456#ifdef CONFIG_DYNAMIC_FTRACE
457extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200458#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
459extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200460#endif
461
Steven Rostedt60a11772008-05-12 21:20:44 +0200462#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200463extern int trace_selftest_startup_function(struct tracer *trace,
464 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200465extern int trace_selftest_startup_irqsoff(struct tracer *trace,
466 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200467extern int trace_selftest_startup_preemptoff(struct tracer *trace,
468 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200469extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
470 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200471extern int trace_selftest_startup_wakeup(struct tracer *trace,
472 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700473extern int trace_selftest_startup_nop(struct tracer *trace,
474 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200475extern int trace_selftest_startup_sched_switch(struct tracer *trace,
476 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200477extern int trace_selftest_startup_sysprof(struct tracer *trace,
478 struct trace_array *tr);
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500479extern int trace_selftest_startup_branch(struct tracer *trace,
480 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200481#endif /* CONFIG_FTRACE_STARTUP_TEST */
482
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200483extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200484extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300485extern void trace_seq_print_cont(struct trace_seq *s,
486 struct trace_iterator *iter);
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100487
488extern int
489seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
490 unsigned long sym_flags);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200491extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
492 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200493extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300494extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200495
Ingo Molnar4e655512008-05-12 21:20:52 +0200496extern unsigned long trace_flags;
497
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100498/* Standard output formatting function used for function return traces */
499#ifdef CONFIG_FUNCTION_RET_TRACER
500extern enum print_line_t print_return_function(struct trace_iterator *iter);
501#else
502static inline enum print_line_t
503print_return_function(struct trace_iterator *iter)
504{
505 return TRACE_TYPE_UNHANDLED;
506}
507#endif
508
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200509/*
510 * trace_iterator_flags is an enumeration that defines bit
511 * positions into trace_flags that controls the output.
512 *
513 * NOTE: These bits must match the trace_options array in
514 * trace.c.
515 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200516enum trace_iterator_flags {
517 TRACE_ITER_PRINT_PARENT = 0x01,
518 TRACE_ITER_SYM_OFFSET = 0x02,
519 TRACE_ITER_SYM_ADDR = 0x04,
520 TRACE_ITER_VERBOSE = 0x08,
521 TRACE_ITER_RAW = 0x10,
522 TRACE_ITER_HEX = 0x20,
523 TRACE_ITER_BIN = 0x40,
524 TRACE_ITER_BLOCK = 0x80,
525 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200526 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200527 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500528 TRACE_ITER_PREEMPTONLY = 0x800,
Steven Rostedt9f029e82008-11-12 15:24:24 -0500529 TRACE_ITER_BRANCH = 0x1000,
Steven Rostedt12ef7d42008-11-12 17:52:38 -0500530 TRACE_ITER_ANNOTATE = 0x2000,
Török Edwinb54d3de2008-11-22 13:28:48 +0200531 TRACE_ITER_USERSTACKTRACE = 0x4000,
532 TRACE_ITER_SYM_USEROBJ = 0x8000
Ingo Molnar4e655512008-05-12 21:20:52 +0200533};
534
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100535/*
536 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
537 * control the output of kernel symbols.
538 */
539#define TRACE_ITER_SYM_MASK \
540 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
541
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200542extern struct tracer nop_trace;
543
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500544/**
545 * ftrace_preempt_disable - disable preemption scheduler safe
546 *
547 * When tracing can happen inside the scheduler, there exists
548 * cases that the tracing might happen before the need_resched
549 * flag is checked. If this happens and the tracer calls
550 * preempt_enable (after a disable), a schedule might take place
551 * causing an infinite recursion.
552 *
553 * To prevent this, we read the need_recshed flag before
554 * disabling preemption. When we want to enable preemption we
555 * check the flag, if it is set, then we call preempt_enable_no_resched.
556 * Otherwise, we call preempt_enable.
557 *
558 * The rational for doing the above is that if need resched is set
559 * and we have yet to reschedule, we are either in an atomic location
560 * (where we do not need to check for scheduling) or we are inside
561 * the scheduler and do not want to resched.
562 */
563static inline int ftrace_preempt_disable(void)
564{
565 int resched;
566
567 resched = need_resched();
568 preempt_disable_notrace();
569
570 return resched;
571}
572
573/**
574 * ftrace_preempt_enable - enable preemption scheduler safe
575 * @resched: the return value from ftrace_preempt_disable
576 *
577 * This is a scheduler safe way to enable preemption and not miss
578 * any preemption checks. The disabled saved the state of preemption.
579 * If resched is set, then we were either inside an atomic or
580 * are inside the scheduler (we would have already scheduled
581 * otherwise). In this case, we do not want to call normal
582 * preempt_enable, but preempt_enable_no_resched instead.
583 */
584static inline void ftrace_preempt_enable(int resched)
585{
586 if (resched)
587 preempt_enable_no_resched_notrace();
588 else
589 preempt_enable_notrace();
590}
591
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500592#ifdef CONFIG_BRANCH_TRACER
Steven Rostedt9f029e82008-11-12 15:24:24 -0500593extern int enable_branch_tracing(struct trace_array *tr);
594extern void disable_branch_tracing(void);
595static inline int trace_branch_enable(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500596{
Steven Rostedt9f029e82008-11-12 15:24:24 -0500597 if (trace_flags & TRACE_ITER_BRANCH)
598 return enable_branch_tracing(tr);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500599 return 0;
600}
Steven Rostedt9f029e82008-11-12 15:24:24 -0500601static inline void trace_branch_disable(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500602{
603 /* due to races, always disable */
Steven Rostedt9f029e82008-11-12 15:24:24 -0500604 disable_branch_tracing();
Steven Rostedt52f232c2008-11-12 00:14:40 -0500605}
606#else
Steven Rostedt9f029e82008-11-12 15:24:24 -0500607static inline int trace_branch_enable(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500608{
609 return 0;
610}
Steven Rostedt9f029e82008-11-12 15:24:24 -0500611static inline void trace_branch_disable(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500612{
613}
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500614#endif /* CONFIG_BRANCH_TRACER */
Steven Rostedt52f232c2008-11-12 00:14:40 -0500615
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200616#endif /* _LINUX_KERNEL_TRACE_H */