bonding: process the err returned by dev_set_allmulti properly in bond_enslave
[pandora-kernel.git] / include / linux / tracepoint.h
1 #ifndef _LINUX_TRACEPOINT_H
2 #define _LINUX_TRACEPOINT_H
3
4 /*
5  * Kernel Tracepoint API.
6  *
7  * See Documentation/trace/tracepoints.txt.
8  *
9  * (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
10  *
11  * Heavily inspired from the Linux Kernel Markers.
12  *
13  * This file is released under the GPLv2.
14  * See the file COPYING for more details.
15  */
16
17 #include <linux/smp.h>
18 #include <linux/errno.h>
19 #include <linux/types.h>
20 #include <linux/cpumask.h>
21 #include <linux/rcupdate.h>
22 #include <linux/jump_label.h>
23
24 struct module;
25 struct tracepoint;
26
27 struct tracepoint_func {
28         void *func;
29         void *data;
30 };
31
32 struct tracepoint {
33         const char *name;               /* Tracepoint name */
34         struct jump_label_key key;
35         void (*regfunc)(void);
36         void (*unregfunc)(void);
37         struct tracepoint_func __rcu *funcs;
38 };
39
40 /*
41  * Connect a probe to a tracepoint.
42  * Internal API, should not be used directly.
43  */
44 extern int tracepoint_probe_register(const char *name, void *probe, void *data);
45
46 /*
47  * Disconnect a probe from a tracepoint.
48  * Internal API, should not be used directly.
49  */
50 extern int
51 tracepoint_probe_unregister(const char *name, void *probe, void *data);
52
53 extern int tracepoint_probe_register_noupdate(const char *name, void *probe,
54                                               void *data);
55 extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
56                                                 void *data);
57 extern void tracepoint_probe_update_all(void);
58
59 #ifdef CONFIG_MODULES
60 struct tp_module {
61         struct list_head list;
62         unsigned int num_tracepoints;
63         struct tracepoint * const *tracepoints_ptrs;
64 };
65 bool trace_module_has_bad_taint(struct module *mod);
66 #else
67 static inline bool trace_module_has_bad_taint(struct module *mod)
68 {
69         return false;
70 }
71 #endif /* CONFIG_MODULES */
72
73 struct tracepoint_iter {
74 #ifdef CONFIG_MODULES
75         struct tp_module *module;
76 #endif /* CONFIG_MODULES */
77         struct tracepoint * const *tracepoint;
78 };
79
80 extern void tracepoint_iter_start(struct tracepoint_iter *iter);
81 extern void tracepoint_iter_next(struct tracepoint_iter *iter);
82 extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
83 extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
84
85 /*
86  * tracepoint_synchronize_unregister must be called between the last tracepoint
87  * probe unregistration and the end of module exit to make sure there is no
88  * caller executing a probe when it is freed.
89  */
90 static inline void tracepoint_synchronize_unregister(void)
91 {
92         synchronize_sched();
93 }
94
95 #define PARAMS(args...) args
96
97 #endif /* _LINUX_TRACEPOINT_H */
98
99 /*
100  * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include
101  *  file ifdef protection.
102  *  This is due to the way trace events work. If a file includes two
103  *  trace event headers under one "CREATE_TRACE_POINTS" the first include
104  *  will override the TRACE_EVENT and break the second include.
105  */
106
107 #ifndef DECLARE_TRACE
108
109 #define TP_PROTO(args...)       args
110 #define TP_ARGS(args...)        args
111 #define TP_CONDITION(args...)   args
112
113 #ifdef CONFIG_TRACEPOINTS
114
115 /*
116  * it_func[0] is never NULL because there is at least one element in the array
117  * when the array itself is non NULL.
118  *
119  * Note, the proto and args passed in includes "__data" as the first parameter.
120  * The reason for this is to handle the "void" prototype. If a tracepoint
121  * has a "void" prototype, then it is invalid to declare a function
122  * as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
123  * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
124  */
125 #define __DO_TRACE(tp, proto, args, cond)                               \
126         do {                                                            \
127                 struct tracepoint_func *it_func_ptr;                    \
128                 void *it_func;                                          \
129                 void *__data;                                           \
130                                                                         \
131                 if (!cpu_online(raw_smp_processor_id()))                \
132                         return;                                         \
133                                                                         \
134                 if (!(cond))                                            \
135                         return;                                         \
136                 rcu_read_lock_sched_notrace();                          \
137                 it_func_ptr = rcu_dereference_sched((tp)->funcs);       \
138                 if (it_func_ptr) {                                      \
139                         do {                                            \
140                                 it_func = (it_func_ptr)->func;          \
141                                 __data = (it_func_ptr)->data;           \
142                                 ((void(*)(proto))(it_func))(args);      \
143                         } while ((++it_func_ptr)->func);                \
144                 }                                                       \
145                 rcu_read_unlock_sched_notrace();                        \
146         } while (0)
147
148 /*
149  * Make sure the alignment of the structure in the __tracepoints section will
150  * not add unwanted padding between the beginning of the section and the
151  * structure. Force alignment to the same alignment as the section start.
152  */
153 #define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
154         extern struct tracepoint __tracepoint_##name;                   \
155         static inline void trace_##name(proto)                          \
156         {                                                               \
157                 if (static_branch(&__tracepoint_##name.key))            \
158                         __DO_TRACE(&__tracepoint_##name,                \
159                                 TP_PROTO(data_proto),                   \
160                                 TP_ARGS(data_args),                     \
161                                 TP_CONDITION(cond));                    \
162         }                                                               \
163         static inline int                                               \
164         register_trace_##name(void (*probe)(data_proto), void *data)    \
165         {                                                               \
166                 return tracepoint_probe_register(#name, (void *)probe,  \
167                                                  data);                 \
168         }                                                               \
169         static inline int                                               \
170         unregister_trace_##name(void (*probe)(data_proto), void *data)  \
171         {                                                               \
172                 return tracepoint_probe_unregister(#name, (void *)probe, \
173                                                    data);               \
174         }                                                               \
175         static inline void                                              \
176         check_trace_callback_type_##name(void (*cb)(data_proto))        \
177         {                                                               \
178         }
179
180 /*
181  * We have no guarantee that gcc and the linker won't up-align the tracepoint
182  * structures, so we create an array of pointers that will be used for iteration
183  * on the tracepoints.
184  */
185 #define DEFINE_TRACE_FN(name, reg, unreg)                                \
186         static const char __tpstrtab_##name[]                            \
187         __attribute__((section("__tracepoints_strings"))) = #name;       \
188         struct tracepoint __tracepoint_##name                            \
189         __attribute__((section("__tracepoints"))) =                      \
190                 { __tpstrtab_##name, JUMP_LABEL_INIT, reg, unreg, NULL };\
191         static struct tracepoint * const __tracepoint_ptr_##name __used  \
192         __attribute__((section("__tracepoints_ptrs"))) =                 \
193                 &__tracepoint_##name;
194
195 #define DEFINE_TRACE(name)                                              \
196         DEFINE_TRACE_FN(name, NULL, NULL);
197
198 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)                              \
199         EXPORT_SYMBOL_GPL(__tracepoint_##name)
200 #define EXPORT_TRACEPOINT_SYMBOL(name)                                  \
201         EXPORT_SYMBOL(__tracepoint_##name)
202
203 #else /* !CONFIG_TRACEPOINTS */
204 #define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
205         static inline void trace_##name(proto)                          \
206         { }                                                             \
207         static inline int                                               \
208         register_trace_##name(void (*probe)(data_proto),                \
209                               void *data)                               \
210         {                                                               \
211                 return -ENOSYS;                                         \
212         }                                                               \
213         static inline int                                               \
214         unregister_trace_##name(void (*probe)(data_proto),              \
215                                 void *data)                             \
216         {                                                               \
217                 return -ENOSYS;                                         \
218         }                                                               \
219         static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
220         {                                                               \
221         }
222
223 #define DEFINE_TRACE_FN(name, reg, unreg)
224 #define DEFINE_TRACE(name)
225 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
226 #define EXPORT_TRACEPOINT_SYMBOL(name)
227
228 #endif /* CONFIG_TRACEPOINTS */
229
230 /*
231  * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
232  * (void). "void" is a special value in a function prototype and can
233  * not be combined with other arguments. Since the DECLARE_TRACE()
234  * macro adds a data element at the beginning of the prototype,
235  * we need a way to differentiate "(void *data, proto)" from
236  * "(void *data, void)". The second prototype is invalid.
237  *
238  * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
239  * and "void *__data" as the callback prototype.
240  *
241  * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
242  * "void *__data, proto" as the callback prototype.
243  */
244 #define DECLARE_TRACE_NOARGS(name)                                      \
245                 __DECLARE_TRACE(name, void, , 1, void *__data, __data)
246
247 #define DECLARE_TRACE(name, proto, args)                                \
248                 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), 1,   \
249                                 PARAMS(void *__data, proto),            \
250                                 PARAMS(__data, args))
251
252 #define DECLARE_TRACE_CONDITION(name, proto, args, cond)                \
253         __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
254                         PARAMS(void *__data, proto),                    \
255                         PARAMS(__data, args))
256
257 #define TRACE_EVENT_FLAGS(event, flag)
258
259 #endif /* DECLARE_TRACE */
260
261 #ifndef TRACE_EVENT
262 /*
263  * For use with the TRACE_EVENT macro:
264  *
265  * We define a tracepoint, its arguments, its printk format
266  * and its 'fast binay record' layout.
267  *
268  * Firstly, name your tracepoint via TRACE_EVENT(name : the
269  * 'subsystem_event' notation is fine.
270  *
271  * Think about this whole construct as the
272  * 'trace_sched_switch() function' from now on.
273  *
274  *
275  *  TRACE_EVENT(sched_switch,
276  *
277  *      *
278  *      * A function has a regular function arguments
279  *      * prototype, declare it via TP_PROTO():
280  *      *
281  *
282  *      TP_PROTO(struct rq *rq, struct task_struct *prev,
283  *               struct task_struct *next),
284  *
285  *      *
286  *      * Define the call signature of the 'function'.
287  *      * (Design sidenote: we use this instead of a
288  *      *  TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
289  *      *
290  *
291  *      TP_ARGS(rq, prev, next),
292  *
293  *      *
294  *      * Fast binary tracing: define the trace record via
295  *      * TP_STRUCT__entry(). You can think about it like a
296  *      * regular C structure local variable definition.
297  *      *
298  *      * This is how the trace record is structured and will
299  *      * be saved into the ring buffer. These are the fields
300  *      * that will be exposed to user-space in
301  *      * /sys/kernel/debug/tracing/events/<*>/format.
302  *      *
303  *      * The declared 'local variable' is called '__entry'
304  *      *
305  *      * __field(pid_t, prev_prid) is equivalent to a standard declariton:
306  *      *
307  *      *       pid_t   prev_pid;
308  *      *
309  *      * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
310  *      *
311  *      *       char    prev_comm[TASK_COMM_LEN];
312  *      *
313  *
314  *      TP_STRUCT__entry(
315  *              __array(        char,   prev_comm,      TASK_COMM_LEN   )
316  *              __field(        pid_t,  prev_pid                        )
317  *              __field(        int,    prev_prio                       )
318  *              __array(        char,   next_comm,      TASK_COMM_LEN   )
319  *              __field(        pid_t,  next_pid                        )
320  *              __field(        int,    next_prio                       )
321  *      ),
322  *
323  *      *
324  *      * Assign the entry into the trace record, by embedding
325  *      * a full C statement block into TP_fast_assign(). You
326  *      * can refer to the trace record as '__entry' -
327  *      * otherwise you can put arbitrary C code in here.
328  *      *
329  *      * Note: this C code will execute every time a trace event
330  *      * happens, on an active tracepoint.
331  *      *
332  *
333  *      TP_fast_assign(
334  *              memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
335  *              __entry->prev_pid       = prev->pid;
336  *              __entry->prev_prio      = prev->prio;
337  *              memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
338  *              __entry->next_pid       = next->pid;
339  *              __entry->next_prio      = next->prio;
340  *      ),
341  *
342  *      *
343  *      * Formatted output of a trace record via TP_printk().
344  *      * This is how the tracepoint will appear under ftrace
345  *      * plugins that make use of this tracepoint.
346  *      *
347  *      * (raw-binary tracing wont actually perform this step.)
348  *      *
349  *
350  *      TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
351  *              __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
352  *              __entry->next_comm, __entry->next_pid, __entry->next_prio),
353  *
354  * );
355  *
356  * This macro construct is thus used for the regular printk format
357  * tracing setup, it is used to construct a function pointer based
358  * tracepoint callback (this is used by programmatic plugins and
359  * can also by used by generic instrumentation like SystemTap), and
360  * it is also used to expose a structured trace record in
361  * /sys/kernel/debug/tracing/events/.
362  *
363  * A set of (un)registration functions can be passed to the variant
364  * TRACE_EVENT_FN to perform any (un)registration work.
365  */
366
367 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
368 #define DEFINE_EVENT(template, name, proto, args)               \
369         DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
370 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)  \
371         DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
372 #define DEFINE_EVENT_CONDITION(template, name, proto,           \
373                                args, cond)                      \
374         DECLARE_TRACE_CONDITION(name, PARAMS(proto),            \
375                                 PARAMS(args), PARAMS(cond))
376
377 #define TRACE_EVENT(name, proto, args, struct, assign, print)   \
378         DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
379 #define TRACE_EVENT_FN(name, proto, args, struct,               \
380                 assign, print, reg, unreg)                      \
381         DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
382 #define TRACE_EVENT_CONDITION(name, proto, args, cond,          \
383                               struct, assign, print)            \
384         DECLARE_TRACE_CONDITION(name, PARAMS(proto),            \
385                                 PARAMS(args), PARAMS(cond))
386
387 #define TRACE_EVENT_FLAGS(event, flag)
388
389 #endif /* ifdef TRACE_EVENT (see note above) */