change some licences to LGPL
[ust.git] / libust / marker.h
CommitLineData
a72ca31a
PMF
1/*
2 * Code markup for dynamic and static tracing.
3 *
4 * See Documentation/marker.txt.
5 *
6 * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
59b161cd 7 * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca>
a72ca31a
PMF
8 *
9 * This file is released under the GPLv2.
10 * See the file COPYING for more details.
11 */
12
e4621c7f
PMF
13#ifndef _LINUX_MARKER_H
14#define _LINUX_MARKER_H
15
a72ca31a 16#include <stdarg.h>
59b161cd
PMF
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"
769d0157 22#include <kcompat/list.h>
59b161cd
PMF
23
24//ust// struct module;
25//ust// struct task_struct;
a72ca31a
PMF
26struct marker;
27
28/**
29 * marker_probe_func - Type of a marker probe function
30 * @mdata: marker data
31 * @probe_private: probe private data
32 * @call_private: call site private data
33 * @fmt: format string
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.
37 *
38 * Type of marker probe functions. They receive the mdata and need to parse the
39 * format string to recover the variable argument list.
40 */
41typedef void marker_probe_func(const struct marker *mdata,
42 void *probe_private, void *call_private,
43 const char *fmt, va_list *args);
44
45struct marker_probe_closure {
46 marker_probe_func *func; /* Callback */
47 void *probe_private; /* Private probe data */
48};
49
50struct marker {
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.
55 */
59b161cd 56 DEFINE_IMV(char, state);/* Immediate value state. */
a72ca31a
PMF
57 char ptype; /* probe type : 0 : single, 1 : multi */
58 /* Probe wrapper */
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)));
67
872037bb
PMF
68#define CONFIG_MARKERS
69#ifdef CONFIG_MARKERS
a72ca31a
PMF
70
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) + \
80 sizeof(#name)], \
81 0, 0, 0, 0, marker_probe_cb, \
82 { __mark_empty_function, NULL}, \
83 NULL, tp_name_str, tp_cb }
84
85#define DEFINE_MARKER(channel, name, format) \
86 _DEFINE_MARKER(channel, name, NULL, NULL, format)
87
88#define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format) \
89 _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
90
91/*
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.
95 *
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.
99 */
100#define __trace_mark(generic, channel, name, call_private, format, args...) \
101 do { \
102 DEFINE_MARKER(channel, name, format); \
103 __mark_check_format(format, ## args); \
104 if (!generic) { \
105 if (unlikely(imv_read( \
106 __mark_##channel##_##name.state))) \
107 (*__mark_##channel##_##name.call) \
108 (&__mark_##channel##_##name, \
109 call_private, ## args); \
110 } else { \
111 if (unlikely(_imv_read( \
112 __mark_##channel##_##name.state))) \
113 (*__mark_##channel##_##name.call) \
114 (&__mark_##channel##_##name, \
115 call_private, ## args); \
116 } \
117 } while (0)
118
119#define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb, \
120 format, args...) \
121 do { \
122 void __check_tp_type(void) \
123 { \
124 register_trace_##tp_name(tp_cb); \
125 } \
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); \
130 } while (0)
131
132extern void marker_update_probe_range(struct marker *begin,
133 struct marker *end);
134
135#define GET_MARKER(channel, name) (__mark_##channel##_##name)
136
872037bb
PMF
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, \
142 format, args...) \
143 do { \
144 void __check_tp_type(void) \
145 { \
146 register_trace_##tp_name(tp_cb); \
147 } \
148 __mark_check_format(format, ## args); \
149 } while (0)
150static inline void marker_update_probe_range(struct marker *begin,
151 struct marker *end)
152{ }
153#define GET_MARKER(channel, name)
154#endif /* CONFIG_MARKERS */
a72ca31a
PMF
155
156/**
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
162 *
163 * Places a marker using optimized code patching technique (imv_read())
164 * to be enabled when immediate values are present.
165 */
166#define trace_mark(channel, name, format, args...) \
167 __trace_mark(0, channel, name, NULL, format, ## args)
168
169/**
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
175 *
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).
180 */
181#define _trace_mark(channel, name, format, args...) \
182 __trace_mark(1, channel, name, NULL, format, ## args)
183
184/**
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
193 *
194 * Places a marker in a tracepoint callback.
195 */
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)
198
199/**
200 * MARK_NOARGS - Format string for a marker with no argument.
201 */
202#define MARK_NOARGS " "
203
204extern void lock_markers(void);
205extern void unlock_markers(void);
206
207extern void markers_compact_event_ids(void);
208
209/* To be used for string format validity checking with gcc */
210static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
211{
212}
213
214#define __mark_check_format(format, args...) \
215 do { \
216 if (0) \
217 ___mark_check_format(format, ## args); \
218 } while (0)
219
220extern marker_probe_func __mark_empty_function;
221
222extern void marker_probe_cb(const struct marker *mdata,
223 void *call_private, ...);
224
225/*
226 * Connect a probe to a marker.
227 * private data pointer must be a valid allocated memory address, or NULL.
228 */
229extern int marker_probe_register(const char *channel, const char *name,
230 const char *format, marker_probe_func *probe, void *probe_private);
231
232/*
233 * Returns the private data given to marker_probe_register.
234 */
235extern int marker_probe_unregister(const char *channel, const char *name,
236 marker_probe_func *probe, void *probe_private);
237/*
238 * Unregister a marker by providing the registered private data.
239 */
240extern int marker_probe_unregister_private_data(marker_probe_func *probe,
241 void *probe_private);
242
243extern void *marker_get_private_data(const char *channel, const char *name,
244 marker_probe_func *probe, int num);
245
246/*
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.
252 */
253#define marker_synchronize_unregister() synchronize_sched()
254
255struct marker_iter {
98963de4
PMF
256//ust// struct module *module;
257 struct lib *lib;
a72ca31a
PMF
258 struct marker *marker;
259};
260
261extern void marker_iter_start(struct marker_iter *iter);
262extern void marker_iter_next(struct marker_iter *iter);
263extern void marker_iter_stop(struct marker_iter *iter);
264extern void marker_iter_reset(struct marker_iter *iter);
265extern int marker_get_iter_range(struct marker **marker, struct marker *begin,
266 struct marker *end);
267
268extern void marker_update_process(void);
269extern int is_marker_enabled(const char *channel, const char *name);
270
59b161cd
PMF
271//ust// #ifdef CONFIG_MARKERS_USERSPACE
272//ust// extern void exit_user_markers(struct task_struct *p);
273//ust// #else
274//ust// static inline void exit_user_markers(struct task_struct *p)
275//ust// {
276//ust// }
277//ust// #endif
a72ca31a 278
98963de4
PMF
279
280struct lib {
281 struct marker *markers_start;
282 int markers_count;
283 struct list_head list;
284};
285
872037bb
PMF
286extern int marker_register_lib(struct marker *markers_start,
287 int markers_count);
c463904d 288
872037bb
PMF
289#define MARKER_LIB \
290extern struct marker __start___markers[] __attribute__((visibility("hidden"))); \
fbd8191b
PMF
291extern struct marker __stop___markers[] __attribute__((visibility("hidden"))); \
292 \
293static void __attribute__((constructor)) __markers__init(void) \
294{ \
c463904d
PMF
295 marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\
296}
98963de4 297
20b37a31 298void marker_set_new_marker_cb(void (*cb)(struct marker *));
474d745f 299
9160b4e4
PMF
300void init_markers(void);
301
474d745f 302#endif
This page took 0.034301 seconds and 4 git commands to generate.