blob: 1882846b73894da07f543aae134b3b094ab82113 [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>
Zhaolei02af61b2009-04-10 14:26:18 +080012#include <linux/kmemtrace.h>
Frederic Weisbecker12922112009-02-07 22:16:12 +010013#include <trace/power.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020014
Steven Rostedt95045042009-04-11 12:59:57 -040015#include <linux/trace_seq.h>
16
Thomas Gleixner72829bc2008-05-23 21:37:28 +020017enum trace_type {
18 __TRACE_FIRST_TYPE = 0,
19
20 TRACE_FN,
21 TRACE_CTX,
22 TRACE_WAKE,
23 TRACE_STACK,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040024 TRACE_PRINT,
Frederic Weisbecker48ead022009-03-12 18:24:49 +010025 TRACE_BPRINT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020026 TRACE_SPECIAL,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020027 TRACE_MMIO_RW,
28 TRACE_MMIO_MAP,
Steven Rostedt9f029e82008-11-12 15:24:24 -050029 TRACE_BRANCH,
Frederic Weisbecker74239072008-11-11 23:24:42 +010030 TRACE_BOOT_CALL,
31 TRACE_BOOT_RET,
Frederic Weisbecker287b6e62008-11-26 00:57:25 +010032 TRACE_GRAPH_RET,
33 TRACE_GRAPH_ENT,
Török Edwin02b67512008-11-22 13:28:47 +020034 TRACE_USER_STACK,
Markus Metzgera93751c2008-12-11 13:53:26 +010035 TRACE_HW_BRANCHES,
Frederic Weisbeckeree08c6e2009-03-07 05:52:59 +010036 TRACE_SYSCALL_ENTER,
37 TRACE_SYSCALL_EXIT,
Frederic Weisbecker36994e52008-12-29 13:42:23 -080038 TRACE_KMEM_ALLOC,
39 TRACE_KMEM_FREE,
Arjan van de Venf3f47a62008-11-23 16:49:58 -080040 TRACE_POWER,
Arnaldo Carvalho de Meloc71a8962009-01-23 12:06:27 -020041 TRACE_BLK,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020042
Steven Rostedtf0868d12008-12-23 23:24:12 -050043 __TRACE_LAST_TYPE,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020044};
45
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020046/*
Steven Rostedt777e2082008-09-29 23:02:42 -040047 * The trace entry - the most basic unit of tracing. This is what
48 * is printed in the end as a single line in the trace output, such as:
49 *
50 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
51 */
52struct trace_entry {
53 unsigned char type;
Steven Rostedt777e2082008-09-29 23:02:42 -040054 unsigned char flags;
55 unsigned char preempt_count;
56 int pid;
Török Edwin02b67512008-11-22 13:28:47 +020057 int tgid;
Steven Rostedt777e2082008-09-29 23:02:42 -040058};
59
60/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020061 * Function trace entry - function address and parent function addres:
62 */
63struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040064 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020065 unsigned long ip;
66 unsigned long parent_ip;
67};
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010068
Frederic Weisbecker287b6e62008-11-26 00:57:25 +010069/* Function call entry */
70struct ftrace_graph_ent_entry {
Frederic Weisbeckerb91facc2009-02-06 18:30:44 +010071 struct trace_entry ent;
Frederic Weisbecker287b6e62008-11-26 00:57:25 +010072 struct ftrace_graph_ent graph_ent;
73};
74
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010075/* Function return entry */
Frederic Weisbecker287b6e62008-11-26 00:57:25 +010076struct ftrace_graph_ret_entry {
Frederic Weisbeckerb91facc2009-02-06 18:30:44 +010077 struct trace_entry ent;
Frederic Weisbecker287b6e62008-11-26 00:57:25 +010078 struct ftrace_graph_ret ret;
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +010079};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010080extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020081
82/*
83 * Context switch trace entry - which task (and prio) we switched from/to:
84 */
85struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040086 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020087 unsigned int prev_pid;
88 unsigned char prev_prio;
89 unsigned char prev_state;
90 unsigned int next_pid;
91 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020092 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020093 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020094};
95
96/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020097 * Special (free-form) trace entry:
98 */
99struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400100 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200101 unsigned long arg1;
102 unsigned long arg2;
103 unsigned long arg3;
104};
105
106/*
Ingo Molnar86387f72008-05-12 21:20:51 +0200107 * Stack-trace entry:
108 */
109
Ingo Molnar74f4e362008-05-12 21:21:15 +0200110#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +0200111
112struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400113 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +0200114 unsigned long caller[FTRACE_STACK_ENTRIES];
115};
116
Török Edwin02b67512008-11-22 13:28:47 +0200117struct userstack_entry {
118 struct trace_entry ent;
119 unsigned long caller[FTRACE_STACK_ENTRIES];
120};
121
Ingo Molnar86387f72008-05-12 21:20:51 +0200122/*
Ingo Molnar5e1607a2009-03-05 10:24:48 +0100123 * trace_printk entry:
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400124 */
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100125struct bprint_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -0400126 struct trace_entry ent;
Ingo Molnar9de36822009-03-06 17:52:03 +0100127 unsigned long ip;
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100128 const char *fmt;
Ingo Molnar9de36822009-03-06 17:52:03 +0100129 u32 buf[];
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100130};
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100131
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100132struct print_entry {
133 struct trace_entry ent;
134 unsigned long ip;
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100135 char buf[];
136};
137
Steven Rostedt777e2082008-09-29 23:02:42 -0400138#define TRACE_OLD_SIZE 88
139
140struct trace_field_cont {
141 unsigned char type;
142 /* Temporary till we get rid of this completely */
143 char buf[TRACE_OLD_SIZE - 1];
144};
145
146struct trace_mmiotrace_rw {
147 struct trace_entry ent;
148 struct mmiotrace_rw rw;
149};
150
151struct trace_mmiotrace_map {
152 struct trace_entry ent;
153 struct mmiotrace_map map;
154};
155
Frederic Weisbecker74239072008-11-11 23:24:42 +0100156struct trace_boot_call {
Steven Rostedt777e2082008-09-29 23:02:42 -0400157 struct trace_entry ent;
Frederic Weisbecker74239072008-11-11 23:24:42 +0100158 struct boot_trace_call boot_call;
159};
160
161struct trace_boot_ret {
162 struct trace_entry ent;
163 struct boot_trace_ret boot_ret;
Steven Rostedt777e2082008-09-29 23:02:42 -0400164};
165
Steven Rostedt52f232c2008-11-12 00:14:40 -0500166#define TRACE_FUNC_SIZE 30
167#define TRACE_FILE_SIZE 20
Steven Rostedt9f029e82008-11-12 15:24:24 -0500168struct trace_branch {
Steven Rostedt52f232c2008-11-12 00:14:40 -0500169 struct trace_entry ent;
170 unsigned line;
171 char func[TRACE_FUNC_SIZE+1];
172 char file[TRACE_FILE_SIZE+1];
173 char correct;
174};
175
Markus Metzgera93751c2008-12-11 13:53:26 +0100176struct hw_branch_entry {
Markus Metzger1e9b51c2008-11-25 09:24:15 +0100177 struct trace_entry ent;
Markus Metzgera93751c2008-12-11 13:53:26 +0100178 u64 from;
179 u64 to;
Markus Metzger1e9b51c2008-11-25 09:24:15 +0100180};
181
Arjan van de Venf3f47a62008-11-23 16:49:58 -0800182struct trace_power {
183 struct trace_entry ent;
184 struct power_trace state_data;
185};
186
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +0200187enum kmemtrace_type_id {
188 KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */
189 KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */
190 KMEMTRACE_TYPE_PAGES, /* __get_free_pages() and friends. */
191};
192
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800193struct kmemtrace_alloc_entry {
194 struct trace_entry ent;
195 enum kmemtrace_type_id type_id;
196 unsigned long call_site;
197 const void *ptr;
198 size_t bytes_req;
199 size_t bytes_alloc;
200 gfp_t gfp_flags;
201 int node;
202};
203
204struct kmemtrace_free_entry {
205 struct trace_entry ent;
206 enum kmemtrace_type_id type_id;
207 unsigned long call_site;
208 const void *ptr;
209};
210
Frederic Weisbeckerbed1ffc2009-03-13 15:42:11 +0100211struct syscall_trace_enter {
212 struct trace_entry ent;
213 int nr;
214 unsigned long args[];
215};
216
217struct syscall_trace_exit {
218 struct trace_entry ent;
219 int nr;
220 unsigned long ret;
221};
222
223
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400224/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300225 * trace_flag_type is an enumeration that holds different
226 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400227 * IRQS_OFF - interrupts were disabled
Ingo Molnar9de36822009-03-06 17:52:03 +0100228 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
Steven Rostedt92444892008-10-24 09:42:59 -0400229 * NEED_RESCED - reschedule is requested
230 * HARDIRQ - inside an interrupt handler
231 * SOFTIRQ - inside a softirq handler
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300232 */
233enum trace_flag_type {
234 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400235 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
236 TRACE_FLAG_NEED_RESCHED = 0x04,
237 TRACE_FLAG_HARDIRQ = 0x08,
238 TRACE_FLAG_SOFTIRQ = 0x10,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300239};
240
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300241#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200242
243/*
244 * The CPU trace array - it consists of thousands of trace entries
245 * plus some other descriptor data: (for example which task started
246 * the trace, etc.)
247 */
248struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200249 atomic_t disabled;
Steven Rostedt2cadf912008-12-01 22:20:19 -0500250 void *buffer_page; /* ring buffer spare */
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200251
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200252 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200253 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200254 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200255 unsigned long saved_latency;
256 unsigned long critical_start;
257 unsigned long critical_end;
258 unsigned long critical_sequence;
259 unsigned long nice;
260 unsigned long policy;
261 unsigned long rt_priority;
262 cycle_t preempt_timestamp;
263 pid_t pid;
264 uid_t uid;
265 char comm[TASK_COMM_LEN];
266};
267
268struct trace_iterator;
269
270/*
271 * The trace array - an array of per-CPU trace arrays. This is the
272 * highest level data structure that individual tracers deal with.
273 * They have on/off state as well:
274 */
275struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400276 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200277 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200278 int cpu;
279 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200280 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200281 struct trace_array_cpu *data[NR_CPUS];
282};
283
Steven Rostedt7104f302008-10-01 10:52:51 -0400284#define FTRACE_CMP_TYPE(var, type) \
285 __builtin_types_compatible_p(typeof(var), type *)
286
287#undef IF_ASSIGN
288#define IF_ASSIGN(var, entry, etype, id) \
289 if (FTRACE_CMP_TYPE(var, etype)) { \
290 var = (typeof(var))(entry); \
291 WARN_ON(id && (entry)->type != id); \
292 break; \
293 }
294
295/* Will cause compile errors if type is not found. */
296extern void __ftrace_bad_type(void);
297
298/*
299 * The trace_assign_type is a verifier that the entry type is
300 * the same as the type being assigned. To add new types simply
301 * add a line with the following format:
302 *
303 * IF_ASSIGN(var, ent, type, id);
304 *
305 * Where "type" is the trace type that includes the trace_entry
306 * as the "ent" item. And "id" is the trace identifier that is
307 * used in the trace_type enum.
308 *
309 * If the type can have more than one id, then use zero.
310 */
311#define trace_assign_type(var, ent) \
312 do { \
313 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
314 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
Steven Rostedt7104f302008-10-01 10:52:51 -0400315 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
Török Edwin02b67512008-11-22 13:28:47 +0200316 IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
Steven Rostedt7104f302008-10-01 10:52:51 -0400317 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100318 IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
Steven Rostedt7104f302008-10-01 10:52:51 -0400319 IF_ASSIGN(var, ent, struct special_entry, 0); \
320 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
321 TRACE_MMIO_RW); \
322 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
323 TRACE_MMIO_MAP); \
Frederic Weisbecker74239072008-11-11 23:24:42 +0100324 IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
325 IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
Steven Rostedt9f029e82008-11-12 15:24:24 -0500326 IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
Frederic Weisbecker287b6e62008-11-26 00:57:25 +0100327 IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
328 TRACE_GRAPH_ENT); \
329 IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
330 TRACE_GRAPH_RET); \
Markus Metzgera93751c2008-12-11 13:53:26 +0100331 IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
Ingo Molnar9de36822009-03-06 17:52:03 +0100332 IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800333 IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \
334 TRACE_KMEM_ALLOC); \
335 IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \
336 TRACE_KMEM_FREE); \
Frederic Weisbeckerbed1ffc2009-03-13 15:42:11 +0100337 IF_ASSIGN(var, ent, struct syscall_trace_enter, \
338 TRACE_SYSCALL_ENTER); \
339 IF_ASSIGN(var, ent, struct syscall_trace_exit, \
340 TRACE_SYSCALL_EXIT); \
Steven Rostedt7104f302008-10-01 10:52:51 -0400341 __ftrace_bad_type(); \
342 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200343
344/* Return values for print_line callback */
345enum print_line_t {
346 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
347 TRACE_TYPE_HANDLED = 1,
Frederic Weisbeckerb91facc2009-02-06 18:30:44 +0100348 TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
349 TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200350};
351
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100352
353/*
354 * An option specific to a tracer. This is a boolean value.
355 * The bit is the bit index that sets its value on the
356 * flags value in struct tracer_flags.
357 */
358struct tracer_opt {
Ingo Molnar9de36822009-03-06 17:52:03 +0100359 const char *name; /* Will appear on the trace_options file */
360 u32 bit; /* Mask assigned in val field in tracer_flags */
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100361};
362
363/*
364 * The set of specific options for a tracer. Your tracer
365 * have to set the initial value of the flags val.
366 */
367struct tracer_flags {
368 u32 val;
Ingo Molnar9de36822009-03-06 17:52:03 +0100369 struct tracer_opt *opts;
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100370};
371
372/* Makes more easy to define a tracer opt */
373#define TRACER_OPT(s, b) .name = #s, .bit = b
374
Frederic Weisbecker034939b2009-01-08 10:03:56 -0800375
Frederic Weisbecker6eaaa5d2009-02-11 02:25:00 +0100376/**
377 * struct tracer - a specific tracer and its callbacks to interact with debugfs
378 * @name: the name chosen to select it on the available_tracers file
379 * @init: called when one switches to this tracer (echo name > current_tracer)
380 * @reset: called when one switches to another tracer
381 * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
382 * @stop: called when tracing is paused (echo 0 > tracing_enabled)
383 * @open: called when the trace file is opened
384 * @pipe_open: called when the trace_pipe file is opened
385 * @wait_pipe: override how the user waits for traces on trace_pipe
386 * @close: called when the trace file is released
387 * @read: override the default read callback on trace_pipe
388 * @splice_read: override the default splice_read callback on trace_pipe
389 * @selftest: selftest to run on boot (see trace_selftest.c)
390 * @print_headers: override the first lines that describe your columns
391 * @print_line: callback that prints a trace
392 * @set_flag: signals one of your private flags changed (trace_options file)
393 * @flags: your private flags
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200394 */
395struct tracer {
396 const char *name;
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100397 int (*init)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200398 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500399 void (*start)(struct trace_array *tr);
400 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200401 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200402 void (*pipe_open)(struct trace_iterator *iter);
Frederic Weisbecker6eaaa5d2009-02-11 02:25:00 +0100403 void (*wait_pipe)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200404 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200405 ssize_t (*read)(struct trace_iterator *iter,
406 struct file *filp, char __user *ubuf,
407 size_t cnt, loff_t *ppos);
Eduard - Gabriel Munteanu3c568192009-02-09 08:15:56 +0200408 ssize_t (*splice_read)(struct trace_iterator *iter,
409 struct file *filp,
410 loff_t *ppos,
411 struct pipe_inode_info *pipe,
412 size_t len,
413 unsigned int flags);
Steven Rostedt60a11772008-05-12 21:20:44 +0200414#ifdef CONFIG_FTRACE_STARTUP_TEST
415 int (*selftest)(struct tracer *trace,
416 struct trace_array *tr);
417#endif
Markus Metzger8bba1bf2008-11-25 09:12:31 +0100418 void (*print_header)(struct seq_file *m);
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200419 enum print_line_t (*print_line)(struct trace_iterator *iter);
Frederic Weisbeckeradf9f192008-11-17 19:23:42 +0100420 /* If you handled the flag setting, return 0 */
421 int (*set_flag)(u32 old_flags, u32 bit, int set);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200422 struct tracer *next;
423 int print_max;
Ingo Molnar9de36822009-03-06 17:52:03 +0100424 struct tracer_flags *flags;
Frederic Weisbecker034939b2009-01-08 10:03:56 -0800425 struct tracer_stat *stats;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200426};
427
Steven Rostedtf9520752009-03-02 14:04:40 -0500428
Frederic Weisbeckerb04cc6b2009-02-25 03:22:28 +0100429#define TRACE_PIPE_ALL_CPU -1
430
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200431/*
432 * Trace iterator - used by printout routines who present trace
433 * results to users and which routines might sleep, etc:
434 */
435struct trace_iterator {
436 struct trace_array *tr;
437 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200438 void *private;
Frederic Weisbeckerb04cc6b2009-02-25 03:22:28 +0100439 int cpu_file;
Frederic Weisbeckerd7350c3f2009-02-25 06:13:16 +0100440 struct mutex mutex;
441 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200442
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200443 /* The below is zeroed out in pipe_read */
444 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200445 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200446 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400447 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200448
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200449 unsigned long iter_flags;
450 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200451 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500452
Rusty Russell44623442009-01-01 10:12:23 +1030453 cpumask_var_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200454};
455
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -0200456int tracer_init(struct tracer *t, struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500457int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300458void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400459void tracing_reset(struct trace_array *tr, int cpu);
Pekka J Enberg213cc062008-12-19 12:08:39 +0200460void tracing_reset_online_cpus(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200461int tracing_open_generic(struct inode *inode, struct file *filp);
Frederic Weisbecker5452af62009-03-27 00:25:38 +0100462struct dentry *trace_create_file(const char *name,
463 mode_t mode,
464 struct dentry *parent,
465 void *data,
466 const struct file_operations *fops);
467
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200468struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200469void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
470
Arnaldo Carvalho de Melo51a763d2009-02-05 16:14:13 -0200471struct ring_buffer_event;
472
473struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
474 unsigned char type,
475 unsigned long len,
476 unsigned long flags,
477 int pc);
478void trace_buffer_unlock_commit(struct trace_array *tr,
479 struct ring_buffer_event *event,
480 unsigned long flags, int pc);
481
Steven Rostedtef5580d2009-02-27 19:38:04 -0500482struct ring_buffer_event *
483trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
484 unsigned long flags, int pc);
485void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
486 unsigned long flags, int pc);
Frederic Weisbecker07edf712009-03-22 23:10:46 +0100487void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event,
488 unsigned long flags, int pc);
Steven Rostedt77d9f462009-04-02 01:16:59 -0400489void trace_current_buffer_discard_commit(struct ring_buffer_event *event);
Steven Rostedtef5580d2009-02-27 19:38:04 -0500490
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300491struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
492 struct trace_array_cpu *data);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200493
494struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
495 int *ent_cpu, u64 *ent_ts);
496
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300497void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400498 unsigned long flags,
499 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300500
Frederic Weisbecker6eaaa5d2009-02-11 02:25:00 +0100501void default_wait_pipe(struct trace_iterator *iter);
502void poll_wait_pipe(struct trace_iterator *iter);
503
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200504void ftrace(struct trace_array *tr,
505 struct trace_array_cpu *data,
506 unsigned long ip,
507 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400508 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200509void tracing_sched_switch_trace(struct trace_array *tr,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200510 struct task_struct *prev,
511 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400512 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200513void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200514
515void tracing_sched_wakeup_trace(struct trace_array *tr,
Ingo Molnar57422792008-05-12 21:20:51 +0200516 struct task_struct *wakee,
517 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400518 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200519void trace_special(struct trace_array *tr,
520 struct trace_array_cpu *data,
521 unsigned long arg1,
522 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400523 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200524void trace_function(struct trace_array *tr,
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200525 unsigned long ip,
526 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400527 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200528
Frederic Weisbecker287b6e62008-11-26 00:57:25 +0100529void trace_graph_return(struct ftrace_graph_ret *trace);
Steven Rostedte49dc192008-12-02 23:50:05 -0500530int trace_graph_entry(struct ftrace_graph_ent *trace);
Markus Metzger1e9b51c2008-11-25 09:24:15 +0100531
Steven Rostedt41bc8142008-05-22 11:49:22 -0400532void tracing_start_cmdline_record(void);
533void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500534void tracing_sched_switch_assign_trace(struct trace_array *tr);
535void tracing_stop_sched_switch_record(void);
536void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200537int register_tracer(struct tracer *type);
538void unregister_tracer(struct tracer *type);
539
540extern unsigned long nsecs_to_usecs(unsigned long nsecs);
541
542extern unsigned long tracing_max_latency;
543extern unsigned long tracing_thresh;
544
545void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
546void update_max_tr_single(struct trace_array *tr,
547 struct task_struct *tsk, int cpu);
548
Steven Rostedt53614992009-01-15 19:12:40 -0500549void __trace_stack(struct trace_array *tr,
Steven Rostedt53614992009-01-15 19:12:40 -0500550 unsigned long flags,
551 int skip, int pc);
552
Ingo Molnare309b412008-05-12 21:20:51 +0200553extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200554
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200555#ifdef CONFIG_CONTEXT_SWITCH_TRACER
556typedef void
557(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200558 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200559 struct task_struct *prev,
560 struct task_struct *next);
561
562struct tracer_switch_ops {
563 tracer_switch_func_t func;
564 void *private;
565 struct tracer_switch_ops *next;
566};
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200567#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
568
Steven Rostedt4ca530852009-03-16 19:20:15 -0400569extern void trace_find_cmdline(int pid, char comm[]);
Ingo Molnarf7d48cb2008-12-29 13:02:17 +0100570
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200571#ifdef CONFIG_DYNAMIC_FTRACE
572extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200573#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
574extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200575#endif
576
Steven Rostedt60a11772008-05-12 21:20:44 +0200577#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200578extern int trace_selftest_startup_function(struct tracer *trace,
579 struct trace_array *tr);
Frederic Weisbecker7447dce2009-02-07 21:33:57 +0100580extern int trace_selftest_startup_function_graph(struct tracer *trace,
581 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200582extern int trace_selftest_startup_irqsoff(struct tracer *trace,
583 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200584extern int trace_selftest_startup_preemptoff(struct tracer *trace,
585 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200586extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
587 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200588extern int trace_selftest_startup_wakeup(struct tracer *trace,
589 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700590extern int trace_selftest_startup_nop(struct tracer *trace,
591 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200592extern int trace_selftest_startup_sched_switch(struct tracer *trace,
593 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200594extern int trace_selftest_startup_sysprof(struct tracer *trace,
595 struct trace_array *tr);
Steven Rostedt80e5ea42008-11-12 15:24:24 -0500596extern int trace_selftest_startup_branch(struct tracer *trace,
597 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200598#endif /* CONFIG_FTRACE_STARTUP_TEST */
599
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200600extern void *head_page(struct trace_array_cpu *data);
Lai Jiangshancf8e3472009-03-30 13:48:00 +0800601extern unsigned long long ns2usecs(cycle_t nsec);
Frederic Weisbecker1fd8f2a2008-12-03 23:45:11 +0100602extern int
Steven Rostedt40ce74f2009-03-19 14:03:53 -0400603trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100604extern int
Steven Rostedt40ce74f2009-03-19 14:03:53 -0400605trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200606
Ingo Molnar4e655512008-05-12 21:20:52 +0200607extern unsigned long trace_flags;
608
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100609/* Standard output formatting function used for function return traces */
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100610#ifdef CONFIG_FUNCTION_GRAPH_TRACER
611extern enum print_line_t print_graph_function(struct trace_iterator *iter);
Steven Rostedt0706f1c2009-03-23 23:12:58 -0400612extern enum print_line_t
613trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500614
615#ifdef CONFIG_DYNAMIC_FTRACE
616/* TODO: make this variable */
617#define FTRACE_GRAPH_MAX_FUNCS 32
618extern int ftrace_graph_count;
619extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
620
621static inline int ftrace_graph_addr(unsigned long addr)
622{
623 int i;
624
625 if (!ftrace_graph_count || test_tsk_trace_graph(current))
626 return 1;
627
628 for (i = 0; i < ftrace_graph_count; i++) {
629 if (addr == ftrace_graph_funcs[i])
630 return 1;
631 }
632
633 return 0;
634}
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100635#else
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500636static inline int ftrace_trace_addr(unsigned long addr)
637{
Ingo Molnar6b253932008-12-04 09:18:28 +0100638 return 1;
639}
640static inline int ftrace_graph_addr(unsigned long addr)
641{
642 return 1;
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500643}
644#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500645#else /* CONFIG_FUNCTION_GRAPH_TRACER */
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100646static inline enum print_line_t
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100647print_graph_function(struct trace_iterator *iter)
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100648{
649 return TRACE_TYPE_UNHANDLED;
650}
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500651#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100652
Steven Rostedt978f3a42008-12-04 00:26:40 -0500653extern struct pid *ftrace_pid_trace;
Steven Rostedt804a6852008-12-03 15:36:59 -0500654
655static inline int ftrace_trace_task(struct task_struct *task)
656{
Frederic Weisbecker77d683f2008-12-04 23:49:47 +0100657 if (!ftrace_pid_trace)
Steven Rostedt804a6852008-12-03 15:36:59 -0500658 return 1;
659
660 return test_tsk_trace_trace(task);
661}
662
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200663/*
664 * trace_iterator_flags is an enumeration that defines bit
665 * positions into trace_flags that controls the output.
666 *
667 * NOTE: These bits must match the trace_options array in
668 * trace.c.
669 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200670enum trace_iterator_flags {
671 TRACE_ITER_PRINT_PARENT = 0x01,
672 TRACE_ITER_SYM_OFFSET = 0x02,
673 TRACE_ITER_SYM_ADDR = 0x04,
674 TRACE_ITER_VERBOSE = 0x08,
675 TRACE_ITER_RAW = 0x10,
676 TRACE_ITER_HEX = 0x20,
677 TRACE_ITER_BIN = 0x40,
678 TRACE_ITER_BLOCK = 0x80,
679 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200680 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200681 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500682 TRACE_ITER_PREEMPTONLY = 0x800,
Steven Rostedt9f029e82008-11-12 15:24:24 -0500683 TRACE_ITER_BRANCH = 0x1000,
Steven Rostedt12ef7d42008-11-12 17:52:38 -0500684 TRACE_ITER_ANNOTATE = 0x2000,
Török Edwinb54d3de2008-11-22 13:28:48 +0200685 TRACE_ITER_USERSTACKTRACE = 0x4000,
Frederic Weisbecker66896a82008-12-13 20:18:13 +0100686 TRACE_ITER_SYM_USEROBJ = 0x8000,
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200687 TRACE_ITER_PRINTK_MSGONLY = 0x10000,
Steven Rostedtc032ef642009-03-04 20:34:24 -0500688 TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */
689 TRACE_ITER_LATENCY_FMT = 0x40000,
Steven Rostedtaf4617b2009-03-17 18:09:55 -0400690 TRACE_ITER_GLOBAL_CLK = 0x80000,
Steven Rostedtbe6f1642009-03-24 11:06:24 -0400691 TRACE_ITER_SLEEP_TIME = 0x100000,
Steven Rostedta2a16d62009-03-24 23:17:58 -0400692 TRACE_ITER_GRAPH_TIME = 0x200000,
Ingo Molnar4e655512008-05-12 21:20:52 +0200693};
694
Frederic Weisbecker15e6cb32008-11-11 07:14:25 +0100695/*
696 * TRACE_ITER_SYM_MASK masks the options in trace_flags that
697 * control the output of kernel symbols.
698 */
699#define TRACE_ITER_SYM_MASK \
700 (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
701
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200702extern struct tracer nop_trace;
703
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500704/**
705 * ftrace_preempt_disable - disable preemption scheduler safe
706 *
707 * When tracing can happen inside the scheduler, there exists
708 * cases that the tracing might happen before the need_resched
709 * flag is checked. If this happens and the tracer calls
710 * preempt_enable (after a disable), a schedule might take place
711 * causing an infinite recursion.
712 *
Wenji Huang57794a92009-02-06 17:33:27 +0800713 * To prevent this, we read the need_resched flag before
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500714 * disabling preemption. When we want to enable preemption we
715 * check the flag, if it is set, then we call preempt_enable_no_resched.
716 * Otherwise, we call preempt_enable.
717 *
Wenji Huang57794a92009-02-06 17:33:27 +0800718 * The rational for doing the above is that if need_resched is set
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500719 * and we have yet to reschedule, we are either in an atomic location
720 * (where we do not need to check for scheduling) or we are inside
721 * the scheduler and do not want to resched.
722 */
723static inline int ftrace_preempt_disable(void)
724{
725 int resched;
726
727 resched = need_resched();
728 preempt_disable_notrace();
729
730 return resched;
731}
732
733/**
734 * ftrace_preempt_enable - enable preemption scheduler safe
735 * @resched: the return value from ftrace_preempt_disable
736 *
737 * This is a scheduler safe way to enable preemption and not miss
738 * any preemption checks. The disabled saved the state of preemption.
Wenji Huang57794a92009-02-06 17:33:27 +0800739 * If resched is set, then we are either inside an atomic or
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500740 * are inside the scheduler (we would have already scheduled
741 * otherwise). In this case, we do not want to call normal
742 * preempt_enable, but preempt_enable_no_resched instead.
743 */
744static inline void ftrace_preempt_enable(int resched)
745{
746 if (resched)
747 preempt_enable_no_resched_notrace();
748 else
749 preempt_enable_notrace();
750}
751
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500752#ifdef CONFIG_BRANCH_TRACER
Steven Rostedt9f029e82008-11-12 15:24:24 -0500753extern int enable_branch_tracing(struct trace_array *tr);
754extern void disable_branch_tracing(void);
755static inline int trace_branch_enable(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500756{
Steven Rostedt9f029e82008-11-12 15:24:24 -0500757 if (trace_flags & TRACE_ITER_BRANCH)
758 return enable_branch_tracing(tr);
Steven Rostedt52f232c2008-11-12 00:14:40 -0500759 return 0;
760}
Steven Rostedt9f029e82008-11-12 15:24:24 -0500761static inline void trace_branch_disable(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500762{
763 /* due to races, always disable */
Steven Rostedt9f029e82008-11-12 15:24:24 -0500764 disable_branch_tracing();
Steven Rostedt52f232c2008-11-12 00:14:40 -0500765}
766#else
Steven Rostedt9f029e82008-11-12 15:24:24 -0500767static inline int trace_branch_enable(struct trace_array *tr)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500768{
769 return 0;
770}
Steven Rostedt9f029e82008-11-12 15:24:24 -0500771static inline void trace_branch_disable(void)
Steven Rostedt52f232c2008-11-12 00:14:40 -0500772{
773}
Steven Rostedt2ed84ee2008-11-12 15:24:24 -0500774#endif /* CONFIG_BRANCH_TRACER */
Steven Rostedt52f232c2008-11-12 00:14:40 -0500775
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400776/* set ring buffers to default size if not already done so */
777int tracing_update_buffers(void);
778
Steven Rostedtfd994982009-02-28 02:41:25 -0500779/* trace event type bit fields, not numeric */
780enum {
781 TRACE_EVENT_TYPE_PRINTF = 1,
782 TRACE_EVENT_TYPE_RAW = 2,
783};
784
Tom Zanussicf027f62009-03-22 03:30:39 -0500785struct ftrace_event_field {
786 struct list_head link;
787 char *name;
788 char *type;
789 int offset;
790 int size;
791};
792
Steven Rostedtc32e8272009-02-27 19:12:30 -0500793struct ftrace_event_call {
Tom Zanussicf027f62009-03-22 03:30:39 -0500794 char *name;
795 char *system;
796 struct dentry *dir;
797 int enabled;
798 int (*regfunc)(void);
799 void (*unregfunc)(void);
800 int id;
801 int (*raw_init)(void);
802 int (*show_format)(struct trace_seq *s);
803 int (*define_fields)(void);
804 struct list_head fields;
Tom Zanussi0a19e532009-04-13 03:17:50 -0500805 int n_preds;
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500806 struct filter_pred **preds;
Peter Zijlstraac199db2009-03-19 20:26:15 +0100807
808#ifdef CONFIG_EVENT_PROFILE
809 atomic_t profile_count;
810 int (*profile_enable)(struct ftrace_event_call *);
811 void (*profile_disable)(struct ftrace_event_call *);
812#endif
Steven Rostedtc32e8272009-02-27 19:12:30 -0500813};
814
Tom Zanussicfb180f2009-03-22 03:31:17 -0500815struct event_subsystem {
816 struct list_head list;
817 const char *name;
818 struct dentry *entry;
Tom Zanussi0a19e532009-04-13 03:17:50 -0500819 int n_preds;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500820 struct filter_pred **preds;
821};
822
823#define events_for_each(event) \
824 for (event = __start_ftrace_events; \
825 (unsigned long)event < (unsigned long)__stop_ftrace_events; \
826 event++)
827
Tom Zanussi0a19e532009-04-13 03:17:50 -0500828#define MAX_FILTER_PRED 8
829#define MAX_FILTER_STR_VAL 128
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500830
831struct filter_pred;
832
833typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
834
835struct filter_pred {
836 filter_pred_fn_t fn;
837 u64 val;
Tom Zanussi0a19e532009-04-13 03:17:50 -0500838 char str_val[MAX_FILTER_STR_VAL];
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500839 int str_len;
840 char *field_name;
841 int offset;
842 int not;
843 int or;
844 int compound;
845 int clear;
846};
847
Tom Zanussicf027f62009-03-22 03:30:39 -0500848int trace_define_field(struct ftrace_event_call *call, char *type,
849 char *name, int offset, int size);
Tom Zanussi0a19e532009-04-13 03:17:50 -0500850extern int init_preds(struct ftrace_event_call *call);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500851extern void filter_free_pred(struct filter_pred *pred);
Tom Zanussi0a19e532009-04-13 03:17:50 -0500852extern void filter_print_preds(struct filter_pred **preds, int n_preds,
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500853 struct trace_seq *s);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500854extern int filter_parse(char **pbuf, struct filter_pred *pred);
855extern int filter_add_pred(struct ftrace_event_call *call,
856 struct filter_pred *pred);
Tom Zanussi0a19e532009-04-13 03:17:50 -0500857extern void filter_disable_preds(struct ftrace_event_call *call);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500858extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
Tom Zanussicfb180f2009-03-22 03:31:17 -0500859extern void filter_free_subsystem_preds(struct event_subsystem *system);
860extern int filter_add_subsystem_pred(struct event_subsystem *system,
861 struct filter_pred *pred);
Tom Zanussieb02ce02009-04-08 03:15:54 -0500862extern int filter_current_check_discard(struct ftrace_event_call *call,
863 void *rec,
864 struct ring_buffer_event *event);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500865
Tom Zanussieb02ce02009-04-08 03:15:54 -0500866static inline int
Tom Zanussie1112b42009-03-31 00:48:49 -0500867filter_check_discard(struct ftrace_event_call *call, void *rec,
Tom Zanussieb02ce02009-04-08 03:15:54 -0500868 struct ring_buffer *buffer,
Tom Zanussie1112b42009-03-31 00:48:49 -0500869 struct ring_buffer_event *event)
870{
Tom Zanussi0a19e532009-04-13 03:17:50 -0500871 if (unlikely(call->n_preds) && !filter_match_preds(call, rec)) {
Tom Zanussieb02ce02009-04-08 03:15:54 -0500872 ring_buffer_discard_commit(buffer, event);
873 return 1;
874 }
875
876 return 0;
Tom Zanussie1112b42009-03-31 00:48:49 -0500877}
878
879#define __common_field(type, item) \
880 ret = trace_define_field(event_call, #type, "common_" #item, \
881 offsetof(typeof(field.ent), item), \
882 sizeof(field.ent.item)); \
883 if (ret) \
884 return ret;
885
Steven Rostedtc32e8272009-02-27 19:12:30 -0500886void event_trace_printk(unsigned long ip, const char *fmt, ...);
887extern struct ftrace_event_call __start_ftrace_events[];
888extern struct ftrace_event_call __stop_ftrace_events[];
889
Peter Zijlstraac199db2009-03-19 20:26:15 +0100890#define for_each_event(event) \
891 for (event = __start_ftrace_events; \
892 (unsigned long)event < (unsigned long)__stop_ftrace_events; \
893 event++)
894
Steven Rostedte9fb2b62009-03-12 14:19:25 -0400895extern const char *__start___trace_bprintk_fmt[];
896extern const char *__stop___trace_bprintk_fmt[];
897
Steven Rostedtbdc067582009-03-13 00:12:52 -0400898/*
899 * The double __builtin_constant_p is because gcc will give us an error
900 * if we try to allocate the static variable to fmt if it is not a
901 * constant. Even with the outer if statement optimizing out.
902 */
Steven Rostedte9fb2b62009-03-12 14:19:25 -0400903#define event_trace_printk(ip, fmt, args...) \
904do { \
905 __trace_printk_check_format(fmt, ##args); \
906 tracing_record_cmdline(current); \
907 if (__builtin_constant_p(fmt)) { \
908 static const char *trace_printk_fmt \
909 __attribute__((section("__trace_printk_fmt"))) = \
910 __builtin_constant_p(fmt) ? fmt : NULL; \
911 \
912 __trace_bprintk(ip, trace_printk_fmt, ##args); \
913 } else \
914 __trace_printk(ip, fmt, ##args); \
915} while (0)
916
Tom Zanussie1112b42009-03-31 00:48:49 -0500917#undef TRACE_EVENT_FORMAT
918#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
919 extern struct ftrace_event_call event_##call;
Tom Zanussie45f2e22009-03-31 00:49:16 -0500920#undef TRACE_EVENT_FORMAT_NOFILTER
921#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, tpfmt)
Tom Zanussie1112b42009-03-31 00:48:49 -0500922#include "trace_event_types.h"
923
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200924#endif /* _LINUX_KERNEL_TRACE_H */