remove some unused code
[ust.git] / include / ust / tracepoint.h
CommitLineData
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
474d745f
PMF
27//#include <linux/immediate.h>
28//#include <linux/types.h>
29//#include <linux/rcupdate.h>
30
872037bb 31#define _LGPL_SOURCE
b7ea1a1c 32#include <urcu-bp.h>
872037bb 33
93d0f2ea 34#include <ust/immediate.h>
fbca6b62 35#include <ust/kernelcompat.h>
f99be407
PMF
36
37struct module;
38struct tracepoint;
39
40struct 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
7166e240
PMF
51#define TP_PROTO(args...) args
52#define TP_ARGS(args...) args
f99be407 53
872037bb
PMF
54#define CONFIG_TRACEPOINTS
55#ifdef CONFIG_TRACEPOINTS
f99be407
PMF
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 \
6cb88bc0 65 rcu_read_lock(); /*ust rcu_read_lock_sched_notrace(); */ \
f99be407
PMF
66 it_func = rcu_dereference((tp)->funcs); \
67 if (it_func) { \
68 do { \
69 ((void(*)(proto))(*it_func))(args); \
70 } while (*(++it_func)); \
71 } \
6cb88bc0 72 rcu_read_unlock(); /*ust rcu_read_unlock_sched_notrace(); */ \
f99be407
PMF
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, \
7166e240 80 TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
81 } else { \
82 if (unlikely(_imv_read(__tracepoint_##name.state))) \
83 __DO_TRACE(&__tracepoint_##name, \
7166e240 84 TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
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 { \
7166e240 102 __CHECK_TRACE(name, 0, TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
103 } \
104 static inline void _trace_##name(proto) \
105 { \
7166e240 106 __CHECK_TRACE(name, 1, TP_PROTO(proto), TP_ARGS(args)); \
f99be407
PMF
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
f99be407
PMF
124extern void tracepoint_update_probe_range(struct tracepoint *begin,
125 struct tracepoint *end);
126
872037bb
PMF
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
146static inline void tracepoint_update_probe_range(struct tracepoint *begin,
147 struct tracepoint *end)
148{ }
149#endif /* CONFIG_TRACEPOINTS */
f99be407
PMF
150
151/*
152 * Connect a probe to a tracepoint.
153 * Internal API, should not be used directly.
154 */
155extern 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 */
161extern int tracepoint_probe_unregister(const char *name, void *probe);
162
163extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
164extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
165extern void tracepoint_probe_update_all(void);
166
167struct tracepoint_iter {
474d745f
PMF
168//ust// struct module *module;
169 struct tracepoint_lib *lib;
f99be407
PMF
170 struct tracepoint *tracepoint;
171};
172
173extern void tracepoint_iter_start(struct tracepoint_iter *iter);
174extern void tracepoint_iter_next(struct tracepoint_iter *iter);
175extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
176extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
177extern 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 */
185static inline void tracepoint_synchronize_unregister(void)
186{
270c6b98 187//ust// synchronize_sched();
f99be407
PMF
188}
189
474d745f
PMF
190struct tracepoint_lib {
191 struct tracepoint *tracepoints_start;
192 int tracepoints_count;
193 struct list_head list;
194};
195
872037bb
PMF
196extern int tracepoint_register_lib(struct tracepoint *tracepoints_start,
197 int tracepoints_count);
24b6668c 198extern int tracepoint_unregister_lib(struct tracepoint *tracepoints_start);
872037bb
PMF
199
200#define TRACEPOINT_LIB \
55994a67
JB
201 extern struct tracepoint __start___tracepoints[] __attribute__((weak, visibility("hidden"))); \
202 extern struct tracepoint __stop___tracepoints[] __attribute__((weak, visibility("hidden"))); \
872037bb
PMF
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)); \
24b6668c
PMF
207 } \
208 \
209 static void __attribute__((destructor)) __tracepoints__destroy(void) \
210 { \
211 tracepoint_unregister_lib(__start___tracepoints); \
872037bb
PMF
212 }
213
27b052e3 214#endif /* _UST_TRACEPOINT_H */
This page took 0.037025 seconds and 4 git commands to generate.