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"
23 //ust// struct module;
24 //ust// struct task_struct;
28 * marker_probe_func - Type of a marker probe function
30 * @probe_private: probe private data
31 * @call_private: call site private data
33 * @args: variable argument list pointer. Use a pointer to overcome C's
34 * inability to pass this around as a pointer in a portable manner in
35 * the callee otherwise.
37 * Type of marker probe functions. They receive the mdata and need to parse the
38 * format string to recover the variable argument list.
40 typedef void marker_probe_func(const struct marker
*mdata
,
41 void *probe_private
, void *call_private
,
42 const char *fmt
, va_list *args
);
44 struct marker_probe_closure
{
45 marker_probe_func
*func
; /* Callback */
46 void *probe_private
; /* Private probe data */
50 const char *channel
; /* Name of channel where to send data */
51 const char *name
; /* Marker name */
52 const char *format
; /* Marker format string, describing the
53 * variable argument list.
55 DEFINE_IMV(char, state
);/* Immediate value state. */
56 char ptype
; /* probe type : 0 : single, 1 : multi */
58 u16 channel_id
; /* Numeric channel identifier, dynamic */
59 u16 event_id
; /* Numeric event identifier, dynamic */
60 void (*call
)(const struct marker
*mdata
, void *call_private
, ...);
61 struct marker_probe_closure single
;
62 struct marker_probe_closure
*multi
;
63 const char *tp_name
; /* Optional tracepoint name */
64 void *tp_cb
; /* Optional tracepoint callback */
65 } __attribute__((aligned(8)));
67 //ust// #ifdef CONFIG_MARKERS
69 #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format) \
70 static const char __mstrtab_##channel##_##name[] \
71 __attribute__((section("__markers_strings"))) \
72 = #channel "\0" #name "\0" format; \
73 static struct marker __mark_##channel##_##name \
74 __attribute__((section("__markers"), aligned(8))) = \
75 { __mstrtab_##channel##_##name, \
76 &__mstrtab_##channel##_##name[sizeof(#channel)], \
77 &__mstrtab_##channel##_##name[sizeof(#channel) + \
79 0, 0, 0, 0, marker_probe_cb, \
80 { __mark_empty_function, NULL}, \
81 NULL, tp_name_str, tp_cb }
83 #define DEFINE_MARKER(channel, name, format) \
84 _DEFINE_MARKER(channel, name, NULL, NULL, format)
86 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
87 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
90 * Make sure the alignment of the structure in the __markers section will
91 * not add unwanted padding between the beginning of the section and the
92 * structure. Force alignment to the same alignment as the section start.
94 * The "generic" argument controls which marker enabling mechanism must be used.
95 * If generic is true, a variable read is used.
96 * If generic is false, immediate values are used.
98 #define __trace_mark(generic, channel, name, call_private, format, args...) \
100 DEFINE_MARKER(channel, name, format); \
101 __mark_check_format(format, ## args); \
103 if (unlikely(imv_read( \
104 __mark_##channel##_##name.state))) \
105 (*__mark_##channel##_##name.call) \
106 (&__mark_##channel##_##name, \
107 call_private, ## args); \
109 if (unlikely(_imv_read( \
110 __mark_##channel##_##name.state))) \
111 (*__mark_##channel##_##name.call) \
112 (&__mark_##channel##_##name, \
113 call_private, ## args); \
117 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
120 void __check_tp_type(void) \
122 register_trace_##tp_name(tp_cb); \
124 DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
125 __mark_check_format(format, ## args); \
126 (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \
127 call_private, ## args); \
130 extern void marker_update_probe_range(struct marker
*begin
,
133 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
135 //ust// #else /* !CONFIG_MARKERS */
136 //ust// #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format)
137 //ust// #define __trace_mark(generic, channel, name, call_private, format, args...) \
138 //ust// __mark_check_format(format, ## args)
139 //ust// #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
140 //ust// format, args...) \
142 //ust// void __check_tp_type(void) \
144 //ust// register_trace_##tp_name(tp_cb); \
146 //ust// __mark_check_format(format, ## args); \
148 //ust// static inline void marker_update_probe_range(struct marker *begin,
149 //ust// struct marker *end)
151 //ust// #define GET_MARKER(channel, name)
152 //ust// #endif /* CONFIG_MARKERS */
155 * trace_mark - Marker using code patching
156 * @channel: marker channel (where to send the data), not quoted.
157 * @name: marker name, not quoted.
158 * @format: format string
159 * @args...: variable argument list
161 * Places a marker using optimized code patching technique (imv_read())
162 * to be enabled when immediate values are present.
164 #define trace_mark(channel, name, format, args...) \
165 __trace_mark(0, channel, name, NULL, format, ## args)
168 * _trace_mark - Marker using variable read
169 * @channel: marker channel (where to send the data), not quoted.
170 * @name: marker name, not quoted.
171 * @format: format string
172 * @args...: variable argument list
174 * Places a marker using a standard memory read (_imv_read()) to be
175 * enabled. Should be used for markers in code paths where instruction
176 * modification based enabling is not welcome. (__init and __exit functions,
177 * lockdep, some traps, printk).
179 #define _trace_mark(channel, name, format, args...) \
180 __trace_mark(1, channel, name, NULL, format, ## args)
183 * trace_mark_tp - Marker in a tracepoint callback
184 * @channel: marker channel (where to send the data), not quoted.
185 * @name: marker name, not quoted.
186 * @tp_name: tracepoint name, not quoted.
187 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
188 * is not optimized away by the compiler (should not be static).
189 * @format: format string
190 * @args...: variable argument list
192 * Places a marker in a tracepoint callback.
194 #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
195 __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
198 * MARK_NOARGS - Format string for a marker with no argument.
200 #define MARK_NOARGS " "
202 extern void lock_markers(void);
203 extern void unlock_markers(void);
205 extern void markers_compact_event_ids(void);
207 /* To be used for string format validity checking with gcc */
208 static inline void __printf(1, 2) ___mark_check_format(const char *fmt
, ...)
212 #define __mark_check_format(format, args...) \
215 ___mark_check_format(format, ## args); \
218 extern marker_probe_func __mark_empty_function
;
220 extern void marker_probe_cb(const struct marker
*mdata
,
221 void *call_private
, ...);
224 * Connect a probe to a marker.
225 * private data pointer must be a valid allocated memory address, or NULL.
227 extern int marker_probe_register(const char *channel
, const char *name
,
228 const char *format
, marker_probe_func
*probe
, void *probe_private
);
231 * Returns the private data given to marker_probe_register.
233 extern int marker_probe_unregister(const char *channel
, const char *name
,
234 marker_probe_func
*probe
, void *probe_private
);
236 * Unregister a marker by providing the registered private data.
238 extern int marker_probe_unregister_private_data(marker_probe_func
*probe
,
239 void *probe_private
);
241 extern void *marker_get_private_data(const char *channel
, const char *name
,
242 marker_probe_func
*probe
, int num
);
245 * marker_synchronize_unregister must be called between the last marker probe
246 * unregistration and the first one of
247 * - the end of module exit function
248 * - the free of any resource used by the probes
249 * to ensure the code and data are valid for any possibly running probes.
251 #define marker_synchronize_unregister() synchronize_sched()
254 struct module
*module
;
255 struct marker
*marker
;
258 extern void marker_iter_start(struct marker_iter
*iter
);
259 extern void marker_iter_next(struct marker_iter
*iter
);
260 extern void marker_iter_stop(struct marker_iter
*iter
);
261 extern void marker_iter_reset(struct marker_iter
*iter
);
262 extern int marker_get_iter_range(struct marker
**marker
, struct marker
*begin
,
265 extern void marker_update_process(void);
266 extern int is_marker_enabled(const char *channel
, const char *name
);
268 //ust// #ifdef CONFIG_MARKERS_USERSPACE
269 //ust// extern void exit_user_markers(struct task_struct *p);
271 //ust// static inline void exit_user_markers(struct task_struct *p)