Add support for ppc hw tb clock, remove kernelcompat.h
[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 #define _LGPL_SOURCE
28 #include <urcu-bp.h>
29 #include <ust/immediate.h>
30 #include <ust/core.h>
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
46 #define TP_PROTO(args...) args
47 #define TP_ARGS(args...) args
48
49 #define CONFIG_TRACEPOINTS
50 #ifdef CONFIG_TRACEPOINTS
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 \
60 rcu_read_lock(); /*ust rcu_read_lock_sched_notrace(); */ \
61 it_func = rcu_dereference((tp)->funcs); \
62 if (it_func) { \
63 do { \
64 ((void(*)(proto))(*it_func))(args); \
65 } while (*(++it_func)); \
66 } \
67 rcu_read_unlock(); /*ust rcu_read_unlock_sched_notrace(); */ \
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, \
75 TP_PROTO(proto), TP_ARGS(args)); \
76 } else { \
77 if (unlikely(_imv_read(__tracepoint_##name.state))) \
78 __DO_TRACE(&__tracepoint_##name, \
79 TP_PROTO(proto), TP_ARGS(args)); \
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 { \
97 __CHECK_TRACE(name, 0, TP_PROTO(proto), TP_ARGS(args)); \
98 } \
99 static inline void _trace_##name(proto) \
100 { \
101 __CHECK_TRACE(name, 1, TP_PROTO(proto), TP_ARGS(args)); \
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
119 extern void tracepoint_update_probe_range(struct tracepoint *begin,
120 struct tracepoint *end);
121
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 */
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 {
163 //ust// struct module *module;
164 struct tracepoint_lib *lib;
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 {
182 //ust// synchronize_sched();
183 }
184
185 struct tracepoint_lib {
186 struct tracepoint *tracepoints_start;
187 int tracepoints_count;
188 struct list_head list;
189 };
190
191 extern int tracepoint_register_lib(struct tracepoint *tracepoints_start,
192 int tracepoints_count);
193 extern int tracepoint_unregister_lib(struct tracepoint *tracepoints_start);
194
195 #define TRACEPOINT_LIB \
196 extern struct tracepoint __start___tracepoints[] __attribute__((weak, visibility("hidden"))); \
197 extern struct tracepoint __stop___tracepoints[] __attribute__((weak, visibility("hidden"))); \
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)); \
202 } \
203 \
204 static void __attribute__((destructor)) __tracepoints__destroy(void) \
205 { \
206 tracepoint_unregister_lib(__start___tracepoints); \
207 }
208
209 #endif /* _UST_TRACEPOINT_H */
This page took 0.03751 seconds and 5 git commands to generate.