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>
10 * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca>
12 * This file is released under the GPLv2.
13 * See the file COPYING for more details.
17 //ust// #include <linux/types.h>
18 #include "immediate.h"
19 //ust// #include <linux/ltt-channels.h>
20 #include "kernelcompat.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 //ust// #ifdef CONFIG_MARKERS
70 #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \
71 static const char __mstrtab_##channel##_##name[] \
72 __attribute__((section("__markers_strings"))) \
73 = #channel "\0" #name "\0" format; \
74 static struct marker __mark_##channel##_##name \
75 __attribute__((section("__markers"), aligned(8))) = \
76 { __mstrtab_##channel##_##name, \
77 &__mstrtab_##channel##_##name[sizeof(#channel)], \
78 &__mstrtab_##channel##_##name[sizeof(#channel) + \
80 0, 0, 0, 0, marker_probe_cb, \
81 { __mark_empty_function, NULL}, \
82 NULL, tp_name_str, tp_cb }
84 #define DEFINE_MARKER(channel, name, format) \
85 _DEFINE_MARKER(channel, name, NULL, NULL, format)
87 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
88 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
91 * Make sure the alignment of the structure in the __markers section will
92 * not add unwanted padding between the beginning of the section and the
93 * structure. Force alignment to the same alignment as the section start.
95 * The "generic" argument controls which marker enabling mechanism must be used.
96 * If generic is true, a variable read is used.
97 * If generic is false, immediate values are used.
99 #define __trace_mark(generic, channel, name, call_private, format, args...) \
101 DEFINE_MARKER(channel, name, format); \
102 __mark_check_format(format, ## args); \
104 if (unlikely(imv_read( \
105 __mark_##channel##_##name.state))) \
106 (*__mark_##channel##_##name.call) \
107 (&__mark_##channel##_##name, \
108 call_private, ## args); \
110 if (unlikely(_imv_read( \
111 __mark_##channel##_##name.state))) \
112 (*__mark_##channel##_##name.call) \
113 (&__mark_##channel##_##name, \
114 call_private, ## args); \
118 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
121 void __check_tp_type(void) \
123 register_trace_##tp_name(tp_cb); \
125 DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
126 __mark_check_format(format, ## args); \
127 (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \
128 call_private, ## args); \
131 extern void marker_update_probe_range(struct marker
*begin
,
134 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
136 //ust// #else /* !CONFIG_MARKERS */
137 //ust// #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format)
138 //ust// #define __trace_mark(generic, channel, name, call_private, format, args...) \
139 //ust// __mark_check_format(format, ## args)
140 //ust// #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
141 //ust// format, args...) \
143 //ust// void __check_tp_type(void) \
145 //ust// register_trace_##tp_name(tp_cb); \
147 //ust// __mark_check_format(format, ## args); \
149 //ust// static inline void marker_update_probe_range(struct marker *begin,
150 //ust// struct marker *end)
152 //ust// #define GET_MARKER(channel, name)
153 //ust// #endif /* CONFIG_MARKERS */
156 * trace_mark - Marker using code patching
157 * @channel: marker channel (where to send the data), not quoted.
158 * @name: marker name, not quoted.
159 * @format: format string
160 * @args...: variable argument list
162 * Places a marker using optimized code patching technique (imv_read())
163 * to be enabled when immediate values are present.
165 #define trace_mark(channel, name, format, args...) \
166 __trace_mark(0, channel, name, NULL, format, ## args)
169 * _trace_mark - Marker using variable read
170 * @channel: marker channel (where to send the data), not quoted.
171 * @name: marker name, not quoted.
172 * @format: format string
173 * @args...: variable argument list
175 * Places a marker using a standard memory read (_imv_read()) to be
176 * enabled. Should be used for markers in code paths where instruction
177 * modification based enabling is not welcome. (__init and __exit functions,
178 * lockdep, some traps, printk).
180 #define _trace_mark(channel, name, format, args...) \
181 __trace_mark(1, channel, name, NULL, format, ## args)
184 * trace_mark_tp - Marker in a tracepoint callback
185 * @channel: marker channel (where to send the data), not quoted.
186 * @name: marker name, not quoted.
187 * @tp_name: tracepoint name, not quoted.
188 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
189 * is not optimized away by the compiler (should not be static).
190 * @format: format string
191 * @args...: variable argument list
193 * Places a marker in a tracepoint callback.
195 #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
196 __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
199 * MARK_NOARGS - Format string for a marker with no argument.
201 #define MARK_NOARGS " "
203 extern void lock_markers(void);
204 extern void unlock_markers(void);
206 extern void markers_compact_event_ids(void);
208 /* To be used for string format validity checking with gcc */
209 static inline void __printf(1, 2) ___mark_check_format(const char *fmt
, ...)
213 #define __mark_check_format(format, args...) \
216 ___mark_check_format(format, ## args); \
219 extern marker_probe_func __mark_empty_function
;
221 extern void marker_probe_cb(const struct marker
*mdata
,
222 void *call_private
, ...);
225 * Connect a probe to a marker.
226 * private data pointer must be a valid allocated memory address, or NULL.
228 extern int marker_probe_register(const char *channel
, const char *name
,
229 const char *format
, marker_probe_func
*probe
, void *probe_private
);
232 * Returns the private data given to marker_probe_register.
234 extern int marker_probe_unregister(const char *channel
, const char *name
,
235 marker_probe_func
*probe
, void *probe_private
);
237 * Unregister a marker by providing the registered private data.
239 extern int marker_probe_unregister_private_data(marker_probe_func
*probe
,
240 void *probe_private
);
242 extern void *marker_get_private_data(const char *channel
, const char *name
,
243 marker_probe_func
*probe
, int num
);
246 * marker_synchronize_unregister must be called between the last marker probe
247 * unregistration and the first one of
248 * - the end of module exit function
249 * - the free of any resource used by the probes
250 * to ensure the code and data are valid for any possibly running probes.
252 #define marker_synchronize_unregister() synchronize_sched()
255 //ust// struct module *module;
257 struct marker
*marker
;
260 extern void marker_iter_start(struct marker_iter
*iter
);
261 extern void marker_iter_next(struct marker_iter
*iter
);
262 extern void marker_iter_stop(struct marker_iter
*iter
);
263 extern void marker_iter_reset(struct marker_iter
*iter
);
264 extern int marker_get_iter_range(struct marker
**marker
, struct marker
*begin
,
267 extern void marker_update_process(void);
268 extern int is_marker_enabled(const char *channel
, const char *name
);
270 //ust// #ifdef CONFIG_MARKERS_USERSPACE
271 //ust// extern void exit_user_markers(struct task_struct *p);
273 //ust// static inline void exit_user_markers(struct task_struct *p)
280 struct marker
*markers_start
;
282 struct list_head list
;
285 int marker_register_lib(struct marker
*markers_start
, int markers_count
);
288 extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \
289 extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \
291 static void __attribute__((constructor)) __markers__init(void) \
293 marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\
296 void marker_set_new_marker_cb(void (*cb
)(struct marker
*));