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> | |
535b0d0a | 29 | #include <bits/wordsize.h> |
22d9080d | 30 | #include <urcu/list.h> |
535b0d0a | 31 | #include <ust/core.h> |
518d7abb | 32 | #include <ust/kcompat/kcompat.h> |
59b161cd | 33 | |
b521931e | 34 | struct ust_marker; |
a72ca31a PMF |
35 | |
36 | /** | |
b521931e | 37 | * ust_marker_probe_func - Type of a marker probe function |
a72ca31a PMF |
38 | * @mdata: marker data |
39 | * @probe_private: probe private data | |
40 | * @call_private: call site private data | |
41 | * @fmt: format string | |
42 | * @args: variable argument list pointer. Use a pointer to overcome C's | |
43 | * inability to pass this around as a pointer in a portable manner in | |
44 | * the callee otherwise. | |
45 | * | |
46 | * Type of marker probe functions. They receive the mdata and need to parse the | |
47 | * format string to recover the variable argument list. | |
48 | */ | |
b521931e | 49 | typedef void ust_marker_probe_func(const struct ust_marker *mdata, |
fe566790 | 50 | void *probe_private, void *call_private, |
a72ca31a PMF |
51 | const char *fmt, va_list *args); |
52 | ||
b521931e MD |
53 | struct ust_marker_probe_closure { |
54 | ust_marker_probe_func *func; /* Callback */ | |
a72ca31a PMF |
55 | void *probe_private; /* Private probe data */ |
56 | }; | |
57 | ||
b521931e | 58 | struct ust_marker { |
a72ca31a PMF |
59 | const char *channel; /* Name of channel where to send data */ |
60 | const char *name; /* Marker name */ | |
61 | const char *format; /* Marker format string, describing the | |
62 | * variable argument list. | |
63 | */ | |
f36c12ab | 64 | char state; /* State. */ |
a72ca31a PMF |
65 | char ptype; /* probe type : 0 : single, 1 : multi */ |
66 | /* Probe wrapper */ | |
67 | u16 channel_id; /* Numeric channel identifier, dynamic */ | |
68 | u16 event_id; /* Numeric event identifier, dynamic */ | |
fe566790 | 69 | void (*call)(const struct ust_marker *mdata, void *call_private, ...); |
b521931e MD |
70 | struct ust_marker_probe_closure single; |
71 | struct ust_marker_probe_closure *multi; | |
a72ca31a PMF |
72 | const char *tp_name; /* Optional tracepoint name */ |
73 | void *tp_cb; /* Optional tracepoint callback */ | |
eb5d20c6 | 74 | }; |
a72ca31a | 75 | |
fe566790 MD |
76 | /* |
77 | * We keep the "channel" as internal field for marker.c *only*. It will be | |
78 | * removed soon. | |
79 | */ | |
7166e240 | 80 | |
fe566790 MD |
81 | /* |
82 | * __ust_marker_ptrs section is not const (read-only) because it needs to be | |
83 | * read-write to let the linker apply relocations and keep the object PIC. | |
84 | */ | |
85 | #define _DEFINE_UST_MARKER(channel, name, tp_name_str, tp_cb, format) \ | |
7166e240 | 86 | static const char __mstrtab_##channel##_##name[] \ |
fe566790 | 87 | __attribute__((section("__ust_markers_strings"))) \ |
7166e240 | 88 | = #channel "\0" #name "\0" format; \ |
fe566790 MD |
89 | static struct ust_marker __ust_marker_def_##name \ |
90 | __attribute__((section("__ust_markers"))) = \ | |
7166e240 | 91 | { __mstrtab_##channel##_##name, \ |
fe566790 MD |
92 | &__mstrtab_##channel##_##name[sizeof(#channel)], \ |
93 | &__mstrtab_##channel##_##name[sizeof(#channel) + \ | |
94 | sizeof(#name)], \ | |
95 | 0, 0, 0, 0, ust_marker_probe_cb, \ | |
96 | { __ust_marker_empty_function, NULL}, \ | |
97 | NULL, tp_name_str, tp_cb }; \ | |
98 | static struct ust_marker * __ust_marker_ptr_##name \ | |
535b0d0a | 99 | __attribute__((used, section("__ust_marker_ptrs"))) = \ |
fe566790 MD |
100 | &__ust_marker_def_##name |
101 | ||
a72ca31a | 102 | /* |
b521931e | 103 | * Make sure the alignment of the structure in the __ust_marker section will |
a72ca31a PMF |
104 | * not add unwanted padding between the beginning of the section and the |
105 | * structure. Force alignment to the same alignment as the section start. | |
a72ca31a | 106 | */ |
bb9ade29 | 107 | |
fe566790 | 108 | #define __ust_marker(channel, name, call_private, format, args...) \ |
a72ca31a | 109 | do { \ |
fe566790 | 110 | _DEFINE_UST_MARKER(channel, name, NULL, NULL, format); \ |
b521931e | 111 | __ust_marker_check_format(format, ## args); \ |
fe566790 MD |
112 | if (unlikely(__ust_marker_def_##name.state)) \ |
113 | (__ust_marker_def_##name.call) \ | |
114 | (&__ust_marker_def_##name, call_private,\ | |
115 | ## args); \ | |
a72ca31a PMF |
116 | } while (0) |
117 | ||
a72ca31a | 118 | /** |
686debc3 | 119 | * ust_marker - Marker using code patching |
a72ca31a PMF |
120 | * @name: marker name, not quoted. |
121 | * @format: format string | |
122 | * @args...: variable argument list | |
123 | * | |
f36c12ab | 124 | * Places a marker at caller site. |
a72ca31a | 125 | */ |
686debc3 | 126 | #define ust_marker(name, format, args...) \ |
f36c12ab | 127 | __ust_marker(ust, name, NULL, format, ## args) |
a72ca31a | 128 | |
67a61c67 MD |
129 | static inline __attribute__((deprecated)) |
130 | void __trace_mark_is_deprecated() | |
131 | { | |
132 | } | |
5389de4d | 133 | |
a72ca31a | 134 | /** |
b521931e | 135 | * UST_MARKER_NOARGS - Format string for a marker with no argument. |
a72ca31a | 136 | */ |
b521931e | 137 | #define UST_MARKER_NOARGS " " |
a72ca31a | 138 | |
a72ca31a | 139 | /* To be used for string format validity checking with gcc */ |
535b0d0a MD |
140 | static inline |
141 | void __printf(1, 2) ___ust_marker_check_format(const char *fmt, ...) | |
a72ca31a PMF |
142 | { |
143 | } | |
144 | ||
b521931e | 145 | #define __ust_marker_check_format(format, args...) \ |
a72ca31a PMF |
146 | do { \ |
147 | if (0) \ | |
b521931e | 148 | ___ust_marker_check_format(format, ## args); \ |
a72ca31a PMF |
149 | } while (0) |
150 | ||
b521931e | 151 | extern ust_marker_probe_func __ust_marker_empty_function; |
a72ca31a | 152 | |
b521931e | 153 | extern void ust_marker_probe_cb(const struct ust_marker *mdata, |
fe566790 | 154 | void *call_private, ...); |
a72ca31a | 155 | |
b521931e MD |
156 | struct ust_marker_lib { |
157 | struct ust_marker * const *ust_marker_start; | |
b521931e | 158 | int ust_marker_count; |
0222e121 | 159 | struct cds_list_head list; |
98963de4 PMF |
160 | }; |
161 | ||
b521931e MD |
162 | #define UST_MARKER_LIB \ |
163 | extern struct ust_marker * const __start___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
164 | extern struct ust_marker * const __stop___ust_marker_ptrs[] __attribute__((weak, visibility("hidden"))); \ | |
fe566790 MD |
165 | static struct ust_marker * __ust_marker_ptr_dummy \ |
166 | __attribute__((used, section("__ust_marker_ptrs"))); \ | |
55994a67 | 167 | \ |
535b0d0a | 168 | static void __attribute__((constructor)) __ust_marker__init(void) \ |
55994a67 | 169 | { \ |
b521931e MD |
170 | ust_marker_register_lib(__start___ust_marker_ptrs, \ |
171 | __stop___ust_marker_ptrs \ | |
535b0d0a | 172 | - __start___ust_marker_ptrs); \ |
900e307e MD |
173 | } \ |
174 | \ | |
535b0d0a | 175 | static void __attribute__((destructor)) __ust_marker__destroy(void) \ |
24b6668c | 176 | { \ |
b521931e | 177 | ust_marker_unregister_lib(__start___ust_marker_ptrs); \ |
55994a67 | 178 | } |
98963de4 | 179 | |
535b0d0a MD |
180 | extern |
181 | int ust_marker_register_lib(struct ust_marker * const *ust_marker_start, | |
182 | int ust_marker_count); | |
183 | extern | |
184 | int ust_marker_unregister_lib(struct ust_marker * const *ust_marker_start); | |
67a61c67 MD |
185 | |
186 | /* | |
535b0d0a | 187 | * trace_mark() -- DEPRECATED |
67a61c67 MD |
188 | * @channel: name prefix, not quoted. Ignored. |
189 | * @name: marker name, not quoted. | |
190 | * @format: format string | |
191 | * @args...: variable argument list | |
192 | * | |
535b0d0a | 193 | * Kept as a compatibility API and is *DEPRECATED* in favor of |
67a61c67 MD |
194 | * ust_marker(). |
195 | */ | |
196 | #define trace_mark(channel, name, format, args...) \ | |
197 | __trace_mark_is_deprecated(); \ | |
198 | ust_marker(name, format, ## args) | |
199 | ||
200 | static inline __attribute__((deprecated)) | |
201 | void __MARKER_LIB_IS_DEPRECATED() | |
202 | { | |
203 | } | |
204 | ||
7a05c99d | 205 | /* |
535b0d0a MD |
206 | * MARKER_LIB is kept for backward compatibility and is *DEPRECATED*. |
207 | * Use UST_MARKER_LIB instead. | |
7a05c99d | 208 | */ |
67a61c67 MD |
209 | #define MARKER_LIB \ |
210 | __MARKER_LIB_IS_DEPRECATED(); \ | |
211 | UST_MARKER_LIB | |
7a05c99d | 212 | |
67a61c67 | 213 | /** |
535b0d0a | 214 | * MARKER_NOARGS - Compatibility API. *DEPRECATED*. Use |
67a61c67 MD |
215 | * UST_MARKER_NOARGS instead. |
216 | */ | |
217 | #define MARK_NOARGS UST_MARKER_NOARGS | |
9160b4e4 | 218 | |
defa46a7 | 219 | #endif /* _UST_MARKER_H */ |