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