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