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