blob: 6ddd6a6556cf41050f2bb84957528711a1ee3115 [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>
Pekka Paalanenbd8ac682008-05-12 21:20:57 +02008#include <linux/mmiotrace.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02009
Thomas Gleixner72829bc2008-05-23 21:37:28 +020010enum trace_type {
11 __TRACE_FIRST_TYPE = 0,
12
13 TRACE_FN,
14 TRACE_CTX,
15 TRACE_WAKE,
16 TRACE_STACK,
17 TRACE_SPECIAL,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020018 TRACE_MMIO_RW,
19 TRACE_MMIO_MAP,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020020
21 __TRACE_LAST_TYPE
22};
23
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020024/*
25 * Function trace entry - function address and parent function addres:
26 */
27struct ftrace_entry {
28 unsigned long ip;
29 unsigned long parent_ip;
30};
31
32/*
33 * Context switch trace entry - which task (and prio) we switched from/to:
34 */
35struct ctx_switch_entry {
36 unsigned int prev_pid;
37 unsigned char prev_prio;
38 unsigned char prev_state;
39 unsigned int next_pid;
40 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020041 unsigned char next_state;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020042};
43
44/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020045 * Special (free-form) trace entry:
46 */
47struct special_entry {
48 unsigned long arg1;
49 unsigned long arg2;
50 unsigned long arg3;
51};
52
53/*
Ingo Molnar86387f72008-05-12 21:20:51 +020054 * Stack-trace entry:
55 */
56
Ingo Molnar74f4e362008-05-12 21:21:15 +020057#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020058
59struct stack_entry {
60 unsigned long caller[FTRACE_STACK_ENTRIES];
61};
62
63/*
Steven Rostedt2e2ca152008-08-01 12:26:40 -040064 * The trace field - the most basic unit of tracing. This is what
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020065 * is printed in the end as a single line in the trace output, such as:
66 *
67 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
68 */
Steven Rostedt2e2ca152008-08-01 12:26:40 -040069struct trace_field {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020070 char cpu;
71 char flags;
72 char preempt_count;
73 int pid;
74 cycle_t t;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020075 union {
76 struct ftrace_entry fn;
77 struct ctx_switch_entry ctx;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020078 struct special_entry special;
Ingo Molnar86387f72008-05-12 21:20:51 +020079 struct stack_entry stack;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020080 struct mmiotrace_rw mmiorw;
81 struct mmiotrace_map mmiomap;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020082 };
83};
84
Steven Rostedt2e2ca152008-08-01 12:26:40 -040085struct trace_field_cont {
86 char buf[sizeof(struct trace_field)];
87};
88
89struct trace_entry {
90 char type;
91 union {
92 struct trace_field field;
93 struct trace_field_cont cont;
94 };
95};
96
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020097#define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
98
99/*
100 * The CPU trace array - it consists of thousands of trace entries
101 * plus some other descriptor data: (for example which task started
102 * the trace, etc.)
103 */
104struct trace_array_cpu {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200105 struct list_head trace_pages;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200106 atomic_t disabled;
Steven Rostedt92205c22008-05-12 21:20:55 +0200107 raw_spinlock_t lock;
Ingo Molnard4c5a2f2008-05-12 21:20:46 +0200108 struct lock_class_key lock_key;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200109
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200110 /* these fields get copied into max-trace: */
Steven Rostedt93a588f2008-05-12 21:20:45 +0200111 unsigned trace_head_idx;
112 unsigned trace_tail_idx;
113 void *trace_head; /* producer */
114 void *trace_tail; /* consumer */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200115 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200116 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200117 unsigned long saved_latency;
118 unsigned long critical_start;
119 unsigned long critical_end;
120 unsigned long critical_sequence;
121 unsigned long nice;
122 unsigned long policy;
123 unsigned long rt_priority;
124 cycle_t preempt_timestamp;
125 pid_t pid;
126 uid_t uid;
127 char comm[TASK_COMM_LEN];
128};
129
130struct trace_iterator;
131
132/*
133 * The trace array - an array of per-CPU trace arrays. This is the
134 * highest level data structure that individual tracers deal with.
135 * They have on/off state as well:
136 */
137struct trace_array {
138 unsigned long entries;
139 long ctrl;
140 int cpu;
141 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200142 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200143 struct trace_array_cpu *data[NR_CPUS];
144};
145
146/*
147 * A specific tracer, represented by methods that operate on a trace array:
148 */
149struct tracer {
150 const char *name;
151 void (*init)(struct trace_array *tr);
152 void (*reset)(struct trace_array *tr);
153 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200154 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200155 void (*close)(struct trace_iterator *iter);
156 void (*start)(struct trace_iterator *iter);
157 void (*stop)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200158 ssize_t (*read)(struct trace_iterator *iter,
159 struct file *filp, char __user *ubuf,
160 size_t cnt, loff_t *ppos);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200161 void (*ctrl_update)(struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200162#ifdef CONFIG_FTRACE_STARTUP_TEST
163 int (*selftest)(struct tracer *trace,
164 struct trace_array *tr);
165#endif
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200166 int (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200167 struct tracer *next;
168 int print_max;
169};
170
Steven Rostedt214023c2008-05-12 21:20:46 +0200171struct trace_seq {
172 unsigned char buffer[PAGE_SIZE];
173 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200174 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200175};
176
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200177/*
178 * Trace iterator - used by printout routines who present trace
179 * results to users and which routines might sleep, etc:
180 */
181struct trace_iterator {
182 struct trace_array *tr;
183 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200184 void *private;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200185 long last_overrun[NR_CPUS];
186 long overrun[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200187
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200188 /* The below is zeroed out in pipe_read */
189 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200190 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200191 int cpu;
192
193 struct trace_entry *prev_ent;
194 int prev_cpu;
195
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200196 unsigned long iter_flags;
197 loff_t pos;
198 unsigned long next_idx[NR_CPUS];
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200199 struct list_head *next_page[NR_CPUS];
200 unsigned next_page_idx[NR_CPUS];
201 long idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200202};
203
Ingo Molnare309b412008-05-12 21:20:51 +0200204void tracing_reset(struct trace_array_cpu *data);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200205int tracing_open_generic(struct inode *inode, struct file *filp);
206struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200207void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
208
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200209void ftrace(struct trace_array *tr,
210 struct trace_array_cpu *data,
211 unsigned long ip,
212 unsigned long parent_ip,
213 unsigned long flags);
214void tracing_sched_switch_trace(struct trace_array *tr,
215 struct trace_array_cpu *data,
216 struct task_struct *prev,
217 struct task_struct *next,
218 unsigned long flags);
219void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200220
221void tracing_sched_wakeup_trace(struct trace_array *tr,
222 struct trace_array_cpu *data,
223 struct task_struct *wakee,
224 struct task_struct *cur,
225 unsigned long flags);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200226void trace_special(struct trace_array *tr,
227 struct trace_array_cpu *data,
228 unsigned long arg1,
229 unsigned long arg2,
230 unsigned long arg3);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200231void trace_function(struct trace_array *tr,
232 struct trace_array_cpu *data,
233 unsigned long ip,
234 unsigned long parent_ip,
235 unsigned long flags);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200236
Steven Rostedt41bc8142008-05-22 11:49:22 -0400237void tracing_start_cmdline_record(void);
238void tracing_stop_cmdline_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200239int register_tracer(struct tracer *type);
240void unregister_tracer(struct tracer *type);
241
242extern unsigned long nsecs_to_usecs(unsigned long nsecs);
243
244extern unsigned long tracing_max_latency;
245extern unsigned long tracing_thresh;
246
247void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
248void update_max_tr_single(struct trace_array *tr,
249 struct task_struct *tsk, int cpu);
250
Ingo Molnare309b412008-05-12 21:20:51 +0200251extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200252
Steven Rostedt001b6762008-07-10 20:58:10 -0400253#ifdef CONFIG_FTRACE
254void tracing_start_function_trace(void);
255void tracing_stop_function_trace(void);
256#else
257# define tracing_start_function_trace() do { } while (0)
258# define tracing_stop_function_trace() do { } while (0)
259#endif
260
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200261#ifdef CONFIG_CONTEXT_SWITCH_TRACER
262typedef void
263(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200264 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200265 struct task_struct *prev,
266 struct task_struct *next);
267
268struct tracer_switch_ops {
269 tracer_switch_func_t func;
270 void *private;
271 struct tracer_switch_ops *next;
272};
273
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200274#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
275
276#ifdef CONFIG_DYNAMIC_FTRACE
277extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200278#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
279extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200280#endif
281
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200282#ifdef CONFIG_MMIOTRACE
283extern void __trace_mmiotrace_rw(struct trace_array *tr,
284 struct trace_array_cpu *data,
285 struct mmiotrace_rw *rw);
286extern void __trace_mmiotrace_map(struct trace_array *tr,
287 struct trace_array_cpu *data,
288 struct mmiotrace_map *map);
289#endif
290
Steven Rostedt60a11772008-05-12 21:20:44 +0200291#ifdef CONFIG_FTRACE_STARTUP_TEST
292#ifdef CONFIG_FTRACE
293extern int trace_selftest_startup_function(struct tracer *trace,
294 struct trace_array *tr);
295#endif
296#ifdef CONFIG_IRQSOFF_TRACER
297extern int trace_selftest_startup_irqsoff(struct tracer *trace,
298 struct trace_array *tr);
299#endif
300#ifdef CONFIG_PREEMPT_TRACER
301extern int trace_selftest_startup_preemptoff(struct tracer *trace,
302 struct trace_array *tr);
303#endif
304#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
305extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
306 struct trace_array *tr);
307#endif
308#ifdef CONFIG_SCHED_TRACER
309extern int trace_selftest_startup_wakeup(struct tracer *trace,
310 struct trace_array *tr);
311#endif
312#ifdef CONFIG_CONTEXT_SWITCH_TRACER
313extern int trace_selftest_startup_sched_switch(struct tracer *trace,
314 struct trace_array *tr);
315#endif
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200316#ifdef CONFIG_SYSPROF_TRACER
317extern int trace_selftest_startup_sysprof(struct tracer *trace,
318 struct trace_array *tr);
319#endif
Steven Rostedt60a11772008-05-12 21:20:44 +0200320#endif /* CONFIG_FTRACE_STARTUP_TEST */
321
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200322extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200323extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200324extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
325 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200326extern long ns2usecs(cycle_t nsec);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200327
Ingo Molnar4e655512008-05-12 21:20:52 +0200328extern unsigned long trace_flags;
329
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200330/*
331 * trace_iterator_flags is an enumeration that defines bit
332 * positions into trace_flags that controls the output.
333 *
334 * NOTE: These bits must match the trace_options array in
335 * trace.c.
336 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200337enum trace_iterator_flags {
338 TRACE_ITER_PRINT_PARENT = 0x01,
339 TRACE_ITER_SYM_OFFSET = 0x02,
340 TRACE_ITER_SYM_ADDR = 0x04,
341 TRACE_ITER_VERBOSE = 0x08,
342 TRACE_ITER_RAW = 0x10,
343 TRACE_ITER_HEX = 0x20,
344 TRACE_ITER_BIN = 0x40,
345 TRACE_ITER_BLOCK = 0x80,
346 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200347 TRACE_ITER_SCHED_TREE = 0x200,
Ingo Molnar4e655512008-05-12 21:20:52 +0200348};
349
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200350#endif /* _LINUX_KERNEL_TRACE_H */