Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[linux-2.6-block.git] / include / linux / ftrace_event.h
CommitLineData
97f20251
SR
1#ifndef _LINUX_FTRACE_EVENT_H
2#define _LINUX_FTRACE_EVENT_H
3
97f20251 4#include <linux/ring_buffer.h>
16bb8eb1 5#include <linux/trace_seq.h>
be74b73a 6#include <linux/percpu.h>
20ab4425 7#include <linux/hardirq.h>
430ad5a6 8#include <linux/perf_event.h>
97f20251
SR
9
10struct trace_array;
11struct tracer;
6d723736 12struct dentry;
97f20251 13
be74b73a
SR
14DECLARE_PER_CPU(struct trace_seq, ftrace_event_seq);
15
16struct trace_print_flags {
17 unsigned long mask;
18 const char *name;
19};
20
21const char *ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
22 unsigned long flags,
23 const struct trace_print_flags *flag_array);
24
0f4fc29d
SR
25const char *ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
26 const struct trace_print_flags *symbol_array);
27
5a2e3995
KT
28const char *ftrace_print_hex_seq(struct trace_seq *p,
29 const unsigned char *buf, int len);
30
97f20251
SR
31/*
32 * The trace entry - the most basic unit of tracing. This is what
33 * is printed in the end as a single line in the trace output, such as:
34 *
35 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
36 */
37struct trace_entry {
89ec0dee 38 unsigned short type;
97f20251
SR
39 unsigned char flags;
40 unsigned char preempt_count;
41 int pid;
637e7e86 42 int lock_depth;
97f20251
SR
43};
44
89ec0dee
SR
45#define FTRACE_MAX_EVENT \
46 ((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
47
97f20251
SR
48/*
49 * Trace iterator - used by printout routines who present trace
50 * results to users and which routines might sleep, etc:
51 */
52struct trace_iterator {
53 struct trace_array *tr;
54 struct tracer *trace;
55 void *private;
56 int cpu_file;
57 struct mutex mutex;
58 struct ring_buffer_iter *buffer_iter[NR_CPUS];
112f38a7 59 unsigned long iter_flags;
97f20251
SR
60
61 /* The below is zeroed out in pipe_read */
62 struct trace_seq seq;
63 struct trace_entry *ent;
bc21b478 64 unsigned long lost_events;
a63ce5b3 65 int leftover;
97f20251
SR
66 int cpu;
67 u64 ts;
68
97f20251
SR
69 loff_t pos;
70 long idx;
71
72 cpumask_var_t started;
73};
74
75
76typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
77 int flags);
78struct trace_event {
79 struct hlist_node node;
060fa5c8 80 struct list_head list;
97f20251
SR
81 int type;
82 trace_print_func trace;
83 trace_print_func raw;
84 trace_print_func hex;
85 trace_print_func binary;
86};
87
88extern int register_ftrace_event(struct trace_event *event);
89extern int unregister_ftrace_event(struct trace_event *event);
90
91/* Return values for print_line callback */
92enum print_line_t {
93 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
94 TRACE_TYPE_HANDLED = 1,
95 TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
96 TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
97};
98
f413cdb8
FW
99void tracing_generic_entry_update(struct trace_entry *entry,
100 unsigned long flags,
101 int pc);
97f20251 102struct ring_buffer_event *
e77405ad
SR
103trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
104 int type, unsigned long len,
97f20251 105 unsigned long flags, int pc);
e77405ad
SR
106void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
107 struct ring_buffer_event *event,
97f20251 108 unsigned long flags, int pc);
e77405ad
SR
109void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer,
110 struct ring_buffer_event *event,
97f20251 111 unsigned long flags, int pc);
e77405ad
SR
112void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
113 struct ring_buffer_event *event);
97f20251
SR
114
115void tracing_record_cmdline(struct task_struct *tsk);
116
1f9963cb
LZ
117struct event_filter;
118
97f20251 119struct ftrace_event_call {
a59fd602 120 struct list_head list;
97f20251
SR
121 char *name;
122 char *system;
123 struct dentry *dir;
6d723736 124 struct trace_event *event;
97f20251 125 int enabled;
bd1a5c84
MH
126 int (*regfunc)(struct ftrace_event_call *);
127 void (*unregfunc)(struct ftrace_event_call *);
97f20251 128 int id;
509e760c 129 const char *print_fmt;
bd1a5c84 130 int (*raw_init)(struct ftrace_event_call *);
14be96c9 131 int (*define_fields)(struct ftrace_event_call *);
97f20251 132 struct list_head fields;
30e673b2 133 int filter_active;
1f9963cb 134 struct event_filter *filter;
6d723736 135 void *mod;
69fd4f0e 136 void *data;
97f20251 137
97d5a220
FW
138 int perf_refcount;
139 int (*perf_event_enable)(struct ftrace_event_call *);
140 void (*perf_event_disable)(struct ftrace_event_call *);
97f20251
SR
141};
142
97d5a220 143#define PERF_MAX_TRACE_SIZE 2048
20ab4425 144
8b372562 145#define MAX_FILTER_PRED 32
16bb8eb1 146#define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
97f20251 147
2df75e41 148extern void destroy_preds(struct ftrace_event_call *call);
6fb2915d 149extern int filter_match_preds(struct event_filter *filter, void *rec);
e77405ad
SR
150extern int filter_current_check_discard(struct ring_buffer *buffer,
151 struct ftrace_event_call *call,
97f20251
SR
152 void *rec,
153 struct ring_buffer_event *event);
154
43b51ead
LZ
155enum {
156 FILTER_OTHER = 0,
157 FILTER_STATIC_STRING,
158 FILTER_DYN_STRING,
87a342f5 159 FILTER_PTR_STRING,
43b51ead
LZ
160};
161
87d9b4e1 162extern int trace_event_raw_init(struct ftrace_event_call *call);
aeaeae11
FW
163extern int trace_define_field(struct ftrace_event_call *call, const char *type,
164 const char *name, int offset, int size,
165 int is_signed, int filter_type);
bd1a5c84
MH
166extern int trace_add_event_call(struct ftrace_event_call *call);
167extern void trace_remove_event_call(struct ftrace_event_call *call);
97f20251 168
a118e4d1 169#define is_signed_type(type) (((type)(-1)) < 0)
97f20251 170
4671c794
SR
171int trace_set_clr_event(const char *system, const char *event, int set);
172
97f20251
SR
173/*
174 * The double __builtin_constant_p is because gcc will give us an error
175 * if we try to allocate the static variable to fmt if it is not a
176 * constant. Even with the outer if statement optimizing out.
177 */
178#define event_trace_printk(ip, fmt, args...) \
179do { \
180 __trace_printk_check_format(fmt, ##args); \
181 tracing_record_cmdline(current); \
182 if (__builtin_constant_p(fmt)) { \
183 static const char *trace_printk_fmt \
184 __attribute__((section("__trace_printk_fmt"))) = \
185 __builtin_constant_p(fmt) ? fmt : NULL; \
186 \
187 __trace_bprintk(ip, trace_printk_fmt, ##args); \
188 } else \
189 __trace_printk(ip, fmt, ##args); \
190} while (0)
191
07b139c8 192#ifdef CONFIG_PERF_EVENTS
6fb2915d 193struct perf_event;
c530665c
FW
194
195DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
196
97d5a220
FW
197extern int perf_trace_enable(int event_id);
198extern void perf_trace_disable(int event_id);
6fb2915d
LZ
199extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
200 char *filter_str);
201extern void ftrace_profile_free_filter(struct perf_event *event);
430ad5a6 202extern void *
97d5a220 203perf_trace_buf_prepare(int size, unsigned short type, int *rctxp,
430ad5a6
XG
204 unsigned long *irq_flags);
205
206static inline void
97d5a220 207perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
c530665c 208 u64 count, unsigned long irq_flags, struct pt_regs *regs)
430ad5a6
XG
209{
210 struct trace_entry *entry = raw_data;
211
c530665c 212 perf_tp_event(entry->type, addr, count, raw_data, size, regs);
430ad5a6
XG
213 perf_swevent_put_recursion_context(rctx);
214 local_irq_restore(irq_flags);
215}
6fb2915d
LZ
216#endif
217
97f20251 218#endif /* _LINUX_FTRACE_EVENT_H */