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