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