mm: move definition for LRU isolation modes to a header
[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);\
97e1c18e
MD
140 }
141
63fbdab3 142
97419875 143#define DEFINE_TRACE_FN(name, reg, unreg) \
7e066fb8
MD
144 static const char __tpstrtab_##name[] \
145 __attribute__((section("__tracepoints_strings"))) = #name; \
146 struct tracepoint __tracepoint_##name \
147 __attribute__((section("__tracepoints"), aligned(32))) = \
97419875
JS
148 { __tpstrtab_##name, 0, reg, unreg, NULL }
149
150#define DEFINE_TRACE(name) \
151 DEFINE_TRACE_FN(name, NULL, NULL);
7e066fb8
MD
152
153#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
154 EXPORT_SYMBOL_GPL(__tracepoint_##name)
155#define EXPORT_TRACEPOINT_SYMBOL(name) \
156 EXPORT_SYMBOL(__tracepoint_##name)
157
97e1c18e 158#else /* !CONFIG_TRACEPOINTS */
97419875 159#define DECLARE_TRACE(name, proto, args) \
97e1c18e
MD
160 static inline void _do_trace_##name(struct tracepoint *tp, proto) \
161 { } \
162 static inline void trace_##name(proto) \
163 { } \
164 static inline int register_trace_##name(void (*probe)(proto)) \
165 { \
166 return -ENOSYS; \
167 } \
c420970e
MD
168 static inline int unregister_trace_##name(void (*probe)(proto)) \
169 { \
170 return -ENOSYS; \
171 }
97e1c18e 172
97419875 173#define DEFINE_TRACE_FN(name, reg, unreg)
7e066fb8
MD
174#define DEFINE_TRACE(name)
175#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
176#define EXPORT_TRACEPOINT_SYMBOL(name)
177
97e1c18e 178#endif /* CONFIG_TRACEPOINTS */
ea20d929 179#endif /* DECLARE_TRACE */
97e1c18e 180
ea20d929 181#ifndef TRACE_EVENT
823f9124
SR
182/*
183 * For use with the TRACE_EVENT macro:
184 *
185 * We define a tracepoint, its arguments, its printk format
186 * and its 'fast binay record' layout.
187 *
188 * Firstly, name your tracepoint via TRACE_EVENT(name : the
189 * 'subsystem_event' notation is fine.
190 *
191 * Think about this whole construct as the
192 * 'trace_sched_switch() function' from now on.
193 *
194 *
195 * TRACE_EVENT(sched_switch,
196 *
197 * *
198 * * A function has a regular function arguments
199 * * prototype, declare it via TP_PROTO():
200 * *
201 *
ef18012b
SR
202 * TP_PROTO(struct rq *rq, struct task_struct *prev,
203 * struct task_struct *next),
823f9124
SR
204 *
205 * *
206 * * Define the call signature of the 'function'.
207 * * (Design sidenote: we use this instead of a
208 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
209 * *
210 *
ef18012b 211 * TP_ARGS(rq, prev, next),
823f9124
SR
212 *
213 * *
214 * * Fast binary tracing: define the trace record via
215 * * TP_STRUCT__entry(). You can think about it like a
216 * * regular C structure local variable definition.
217 * *
218 * * This is how the trace record is structured and will
219 * * be saved into the ring buffer. These are the fields
220 * * that will be exposed to user-space in
156f5a78 221 * * /sys/kernel/debug/tracing/events/<*>/format.
823f9124
SR
222 * *
223 * * The declared 'local variable' is called '__entry'
224 * *
225 * * __field(pid_t, prev_prid) is equivalent to a standard declariton:
226 * *
227 * * pid_t prev_pid;
228 * *
229 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
230 * *
231 * * char prev_comm[TASK_COMM_LEN];
232 * *
233 *
234 * TP_STRUCT__entry(
235 * __array( char, prev_comm, TASK_COMM_LEN )
236 * __field( pid_t, prev_pid )
237 * __field( int, prev_prio )
238 * __array( char, next_comm, TASK_COMM_LEN )
239 * __field( pid_t, next_pid )
240 * __field( int, next_prio )
241 * ),
242 *
243 * *
244 * * Assign the entry into the trace record, by embedding
245 * * a full C statement block into TP_fast_assign(). You
246 * * can refer to the trace record as '__entry' -
247 * * otherwise you can put arbitrary C code in here.
248 * *
249 * * Note: this C code will execute every time a trace event
250 * * happens, on an active tracepoint.
251 * *
252 *
ef18012b
SR
253 * TP_fast_assign(
254 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
255 * __entry->prev_pid = prev->pid;
256 * __entry->prev_prio = prev->prio;
823f9124
SR
257 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
258 * __entry->next_pid = next->pid;
ef18012b 259 * __entry->next_prio = next->prio;
823f9124
SR
260 * )
261 *
262 * *
263 * * Formatted output of a trace record via TP_printk().
264 * * This is how the tracepoint will appear under ftrace
265 * * plugins that make use of this tracepoint.
266 * *
267 * * (raw-binary tracing wont actually perform this step.)
268 * *
269 *
270 * TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
271 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
272 * __entry->next_comm, __entry->next_pid, __entry->next_prio),
273 *
274 * );
275 *
276 * This macro construct is thus used for the regular printk format
277 * tracing setup, it is used to construct a function pointer based
278 * tracepoint callback (this is used by programmatic plugins and
279 * can also by used by generic instrumentation like SystemTap), and
280 * it is also used to expose a structured trace record in
156f5a78 281 * /sys/kernel/debug/tracing/events/.
97419875
JS
282 *
283 * A set of (un)registration functions can be passed to the variant
284 * TRACE_EVENT_FN to perform any (un)registration work.
823f9124
SR
285 */
286
091ad365 287#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
ff038f5c
SR
288#define DEFINE_EVENT(template, name, proto, args) \
289 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
e5bc9721
SR
290#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
291 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
ff038f5c 292
30a8fecc 293#define TRACE_EVENT(name, proto, args, struct, assign, print) \
da4d0302 294 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
97419875
JS
295#define TRACE_EVENT_FN(name, proto, args, struct, \
296 assign, print, reg, unreg) \
297 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
7cb2e3ee
SR
298
299#endif /* ifdef TRACE_EVENT (see note above) */
This page took 0.150045 seconds and 5 git commands to generate.