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