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 file is released under the GPLv2.
10 * See the file COPYING for more details.
13 #ifndef _LINUX_MARKER_H
14 #define _LINUX_MARKER_H
17 //ust// #include <linux/types.h>
18 #include "immediate.h"
19 //ust// #include <linux/ltt-channels.h>
20 #include "kernelcompat.h"
22 #include <kcompat/list.h>
24 //ust// struct module;
25 //ust// struct task_struct;
29 * marker_probe_func - Type of a marker probe function
31 * @probe_private: probe private data
32 * @call_private: call site private data
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.
38 * Type of marker probe functions. They receive the mdata and need to parse the
39 * format string to recover the variable argument list.
41 typedef void marker_probe_func(const struct marker
*mdata
,
42 void *probe_private
, void *call_private
,
43 const char *fmt
, va_list *args
);
45 struct marker_probe_closure
{
46 marker_probe_func
*func
; /* Callback */
47 void *probe_private
; /* Private probe data */
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.
56 DEFINE_IMV(char, state
);/* Immediate value state. */
57 char ptype
; /* probe type : 0 : single, 1 : multi */
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)));
68 #define CONFIG_MARKERS
71 #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \
72 static const char __mstrtab_##channel##_##name[] \
73 __attribute__((section("__markers_strings"))) \
74 = #channel "\0" #name "\0" format; \
75 static struct marker __mark_##channel##_##name \
76 __attribute__((section("__markers"), aligned(8))) = \
77 { __mstrtab_##channel##_##name, \
78 &__mstrtab_##channel##_##name[sizeof(#channel)], \
79 &__mstrtab_##channel##_##name[sizeof(#channel) + \
81 0, 0, 0, 0, marker_probe_cb, \
82 { __mark_empty_function, NULL}, \
83 NULL, tp_name_str, tp_cb }
85 #define DEFINE_MARKER(channel, name, format) \
86 _DEFINE_MARKER(channel, name, NULL, NULL, format)
88 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
89 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
92 * Make sure the alignment of the structure in the __markers section will
93 * not add unwanted padding between the beginning of the section and the
94 * structure. Force alignment to the same alignment as the section start.
96 * The "generic" argument controls which marker enabling mechanism must be used.
97 * If generic is true, a variable read is used.
98 * If generic is false, immediate values are used.
100 #define __trace_mark(generic, channel, name, call_private, format, args...) \
102 DEFINE_MARKER(channel, name, format); \
103 __mark_check_format(format, ## args); \
105 if (unlikely(imv_read( \
106 __mark_##channel##_##name.state))) \
107 (*__mark_##channel##_##name.call) \
108 (&__mark_##channel##_##name, \
109 call_private, ## args); \
111 if (unlikely(_imv_read( \
112 __mark_##channel##_##name.state))) \
113 (*__mark_##channel##_##name.call) \
114 (&__mark_##channel##_##name, \
115 call_private, ## args); \
119 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
122 void __check_tp_type(void) \
124 register_trace_##tp_name(tp_cb); \
126 DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
127 __mark_check_format(format, ## args); \
128 (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \
129 call_private, ## args); \
132 extern void marker_update_probe_range(struct marker
*begin
,
135 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
137 #else /* !CONFIG_MARKERS */
138 #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format)
139 #define __trace_mark(generic, channel, name, call_private, format, args...) \
140 __mark_check_format(format, ## args)
141 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
144 void __check_tp_type(void) \
146 register_trace_##tp_name(tp_cb); \
148 __mark_check_format(format, ## args); \
150 static inline void marker_update_probe_range(struct marker
*begin
,
153 #define GET_MARKER(channel, name)
154 #endif /* CONFIG_MARKERS */
157 * trace_mark - Marker using code patching
158 * @channel: marker channel (where to send the data), not quoted.
159 * @name: marker name, not quoted.
160 * @format: format string
161 * @args...: variable argument list
163 * Places a marker using optimized code patching technique (imv_read())
164 * to be enabled when immediate values are present.
166 #define trace_mark(channel, name, format, args...) \
167 __trace_mark(0, channel, name, NULL, format, ## args)
170 * _trace_mark - Marker using variable read
171 * @channel: marker channel (where to send the data), not quoted.
172 * @name: marker name, not quoted.
173 * @format: format string
174 * @args...: variable argument list
176 * Places a marker using a standard memory read (_imv_read()) to be
177 * enabled. Should be used for markers in code paths where instruction
178 * modification based enabling is not welcome. (__init and __exit functions,
179 * lockdep, some traps, printk).
181 #define _trace_mark(channel, name, format, args...) \
182 __trace_mark(1, channel, name, NULL, format, ## args)
185 * trace_mark_tp - Marker in a tracepoint callback
186 * @channel: marker channel (where to send the data), not quoted.
187 * @name: marker name, not quoted.
188 * @tp_name: tracepoint name, not quoted.
189 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
190 * is not optimized away by the compiler (should not be static).
191 * @format: format string
192 * @args...: variable argument list
194 * Places a marker in a tracepoint callback.
196 #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
197 __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
200 * MARK_NOARGS - Format string for a marker with no argument.
202 #define MARK_NOARGS " "
204 extern void lock_markers(void);
205 extern void unlock_markers(void);
207 extern void markers_compact_event_ids(void);
209 /* To be used for string format validity checking with gcc */
210 static inline void __printf(1, 2) ___mark_check_format(const char *fmt
, ...)
214 #define __mark_check_format(format, args...) \
217 ___mark_check_format(format, ## args); \
220 extern marker_probe_func __mark_empty_function
;
222 extern void marker_probe_cb(const struct marker
*mdata
,
223 void *call_private
, ...);
226 * Connect a probe to a marker.
227 * private data pointer must be a valid allocated memory address, or NULL.
229 extern int marker_probe_register(const char *channel
, const char *name
,
230 const char *format
, marker_probe_func
*probe
, void *probe_private
);
233 * Returns the private data given to marker_probe_register.
235 extern int marker_probe_unregister(const char *channel
, const char *name
,
236 marker_probe_func
*probe
, void *probe_private
);
238 * Unregister a marker by providing the registered private data.
240 extern int marker_probe_unregister_private_data(marker_probe_func
*probe
,
241 void *probe_private
);
243 extern void *marker_get_private_data(const char *channel
, const char *name
,
244 marker_probe_func
*probe
, int num
);
247 * marker_synchronize_unregister must be called between the last marker probe
248 * unregistration and the first one of
249 * - the end of module exit function
250 * - the free of any resource used by the probes
251 * to ensure the code and data are valid for any possibly running probes.
253 #define marker_synchronize_unregister() synchronize_sched()
256 //ust// struct module *module;
258 struct marker
*marker
;
261 extern void marker_iter_start(struct marker_iter
*iter
);
262 extern void marker_iter_next(struct marker_iter
*iter
);
263 extern void marker_iter_stop(struct marker_iter
*iter
);
264 extern void marker_iter_reset(struct marker_iter
*iter
);
265 extern int marker_get_iter_range(struct marker
**marker
, struct marker
*begin
,
268 extern void marker_update_process(void);
269 extern int is_marker_enabled(const char *channel
, const char *name
);
271 //ust// #ifdef CONFIG_MARKERS_USERSPACE
272 //ust// extern void exit_user_markers(struct task_struct *p);
274 //ust// static inline void exit_user_markers(struct task_struct *p)
281 struct marker
*markers_start
;
283 struct list_head list
;
286 extern int marker_register_lib(struct marker
*markers_start
,
290 extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \
291 extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \
293 static void __attribute__((constructor)) __markers__init(void) \
295 marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\
298 void marker_set_new_marker_cb(void (*cb
)(struct marker
*));