1 #ifndef _LINUX_MARKER_H
2 #define _LINUX_MARKER_H
5 * Code markup for dynamic and static tracing.
7 * See Documentation/marker.txt.
9 * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
11 * This file is released under the GPLv2.
12 * See the file COPYING for more details.
16 #include <linux/types.h>
17 #include <linux/immediate.h>
18 #include <linux/ltt-channels.h>
25 * marker_probe_func - Type of a marker probe function
27 * @probe_private: probe private data
28 * @call_private: call site private data
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.
34 * Type of marker probe functions. They receive the mdata and need to parse the
35 * format string to recover the variable argument list.
37 typedef void marker_probe_func(const struct marker
*mdata
,
38 void *probe_private
, void *call_private
,
39 const char *fmt
, va_list *args
);
41 struct marker_probe_closure
{
42 marker_probe_func
*func
; /* Callback */
43 void *probe_private
; /* Private probe data */
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.
52 DEFINE_IMV(char, state
);/* Immediate value state. */
53 char ptype
; /* probe type : 0 : single, 1 : multi */
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)));
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) + \
76 0, 0, 0, 0, marker_probe_cb, \
77 { __mark_empty_function, NULL}, \
78 NULL, tp_name_str, tp_cb }
80 #define DEFINE_MARKER(channel, name, format) \
81 _DEFINE_MARKER(channel, name, NULL, NULL, format)
83 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
84 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
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.
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.
95 #define __trace_mark(generic, channel, name, call_private, format, args...) \
97 DEFINE_MARKER(channel, name, format); \
98 __mark_check_format(format, ## args); \
100 if (unlikely(imv_read( \
101 __mark_##channel##_##name.state))) \
102 (*__mark_##channel##_##name.call) \
103 (&__mark_##channel##_##name, \
104 call_private, ## args); \
106 if (unlikely(_imv_read( \
107 __mark_##channel##_##name.state))) \
108 (*__mark_##channel##_##name.call) \
109 (&__mark_##channel##_##name, \
110 call_private, ## args); \
114 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
117 void __check_tp_type(void) \
119 register_trace_##tp_name(tp_cb); \
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); \
127 extern void marker_update_probe_range(struct marker
*begin
,
130 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
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, \
139 void __check_tp_type(void) \
141 register_trace_##tp_name(tp_cb); \
143 __mark_check_format(format, ## args); \
145 static inline void marker_update_probe_range(struct marker
*begin
,
148 #define GET_MARKER(channel, name)
149 #endif /* CONFIG_MARKERS */
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
158 * Places a marker using optimized code patching technique (imv_read())
159 * to be enabled when immediate values are present.
161 #define trace_mark(channel, name, format, args...) \
162 __trace_mark(0, channel, name, NULL, format, ## args)
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
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).
176 #define _trace_mark(channel, name, format, args...) \
177 __trace_mark(1, channel, name, NULL, format, ## args)
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
189 * Places a marker in a tracepoint callback.
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)
195 * MARK_NOARGS - Format string for a marker with no argument.
197 #define MARK_NOARGS " "
199 extern void lock_markers(void);
200 extern void unlock_markers(void);
202 extern void markers_compact_event_ids(void);
204 /* To be used for string format validity checking with gcc */
205 static inline void __printf(1, 2) ___mark_check_format(const char *fmt
, ...)
209 #define __mark_check_format(format, args...) \
212 ___mark_check_format(format, ## args); \
215 extern marker_probe_func __mark_empty_function
;
217 extern void marker_probe_cb(const struct marker
*mdata
,
218 void *call_private
, ...);
221 * Connect a probe to a marker.
222 * private data pointer must be a valid allocated memory address, or NULL.
224 extern int marker_probe_register(const char *channel
, const char *name
,
225 const char *format
, marker_probe_func
*probe
, void *probe_private
);
228 * Returns the private data given to marker_probe_register.
230 extern int marker_probe_unregister(const char *channel
, const char *name
,
231 marker_probe_func
*probe
, void *probe_private
);
233 * Unregister a marker by providing the registered private data.
235 extern int marker_probe_unregister_private_data(marker_probe_func
*probe
,
236 void *probe_private
);
238 extern void *marker_get_private_data(const char *channel
, const char *name
,
239 marker_probe_func
*probe
, int num
);
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.
248 #define marker_synchronize_unregister() synchronize_sched()
251 struct module
*module
;
252 struct marker
*marker
;
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
,
262 extern void marker_update_process(void);
263 extern int is_marker_enabled(const char *channel
, const char *name
);
265 #ifdef CONFIG_MARKERS_USERSPACE
266 extern void exit_user_markers(struct task_struct
*p
);
268 static inline void exit_user_markers(struct task_struct
*p
)