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