blob: 96951a8d09a4b3cdf4e27a749d6ec59c4aacfdf4 [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>
8
9/*
10 * Function trace entry - function address and parent function addres:
11 */
12struct ftrace_entry {
13 unsigned long ip;
14 unsigned long parent_ip;
15};
16
17/*
18 * Context switch trace entry - which task (and prio) we switched from/to:
19 */
20struct ctx_switch_entry {
21 unsigned int prev_pid;
22 unsigned char prev_prio;
23 unsigned char prev_state;
24 unsigned int next_pid;
25 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020026 unsigned char next_state;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020027};
28
29/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020030 * Special (free-form) trace entry:
31 */
32struct special_entry {
33 unsigned long arg1;
34 unsigned long arg2;
35 unsigned long arg3;
36};
37
38/*
Ingo Molnar86387f72008-05-12 21:20:51 +020039 * Stack-trace entry:
40 */
41
42#define FTRACE_STACK_ENTRIES 5
43
44struct stack_entry {
45 unsigned long caller[FTRACE_STACK_ENTRIES];
46};
47
48/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020049 * The trace entry - the most basic unit of tracing. This is what
50 * is printed in the end as a single line in the trace output, such as:
51 *
52 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
53 */
54struct trace_entry {
55 char type;
56 char cpu;
57 char flags;
58 char preempt_count;
59 int pid;
60 cycle_t t;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020061 union {
62 struct ftrace_entry fn;
63 struct ctx_switch_entry ctx;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020064 struct special_entry special;
Ingo Molnar86387f72008-05-12 21:20:51 +020065 struct stack_entry stack;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020066 };
67};
68
69#define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
70
71/*
72 * The CPU trace array - it consists of thousands of trace entries
73 * plus some other descriptor data: (for example which task started
74 * the trace, etc.)
75 */
76struct trace_array_cpu {
Steven Rostedt4c11d7a2008-05-12 21:20:43 +020077 struct list_head trace_pages;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020078 atomic_t disabled;
Steven Rostedtb3806b42008-05-12 21:20:46 +020079 spinlock_t lock;
Ingo Molnard4c5a2f2008-05-12 21:20:46 +020080 struct lock_class_key lock_key;
Ingo Molnar4e3c3332008-05-12 21:20:45 +020081
Ingo Molnarc7aafc52008-05-12 21:20:45 +020082 /* these fields get copied into max-trace: */
Steven Rostedt93a588f2008-05-12 21:20:45 +020083 unsigned trace_head_idx;
84 unsigned trace_tail_idx;
85 void *trace_head; /* producer */
86 void *trace_tail; /* consumer */
Ingo Molnarc7aafc52008-05-12 21:20:45 +020087 unsigned long trace_idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020088 unsigned long saved_latency;
89 unsigned long critical_start;
90 unsigned long critical_end;
91 unsigned long critical_sequence;
92 unsigned long nice;
93 unsigned long policy;
94 unsigned long rt_priority;
95 cycle_t preempt_timestamp;
96 pid_t pid;
97 uid_t uid;
98 char comm[TASK_COMM_LEN];
99};
100
101struct trace_iterator;
102
103/*
104 * The trace array - an array of per-CPU trace arrays. This is the
105 * highest level data structure that individual tracers deal with.
106 * They have on/off state as well:
107 */
108struct trace_array {
109 unsigned long entries;
110 long ctrl;
111 int cpu;
112 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200113 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200114 struct trace_array_cpu *data[NR_CPUS];
115};
116
117/*
118 * A specific tracer, represented by methods that operate on a trace array:
119 */
120struct tracer {
121 const char *name;
122 void (*init)(struct trace_array *tr);
123 void (*reset)(struct trace_array *tr);
124 void (*open)(struct trace_iterator *iter);
125 void (*close)(struct trace_iterator *iter);
126 void (*start)(struct trace_iterator *iter);
127 void (*stop)(struct trace_iterator *iter);
128 void (*ctrl_update)(struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200129#ifdef CONFIG_FTRACE_STARTUP_TEST
130 int (*selftest)(struct tracer *trace,
131 struct trace_array *tr);
132#endif
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200133 struct tracer *next;
134 int print_max;
135};
136
Steven Rostedt214023c2008-05-12 21:20:46 +0200137struct trace_seq {
138 unsigned char buffer[PAGE_SIZE];
139 unsigned int len;
140};
141
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200142/*
143 * Trace iterator - used by printout routines who present trace
144 * results to users and which routines might sleep, etc:
145 */
146struct trace_iterator {
Steven Rostedt214023c2008-05-12 21:20:46 +0200147 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200148 struct trace_array *tr;
149 struct tracer *trace;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200150
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200151 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200152 int cpu;
153
154 struct trace_entry *prev_ent;
155 int prev_cpu;
156
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200157 unsigned long iter_flags;
158 loff_t pos;
159 unsigned long next_idx[NR_CPUS];
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200160 struct list_head *next_page[NR_CPUS];
161 unsigned next_page_idx[NR_CPUS];
162 long idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200163};
164
Ingo Molnare309b412008-05-12 21:20:51 +0200165void tracing_reset(struct trace_array_cpu *data);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200166int tracing_open_generic(struct inode *inode, struct file *filp);
167struct dentry *tracing_init_dentry(void);
168void ftrace(struct trace_array *tr,
169 struct trace_array_cpu *data,
170 unsigned long ip,
171 unsigned long parent_ip,
172 unsigned long flags);
173void tracing_sched_switch_trace(struct trace_array *tr,
174 struct trace_array_cpu *data,
175 struct task_struct *prev,
176 struct task_struct *next,
177 unsigned long flags);
178void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200179
180void tracing_sched_wakeup_trace(struct trace_array *tr,
181 struct trace_array_cpu *data,
182 struct task_struct *wakee,
183 struct task_struct *cur,
184 unsigned long flags);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200185void trace_special(struct trace_array *tr,
186 struct trace_array_cpu *data,
187 unsigned long arg1,
188 unsigned long arg2,
189 unsigned long arg3);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200190void trace_function(struct trace_array *tr,
191 struct trace_array_cpu *data,
192 unsigned long ip,
193 unsigned long parent_ip,
194 unsigned long flags);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200195
196void tracing_start_function_trace(void);
197void tracing_stop_function_trace(void);
198int register_tracer(struct tracer *type);
199void unregister_tracer(struct tracer *type);
200
201extern unsigned long nsecs_to_usecs(unsigned long nsecs);
202
203extern unsigned long tracing_max_latency;
204extern unsigned long tracing_thresh;
205
206void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
207void update_max_tr_single(struct trace_array *tr,
208 struct task_struct *tsk, int cpu);
209
Ingo Molnare309b412008-05-12 21:20:51 +0200210extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200211
212#ifdef CONFIG_SCHED_TRACER
Ingo Molnare309b412008-05-12 21:20:51 +0200213extern void
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200214wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
Ingo Molnar57422792008-05-12 21:20:51 +0200215extern void
216wakeup_sched_wakeup(struct task_struct *wakee, struct task_struct *curr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200217#else
218static inline void
219wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
220{
221}
Ingo Molnar57422792008-05-12 21:20:51 +0200222static inline void
223wakeup_sched_wakeup(struct task_struct *wakee, struct task_struct *curr)
224{
225}
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200226#endif
227
228#ifdef CONFIG_CONTEXT_SWITCH_TRACER
229typedef void
230(*tracer_switch_func_t)(void *private,
231 struct task_struct *prev,
232 struct task_struct *next);
233
234struct tracer_switch_ops {
235 tracer_switch_func_t func;
236 void *private;
237 struct tracer_switch_ops *next;
238};
239
240extern int register_tracer_switch(struct tracer_switch_ops *ops);
241extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
242
243#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
244
245#ifdef CONFIG_DYNAMIC_FTRACE
246extern unsigned long ftrace_update_tot_cnt;
247#endif
248
Steven Rostedt60a11772008-05-12 21:20:44 +0200249#ifdef CONFIG_FTRACE_STARTUP_TEST
250#ifdef CONFIG_FTRACE
251extern int trace_selftest_startup_function(struct tracer *trace,
252 struct trace_array *tr);
253#endif
254#ifdef CONFIG_IRQSOFF_TRACER
255extern int trace_selftest_startup_irqsoff(struct tracer *trace,
256 struct trace_array *tr);
257#endif
258#ifdef CONFIG_PREEMPT_TRACER
259extern int trace_selftest_startup_preemptoff(struct tracer *trace,
260 struct trace_array *tr);
261#endif
262#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
263extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
264 struct trace_array *tr);
265#endif
266#ifdef CONFIG_SCHED_TRACER
267extern int trace_selftest_startup_wakeup(struct tracer *trace,
268 struct trace_array *tr);
269#endif
270#ifdef CONFIG_CONTEXT_SWITCH_TRACER
271extern int trace_selftest_startup_sched_switch(struct tracer *trace,
272 struct trace_array *tr);
273#endif
274#endif /* CONFIG_FTRACE_STARTUP_TEST */
275
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200276extern void *head_page(struct trace_array_cpu *data);
277
Ingo Molnar4e655512008-05-12 21:20:52 +0200278extern unsigned long trace_flags;
279
280enum trace_iterator_flags {
281 TRACE_ITER_PRINT_PARENT = 0x01,
282 TRACE_ITER_SYM_OFFSET = 0x02,
283 TRACE_ITER_SYM_ADDR = 0x04,
284 TRACE_ITER_VERBOSE = 0x08,
285 TRACE_ITER_RAW = 0x10,
286 TRACE_ITER_HEX = 0x20,
287 TRACE_ITER_BIN = 0x40,
288 TRACE_ITER_BLOCK = 0x80,
289 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200290 TRACE_ITER_SCHED_TREE = 0x200,
Ingo Molnar4e655512008-05-12 21:20:52 +0200291};
292
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200293#endif /* _LINUX_KERNEL_TRACE_H */