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