tracepoints: Add check trace callback type
[deliverable/linux.git] / include / linux / tracepoint.h
CommitLineData
97e1c18e
MD
1#ifndef _LINUX_TRACEPOINT_H
2#define _LINUX_TRACEPOINT_H
3
4/*
5 * Kernel Tracepoint API.
6 *
8cd09a59 7 * See Documentation/trace/tracepoints.txt.
97e1c18e
MD
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/types.h>
18#include <linux/rcupdate.h>
19
20struct module;
21struct tracepoint;
22
23struct tracepoint {
24 const char *name; /* Tracepoint name */
25 int state; /* State. */
97419875
JS
26 void (*regfunc)(void);
27 void (*unregfunc)(void);
97e1c18e 28 void **funcs;
7e066fb8
MD
29} __attribute__((aligned(32))); /*
30 * Aligned on 32 bytes because it is
31 * globally visible and gcc happily
32 * align these on the structure size.
33 * Keep in sync with vmlinux.lds.h.
34 */
97e1c18e 35
2e26ca71
SR
36/*
37 * Connect a probe to a tracepoint.
38 * Internal API, should not be used directly.
39 */
40extern int tracepoint_probe_register(const char *name, void *probe);
41
42/*
43 * Disconnect a probe from a tracepoint.
44 * Internal API, should not be used directly.
45 */
46extern int tracepoint_probe_unregister(const char *name, void *probe);
47
48extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
49extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
50extern void tracepoint_probe_update_all(void);
51
52struct tracepoint_iter {
53 struct module *module;
54 struct tracepoint *tracepoint;
55};
56
57extern void tracepoint_iter_start(struct tracepoint_iter *iter);
58extern void tracepoint_iter_next(struct tracepoint_iter *iter);
59extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
60extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
61extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
62 struct tracepoint *begin, struct tracepoint *end);
63
64/*
65 * tracepoint_synchronize_unregister must be called between the last tracepoint
66 * probe unregistration and the end of module exit to make sure there is no
67 * caller executing a probe when it is freed.
68 */
69static inline void tracepoint_synchronize_unregister(void)
70{
71 synchronize_sched();
72}
73
74#define PARAMS(args...) args
75
76#ifdef CONFIG_TRACEPOINTS
77extern void tracepoint_update_probe_range(struct tracepoint *begin,
78 struct tracepoint *end);
79#else
80static inline void tracepoint_update_probe_range(struct tracepoint *begin,
81 struct tracepoint *end)
82{ }
83#endif /* CONFIG_TRACEPOINTS */
84
85#endif /* _LINUX_TRACEPOINT_H */
86
87/*
88 * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include
89 * file ifdef protection.
90 * This is due to the way trace events work. If a file includes two
91 * trace event headers under one "CREATE_TRACE_POINTS" the first include
92 * will override the TRACE_EVENT and break the second include.
93 */
94
ea20d929
SR
95#ifndef DECLARE_TRACE
96
2939b046 97#define TP_PROTO(args...) args
8cd09a59 98#define TP_ARGS(args...) args
97e1c18e
MD
99
100#ifdef CONFIG_TRACEPOINTS
101
102/*
103 * it_func[0] is never NULL because there is at least one element in the array
104 * when the array itself is non NULL.
105 */
106#define __DO_TRACE(tp, proto, args) \
107 do { \
108 void **it_func; \
109 \
da7b3eab 110 rcu_read_lock_sched_notrace(); \
7f5b7742 111 it_func = rcu_dereference_sched((tp)->funcs); \
97e1c18e
MD
112 if (it_func) { \
113 do { \
114 ((void(*)(proto))(*it_func))(args); \
115 } while (*(++it_func)); \
116 } \
da7b3eab 117 rcu_read_unlock_sched_notrace(); \
97e1c18e
MD
118 } while (0)
119
120/*
121 * Make sure the alignment of the structure in the __tracepoints section will
122 * not add unwanted padding between the beginning of the section and the
123 * structure. Force alignment to the same alignment as the section start.
124 */
97419875 125#define DECLARE_TRACE(name, proto, args) \
7e066fb8 126 extern struct tracepoint __tracepoint_##name; \
97e1c18e
MD
127 static inline void trace_##name(proto) \
128 { \
97e1c18e
MD
129 if (unlikely(__tracepoint_##name.state)) \
130 __DO_TRACE(&__tracepoint_##name, \
2939b046 131 TP_PROTO(proto), TP_ARGS(args)); \
97e1c18e
MD
132 } \
133 static inline int register_trace_##name(void (*probe)(proto)) \
134 { \
97419875 135 return tracepoint_probe_register(#name, (void *)probe); \
97e1c18e 136 } \
c420970e 137 static inline int unregister_trace_##name(void (*probe)(proto)) \
97e1c18e 138 { \
97419875 139 return tracepoint_probe_unregister(#name, (void *)probe);\
53da59aa
MD
140 } \
141 static inline void check_trace_callback_type_##name(void (*cb)(proto)) \
142 { \
97e1c18e
MD
143 }
144
97419875 145#define DEFINE_TRACE_FN(name, reg, unreg) \
7e066fb8
MD
146 static const char __tpstrtab_##name[] \
147 __attribute__((section("__tracepoints_strings"))) = #name; \
148 struct tracepoint __tracepoint_##name \
149 __attribute__((section("__tracepoints"), aligned(32))) = \
97419875
JS
150 { __tpstrtab_##name, 0, reg, unreg, NULL }
151
152#define DEFINE_TRACE(name) \
153 DEFINE_TRACE_FN(name, NULL, NULL);
7e066fb8
MD
154
155#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
156 EXPORT_SYMBOL_GPL(__tracepoint_##name)
157#define EXPORT_TRACEPOINT_SYMBOL(name) \
158 EXPORT_SYMBOL(__tracepoint_##name)
159
97e1c18e 160#else /* !CONFIG_TRACEPOINTS */
97419875 161#define DECLARE_TRACE(name, proto, args) \
97e1c18e
MD
162 static inline void _do_trace_##name(struct tracepoint *tp, proto) \
163 { } \
164 static inline void trace_##name(proto) \
165 { } \
166 static inline int register_trace_##name(void (*probe)(proto)) \
167 { \
168 return -ENOSYS; \
169 } \
c420970e
MD
170 static inline int unregister_trace_##name(void (*probe)(proto)) \
171 { \
172 return -ENOSYS; \
53da59aa
MD
173 } \
174 static inline void check_trace_callback_type_##name(void (*cb)(proto)) \
175 { \
c420970e 176 }
97e1c18e 177
97419875 178#define DEFINE_TRACE_FN(name, reg, unreg)
7e066fb8
MD
179#define DEFINE_TRACE(name)
180#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
181#define EXPORT_TRACEPOINT_SYMBOL(name)
182
97e1c18e 183#endif /* CONFIG_TRACEPOINTS */
ea20d929 184#endif /* DECLARE_TRACE */
97e1c18e 185
ea20d929 186#ifndef TRACE_EVENT
823f9124
SR
187/*
188 * For use with the TRACE_EVENT macro:
189 *
190 * We define a tracepoint, its arguments, its printk format
191 * and its 'fast binay record' layout.
192 *
193 * Firstly, name your tracepoint via TRACE_EVENT(name : the
194 * 'subsystem_event' notation is fine.
195 *
196 * Think about this whole construct as the
197 * 'trace_sched_switch() function' from now on.
198 *
199 *
200 * TRACE_EVENT(sched_switch,
201 *
202 * *
203 * * A function has a regular function arguments
204 * * prototype, declare it via TP_PROTO():
205 * *
206 *
ef18012b
SR
207 * TP_PROTO(struct rq *rq, struct task_struct *prev,
208 * struct task_struct *next),
823f9124
SR
209 *
210 * *
211 * * Define the call signature of the 'function'.
212 * * (Design sidenote: we use this instead of a
213 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
214 * *
215 *
ef18012b 216 * TP_ARGS(rq, prev, next),
823f9124
SR
217 *
218 * *
219 * * Fast binary tracing: define the trace record via
220 * * TP_STRUCT__entry(). You can think about it like a
221 * * regular C structure local variable definition.
222 * *
223 * * This is how the trace record is structured and will
224 * * be saved into the ring buffer. These are the fields
225 * * that will be exposed to user-space in
156f5a78 226 * * /sys/kernel/debug/tracing/events/<*>/format.
823f9124
SR
227 * *
228 * * The declared 'local variable' is called '__entry'
229 * *
230 * * __field(pid_t, prev_prid) is equivalent to a standard declariton:
231 * *
232 * * pid_t prev_pid;
233 * *
234 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
235 * *
236 * * char prev_comm[TASK_COMM_LEN];
237 * *
238 *
239 * TP_STRUCT__entry(
240 * __array( char, prev_comm, TASK_COMM_LEN )
241 * __field( pid_t, prev_pid )
242 * __field( int, prev_prio )
243 * __array( char, next_comm, TASK_COMM_LEN )
244 * __field( pid_t, next_pid )
245 * __field( int, next_prio )
246 * ),
247 *
248 * *
249 * * Assign the entry into the trace record, by embedding
250 * * a full C statement block into TP_fast_assign(). You
251 * * can refer to the trace record as '__entry' -
252 * * otherwise you can put arbitrary C code in here.
253 * *
254 * * Note: this C code will execute every time a trace event
255 * * happens, on an active tracepoint.
256 * *
257 *
ef18012b
SR
258 * TP_fast_assign(
259 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
260 * __entry->prev_pid = prev->pid;
261 * __entry->prev_prio = prev->prio;
823f9124
SR
262 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
263 * __entry->next_pid = next->pid;
ef18012b 264 * __entry->next_prio = next->prio;
823f9124
SR
265 * )
266 *
267 * *
268 * * Formatted output of a trace record via TP_printk().
269 * * This is how the tracepoint will appear under ftrace
270 * * plugins that make use of this tracepoint.
271 * *
272 * * (raw-binary tracing wont actually perform this step.)
273 * *
274 *
275 * TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
276 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
277 * __entry->next_comm, __entry->next_pid, __entry->next_prio),
278 *
279 * );
280 *
281 * This macro construct is thus used for the regular printk format
282 * tracing setup, it is used to construct a function pointer based
283 * tracepoint callback (this is used by programmatic plugins and
284 * can also by used by generic instrumentation like SystemTap), and
285 * it is also used to expose a structured trace record in
156f5a78 286 * /sys/kernel/debug/tracing/events/.
97419875
JS
287 *
288 * A set of (un)registration functions can be passed to the variant
289 * TRACE_EVENT_FN to perform any (un)registration work.
823f9124
SR
290 */
291
091ad365 292#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
ff038f5c
SR
293#define DEFINE_EVENT(template, name, proto, args) \
294 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
e5bc9721
SR
295#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
296 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
ff038f5c 297
30a8fecc 298#define TRACE_EVENT(name, proto, args, struct, assign, print) \
da4d0302 299 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
97419875
JS
300#define TRACE_EVENT_FN(name, proto, args, struct, \
301 assign, print, reg, unreg) \
302 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
7cb2e3ee
SR
303
304#endif /* ifdef TRACE_EVENT (see note above) */
This page took 0.143228 seconds and 5 git commands to generate.