blob: a921ba5d292df3b129ed6c28b8c57f1b9dcac51f [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,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020025
26 __TRACE_LAST_TYPE
27};
28
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020029/*
Steven Rostedt777e2082008-09-29 23:02:42 -040030 * The trace entry - the most basic unit of tracing. This is what
31 * is printed in the end as a single line in the trace output, such as:
32 *
33 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
34 */
35struct trace_entry {
36 unsigned char type;
37 unsigned char cpu;
38 unsigned char flags;
39 unsigned char preempt_count;
40 int pid;
41};
42
43/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020044 * Function trace entry - function address and parent function addres:
45 */
46struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040047 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020048 unsigned long ip;
49 unsigned long parent_ip;
50};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010051extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020052
53/*
54 * Context switch trace entry - which task (and prio) we switched from/to:
55 */
56struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040057 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020058 unsigned int prev_pid;
59 unsigned char prev_prio;
60 unsigned char prev_state;
61 unsigned int next_pid;
62 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020063 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020064 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020065};
66
67/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020068 * Special (free-form) trace entry:
69 */
70struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040071 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020072 unsigned long arg1;
73 unsigned long arg2;
74 unsigned long arg3;
75};
76
77/*
Ingo Molnar86387f72008-05-12 21:20:51 +020078 * Stack-trace entry:
79 */
80
Ingo Molnar74f4e362008-05-12 21:21:15 +020081#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020082
83struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040084 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +020085 unsigned long caller[FTRACE_STACK_ENTRIES];
86};
87
88/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -040089 * ftrace_printk entry:
90 */
91struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040092 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -040093 unsigned long ip;
94 char buf[];
95};
96
Steven Rostedt777e2082008-09-29 23:02:42 -040097#define TRACE_OLD_SIZE 88
98
99struct trace_field_cont {
100 unsigned char type;
101 /* Temporary till we get rid of this completely */
102 char buf[TRACE_OLD_SIZE - 1];
103};
104
105struct trace_mmiotrace_rw {
106 struct trace_entry ent;
107 struct mmiotrace_rw rw;
108};
109
110struct trace_mmiotrace_map {
111 struct trace_entry ent;
112 struct mmiotrace_map map;
113};
114
115struct trace_boot {
116 struct trace_entry ent;
117 struct boot_trace initcall;
118};
119
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400120/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300121 * trace_flag_type is an enumeration that holds different
122 * states when a trace occurs. These are:
123 * IRQS_OFF - interrupts were disabled
124 * NEED_RESCED - reschedule is requested
125 * HARDIRQ - inside an interrupt handler
126 * SOFTIRQ - inside a softirq handler
127 * CONT - multiple entries hold the trace item
128 */
129enum trace_flag_type {
130 TRACE_FLAG_IRQS_OFF = 0x01,
131 TRACE_FLAG_NEED_RESCHED = 0x02,
132 TRACE_FLAG_HARDIRQ = 0x04,
133 TRACE_FLAG_SOFTIRQ = 0x08,
134 TRACE_FLAG_CONT = 0x10,
135};
136
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300137#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200138
139/*
140 * The CPU trace array - it consists of thousands of trace entries
141 * plus some other descriptor data: (for example which task started
142 * the trace, etc.)
143 */
144struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200145 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200146
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200147 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200148 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200149 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200150 unsigned long saved_latency;
151 unsigned long critical_start;
152 unsigned long critical_end;
153 unsigned long critical_sequence;
154 unsigned long nice;
155 unsigned long policy;
156 unsigned long rt_priority;
157 cycle_t preempt_timestamp;
158 pid_t pid;
159 uid_t uid;
160 char comm[TASK_COMM_LEN];
161};
162
163struct trace_iterator;
164
165/*
166 * The trace array - an array of per-CPU trace arrays. This is the
167 * highest level data structure that individual tracers deal with.
168 * They have on/off state as well:
169 */
170struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400171 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200172 unsigned long entries;
173 long ctrl;
174 int cpu;
175 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200176 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200177 struct trace_array_cpu *data[NR_CPUS];
178};
179
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200180
181/* Return values for print_line callback */
182enum print_line_t {
183 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
184 TRACE_TYPE_HANDLED = 1,
185 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
186};
187
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200188/*
189 * A specific tracer, represented by methods that operate on a trace array:
190 */
191struct tracer {
192 const char *name;
193 void (*init)(struct trace_array *tr);
194 void (*reset)(struct trace_array *tr);
195 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200196 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200197 void (*close)(struct trace_iterator *iter);
198 void (*start)(struct trace_iterator *iter);
199 void (*stop)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200200 ssize_t (*read)(struct trace_iterator *iter,
201 struct file *filp, char __user *ubuf,
202 size_t cnt, loff_t *ppos);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200203 void (*ctrl_update)(struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200204#ifdef CONFIG_FTRACE_STARTUP_TEST
205 int (*selftest)(struct tracer *trace,
206 struct trace_array *tr);
207#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200208 enum print_line_t (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200209 struct tracer *next;
210 int print_max;
211};
212
Steven Rostedt214023c2008-05-12 21:20:46 +0200213struct trace_seq {
214 unsigned char buffer[PAGE_SIZE];
215 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200216 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200217};
218
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200219/*
220 * Trace iterator - used by printout routines who present trace
221 * results to users and which routines might sleep, etc:
222 */
223struct trace_iterator {
224 struct trace_array *tr;
225 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200226 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400227 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200228
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200229 /* The below is zeroed out in pipe_read */
230 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200231 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200232 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400233 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200234
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200235 unsigned long iter_flags;
236 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200237 long idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200238};
239
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300240void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400241void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200242int tracing_open_generic(struct inode *inode, struct file *filp);
243struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200244void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
245
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300246struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
247 struct trace_array_cpu *data);
248void tracing_generic_entry_update(struct trace_entry *entry,
249 unsigned long flags);
250
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200251void ftrace(struct trace_array *tr,
252 struct trace_array_cpu *data,
253 unsigned long ip,
254 unsigned long parent_ip,
255 unsigned long flags);
256void tracing_sched_switch_trace(struct trace_array *tr,
257 struct trace_array_cpu *data,
258 struct task_struct *prev,
259 struct task_struct *next,
260 unsigned long flags);
261void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200262
263void tracing_sched_wakeup_trace(struct trace_array *tr,
264 struct trace_array_cpu *data,
265 struct task_struct *wakee,
266 struct task_struct *cur,
267 unsigned long flags);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200268void trace_special(struct trace_array *tr,
269 struct trace_array_cpu *data,
270 unsigned long arg1,
271 unsigned long arg2,
272 unsigned long arg3);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200273void trace_function(struct trace_array *tr,
274 struct trace_array_cpu *data,
275 unsigned long ip,
276 unsigned long parent_ip,
277 unsigned long flags);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200278
Steven Rostedt41bc8142008-05-22 11:49:22 -0400279void tracing_start_cmdline_record(void);
280void tracing_stop_cmdline_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200281int register_tracer(struct tracer *type);
282void unregister_tracer(struct tracer *type);
283
284extern unsigned long nsecs_to_usecs(unsigned long nsecs);
285
286extern unsigned long tracing_max_latency;
287extern unsigned long tracing_thresh;
288
289void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
290void update_max_tr_single(struct trace_array *tr,
291 struct task_struct *tsk, int cpu);
292
Ingo Molnare309b412008-05-12 21:20:51 +0200293extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200294
Steven Rostedt001b6762008-07-10 20:58:10 -0400295#ifdef CONFIG_FTRACE
296void tracing_start_function_trace(void);
297void tracing_stop_function_trace(void);
298#else
299# define tracing_start_function_trace() do { } while (0)
300# define tracing_stop_function_trace() do { } while (0)
301#endif
302
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200303#ifdef CONFIG_CONTEXT_SWITCH_TRACER
304typedef void
305(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200306 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200307 struct task_struct *prev,
308 struct task_struct *next);
309
310struct tracer_switch_ops {
311 tracer_switch_func_t func;
312 void *private;
313 struct tracer_switch_ops *next;
314};
315
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200316#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
317
318#ifdef CONFIG_DYNAMIC_FTRACE
319extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200320#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
321extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200322#endif
323
Steven Rostedt60a11772008-05-12 21:20:44 +0200324#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200325extern int trace_selftest_startup_function(struct tracer *trace,
326 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200327extern int trace_selftest_startup_irqsoff(struct tracer *trace,
328 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200329extern int trace_selftest_startup_preemptoff(struct tracer *trace,
330 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200331extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
332 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200333extern int trace_selftest_startup_wakeup(struct tracer *trace,
334 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700335extern int trace_selftest_startup_nop(struct tracer *trace,
336 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200337extern int trace_selftest_startup_sched_switch(struct tracer *trace,
338 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200339extern int trace_selftest_startup_sysprof(struct tracer *trace,
340 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200341#endif /* CONFIG_FTRACE_STARTUP_TEST */
342
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200343extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200344extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300345extern void trace_seq_print_cont(struct trace_seq *s,
346 struct trace_iterator *iter);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200347extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
348 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200349extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300350extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200351
Ingo Molnar4e655512008-05-12 21:20:52 +0200352extern unsigned long trace_flags;
353
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200354/*
355 * trace_iterator_flags is an enumeration that defines bit
356 * positions into trace_flags that controls the output.
357 *
358 * NOTE: These bits must match the trace_options array in
359 * trace.c.
360 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200361enum trace_iterator_flags {
362 TRACE_ITER_PRINT_PARENT = 0x01,
363 TRACE_ITER_SYM_OFFSET = 0x02,
364 TRACE_ITER_SYM_ADDR = 0x04,
365 TRACE_ITER_VERBOSE = 0x08,
366 TRACE_ITER_RAW = 0x10,
367 TRACE_ITER_HEX = 0x20,
368 TRACE_ITER_BIN = 0x40,
369 TRACE_ITER_BLOCK = 0x80,
370 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200371 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200372 TRACE_ITER_PRINTK = 0x400,
Ingo Molnar4e655512008-05-12 21:20:52 +0200373};
374
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200375extern struct tracer nop_trace;
376
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200377#endif /* _LINUX_KERNEL_TRACE_H */