Commit | Line | Data |
---|---|---|
535b0d0a MD |
1 | #ifndef _UST_MARKER_H |
2 | #define _UST_MARKER_H | |
3 | ||
a72ca31a PMF |
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> | |
59b161cd | 10 | * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca> |
fe566790 | 11 | * (C) Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
a72ca31a | 12 | * |
8fc2d8db PMF |
13 | * This library is free software; you can redistribute it and/or |
14 | * modify it under the terms of the GNU Lesser General Public | |
f37142a4 MD |
15 | * License as published by the Free Software Foundation; |
16 | * version 2.1 of the License. | |
8fc2d8db PMF |
17 | * |
18 | * This library is distributed in the hope that it will be useful, | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | * Lesser General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU Lesser General Public | |
24 | * License along with this library; if not, write to the Free Software | |
25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
a72ca31a PMF |
26 | */ |
27 | ||
28 | #include <stdarg.h> | |
9edd34bd MD |
29 | #include <stdint.h> |
30 | #include <stddef.h> | |
535b0d0a | 31 | #include <bits/wordsize.h> |
22d9080d | 32 | #include <urcu/list.h> |
59b161cd | 33 | |
b521931e | 34 | struct ust_marker; |
fd0a1aea | 35 | struct ust_marker_probe_array; |
a72ca31a PMF |
36 | |
37 | /** | |
b521931e | 38 | * ust_marker_probe_func - Type of a marker probe function |
a72ca31a PMF |
39 | * @mdata: marker data |
40 | * @probe_private: probe private data | |
41 | * @call_private: call site private data | |
42 | * @fmt: format string | |
43 | * @args: variable argument list pointer. Use a pointer to overcome C's | |
44 | * inability to pass this around as a pointer in a portable manner in | |
45 | * the callee otherwise. | |
46 | * | |
47 | * Type of marker probe functions. They receive the mdata and need to parse the | |
48 | * format string to recover the variable argument list. | |
49 | */ | |
b521931e | 50 | typedef void ust_marker_probe_func(const struct ust_marker *mdata, |
fe566790 | 51 | void *probe_private, void *call_private, |
a72ca31a PMF |
52 | const char *fmt, va_list *args); |
53 | ||
b521931e MD |
54 | struct ust_marker_probe_closure { |
55 | ust_marker_probe_func *func; /* Callback */ | |
a72ca31a PMF |
56 | void *probe_private; /* Private probe data */ |
57 | }; | |
58 | ||
b521931e | 59 | struct ust_marker { |
a72ca31a PMF |
60 | const char *channel; /* Name of channel where to send data */ |
61 | const char *name; /* Marker name */ | |
62 | const char *format; /* Marker format string, describing the | |
63 | * variable argument list. | |
64 | */ | |
f36c12ab | 65 | char state; /* State. */ |
a72ca31a PMF |
66 | char ptype; /* probe type : 0 : single, 1 : multi */ |
67 | /* Probe wrapper */ | |
9edd34bd MD |
68 | uint16_t channel_id; /* Numeric channel identifier, dynamic */ |
69 | uint16_t event_id; /* Numeric event identifier, dynamic */ | |
fe566790 | 70 | void (*call)(const struct ust_marker *mdata, void *call_private, ...); |
b521931e | 71 | struct ust_marker_probe_closure single; |
fd0a1aea | 72 | struct ust_marker_probe_array *multi; |
a72ca31a PMF |
73 | const char *tp_name; /* Optional tracepoint name */ |
74 | void *tp_cb; /* Optional tracepoint callback */ | |
eb5d20c6 | 75 | }; |
a72ca31a | 76 | |
fe566790 MD |
77 | /* |
78 | * We keep the "channel" as internal field for marker.c *only*. It will be | |
79 | * removed soon. | |
80 | */ | |
7166e240 | 81 | |
fe566790 MD |
82 | /* |
83 | * __ust_marker_ptrs section is not const (read-only) because it needs to be | |
84 | * read-write to let the linker apply relocations and keep the object PIC. | |
85 | */ | |
86 | #define _DEFINE_UST_MARKER(channel, name, tp_name_str, tp_cb, format) \ | |
7166e240 | 87 | static const char __mstrtab_##channel##_##name[] \ |
fe566790 | 88 | __attribute__((section("__ust_markers_strings"))) \ |
7166e240 | 89 | = #channel "\0" #name "\0" format; \ |
fe566790 MD |
90 | static struct ust_marker __ust_marker_def_##name \ |
91 | __attribute__((section("__ust_markers"))) = \ | |
7166e240 | 92 | { __mstrtab_##channel##_##name, \ |
fe566790 MD |
93 | &__mstrtab_##channel##_##name[sizeof(#channel)], \ |
94 | &__mstrtab_##channel##_##name[sizeof(#channel) + \ | |
95 | sizeof(#name)], \ | |
96 | 0, 0, 0, 0, ust_marker_probe_cb, \ | |
97 | { __ust_marker_empty_function, NULL}, \ | |
98 | NULL, tp_name_str, tp_cb }; \ | |
99 | static struct ust_marker * __ust_marker_ptr_##name \ | |
535b0d0a | 100 | __attribute__((used, section("__ust_marker_ptrs"))) = \ |
fe566790 MD |
101 | &__ust_marker_def_##name |
102 | ||
a72ca31a | 103 | /* |
b521931e | 104 | * Make sure the alignment of the structure in the __ust_marker section will |
a72ca31a PMF |
105 | * not add unwanted padding between the beginning of the section and the |
106 | * structure. Force alignment to the same alignment as the section start. | |
a72ca31a | 107 | */ |
bb9ade29 | 108 | |
fe566790 | 109 | #define __ust_marker(channel, name, call_private, format, args...) \ |
a72ca31a | 110 | do { \ |
fe566790 | 111 | _DEFINE_UST_MARKER(channel, name, NULL, NULL, format); \ |
b521931e | 112 | __ust_marker_check_format(format, ## args); \ |
9edd34bd | 113 | if (__builtin_expect(!!(__ust_marker_def_##name.state), 0)) \ |
fe566790 MD |
114 | (__ust_marker_def_##name.call) \ |
115 | (&__ust_marker_def_##name, call_private,\ | |
116 | ## args); \ | |
a72ca31a PMF |
117 | } while (0) |
118 | ||
a72ca31a | 119 | /** |
686debc3 | 120 | * ust_marker - Marker using code patching |
a72ca31a PMF |
121 | * @name: marker name, not quoted. |
122 | * @format: format string | |
123 | * @args...: variable argument list | |
124 | * | |
f36c12ab | 125 | * Places a marker at caller site. |
a72ca31a | 126 | */ |
686debc3 | 127 | #define ust_marker(name, format, args...) \ |
f36c12ab | 128 | __ust_marker(ust, name, NULL, format, ## args) |
a72ca31a | 129 | |
67a61c67 MD |
130 | static inline __attribute__((deprecated)) |
131 | void __trace_mark_is_deprecated() | |
132 | { | |
133 | } | |
5389de4d | 134 | |
a72ca31a | 135 | /** |
b521931e | 136 | * UST_MARKER_NOARGS - Format string for a marker with no argument. |
a72ca31a | 137 | */ |
b521931e | 138 | #define UST_MARKER_NOARGS " " |
a72ca31a | 139 | |
a72ca31a | 140 | /* To be used for string format validity checking with gcc */ |
535b0d0a | 141 | static inline |
9edd34bd MD |
142 | void __attribute__((format(printf, 1, 2))) |
143 | ___ust_marker_check_format(const char *fmt, ...) | |
a72ca31a PMF |
144 | { |
145 | } | |
146 | ||
b521931e | 147 | #define __ust_marker_check_format(format, args...) \ |
a72ca31a PMF |
148 | do { \ |
149 | if (0) \ | |
b521931e | 150 | ___ust_marker_check_format(format, ## args); \ |
a72ca31a PMF |
151 | } while (0) |
152 | ||
b521931e | 153 | extern ust_marker_probe_func __ust_marker_empty_function; |
a72ca31a | 154 | |
b521931e | 155 | extern void ust_marker_probe_cb(const struct ust_marker *mdata, |
fe566790 | 156 | void *call_private, ...); |
a72ca31a | 157 | |
b521931e MD |
158 | struct ust_marker_lib { |
159 | struct ust_marker * const *ust_marker_start; | |
b521931e | 160 | int ust_marker_count; |
0222e121 | 161 | struct cds_list_head list; |
98963de4 PMF |
162 | }; |
163 | ||
b521931e MD |
164 | #define UST_MARKER_LIB \ |
165 | extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
166 | extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
fe566790 MD |
167 | static struct ust_marker * __ust_marker_ptr_dummy \ |
168 | __attribute__((used, section("__ust_marker_ptrs"))); \ | |
55994a67 | 169 | \ |
535b0d0a | 170 | static void __attribute__((constructor)) __ust_marker__init(void) \ |
55994a67 | 171 | { \ |
b521931e MD |
172 | ust_marker_register_lib(__start___ust_marker_ptrs, \ |
173 | __stop___ust_marker_ptrs \ | |
535b0d0a | 174 | - __start___ust_marker_ptrs); \ |
900e307e MD |
175 | } \ |
176 | \ | |
535b0d0a | 177 | static void __attribute__((destructor)) __ust_marker__destroy(void) \ |
24b6668c | 178 | { \ |
b521931e | 179 | ust_marker_unregister_lib(__start___ust_marker_ptrs); \ |
55994a67 | 180 | } |
98963de4 | 181 | |
535b0d0a MD |
182 | extern |
183 | int ust_marker_register_lib(struct ust_marker * const *ust_marker_start, | |
184 | int ust_marker_count); | |
185 | extern | |
186 | int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start); | |
67a61c67 MD |
187 | |
188 | /* | |
535b0d0a | 189 | * trace_mark() -- DEPRECATED |
67a61c67 MD |
190 | * @channel: name prefix, not quoted. Ignored. |
191 | * @name: marker name, not quoted. | |
192 | * @format: format string | |
193 | * @args...: variable argument list | |
194 | * | |
535b0d0a | 195 | * Kept as a compatibility API and is *DEPRECATED* in favor of |
67a61c67 MD |
196 | * ust_marker(). |
197 | */ | |
198 | #define trace_mark(channel, name, format, args...) \ | |
199 | __trace_mark_is_deprecated(); \ | |
200 | ust_marker(name, format, ## args) | |
201 | ||
202 | static inline __attribute__((deprecated)) | |
203 | void __MARKER_LIB_IS_DEPRECATED() | |
204 | { | |
205 | } | |
206 | ||
7a05c99d | 207 | /* |
535b0d0a MD |
208 | * MARKER_LIB is kept for backward compatibility and is *DEPRECATED*. |
209 | * Use UST_MARKER_LIB instead. | |
7a05c99d | 210 | */ |
67a61c67 MD |
211 | #define MARKER_LIB \ |
212 | __MARKER_LIB_IS_DEPRECATED(); \ | |
213 | UST_MARKER_LIB | |
7a05c99d | 214 | |
67a61c67 | 215 | /** |
535b0d0a | 216 | * MARKER_NOARGS - Compatibility API. *DEPRECATED*. Use |
67a61c67 MD |
217 | * UST_MARKER_NOARGS instead. |
218 | */ | |
219 | #define MARK_NOARGS UST_MARKER_NOARGS | |
9160b4e4 | 220 | |
defa46a7 | 221 | #endif /* _UST_MARKER_H */ |