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;
12 * version 2.1 of the License.
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
29 #include <urcu/list.h>
30 #include <ust/processor.h>
31 #include <ust/kcompat/kcompat.h>
32 #include <ust/kcompat/stringify.h>
34 #include <bits/wordsize.h>
39 * ust_marker_probe_func - Type of a marker probe function
41 * @probe_private: probe private data
42 * @call_private: call site private data
44 * @args: variable argument list pointer. Use a pointer to overcome C's
45 * inability to pass this around as a pointer in a portable manner in
46 * the callee otherwise.
48 * Type of marker probe functions. They receive the mdata and need to parse the
49 * format string to recover the variable argument list.
51 typedef void ust_marker_probe_func(const struct ust_marker
*mdata
,
52 void *probe_private
, struct registers
*regs
, void *call_private
,
53 const char *fmt
, va_list *args
);
55 struct ust_marker_probe_closure
{
56 ust_marker_probe_func
*func
; /* Callback */
57 void *probe_private
; /* Private probe data */
61 const char *channel
; /* Name of channel where to send data */
62 const char *name
; /* Marker name */
63 const char *format
; /* Marker format string, describing the
64 * variable argument list.
66 char state
; /* State. */
67 char ptype
; /* probe type : 0 : single, 1 : multi */
69 u16 channel_id
; /* Numeric channel identifier, dynamic */
70 u16 event_id
; /* Numeric event identifier, dynamic */
71 void (*call
)(const struct ust_marker
*mdata
, void *call_private
, struct registers
*regs
, ...);
72 struct ust_marker_probe_closure single
;
73 struct ust_marker_probe_closure
*multi
;
74 const char *tp_name
; /* Optional tracepoint name */
75 void *tp_cb
; /* Optional tracepoint callback */
76 void *location
; /* Address of marker in code */
79 #define GET_UST_MARKER(name) (__ust_marker_ust_##name)
81 #define _DEFINE_UST_MARKER(channel, name, tp_name_str, tp_cb, format, unique, m) \
82 struct registers __ust_marker_regs; \
84 /* This next asm has to be a basic inline asm (no input/output/clobber), \
85 * because it must not require %-sign escaping, as we most certainly \
86 * have some %-signs in the format string. \
89 /* We only define these symbols if they have not yet been defined. Indeed, \
90 * if two markers with the same channel/name are on the same line, they \
91 * will try to create the same symbols, resulting in a conflict. This \
92 * is not unusual as it can be the result of function inlining. \
94 ".ifndef __mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) "\n\t" \
95 /*".section __ust_marker_strings\n\t"*/ \
96 ".section __ust_marker_strings,\"aw\"\n\t" \
97 "__mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) ":\n\t" \
98 ".string \"" __stringify(channel) "\"\n\t" \
99 "__mstrtab_" __stringify(channel) "_" __stringify(name) "_name_" __stringify(unique) ":\n\t" \
100 ".string \"" __stringify(name) "\"\n\t" \
101 "__mstrtab_" __stringify(channel) "_" __stringify(name) "_format_" __stringify(unique) ":\n\t" \
102 ".string " "\"" format "\"" "\n\t" \
107 /*".section __ust_marker\n\t"*/ \
108 ".section __ust_marker,\"aw\"\n\t" \
110 _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_channel_" __stringify(unique) ")\n\t" /* channel string */ \
111 _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_name_" __stringify(unique) ")\n\t" /* name string */ \
112 _ASM_PTR "(__mstrtab_" __stringify(channel) "_" __stringify(name) "_format_" __stringify(unique) ")\n\t" /* format string */ \
113 ".byte 0\n\t" /* state imv */ \
114 ".byte 0\n\t" /* ptype */ \
115 ".hword 0\n\t" /* channel_id */ \
116 ".hword 0\n\t" /* event_id */ \
117 ".balign " __stringify(__WORDSIZE) " / 8\n\t" /* alignment */ \
118 _ASM_PTR "(ust_marker_probe_cb)\n\t" /* call */ \
119 _ASM_PTR "(__ust_marker_empty_function)\n\t" /* ust_marker_probe_closure single.field1 */ \
120 _ASM_PTR "0\n\t" /* ust_marker_probe_closure single.field2 */ \
121 _ASM_PTR "0\n\t" /* ust_marker_probe_closure *multi */ \
122 _ASM_PTR "0\n\t" /* tp_name */ \
123 _ASM_PTR "0\n\t" /* tp_cb */ \
124 _ASM_PTR "(1f)\n\t" /* location */ \
126 /*".section __ust_marker_ptrs\n\t"*/ \
127 ".section __ust_marker_ptrs,\"aw\"\n\t" \
128 _ASM_PTR "(2b)\n\t" \
131 ARCH_COPY_ADDR("%[outptr]") \
132 : [outptr] "=r" (m) ); \
134 save_registers(&__ust_marker_regs)
137 #define DEFINE_UST_MARKER(name, format, unique, m) \
138 _DEFINE_UST_MARKER(ust, name, NULL, NULL, format, unique, m)
140 #define DEFINE_UST_MARKER_TP(name, tp_name, tp_cb, format) \
141 _DEFINE_UST_MARKER_TP(ust, name, #tp_name, tp_cb, format)
143 #define _DEFINE_UST_MARKER_TP(channel, name, tp_name_str, tp_cb, format)\
144 static const char __mstrtab_##channel##_##name[] \
145 __attribute__((section("__ust_marker_strings"))) \
146 = #channel "\0" #name "\0" format; \
147 static struct ust_marker __ust_marker_##channel##_##name\
148 __attribute__((section("__ust_marker"))) = \
149 { __mstrtab_##channel##_##name, \
150 &__mstrtab_##channel##_##name[sizeof(#channel)],\
151 &__mstrtab_##channel##_##name[sizeof(#channel) + sizeof(#name)], \
152 0, 0, 0, 0, ust_marker_probe_cb, \
153 { __ust_marker_empty_function, NULL}, \
154 NULL, tp_name_str, tp_cb }; \
155 static struct ust_marker * const __ust_marker_ptr_##channel##_##name \
156 __attribute__((used, section("__ust_marker_ptrs"))) = \
157 &__ust_marker_##channel##_##name;
160 * Make sure the alignment of the structure in the __ust_marker section will
161 * not add unwanted padding between the beginning of the section and the
162 * structure. Force alignment to the same alignment as the section start.
165 #define __ust_marker(channel, name, call_private, format, args...) \
166 __ust_marker_counter(channel, name, __LINE__, call_private, format, ## args)
168 #define __ust_marker_counter(channel, name, unique, call_private, format, args...) \
170 struct ust_marker *__ust_marker_counter_ptr; \
171 _DEFINE_UST_MARKER(channel, name, NULL, NULL, format, unique, __ust_marker_counter_ptr); \
172 __ust_marker_check_format(format, ## args); \
173 if (unlikely(__ust_marker_counter_ptr->state)) \
174 (__ust_marker_counter_ptr->call)(__ust_marker_counter_ptr, call_private, &__ust_marker_regs, ## args); \
177 #define __ust_marker_tp(channel, name, call_private, tp_name, tp_cb, format, args...) \
178 __ust_marker_tp_counter(channel, name, __LINE__, call_private, tp_name, tp_cb, format, ## args)
180 #define __ust_marker_tp_counter(channel, name, unique, call_private, tp_name, tp_cb, format, args...) \
182 struct registers __ust_marker_regs; \
183 void __check_tp_type(void) \
185 register_trace_##tp_name(tp_cb, call_private); \
187 _DEFINE_UST_MARKER_TP(channel, name, #tp_name, tp_cb, format); \
188 __ust_marker_check_format(format, ## args); \
189 (*__ust_marker_##channel##_##name.call)(&__ust_marker_##channel##_##name, \
190 call_private, &__ust_marker_regs, ## args); \
193 extern void ust_marker_update_probe_range(struct ust_marker
* const *begin
,
194 struct ust_marker
* const *end
);
197 * ust_marker - Marker using code patching
198 * @name: marker name, not quoted.
199 * @format: format string
200 * @args...: variable argument list
202 * Places a marker at caller site.
204 #define ust_marker(name, format, args...) \
205 __ust_marker(ust, name, NULL, format, ## args)
209 * trace_mark() -- TO BE DEPRECATED
210 * @channel: name prefix, not quoted. Ignored.
211 * @name: marker name, not quoted.
212 * @format: format string
213 * @args...: variable argument list
215 * Kept as a compatibility API and will be *DEPRECATED* in favor of
218 #define trace_mark(channel, name, format, args...) \
219 ust_marker(name, format, ## args)
222 * ust_marker_tp - Marker in a tracepoint callback
223 * @name: marker name, not quoted.
224 * @tp_name: tracepoint name, not quoted.
225 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
226 * is not optimized away by the compiler (should not be static).
227 * @format: format string
228 * @args...: variable argument list
230 * Places a marker in a tracepoint callback.
232 #define ust_marker_tp(name, tp_name, tp_cb, format, args...) \
233 __ust_marker_tp(ust, name, NULL, tp_name, tp_cb, format, ## args)
236 * UST_MARKER_NOARGS - Format string for a marker with no argument.
238 #define UST_MARKER_NOARGS " "
241 * MARKER_NOARGS - Compatibility API. Will be *DEPRECATED*. Use
242 * UST_MARKER_NOARGS instead.
244 #define MARK_NOARGS UST_MARKER_NOARGS
246 extern void lock_ust_marker(void);
247 extern void unlock_ust_marker(void);
249 extern void ust_marker_compact_event_ids(void);
251 /* To be used for string format validity checking with gcc */
252 static inline void __printf(1, 2) ___ust_marker_check_format(const char *fmt
, ...)
256 #define __ust_marker_check_format(format, args...) \
259 ___ust_marker_check_format(format, ## args); \
262 extern ust_marker_probe_func __ust_marker_empty_function
;
264 extern void ust_marker_probe_cb(const struct ust_marker
*mdata
,
265 void *call_private
, struct registers
*regs
, ...);
268 * Connect a probe to a marker.
269 * private data pointer must be a valid allocated memory address, or NULL.
271 extern int ust_marker_probe_register(const char *channel
, const char *name
,
272 const char *format
, ust_marker_probe_func
*probe
, void *probe_private
);
275 * Returns the private data given to ust_marker_probe_register.
277 extern int ust_marker_probe_unregister(const char *channel
, const char *name
,
278 ust_marker_probe_func
*probe
, void *probe_private
);
280 * Unregister a marker by providing the registered private data.
282 extern int ust_marker_probe_unregister_private_data(ust_marker_probe_func
*probe
,
283 void *probe_private
);
285 extern void *ust_marker_get_private_data(const char *channel
, const char *name
,
286 ust_marker_probe_func
*probe
, int num
);
289 * ust_marker_synchronize_unregister must be called between the last marker probe
290 * unregistration and the first one of
291 * - the end of module exit function
292 * - the free of any resource used by the probes
293 * to ensure the code and data are valid for any possibly running probes.
295 #define ust_marker_synchronize_unregister() synchronize_sched()
297 struct ust_marker_iter
{
298 //ust// struct module *module;
299 struct ust_marker_lib
*lib
;
300 struct ust_marker
* const *ust_marker
;
303 extern void ust_marker_iter_start(struct ust_marker_iter
*iter
);
304 extern void ust_marker_iter_next(struct ust_marker_iter
*iter
);
305 extern void ust_marker_iter_stop(struct ust_marker_iter
*iter
);
306 extern void ust_marker_iter_reset(struct ust_marker_iter
*iter
);
307 extern int ust_marker_get_iter_range(struct ust_marker
* const **marker
, struct ust_marker
* const *begin
,
308 struct ust_marker
* const *end
);
310 extern void ust_marker_update_process(void);
311 extern int is_ust_marker_enabled(const char *channel
, const char *name
);
313 //ust// #ifdef CONFIG_UST_MARKER_USERSPACE
314 //ust// extern void exit_user_ust_marker(struct task_struct *p);
316 //ust// static inline void exit_user_ust_marker(struct task_struct *p)
321 struct ust_marker_addr
{
322 struct ust_marker
*marker
;
326 struct ust_marker_lib
{
327 struct ust_marker
* const *ust_marker_start
;
328 #ifdef CONFIG_UST_GDB_INTEGRATION
329 struct ust_marker_addr
*ust_marker_addr_start
;
331 int ust_marker_count
;
332 struct cds_list_head list
;
335 extern int ust_marker_register_lib(struct ust_marker
* const *ust_marker_start
, int ust_marker_count
);
336 extern int ust_marker_unregister_lib(struct ust_marker
* const *ust_marker_start
);
338 #define UST_MARKER_LIB \
339 extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
340 extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \
341 static struct ust_marker * const __ust_marker_ptr_dummy \
342 __attribute__((used, section("__ust_marker_ptrs"))) = NULL;\
344 static void __attribute__((constructor)) __ust_marker__init(void) \
346 ust_marker_register_lib(__start___ust_marker_ptrs, \
347 __stop___ust_marker_ptrs \
348 - __start___ust_marker_ptrs); \
351 static void __attribute__((destructor)) __ust_marker__destroy(void)\
353 ust_marker_unregister_lib(__start___ust_marker_ptrs); \
356 extern void ust_marker_set_new_ust_marker_cb(void (*cb
)(struct ust_marker
*));
357 extern void init_ust_marker(void);
359 #endif /* _UST_MARKER_H */