Merge branch 'for-pierre-marc' of git://git.infradead.org/users/jblunck/ust
[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 _LINUX_MARKER_H
25 #define _LINUX_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 "processor.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, struct registers *regs, 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, struct registers *regs, ...);
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 void *location; /* Address of marker in code */
78 } __attribute__((aligned(8)));
79
80 #define CONFIG_MARKERS
81 #ifdef CONFIG_MARKERS
82
83 #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \
84 static const char __mstrtab_##channel##_##name[] \
85 __attribute__((section("__markers_strings"))) \
86 = #channel "\0" #name "\0" format; \
87 struct registers regs; \
88 static struct marker __mark_##channel##_##name \
89 __attribute__((section("__markers"), aligned(8))) = \
90 { __mstrtab_##channel##_##name, \
91 &__mstrtab_##channel##_##name[sizeof(#channel)], \
92 &__mstrtab_##channel##_##name[sizeof(#channel) + \
93 sizeof(#name)], \
94 0, 0, 0, 0, marker_probe_cb, \
95 { __mark_empty_function, NULL}, \
96 NULL, tp_name_str, tp_cb, NULL }; \
97 asm (".section __marker_addr,\"aw\",@progbits\n\t" \
98 _ASM_PTR "%c[marker_struct], (1f)\n\t" \
99 ".previous\n\t" \
100 "1:\n\t" \
101 :: [marker_struct] "i" (&__mark_##channel##_##name));\
102 save_registers(&regs)
103
104
105
106 #define DEFINE_MARKER(channel, name, format) \
107 _DEFINE_MARKER(channel, name, NULL, NULL, format)
108
109 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
110 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
111
112 /*
113 * Make sure the alignment of the structure in the __markers section will
114 * not add unwanted padding between the beginning of the section and the
115 * structure. Force alignment to the same alignment as the section start.
116 *
117 * The "generic" argument controls which marker enabling mechanism must be used.
118 * If generic is true, a variable read is used.
119 * If generic is false, immediate values are used.
120 */
121 #define __trace_mark(generic, channel, name, call_private, format, args...) \
122 do { \
123 DEFINE_MARKER(channel, name, format); \
124 __mark_check_format(format, ## args); \
125 if (!generic) { \
126 if (unlikely(imv_read( \
127 __mark_##channel##_##name.state))) \
128 (*__mark_##channel##_##name.call) \
129 (&__mark_##channel##_##name, \
130 call_private, &regs, ## args); \
131 } else { \
132 if (unlikely(_imv_read( \
133 __mark_##channel##_##name.state))) \
134 (*__mark_##channel##_##name.call) \
135 (&__mark_##channel##_##name, \
136 call_private, &regs, ## args); \
137 } \
138 } while (0)
139
140 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
141 format, args...) \
142 do { \
143 void __check_tp_type(void) \
144 { \
145 register_trace_##tp_name(tp_cb); \
146 } \
147 DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
148 __mark_check_format(format, ## args); \
149 (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \
150 call_private, &regs, ## args); \
151 } while (0)
152
153 extern void marker_update_probe_range(struct marker *begin,
154 struct marker *end);
155
156 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
157
158 #else /* !CONFIG_MARKERS */
159 #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format)
160 #define __trace_mark(generic, channel, name, call_private, format, args...) \
161 __mark_check_format(format, ## args)
162 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
163 format, args...) \
164 do { \
165 void __check_tp_type(void) \
166 { \
167 register_trace_##tp_name(tp_cb); \
168 } \
169 __mark_check_format(format, ## args); \
170 } while (0)
171 static inline void marker_update_probe_range(struct marker *begin,
172 struct marker *end)
173 { }
174 #define GET_MARKER(channel, name)
175 #endif /* CONFIG_MARKERS */
176
177 /**
178 * trace_mark - Marker using code patching
179 * @channel: marker channel (where to send the data), not quoted.
180 * @name: marker name, not quoted.
181 * @format: format string
182 * @args...: variable argument list
183 *
184 * Places a marker using optimized code patching technique (imv_read())
185 * to be enabled when immediate values are present.
186 */
187 #define trace_mark(channel, name, format, args...) \
188 __trace_mark(0, channel, name, NULL, format, ## args)
189
190 /**
191 * _trace_mark - Marker using variable read
192 * @channel: marker channel (where to send the data), not quoted.
193 * @name: marker name, not quoted.
194 * @format: format string
195 * @args...: variable argument list
196 *
197 * Places a marker using a standard memory read (_imv_read()) to be
198 * enabled. Should be used for markers in code paths where instruction
199 * modification based enabling is not welcome. (__init and __exit functions,
200 * lockdep, some traps, printk).
201 */
202 #define _trace_mark(channel, name, format, args...) \
203 __trace_mark(1, channel, name, NULL, format, ## args)
204
205 /**
206 * trace_mark_tp - Marker in a tracepoint callback
207 * @channel: marker channel (where to send the data), not quoted.
208 * @name: marker name, not quoted.
209 * @tp_name: tracepoint name, not quoted.
210 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
211 * is not optimized away by the compiler (should not be static).
212 * @format: format string
213 * @args...: variable argument list
214 *
215 * Places a marker in a tracepoint callback.
216 */
217 #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
218 __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
219
220 /**
221 * MARK_NOARGS - Format string for a marker with no argument.
222 */
223 #define MARK_NOARGS " "
224
225 extern void lock_markers(void);
226 extern void unlock_markers(void);
227
228 extern void markers_compact_event_ids(void);
229
230 /* To be used for string format validity checking with gcc */
231 static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
232 {
233 }
234
235 #define __mark_check_format(format, args...) \
236 do { \
237 if (0) \
238 ___mark_check_format(format, ## args); \
239 } while (0)
240
241 extern marker_probe_func __mark_empty_function;
242
243 extern void marker_probe_cb(const struct marker *mdata,
244 void *call_private, struct registers *regs, ...);
245
246 /*
247 * Connect a probe to a marker.
248 * private data pointer must be a valid allocated memory address, or NULL.
249 */
250 extern int marker_probe_register(const char *channel, const char *name,
251 const char *format, marker_probe_func *probe, void *probe_private);
252
253 /*
254 * Returns the private data given to marker_probe_register.
255 */
256 extern int marker_probe_unregister(const char *channel, const char *name,
257 marker_probe_func *probe, void *probe_private);
258 /*
259 * Unregister a marker by providing the registered private data.
260 */
261 extern int marker_probe_unregister_private_data(marker_probe_func *probe,
262 void *probe_private);
263
264 extern void *marker_get_private_data(const char *channel, const char *name,
265 marker_probe_func *probe, int num);
266
267 /*
268 * marker_synchronize_unregister must be called between the last marker probe
269 * unregistration and the first one of
270 * - the end of module exit function
271 * - the free of any resource used by the probes
272 * to ensure the code and data are valid for any possibly running probes.
273 */
274 #define marker_synchronize_unregister() synchronize_sched()
275
276 struct marker_iter {
277 //ust// struct module *module;
278 struct lib *lib;
279 struct marker *marker;
280 };
281
282 extern void marker_iter_start(struct marker_iter *iter);
283 extern void marker_iter_next(struct marker_iter *iter);
284 extern void marker_iter_stop(struct marker_iter *iter);
285 extern void marker_iter_reset(struct marker_iter *iter);
286 extern int marker_get_iter_range(struct marker **marker, struct marker *begin,
287 struct marker *end);
288
289 extern void marker_update_process(void);
290 extern int is_marker_enabled(const char *channel, const char *name);
291
292 //ust// #ifdef CONFIG_MARKERS_USERSPACE
293 //ust// extern void exit_user_markers(struct task_struct *p);
294 //ust// #else
295 //ust// static inline void exit_user_markers(struct task_struct *p)
296 //ust// {
297 //ust// }
298 //ust// #endif
299
300 struct marker_addr {
301 struct marker *marker;
302 void *addr;
303 };
304
305 struct lib {
306 struct marker *markers_start;
307 struct marker_addr *markers_addr_start;
308 int markers_count;
309 struct list_head list;
310 };
311
312 extern int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count);
313
314 #define MARKER_LIB \
315 extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \
316 extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \
317 extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden"))); \
318 extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden"))); \
319 \
320 static void __attribute__((constructor)) __markers__init(void) \
321 { \
322 marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \
323 }
324
325 extern void marker_set_new_marker_cb(void (*cb)(struct marker *));
326 extern void init_markers(void);
327
328 #endif
This page took 0.03612 seconds and 4 git commands to generate.