Commit | Line | Data |
---|---|---|
a72ca31a PMF |
1 | /* |
2 | * Code markup for dynamic and static tracing. | |
3 | * | |
4 | * See Documentation/marker.txt. | |
5 | * | |
6 | * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
59b161cd | 7 | * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca> |
a72ca31a | 8 | * |
8fc2d8db PMF |
9 | * This library is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License as published by the Free Software Foundation; either | |
12 | * version 2.1 of the License, or (at your option) any later version. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * Lesser General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Lesser General Public | |
20 | * License along with this library; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
a72ca31a PMF |
22 | */ |
23 | ||
e4621c7f PMF |
24 | #ifndef _LINUX_MARKER_H |
25 | #define _LINUX_MARKER_H | |
26 | ||
a72ca31a | 27 | #include <stdarg.h> |
59b161cd | 28 | //ust// #include <linux/types.h> |
93d0f2ea | 29 | #include <ust/immediate.h> |
59b161cd | 30 | //ust// #include <linux/ltt-channels.h> |
fbca6b62 | 31 | #include <ust/kernelcompat.h> |
769d0157 | 32 | #include <kcompat/list.h> |
59b161cd PMF |
33 | |
34 | //ust// struct module; | |
35 | //ust// struct task_struct; | |
a72ca31a PMF |
36 | struct marker; |
37 | ||
38 | /** | |
39 | * marker_probe_func - Type of a marker probe function | |
40 | * @mdata: marker data | |
41 | * @probe_private: probe private data | |
42 | * @call_private: call site private data | |
43 | * @fmt: format string | |
44 | * @args: variable argument list pointer. Use a pointer to overcome C's | |
45 | * inability to pass this around as a pointer in a portable manner in | |
46 | * the callee otherwise. | |
47 | * | |
48 | * Type of marker probe functions. They receive the mdata and need to parse the | |
49 | * format string to recover the variable argument list. | |
50 | */ | |
51 | typedef void marker_probe_func(const struct marker *mdata, | |
52 | void *probe_private, void *call_private, | |
53 | const char *fmt, va_list *args); | |
54 | ||
55 | struct marker_probe_closure { | |
56 | marker_probe_func *func; /* Callback */ | |
57 | void *probe_private; /* Private probe data */ | |
58 | }; | |
59 | ||
60 | struct marker { | |
61 | const char *channel; /* Name of channel where to send data */ | |
62 | const char *name; /* Marker name */ | |
63 | const char *format; /* Marker format string, describing the | |
64 | * variable argument list. | |
65 | */ | |
59b161cd | 66 | DEFINE_IMV(char, state);/* Immediate value state. */ |
a72ca31a PMF |
67 | char ptype; /* probe type : 0 : single, 1 : multi */ |
68 | /* Probe wrapper */ | |
69 | u16 channel_id; /* Numeric channel identifier, dynamic */ | |
70 | u16 event_id; /* Numeric event identifier, dynamic */ | |
71 | void (*call)(const struct marker *mdata, void *call_private, ...); | |
72 | struct marker_probe_closure single; | |
73 | struct marker_probe_closure *multi; | |
74 | const char *tp_name; /* Optional tracepoint name */ | |
75 | void *tp_cb; /* Optional tracepoint callback */ | |
76 | } __attribute__((aligned(8))); | |
77 | ||
872037bb PMF |
78 | #define CONFIG_MARKERS |
79 | #ifdef CONFIG_MARKERS | |
a72ca31a PMF |
80 | |
81 | #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \ | |
82 | static const char __mstrtab_##channel##_##name[] \ | |
83 | __attribute__((section("__markers_strings"))) \ | |
84 | = #channel "\0" #name "\0" format; \ | |
85 | static struct marker __mark_##channel##_##name \ | |
86 | __attribute__((section("__markers"), aligned(8))) = \ | |
87 | { __mstrtab_##channel##_##name, \ | |
88 | &__mstrtab_##channel##_##name[sizeof(#channel)], \ | |
89 | &__mstrtab_##channel##_##name[sizeof(#channel) + \ | |
90 | sizeof(#name)], \ | |
91 | 0, 0, 0, 0, marker_probe_cb, \ | |
92 | { __mark_empty_function, NULL}, \ | |
93 | NULL, tp_name_str, tp_cb } | |
94 | ||
95 | #define DEFINE_MARKER(channel, name, format) \ | |
96 | _DEFINE_MARKER(channel, name, NULL, NULL, format) | |
97 | ||
98 | #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \ | |
99 | _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format) | |
100 | ||
101 | /* | |
102 | * Make sure the alignment of the structure in the __markers section will | |
103 | * not add unwanted padding between the beginning of the section and the | |
104 | * structure. Force alignment to the same alignment as the section start. | |
105 | * | |
106 | * The "generic" argument controls which marker enabling mechanism must be used. | |
107 | * If generic is true, a variable read is used. | |
108 | * If generic is false, immediate values are used. | |
109 | */ | |
110 | #define __trace_mark(generic, channel, name, call_private, format, args...) \ | |
111 | do { \ | |
112 | DEFINE_MARKER(channel, name, format); \ | |
113 | __mark_check_format(format, ## args); \ | |
114 | if (!generic) { \ | |
115 | if (unlikely(imv_read( \ | |
116 | __mark_##channel##_##name.state))) \ | |
117 | (*__mark_##channel##_##name.call) \ | |
118 | (&__mark_##channel##_##name, \ | |
119 | call_private, ## args); \ | |
120 | } else { \ | |
121 | if (unlikely(_imv_read( \ | |
122 | __mark_##channel##_##name.state))) \ | |
123 | (*__mark_##channel##_##name.call) \ | |
124 | (&__mark_##channel##_##name, \ | |
125 | call_private, ## args); \ | |
126 | } \ | |
127 | } while (0) | |
128 | ||
129 | #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \ | |
130 | format, args...) \ | |
131 | do { \ | |
132 | void __check_tp_type(void) \ | |
133 | { \ | |
134 | register_trace_##tp_name(tp_cb); \ | |
135 | } \ | |
136 | DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\ | |
137 | __mark_check_format(format, ## args); \ | |
138 | (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \ | |
139 | call_private, ## args); \ | |
140 | } while (0) | |
141 | ||
142 | extern void marker_update_probe_range(struct marker *begin, | |
143 | struct marker *end); | |
144 | ||
145 | #define GET_MARKER(channel, name) (__mark_##channel##_##name) | |
146 | ||
872037bb PMF |
147 | #else /* !CONFIG_MARKERS */ |
148 | #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format) | |
149 | #define __trace_mark(generic, channel, name, call_private, format, args...) \ | |
150 | __mark_check_format(format, ## args) | |
151 | #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \ | |
152 | format, args...) \ | |
153 | do { \ | |
154 | void __check_tp_type(void) \ | |
155 | { \ | |
156 | register_trace_##tp_name(tp_cb); \ | |
157 | } \ | |
158 | __mark_check_format(format, ## args); \ | |
159 | } while (0) | |
160 | static inline void marker_update_probe_range(struct marker *begin, | |
161 | struct marker *end) | |
162 | { } | |
163 | #define GET_MARKER(channel, name) | |
164 | #endif /* CONFIG_MARKERS */ | |
a72ca31a PMF |
165 | |
166 | /** | |
167 | * trace_mark - Marker using code patching | |
168 | * @channel: marker channel (where to send the data), not quoted. | |
169 | * @name: marker name, not quoted. | |
170 | * @format: format string | |
171 | * @args...: variable argument list | |
172 | * | |
173 | * Places a marker using optimized code patching technique (imv_read()) | |
174 | * to be enabled when immediate values are present. | |
175 | */ | |
176 | #define trace_mark(channel, name, format, args...) \ | |
177 | __trace_mark(0, channel, name, NULL, format, ## args) | |
178 | ||
179 | /** | |
180 | * _trace_mark - Marker using variable read | |
181 | * @channel: marker channel (where to send the data), not quoted. | |
182 | * @name: marker name, not quoted. | |
183 | * @format: format string | |
184 | * @args...: variable argument list | |
185 | * | |
186 | * Places a marker using a standard memory read (_imv_read()) to be | |
187 | * enabled. Should be used for markers in code paths where instruction | |
188 | * modification based enabling is not welcome. (__init and __exit functions, | |
189 | * lockdep, some traps, printk). | |
190 | */ | |
191 | #define _trace_mark(channel, name, format, args...) \ | |
192 | __trace_mark(1, channel, name, NULL, format, ## args) | |
193 | ||
194 | /** | |
195 | * trace_mark_tp - Marker in a tracepoint callback | |
196 | * @channel: marker channel (where to send the data), not quoted. | |
197 | * @name: marker name, not quoted. | |
198 | * @tp_name: tracepoint name, not quoted. | |
199 | * @tp_cb: tracepoint callback. Should have an associated global symbol so it | |
200 | * is not optimized away by the compiler (should not be static). | |
201 | * @format: format string | |
202 | * @args...: variable argument list | |
203 | * | |
204 | * Places a marker in a tracepoint callback. | |
205 | */ | |
206 | #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \ | |
207 | __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args) | |
208 | ||
209 | /** | |
210 | * MARK_NOARGS - Format string for a marker with no argument. | |
211 | */ | |
212 | #define MARK_NOARGS " " | |
213 | ||
214 | extern void lock_markers(void); | |
215 | extern void unlock_markers(void); | |
216 | ||
217 | extern void markers_compact_event_ids(void); | |
218 | ||
219 | /* To be used for string format validity checking with gcc */ | |
220 | static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...) | |
221 | { | |
222 | } | |
223 | ||
224 | #define __mark_check_format(format, args...) \ | |
225 | do { \ | |
226 | if (0) \ | |
227 | ___mark_check_format(format, ## args); \ | |
228 | } while (0) | |
229 | ||
230 | extern marker_probe_func __mark_empty_function; | |
231 | ||
232 | extern void marker_probe_cb(const struct marker *mdata, | |
233 | void *call_private, ...); | |
234 | ||
235 | /* | |
236 | * Connect a probe to a marker. | |
237 | * private data pointer must be a valid allocated memory address, or NULL. | |
238 | */ | |
239 | extern int marker_probe_register(const char *channel, const char *name, | |
240 | const char *format, marker_probe_func *probe, void *probe_private); | |
241 | ||
242 | /* | |
243 | * Returns the private data given to marker_probe_register. | |
244 | */ | |
245 | extern int marker_probe_unregister(const char *channel, const char *name, | |
246 | marker_probe_func *probe, void *probe_private); | |
247 | /* | |
248 | * Unregister a marker by providing the registered private data. | |
249 | */ | |
250 | extern int marker_probe_unregister_private_data(marker_probe_func *probe, | |
251 | void *probe_private); | |
252 | ||
253 | extern void *marker_get_private_data(const char *channel, const char *name, | |
254 | marker_probe_func *probe, int num); | |
255 | ||
256 | /* | |
257 | * marker_synchronize_unregister must be called between the last marker probe | |
258 | * unregistration and the first one of | |
259 | * - the end of module exit function | |
260 | * - the free of any resource used by the probes | |
261 | * to ensure the code and data are valid for any possibly running probes. | |
262 | */ | |
263 | #define marker_synchronize_unregister() synchronize_sched() | |
264 | ||
265 | struct marker_iter { | |
98963de4 PMF |
266 | //ust// struct module *module; |
267 | struct lib *lib; | |
a72ca31a PMF |
268 | struct marker *marker; |
269 | }; | |
270 | ||
271 | extern void marker_iter_start(struct marker_iter *iter); | |
272 | extern void marker_iter_next(struct marker_iter *iter); | |
273 | extern void marker_iter_stop(struct marker_iter *iter); | |
274 | extern void marker_iter_reset(struct marker_iter *iter); | |
275 | extern int marker_get_iter_range(struct marker **marker, struct marker *begin, | |
276 | struct marker *end); | |
277 | ||
278 | extern void marker_update_process(void); | |
279 | extern int is_marker_enabled(const char *channel, const char *name); | |
280 | ||
59b161cd PMF |
281 | //ust// #ifdef CONFIG_MARKERS_USERSPACE |
282 | //ust// extern void exit_user_markers(struct task_struct *p); | |
283 | //ust// #else | |
284 | //ust// static inline void exit_user_markers(struct task_struct *p) | |
285 | //ust// { | |
286 | //ust// } | |
287 | //ust// #endif | |
a72ca31a | 288 | |
98963de4 PMF |
289 | |
290 | struct lib { | |
291 | struct marker *markers_start; | |
292 | int markers_count; | |
293 | struct list_head list; | |
294 | }; | |
295 | ||
872037bb PMF |
296 | extern int marker_register_lib(struct marker *markers_start, |
297 | int markers_count); | |
c463904d | 298 | |
872037bb PMF |
299 | #define MARKER_LIB \ |
300 | extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \ | |
fbd8191b PMF |
301 | extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \ |
302 | \ | |
303 | static void __attribute__((constructor)) __markers__init(void) \ | |
304 | { \ | |
c463904d PMF |
305 | marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\ |
306 | } | |
98963de4 | 307 | |
064842c6 PMF |
308 | extern void marker_set_new_marker_cb(void (*cb)(struct marker *)); |
309 | extern void init_markers(void); | |
9160b4e4 | 310 | |
474d745f | 311 | #endif |