2 * Code markup for dynamic and static tracing.
4 * See Documentation/marker.txt.
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>
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.
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.
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
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>
35 //ust// struct module;
36 //ust// struct task_struct;
39 /* To stringify the expansion of a define */
40 #define XSTR(d) STR(d)
44 * marker_probe_func - Type of a marker probe function
46 * @probe_private: probe private data
47 * @call_private: call site private data
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.
53 * Type of marker probe functions. They receive the mdata and need to parse the
54 * format string to recover the variable argument list.
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
);
60 struct marker_probe_closure
{
61 marker_probe_func
*func
; /* Callback */
62 void *probe_private
; /* Private probe data */
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.
71 DEFINE_IMV(char, state
);/* Immediate value state. */
72 char ptype
; /* probe type : 0 : single, 1 : multi */
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)));
84 #define CONFIG_MARKERS
87 #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format, unique) \
88 static const char __old_mstrtab_##channel##_##name[] \
89 __attribute__((section("__old_markers_strings"))) \
90 = #channel "\0" #name "\0" format; \
91 struct registers regs; \
92 static struct marker *__pmark_##channel##_##name; \
93 static struct marker __old_mark_##channel##_##name \
94 __attribute__((section("__old_markers"), aligned(8))) = \
95 { __old_mstrtab_##channel##_##name, \
96 &__old_mstrtab_##channel##_##name[sizeof(#channel)], \
97 &__old_mstrtab_##channel##_##name[sizeof(#channel) + \
99 0, 0, 0, 0, marker_probe_cb, \
100 { __mark_empty_function, NULL}, \
101 NULL, tp_name_str, tp_cb, NULL }; \
103 /* This next asm has to be a basic inline asm (no input/output/clobber), \
104 because it must not require %-sign escaping, as we most certainly \
105 have some %-signs in the format string. */ \
107 ".section __markers_strings,\"aw\",@progbits\n\t" \
108 "__mstrtab_" XSTR(channel) "_" XSTR(name) "_channel_" XSTR(unique) ":\n\t" \
109 ".string \"" XSTR(channel) "\"\n\t" \
110 "__mstrtab_" XSTR(channel) "_" XSTR(name) "_name_" XSTR(unique) ":\n\t" \
111 ".string \"" XSTR(name) "\"\n\t" \
112 "__mstrtab_" XSTR(channel) "_" XSTR(name) "_format_" XSTR(unique) ":\n\t" \
113 ".string " XSTR(format) "\n\t" \
115 ".section __markers,\"aw\",@progbits\n\t" \
117 "__mark_struct_" XSTR(unique) ":\n\t" \
118 _ASM_PTR "(__mstrtab_" XSTR(channel) "_" XSTR(name) "_channel_" XSTR(unique) ")\n\t" /* channel string */ \
119 _ASM_PTR "(__mstrtab_" XSTR(channel) "_" XSTR(name) "_name_" XSTR(unique) ")\n\t" /* name string */ \
120 _ASM_PTR "(__mstrtab_" XSTR(channel) "_" XSTR(name) "_format_" XSTR(unique) ")\n\t" /* format string */ \
121 ".byte 0\n\t" /* state imv */ \
122 ".byte 0\n\t" /* ptype */ \
123 ".word 0\n\t" /* channel_id */ \
124 ".word 0\n\t" /* event_id */ \
125 ".align " XSTR(__SIZEOF_POINTER__) "\n\t" /* alignment */ \
126 _ASM_PTR "(marker_probe_cb)\n\t" /* call */ \
127 _ASM_PTR "(__mark_empty_function)\n\t" /* marker_probe_closure single.field1 */ \
128 _ASM_PTR "0\n\t" /* marker_probe_closure single.field2 */ \
129 _ASM_PTR "0\n\t" /* marker_probe_closure *multi */ \
130 _ASM_PTR "0\n\t" /* tp_name */ \
131 _ASM_PTR "0\n\t" /* tp_cb */ \
132 "__mark_location_" XSTR(unique) ":\n\t" \
133 _ASM_PTR "(1f)\n\t" /* location */ \
138 "mov ""$__mark_struct_" XSTR(unique) ", %[pmark_struct]\n\t" \
139 : [pmark_struct] "=r" (__pmark_##channel##_##name) :: "memory" \
142 save_registers(®s)
145 #define DEFINE_MARKER(channel, name, format) \
146 _DEFINE_MARKER(channel, name, NULL, NULL, format, __COUNTER__)
148 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
149 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format, __COUNTER__)
152 * Make sure the alignment of the structure in the __markers section will
153 * not add unwanted padding between the beginning of the section and the
154 * structure. Force alignment to the same alignment as the section start.
156 * The "generic" argument controls which marker enabling mechanism must be used.
157 * If generic is true, a variable read is used.
158 * If generic is false, immediate values are used.
160 #define __trace_mark(generic, channel, name, call_private, format, args...) \
162 DEFINE_MARKER(channel, name, format); \
163 __mark_check_format(format, ## args); \
165 if (unlikely(imv_read( \
166 __pmark_##channel##_##name->state))) \
167 (*__pmark_##channel##_##name->call) \
168 (__pmark_##channel##_##name, \
169 call_private, ®s, ## args); \
171 if (unlikely(_imv_read( \
172 __pmark_##channel##_##name->state))) \
173 (__pmark_##channel##_##name->call) \
174 (__pmark_##channel##_##name, \
175 call_private, ®s, ## args); \
179 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
182 void __check_tp_type(void) \
184 register_trace_##tp_name(tp_cb); \
186 DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
187 __mark_check_format(format, ## args); \
188 (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \
189 call_private, ®s, ## args); \
192 extern void marker_update_probe_range(struct marker
*begin
,
195 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
197 #else /* !CONFIG_MARKERS */
198 #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format)
199 #define __trace_mark(generic, channel, name, call_private, format, args...) \
200 __mark_check_format(format, ## args)
201 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
204 void __check_tp_type(void) \
206 register_trace_##tp_name(tp_cb); \
208 __mark_check_format(format, ## args); \
210 static inline void marker_update_probe_range(struct marker
*begin
,
213 #define GET_MARKER(channel, name)
214 #endif /* CONFIG_MARKERS */
217 * trace_mark - Marker using code patching
218 * @channel: marker channel (where to send the data), not quoted.
219 * @name: marker name, not quoted.
220 * @format: format string
221 * @args...: variable argument list
223 * Places a marker using optimized code patching technique (imv_read())
224 * to be enabled when immediate values are present.
226 #define trace_mark(channel, name, format, args...) \
227 __trace_mark(0, channel, name, NULL, format, ## args)
230 * _trace_mark - Marker using variable read
231 * @channel: marker channel (where to send the data), not quoted.
232 * @name: marker name, not quoted.
233 * @format: format string
234 * @args...: variable argument list
236 * Places a marker using a standard memory read (_imv_read()) to be
237 * enabled. Should be used for markers in code paths where instruction
238 * modification based enabling is not welcome. (__init and __exit functions,
239 * lockdep, some traps, printk).
241 #define _trace_mark(channel, name, format, args...) \
242 __trace_mark(1, channel, name, NULL, format, ## args)
245 * trace_mark_tp - Marker in a tracepoint callback
246 * @channel: marker channel (where to send the data), not quoted.
247 * @name: marker name, not quoted.
248 * @tp_name: tracepoint name, not quoted.
249 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
250 * is not optimized away by the compiler (should not be static).
251 * @format: format string
252 * @args...: variable argument list
254 * Places a marker in a tracepoint callback.
256 #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
257 __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
260 * MARK_NOARGS - Format string for a marker with no argument.
262 #define MARK_NOARGS " "
264 extern void lock_markers(void);
265 extern void unlock_markers(void);
267 extern void markers_compact_event_ids(void);
269 /* To be used for string format validity checking with gcc */
270 static inline void __printf(1, 2) ___mark_check_format(const char *fmt
, ...)
274 #define __mark_check_format(format, args...) \
277 ___mark_check_format(format, ## args); \
280 extern marker_probe_func __mark_empty_function
;
282 extern void marker_probe_cb(const struct marker
*mdata
,
283 void *call_private
, struct registers
*regs
, ...);
286 * Connect a probe to a marker.
287 * private data pointer must be a valid allocated memory address, or NULL.
289 extern int marker_probe_register(const char *channel
, const char *name
,
290 const char *format
, marker_probe_func
*probe
, void *probe_private
);
293 * Returns the private data given to marker_probe_register.
295 extern int marker_probe_unregister(const char *channel
, const char *name
,
296 marker_probe_func
*probe
, void *probe_private
);
298 * Unregister a marker by providing the registered private data.
300 extern int marker_probe_unregister_private_data(marker_probe_func
*probe
,
301 void *probe_private
);
303 extern void *marker_get_private_data(const char *channel
, const char *name
,
304 marker_probe_func
*probe
, int num
);
307 * marker_synchronize_unregister must be called between the last marker probe
308 * unregistration and the first one of
309 * - the end of module exit function
310 * - the free of any resource used by the probes
311 * to ensure the code and data are valid for any possibly running probes.
313 #define marker_synchronize_unregister() synchronize_sched()
316 //ust// struct module *module;
318 struct marker
*marker
;
321 extern void marker_iter_start(struct marker_iter
*iter
);
322 extern void marker_iter_next(struct marker_iter
*iter
);
323 extern void marker_iter_stop(struct marker_iter
*iter
);
324 extern void marker_iter_reset(struct marker_iter
*iter
);
325 extern int marker_get_iter_range(struct marker
**marker
, struct marker
*begin
,
328 extern void marker_update_process(void);
329 extern int is_marker_enabled(const char *channel
, const char *name
);
331 //ust// #ifdef CONFIG_MARKERS_USERSPACE
332 //ust// extern void exit_user_markers(struct task_struct *p);
334 //ust// static inline void exit_user_markers(struct task_struct *p)
340 struct marker
*marker
;
345 struct marker
*markers_start
;
346 #ifdef CONFIG_UST_GDB_INTEGRATION
347 struct marker_addr
*markers_addr_start
;
350 struct list_head list
;
353 extern int marker_register_lib(struct marker
*markers_start
, int markers_count
);
356 extern struct marker __start___markers[] __attribute__((weak, visibility("hidden"))); \
357 extern struct marker __stop___markers[] __attribute__((weak, visibility("hidden"))); \
359 static void __attribute__((constructor)) __markers__init(void) \
361 marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \
364 extern void marker_set_new_marker_cb(void (*cb
)(struct marker
*));
365 extern void init_markers(void);
367 #endif /* _UST_MARKER_H */