Commit | Line | Data |
---|---|---|
27b052e3 PMF |
1 | #ifndef _UST_TRACEPOINT_H |
2 | #define _UST_TRACEPOINT_H | |
f99be407 PMF |
3 | |
4 | /* | |
1f8b0dff PMF |
5 | * Copyright (C) 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
6 | * Copyright (C) 2009 Pierre-Marc Fournier | |
f99be407 | 7 | * |
8fc2d8db PMF |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
f99be407 | 12 | * |
8fc2d8db | 13 | * This library is distributed in the hope that it will be useful, |
1f8b0dff | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8fc2d8db PMF |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
1f8b0dff | 17 | * |
8fc2d8db PMF |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
f99be407 PMF |
21 | * |
22 | * Heavily inspired from the Linux Kernel Markers. | |
23 | * | |
1f8b0dff | 24 | * Ported to userspace by Pierre-Marc Fournier. |
f99be407 PMF |
25 | */ |
26 | ||
872037bb | 27 | #define _LGPL_SOURCE |
b7ea1a1c | 28 | #include <urcu-bp.h> |
93d0f2ea | 29 | #include <ust/immediate.h> |
518d7abb | 30 | #include <ust/core.h> |
f99be407 PMF |
31 | |
32 | struct module; | |
33 | struct tracepoint; | |
34 | ||
35 | struct tracepoint { | |
36 | const char *name; /* Tracepoint name */ | |
37 | DEFINE_IMV(char, state); /* State. */ | |
38 | void **funcs; | |
39 | } __attribute__((aligned(32))); /* | |
40 | * Aligned on 32 bytes because it is | |
41 | * globally visible and gcc happily | |
42 | * align these on the structure size. | |
43 | * Keep in sync with vmlinux.lds.h. | |
44 | */ | |
45 | ||
7166e240 PMF |
46 | #define TP_PROTO(args...) args |
47 | #define TP_ARGS(args...) args | |
f99be407 | 48 | |
872037bb PMF |
49 | #define CONFIG_TRACEPOINTS |
50 | #ifdef CONFIG_TRACEPOINTS | |
f99be407 PMF |
51 | |
52 | /* | |
53 | * it_func[0] is never NULL because there is at least one element in the array | |
54 | * when the array itself is non NULL. | |
55 | */ | |
56 | #define __DO_TRACE(tp, proto, args) \ | |
57 | do { \ | |
58 | void **it_func; \ | |
59 | \ | |
6cb88bc0 | 60 | rcu_read_lock(); /*ust rcu_read_lock_sched_notrace(); */ \ |
f99be407 PMF |
61 | it_func = rcu_dereference((tp)->funcs); \ |
62 | if (it_func) { \ | |
63 | do { \ | |
64 | ((void(*)(proto))(*it_func))(args); \ | |
65 | } while (*(++it_func)); \ | |
66 | } \ | |
6cb88bc0 | 67 | rcu_read_unlock(); /*ust rcu_read_unlock_sched_notrace(); */ \ |
f99be407 PMF |
68 | } while (0) |
69 | ||
70 | #define __CHECK_TRACE(name, generic, proto, args) \ | |
71 | do { \ | |
72 | if (!generic) { \ | |
73 | if (unlikely(imv_read(__tracepoint_##name.state))) \ | |
74 | __DO_TRACE(&__tracepoint_##name, \ | |
7166e240 | 75 | TP_PROTO(proto), TP_ARGS(args)); \ |
f99be407 PMF |
76 | } else { \ |
77 | if (unlikely(_imv_read(__tracepoint_##name.state))) \ | |
78 | __DO_TRACE(&__tracepoint_##name, \ | |
7166e240 | 79 | TP_PROTO(proto), TP_ARGS(args)); \ |
f99be407 PMF |
80 | } \ |
81 | } while (0) | |
82 | ||
83 | /* | |
84 | * Make sure the alignment of the structure in the __tracepoints section will | |
85 | * not add unwanted padding between the beginning of the section and the | |
86 | * structure. Force alignment to the same alignment as the section start. | |
87 | * | |
88 | * The "generic" argument, passed to the declared __trace_##name inline | |
89 | * function controls which tracepoint enabling mechanism must be used. | |
90 | * If generic is true, a variable read is used. | |
91 | * If generic is false, immediate values are used. | |
92 | */ | |
93 | #define DECLARE_TRACE(name, proto, args) \ | |
94 | extern struct tracepoint __tracepoint_##name; \ | |
95 | static inline void trace_##name(proto) \ | |
96 | { \ | |
7166e240 | 97 | __CHECK_TRACE(name, 0, TP_PROTO(proto), TP_ARGS(args)); \ |
f99be407 PMF |
98 | } \ |
99 | static inline void _trace_##name(proto) \ | |
100 | { \ | |
7166e240 | 101 | __CHECK_TRACE(name, 1, TP_PROTO(proto), TP_ARGS(args)); \ |
f99be407 PMF |
102 | } \ |
103 | static inline int register_trace_##name(void (*probe)(proto)) \ | |
104 | { \ | |
105 | return tracepoint_probe_register(#name, (void *)probe); \ | |
106 | } \ | |
107 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | |
108 | { \ | |
109 | return tracepoint_probe_unregister(#name, (void *)probe);\ | |
110 | } | |
111 | ||
112 | #define DEFINE_TRACE(name) \ | |
113 | static const char __tpstrtab_##name[] \ | |
114 | __attribute__((section("__tracepoints_strings"))) = #name; \ | |
115 | struct tracepoint __tracepoint_##name \ | |
116 | __attribute__((section("__tracepoints"), aligned(32))) = \ | |
117 | { __tpstrtab_##name, 0, NULL } | |
118 | ||
f99be407 PMF |
119 | extern void tracepoint_update_probe_range(struct tracepoint *begin, |
120 | struct tracepoint *end); | |
121 | ||
872037bb PMF |
122 | #else /* !CONFIG_TRACEPOINTS */ |
123 | #define DECLARE_TRACE(name, proto, args) \ | |
124 | static inline void trace_##name(proto) \ | |
125 | { } \ | |
126 | static inline void _trace_##name(proto) \ | |
127 | { } \ | |
128 | static inline int register_trace_##name(void (*probe)(proto)) \ | |
129 | { \ | |
130 | return -ENOSYS; \ | |
131 | } \ | |
132 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | |
133 | { \ | |
134 | return -ENOSYS; \ | |
135 | } | |
136 | ||
137 | #define DEFINE_TRACE(name) | |
138 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) | |
139 | #define EXPORT_TRACEPOINT_SYMBOL(name) | |
140 | ||
141 | static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |
142 | struct tracepoint *end) | |
143 | { } | |
144 | #endif /* CONFIG_TRACEPOINTS */ | |
f99be407 PMF |
145 | |
146 | /* | |
147 | * Connect a probe to a tracepoint. | |
148 | * Internal API, should not be used directly. | |
149 | */ | |
150 | extern int tracepoint_probe_register(const char *name, void *probe); | |
151 | ||
152 | /* | |
153 | * Disconnect a probe from a tracepoint. | |
154 | * Internal API, should not be used directly. | |
155 | */ | |
156 | extern int tracepoint_probe_unregister(const char *name, void *probe); | |
157 | ||
158 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | |
159 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | |
160 | extern void tracepoint_probe_update_all(void); | |
161 | ||
162 | struct tracepoint_iter { | |
474d745f PMF |
163 | //ust// struct module *module; |
164 | struct tracepoint_lib *lib; | |
f99be407 PMF |
165 | struct tracepoint *tracepoint; |
166 | }; | |
167 | ||
168 | extern void tracepoint_iter_start(struct tracepoint_iter *iter); | |
169 | extern void tracepoint_iter_next(struct tracepoint_iter *iter); | |
170 | extern void tracepoint_iter_stop(struct tracepoint_iter *iter); | |
171 | extern void tracepoint_iter_reset(struct tracepoint_iter *iter); | |
172 | extern int tracepoint_get_iter_range(struct tracepoint **tracepoint, | |
173 | struct tracepoint *begin, struct tracepoint *end); | |
174 | ||
175 | /* | |
176 | * tracepoint_synchronize_unregister must be called between the last tracepoint | |
177 | * probe unregistration and the end of module exit to make sure there is no | |
178 | * caller executing a probe when it is freed. | |
179 | */ | |
180 | static inline void tracepoint_synchronize_unregister(void) | |
181 | { | |
270c6b98 | 182 | //ust// synchronize_sched(); |
f99be407 PMF |
183 | } |
184 | ||
474d745f PMF |
185 | struct tracepoint_lib { |
186 | struct tracepoint *tracepoints_start; | |
187 | int tracepoints_count; | |
188 | struct list_head list; | |
189 | }; | |
190 | ||
872037bb PMF |
191 | extern int tracepoint_register_lib(struct tracepoint *tracepoints_start, |
192 | int tracepoints_count); | |
24b6668c | 193 | extern int tracepoint_unregister_lib(struct tracepoint *tracepoints_start); |
872037bb PMF |
194 | |
195 | #define TRACEPOINT_LIB \ | |
55994a67 JB |
196 | extern struct tracepoint __start___tracepoints[] __attribute__((weak, visibility("hidden"))); \ |
197 | extern struct tracepoint __stop___tracepoints[] __attribute__((weak, visibility("hidden"))); \ | |
872037bb PMF |
198 | static void __attribute__((constructor)) __tracepoints__init(void) \ |
199 | { \ | |
200 | tracepoint_register_lib(__start___tracepoints, \ | |
201 | (((long)__stop___tracepoints)-((long)__start___tracepoints))/sizeof(struct tracepoint)); \ | |
24b6668c PMF |
202 | } \ |
203 | \ | |
204 | static void __attribute__((destructor)) __tracepoints__destroy(void) \ | |
205 | { \ | |
206 | tracepoint_unregister_lib(__start___tracepoints); \ | |
872037bb PMF |
207 | } |
208 | ||
27b052e3 | 209 | #endif /* _UST_TRACEPOINT_H */ |