ftrace: take advantage of variable length entries
[deliverable/linux.git] / kernel / trace / trace.h
CommitLineData
bc0c38d1
SR
1#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>
3928a8a2 8#include <linux/ring_buffer.h>
bd8ac686 9#include <linux/mmiotrace.h>
d13744cd 10#include <linux/ftrace.h>
bc0c38d1 11
72829bc3
TG
12enum trace_type {
13 __TRACE_FIRST_TYPE = 0,
14
15 TRACE_FN,
16 TRACE_CTX,
17 TRACE_WAKE,
dd0e545f 18 TRACE_CONT,
72829bc3 19 TRACE_STACK,
dd0e545f 20 TRACE_PRINT,
72829bc3 21 TRACE_SPECIAL,
bd8ac686
PP
22 TRACE_MMIO_RW,
23 TRACE_MMIO_MAP,
d13744cd 24 TRACE_BOOT,
72829bc3
TG
25
26 __TRACE_LAST_TYPE
27};
28
777e208d
SR
29/*
30 * 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
bc0c38d1
SR
43/*
44 * Function trace entry - function address and parent function addres:
45 */
46struct ftrace_entry {
777e208d 47 struct trace_entry ent;
bc0c38d1
SR
48 unsigned long ip;
49 unsigned long parent_ip;
50};
d13744cd 51extern struct tracer boot_tracer;
bc0c38d1
SR
52
53/*
54 * Context switch trace entry - which task (and prio) we switched from/to:
55 */
56struct ctx_switch_entry {
777e208d 57 struct trace_entry ent;
bc0c38d1
SR
58 unsigned int prev_pid;
59 unsigned char prev_prio;
60 unsigned char prev_state;
61 unsigned int next_pid;
62 unsigned char next_prio;
bac524d3 63 unsigned char next_state;
80b5e940 64 unsigned int next_cpu;
bc0c38d1
SR
65};
66
f0a920d5
IM
67/*
68 * Special (free-form) trace entry:
69 */
70struct special_entry {
777e208d 71 struct trace_entry ent;
f0a920d5
IM
72 unsigned long arg1;
73 unsigned long arg2;
74 unsigned long arg3;
75};
76
86387f7e
IM
77/*
78 * Stack-trace entry:
79 */
80
74f4e369 81#define FTRACE_STACK_ENTRIES 8
86387f7e
IM
82
83struct stack_entry {
777e208d 84 struct trace_entry ent;
86387f7e
IM
85 unsigned long caller[FTRACE_STACK_ENTRIES];
86};
87
dd0e545f
SR
88/*
89 * ftrace_printk entry:
90 */
91struct print_entry {
777e208d 92 struct trace_entry ent;
dd0e545f
SR
93 unsigned long ip;
94 char buf[];
95};
96
777e208d
SR
97#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
fc5e27ae
PP
120/*
121 * 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
5bf9a1ee 137#define TRACE_BUF_SIZE 1024
bc0c38d1
SR
138
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 {
bc0c38d1 145 atomic_t disabled;
4e3c3333 146
c7aafc54 147 /* these fields get copied into max-trace: */
c7aafc54 148 unsigned long trace_idx;
53d0aa77 149 unsigned long overrun;
bc0c38d1
SR
150 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 {
3928a8a2 171 struct ring_buffer *buffer;
bc0c38d1
SR
172 unsigned long entries;
173 long ctrl;
174 int cpu;
175 cycle_t time_start;
b3806b43 176 struct task_struct *waiter;
bc0c38d1
SR
177 struct trace_array_cpu *data[NR_CPUS];
178};
179
180/*
181 * A specific tracer, represented by methods that operate on a trace array:
182 */
183struct tracer {
184 const char *name;
185 void (*init)(struct trace_array *tr);
186 void (*reset)(struct trace_array *tr);
187 void (*open)(struct trace_iterator *iter);
107bad8b 188 void (*pipe_open)(struct trace_iterator *iter);
bc0c38d1
SR
189 void (*close)(struct trace_iterator *iter);
190 void (*start)(struct trace_iterator *iter);
191 void (*stop)(struct trace_iterator *iter);
107bad8b
SR
192 ssize_t (*read)(struct trace_iterator *iter,
193 struct file *filp, char __user *ubuf,
194 size_t cnt, loff_t *ppos);
bc0c38d1 195 void (*ctrl_update)(struct trace_array *tr);
60a11774
SR
196#ifdef CONFIG_FTRACE_STARTUP_TEST
197 int (*selftest)(struct tracer *trace,
198 struct trace_array *tr);
199#endif
72829bc3 200 int (*print_line)(struct trace_iterator *iter);
bc0c38d1
SR
201 struct tracer *next;
202 int print_max;
203};
204
214023c3
SR
205struct trace_seq {
206 unsigned char buffer[PAGE_SIZE];
207 unsigned int len;
6c6c2796 208 unsigned int readpos;
214023c3
SR
209};
210
bc0c38d1
SR
211/*
212 * Trace iterator - used by printout routines who present trace
213 * results to users and which routines might sleep, etc:
214 */
215struct trace_iterator {
216 struct trace_array *tr;
217 struct tracer *trace;
107bad8b 218 void *private;
3928a8a2 219 struct ring_buffer_iter *buffer_iter[NR_CPUS];
4e3c3333 220
53d0aa77
SR
221 /* The below is zeroed out in pipe_read */
222 struct trace_seq seq;
bc0c38d1 223 struct trace_entry *ent;
4e3c3333 224 int cpu;
3928a8a2 225 u64 ts;
4e3c3333 226
bc0c38d1
SR
227 unsigned long iter_flags;
228 loff_t pos;
4c11d7ae 229 long idx;
bc0c38d1
SR
230};
231
45dcd8b8 232void trace_wake_up(void);
3928a8a2 233void tracing_reset(struct trace_array *tr, int cpu);
bc0c38d1
SR
234int tracing_open_generic(struct inode *inode, struct file *filp);
235struct dentry *tracing_init_dentry(void);
d618b3e6
IM
236void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
237
45dcd8b8
PP
238struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
239 struct trace_array_cpu *data);
240void tracing_generic_entry_update(struct trace_entry *entry,
241 unsigned long flags);
242
bc0c38d1
SR
243void ftrace(struct trace_array *tr,
244 struct trace_array_cpu *data,
245 unsigned long ip,
246 unsigned long parent_ip,
247 unsigned long flags);
248void tracing_sched_switch_trace(struct trace_array *tr,
249 struct trace_array_cpu *data,
250 struct task_struct *prev,
251 struct task_struct *next,
252 unsigned long flags);
253void tracing_record_cmdline(struct task_struct *tsk);
57422797
IM
254
255void tracing_sched_wakeup_trace(struct trace_array *tr,
256 struct trace_array_cpu *data,
257 struct task_struct *wakee,
258 struct task_struct *cur,
259 unsigned long flags);
f0a920d5
IM
260void trace_special(struct trace_array *tr,
261 struct trace_array_cpu *data,
262 unsigned long arg1,
263 unsigned long arg2,
264 unsigned long arg3);
6fb44b71
SR
265void trace_function(struct trace_array *tr,
266 struct trace_array_cpu *data,
267 unsigned long ip,
268 unsigned long parent_ip,
269 unsigned long flags);
bc0c38d1 270
41bc8144
SR
271void tracing_start_cmdline_record(void);
272void tracing_stop_cmdline_record(void);
bc0c38d1
SR
273int register_tracer(struct tracer *type);
274void unregister_tracer(struct tracer *type);
275
276extern unsigned long nsecs_to_usecs(unsigned long nsecs);
277
278extern unsigned long tracing_max_latency;
279extern unsigned long tracing_thresh;
280
281void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
282void update_max_tr_single(struct trace_array *tr,
283 struct task_struct *tsk, int cpu);
284
e309b41d 285extern cycle_t ftrace_now(int cpu);
bc0c38d1 286
001b6767
SR
287#ifdef CONFIG_FTRACE
288void tracing_start_function_trace(void);
289void tracing_stop_function_trace(void);
290#else
291# define tracing_start_function_trace() do { } while (0)
292# define tracing_stop_function_trace() do { } while (0)
293#endif
294
bc0c38d1
SR
295#ifdef CONFIG_CONTEXT_SWITCH_TRACER
296typedef void
297(*tracer_switch_func_t)(void *private,
5b82a1b0 298 void *__rq,
bc0c38d1
SR
299 struct task_struct *prev,
300 struct task_struct *next);
301
302struct tracer_switch_ops {
303 tracer_switch_func_t func;
304 void *private;
305 struct tracer_switch_ops *next;
306};
307
bc0c38d1
SR
308#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
309
310#ifdef CONFIG_DYNAMIC_FTRACE
311extern unsigned long ftrace_update_tot_cnt;
d05cdb25
SR
312#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
313extern int DYN_FTRACE_TEST_NAME(void);
bc0c38d1
SR
314#endif
315
60a11774 316#ifdef CONFIG_FTRACE_STARTUP_TEST
60a11774
SR
317extern int trace_selftest_startup_function(struct tracer *trace,
318 struct trace_array *tr);
60a11774
SR
319extern int trace_selftest_startup_irqsoff(struct tracer *trace,
320 struct trace_array *tr);
60a11774
SR
321extern int trace_selftest_startup_preemptoff(struct tracer *trace,
322 struct trace_array *tr);
60a11774
SR
323extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
324 struct trace_array *tr);
60a11774
SR
325extern int trace_selftest_startup_wakeup(struct tracer *trace,
326 struct trace_array *tr);
fb1b6d8b
SN
327extern int trace_selftest_startup_nop(struct tracer *trace,
328 struct trace_array *tr);
60a11774
SR
329extern int trace_selftest_startup_sched_switch(struct tracer *trace,
330 struct trace_array *tr);
a6dd24f8
IM
331extern int trace_selftest_startup_sysprof(struct tracer *trace,
332 struct trace_array *tr);
60a11774
SR
333#endif /* CONFIG_FTRACE_STARTUP_TEST */
334
c7aafc54 335extern void *head_page(struct trace_array_cpu *data);
72829bc3 336extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
fc5e27ae
PP
337extern void trace_seq_print_cont(struct trace_seq *s,
338 struct trace_iterator *iter);
6c6c2796
PP
339extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
340 size_t cnt);
72829bc3 341extern long ns2usecs(cycle_t nsec);
801fe400 342extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
c7aafc54 343
4e655519
IM
344extern unsigned long trace_flags;
345
4fcdae83
SR
346/*
347 * trace_iterator_flags is an enumeration that defines bit
348 * positions into trace_flags that controls the output.
349 *
350 * NOTE: These bits must match the trace_options array in
351 * trace.c.
352 */
4e655519
IM
353enum trace_iterator_flags {
354 TRACE_ITER_PRINT_PARENT = 0x01,
355 TRACE_ITER_SYM_OFFSET = 0x02,
356 TRACE_ITER_SYM_ADDR = 0x04,
357 TRACE_ITER_VERBOSE = 0x08,
358 TRACE_ITER_RAW = 0x10,
359 TRACE_ITER_HEX = 0x20,
360 TRACE_ITER_BIN = 0x40,
361 TRACE_ITER_BLOCK = 0x80,
362 TRACE_ITER_STACKTRACE = 0x100,
4ac3ba41 363 TRACE_ITER_SCHED_TREE = 0x200,
f09ce573 364 TRACE_ITER_PRINTK = 0x400,
4e655519
IM
365};
366
43a15386
FW
367extern struct tracer nop_trace;
368
bc0c38d1 369#endif /* _LINUX_KERNEL_TRACE_H */
This page took 0.085789 seconds and 5 git commands to generate.