5fdd66ff45feef3f5c1d2b3126304d630524b6ee
[lttng-ust.git] / libmarkers / marker.h
1 #ifndef _LINUX_MARKER_H
2 #define _LINUX_MARKER_H
3
4 /*
5 * Code markup for dynamic and static tracing.
6 *
7 * See Documentation/marker.txt.
8 *
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>
11 *
12 * This file is released under the GPLv2.
13 * See the file COPYING for more details.
14 */
15
16 #include <stdarg.h>
17 //ust// #include <linux/types.h>
18 #include "immediate.h"
19 //ust// #include <linux/ltt-channels.h>
20 #include "kernelcompat.h"
21 #include "compiler.h"
22
23 //ust// struct module;
24 //ust// struct task_struct;
25 struct marker;
26
27 /**
28 * marker_probe_func - Type of a marker probe function
29 * @mdata: marker data
30 * @probe_private: probe private data
31 * @call_private: call site private data
32 * @fmt: format string
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.
36 *
37 * Type of marker probe functions. They receive the mdata and need to parse the
38 * format string to recover the variable argument list.
39 */
40 typedef void marker_probe_func(const struct marker *mdata,
41 void *probe_private, void *call_private,
42 const char *fmt, va_list *args);
43
44 struct marker_probe_closure {
45 marker_probe_func *func; /* Callback */
46 void *probe_private; /* Private probe data */
47 };
48
49 struct marker {
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.
54 */
55 DEFINE_IMV(char, state);/* Immediate value state. */
56 char ptype; /* probe type : 0 : single, 1 : multi */
57 /* Probe wrapper */
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)));
66
67 //ust// #ifdef CONFIG_MARKERS
68
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) + \
78 sizeof(#name)], \
79 0, 0, 0, 0, marker_probe_cb, \
80 { __mark_empty_function, NULL}, \
81 NULL, tp_name_str, tp_cb }
82
83 #define DEFINE_MARKER(channel, name, format) \
84 _DEFINE_MARKER(channel, name, NULL, NULL, format)
85
86 #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
87 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
88
89 /*
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.
93 *
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.
97 */
98 #define __trace_mark(generic, channel, name, call_private, format, args...) \
99 do { \
100 DEFINE_MARKER(channel, name, format); \
101 __mark_check_format(format, ## args); \
102 if (!generic) { \
103 if (unlikely(imv_read( \
104 __mark_##channel##_##name.state))) \
105 (*__mark_##channel##_##name.call) \
106 (&__mark_##channel##_##name, \
107 call_private, ## args); \
108 } else { \
109 if (unlikely(_imv_read( \
110 __mark_##channel##_##name.state))) \
111 (*__mark_##channel##_##name.call) \
112 (&__mark_##channel##_##name, \
113 call_private, ## args); \
114 } \
115 } while (0)
116
117 #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
118 format, args...) \
119 do { \
120 void __check_tp_type(void) \
121 { \
122 register_trace_##tp_name(tp_cb); \
123 } \
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); \
128 } while (0)
129
130 extern void marker_update_probe_range(struct marker *begin,
131 struct marker *end);
132
133 #define GET_MARKER(channel, name) (__mark_##channel##_##name)
134
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...) \
141 //ust// do { \
142 //ust// void __check_tp_type(void) \
143 //ust// { \
144 //ust// register_trace_##tp_name(tp_cb); \
145 //ust// } \
146 //ust// __mark_check_format(format, ## args); \
147 //ust// } while (0)
148 //ust// static inline void marker_update_probe_range(struct marker *begin,
149 //ust// struct marker *end)
150 //ust// { }
151 //ust// #define GET_MARKER(channel, name)
152 //ust// #endif /* CONFIG_MARKERS */
153
154 /**
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
160 *
161 * Places a marker using optimized code patching technique (imv_read())
162 * to be enabled when immediate values are present.
163 */
164 #define trace_mark(channel, name, format, args...) \
165 __trace_mark(0, channel, name, NULL, format, ## args)
166
167 /**
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
173 *
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).
178 */
179 #define _trace_mark(channel, name, format, args...) \
180 __trace_mark(1, channel, name, NULL, format, ## args)
181
182 /**
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
191 *
192 * Places a marker in a tracepoint callback.
193 */
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)
196
197 /**
198 * MARK_NOARGS - Format string for a marker with no argument.
199 */
200 #define MARK_NOARGS " "
201
202 extern void lock_markers(void);
203 extern void unlock_markers(void);
204
205 extern void markers_compact_event_ids(void);
206
207 /* To be used for string format validity checking with gcc */
208 static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
209 {
210 }
211
212 #define __mark_check_format(format, args...) \
213 do { \
214 if (0) \
215 ___mark_check_format(format, ## args); \
216 } while (0)
217
218 extern marker_probe_func __mark_empty_function;
219
220 extern void marker_probe_cb(const struct marker *mdata,
221 void *call_private, ...);
222
223 /*
224 * Connect a probe to a marker.
225 * private data pointer must be a valid allocated memory address, or NULL.
226 */
227 extern int marker_probe_register(const char *channel, const char *name,
228 const char *format, marker_probe_func *probe, void *probe_private);
229
230 /*
231 * Returns the private data given to marker_probe_register.
232 */
233 extern int marker_probe_unregister(const char *channel, const char *name,
234 marker_probe_func *probe, void *probe_private);
235 /*
236 * Unregister a marker by providing the registered private data.
237 */
238 extern int marker_probe_unregister_private_data(marker_probe_func *probe,
239 void *probe_private);
240
241 extern void *marker_get_private_data(const char *channel, const char *name,
242 marker_probe_func *probe, int num);
243
244 /*
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.
250 */
251 #define marker_synchronize_unregister() synchronize_sched()
252
253 struct marker_iter {
254 struct module *module;
255 struct marker *marker;
256 };
257
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,
263 struct marker *end);
264
265 extern void marker_update_process(void);
266 extern int is_marker_enabled(const char *channel, const char *name);
267
268 //ust// #ifdef CONFIG_MARKERS_USERSPACE
269 //ust// extern void exit_user_markers(struct task_struct *p);
270 //ust// #else
271 //ust// static inline void exit_user_markers(struct task_struct *p)
272 //ust// {
273 //ust// }
274 //ust// #endif
275
276 #endif
This page took 0.075192 seconds and 3 git commands to generate.