Commit | Line | Data |
---|---|---|
f99be407 PMF |
1 | /* |
2 | * Copyright (C) 2008 Mathieu Desnoyers | |
1f8b0dff | 3 | * Copyright (C) 2009 Pierre-Marc Fournier |
f99be407 | 4 | * |
34e4b7db PMF |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public | |
f37142a4 MD |
7 | * License as published by the Free Software Foundation; |
8 | * version 2.1 of the License. | |
f99be407 | 9 | * |
34e4b7db | 10 | * This library is distributed in the hope that it will be useful, |
f99be407 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
34e4b7db PMF |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. | |
f99be407 | 14 | * |
34e4b7db PMF |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
1f8b0dff PMF |
18 | * |
19 | * Ported to userspace by Pierre-Marc Fournier. | |
f99be407 | 20 | */ |
1f8b0dff | 21 | |
b0c4126f | 22 | #define _LGPL_SOURCE |
474d745f | 23 | #include <errno.h> |
93d0f2ea | 24 | #include <ust/tracepoint.h> |
81614639 | 25 | #include <ust/tracepoint-internal.h> |
518d7abb PMF |
26 | #include <ust/core.h> |
27 | #include <ust/kcompat/kcompat.h> | |
b7ea1a1c | 28 | #include <urcu-bp.h> |
10c56168 | 29 | #include <urcu/hlist.h> |
474d745f | 30 | |
b0c4126f MD |
31 | #include "usterr_signal_safe.h" |
32 | ||
474d745f PMF |
33 | //extern struct tracepoint __start___tracepoints[] __attribute__((visibility("hidden"))); |
34 | //extern struct tracepoint __stop___tracepoints[] __attribute__((visibility("hidden"))); | |
f99be407 PMF |
35 | |
36 | /* Set to 1 to enable tracepoint debug output */ | |
37 | static const int tracepoint_debug; | |
38 | ||
474d745f | 39 | /* libraries that contain tracepoints (struct tracepoint_lib) */ |
0222e121 | 40 | static CDS_LIST_HEAD(libs); |
474d745f | 41 | |
f99be407 PMF |
42 | /* |
43 | * tracepoints_mutex nests inside module_mutex. Tracepoints mutex protects the | |
44 | * builtin and module tracepoints and the hash table. | |
45 | */ | |
46 | static DEFINE_MUTEX(tracepoints_mutex); | |
47 | ||
48 | /* | |
49 | * Tracepoint hash table, containing the active tracepoints. | |
50 | * Protected by tracepoints_mutex. | |
51 | */ | |
52 | #define TRACEPOINT_HASH_BITS 6 | |
53 | #define TRACEPOINT_TABLE_SIZE (1 << TRACEPOINT_HASH_BITS) | |
10c56168 | 54 | static struct cds_hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE]; |
f99be407 PMF |
55 | |
56 | /* | |
57 | * Note about RCU : | |
58 | * It is used to to delay the free of multiple probes array until a quiescent | |
59 | * state is reached. | |
60 | * Tracepoint entries modifications are protected by the tracepoints_mutex. | |
61 | */ | |
62 | struct tracepoint_entry { | |
10c56168 | 63 | struct cds_hlist_node hlist; |
b979b346 | 64 | struct tracepoint_probe *probes; |
f99be407 PMF |
65 | int refcount; /* Number of times armed. 0 if disarmed. */ |
66 | char name[0]; | |
67 | }; | |
68 | ||
69 | struct tp_probes { | |
70 | union { | |
474d745f | 71 | //ust// struct rcu_head rcu; |
0222e121 | 72 | struct cds_list_head list; |
f99be407 | 73 | } u; |
b979b346 | 74 | struct tracepoint_probe probes[0]; |
f99be407 PMF |
75 | }; |
76 | ||
77 | static inline void *allocate_probes(int count) | |
78 | { | |
b979b346 | 79 | struct tp_probes *p = zmalloc(count * sizeof(struct tracepoint_probe) |
909bc43f | 80 | + sizeof(struct tp_probes)); |
f99be407 PMF |
81 | return p == NULL ? NULL : p->probes; |
82 | } | |
83 | ||
474d745f PMF |
84 | //ust// static void rcu_free_old_probes(struct rcu_head *head) |
85 | //ust// { | |
86 | //ust// kfree(container_of(head, struct tp_probes, u.rcu)); | |
87 | //ust// } | |
f99be407 PMF |
88 | |
89 | static inline void release_probes(void *old) | |
90 | { | |
91 | if (old) { | |
1e4b909b | 92 | struct tp_probes *tp_probes = _ust_container_of(old, |
f99be407 | 93 | struct tp_probes, probes[0]); |
474d745f PMF |
94 | //ust// call_rcu_sched(&tp_probes->u.rcu, rcu_free_old_probes); |
95 | synchronize_rcu(); | |
909bc43f | 96 | free(tp_probes); |
f99be407 PMF |
97 | } |
98 | } | |
99 | ||
100 | static void debug_print_probes(struct tracepoint_entry *entry) | |
101 | { | |
102 | int i; | |
103 | ||
9dec086e | 104 | if (!tracepoint_debug || !entry->probes) |
f99be407 PMF |
105 | return; |
106 | ||
9dec086e NC |
107 | for (i = 0; entry->probes[i].func; i++) |
108 | DBG("Probe %d : %p", i, entry->probes[i].func); | |
f99be407 PMF |
109 | } |
110 | ||
111 | static void * | |
9dec086e NC |
112 | tracepoint_entry_add_probe(struct tracepoint_entry *entry, |
113 | void *probe, void *data) | |
f99be407 PMF |
114 | { |
115 | int nr_probes = 0; | |
b979b346 | 116 | struct tracepoint_probe *old, *new; |
f99be407 PMF |
117 | |
118 | WARN_ON(!probe); | |
119 | ||
120 | debug_print_probes(entry); | |
9dec086e | 121 | old = entry->probes; |
f99be407 PMF |
122 | if (old) { |
123 | /* (N -> N+1), (N != 0, 1) probes */ | |
9dec086e NC |
124 | for (nr_probes = 0; old[nr_probes].func; nr_probes++) |
125 | if (old[nr_probes].func == probe && | |
126 | old[nr_probes].data == data) | |
f99be407 PMF |
127 | return ERR_PTR(-EEXIST); |
128 | } | |
129 | /* + 2 : one for new probe, one for NULL func */ | |
130 | new = allocate_probes(nr_probes + 2); | |
131 | if (new == NULL) | |
132 | return ERR_PTR(-ENOMEM); | |
133 | if (old) | |
b979b346 | 134 | memcpy(new, old, nr_probes * sizeof(struct tracepoint_probe)); |
9dec086e NC |
135 | new[nr_probes].func = probe; |
136 | new[nr_probes].data = data; | |
137 | new[nr_probes + 1].func = NULL; | |
f99be407 | 138 | entry->refcount = nr_probes + 1; |
9dec086e | 139 | entry->probes = new; |
f99be407 PMF |
140 | debug_print_probes(entry); |
141 | return old; | |
142 | } | |
143 | ||
144 | static void * | |
9dec086e NC |
145 | tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe, |
146 | void *data) | |
f99be407 PMF |
147 | { |
148 | int nr_probes = 0, nr_del = 0, i; | |
b979b346 | 149 | struct tracepoint_probe *old, *new; |
f99be407 | 150 | |
9dec086e | 151 | old = entry->probes; |
f99be407 PMF |
152 | |
153 | if (!old) | |
154 | return ERR_PTR(-ENOENT); | |
155 | ||
156 | debug_print_probes(entry); | |
157 | /* (N -> M), (N > 1, M >= 0) probes */ | |
9dec086e | 158 | for (nr_probes = 0; old[nr_probes].func; nr_probes++) { |
c66428ac DG |
159 | if (!probe || |
160 | (old[nr_probes].func == probe && | |
9dec086e | 161 | old[nr_probes].data == data)) |
f99be407 PMF |
162 | nr_del++; |
163 | } | |
164 | ||
165 | if (nr_probes - nr_del == 0) { | |
166 | /* N -> 0, (N > 1) */ | |
9dec086e | 167 | entry->probes = NULL; |
f99be407 PMF |
168 | entry->refcount = 0; |
169 | debug_print_probes(entry); | |
170 | return old; | |
171 | } else { | |
172 | int j = 0; | |
173 | /* N -> M, (N > 1, M > 0) */ | |
174 | /* + 1 for NULL */ | |
175 | new = allocate_probes(nr_probes - nr_del + 1); | |
176 | if (new == NULL) | |
177 | return ERR_PTR(-ENOMEM); | |
9dec086e NC |
178 | for (i = 0; old[i].func; i++) |
179 | if (probe && | |
180 | (old[i].func != probe || old[i].data != data)) | |
f99be407 | 181 | new[j++] = old[i]; |
9dec086e | 182 | new[nr_probes - nr_del].func = NULL; |
f99be407 | 183 | entry->refcount = nr_probes - nr_del; |
9dec086e | 184 | entry->probes = new; |
f99be407 PMF |
185 | } |
186 | debug_print_probes(entry); | |
187 | return old; | |
188 | } | |
189 | ||
190 | /* | |
191 | * Get tracepoint if the tracepoint is present in the tracepoint hash table. | |
192 | * Must be called with tracepoints_mutex held. | |
193 | * Returns NULL if not present. | |
194 | */ | |
195 | static struct tracepoint_entry *get_tracepoint(const char *name) | |
196 | { | |
10c56168 DG |
197 | struct cds_hlist_head *head; |
198 | struct cds_hlist_node *node; | |
f99be407 PMF |
199 | struct tracepoint_entry *e; |
200 | u32 hash = jhash(name, strlen(name), 0); | |
201 | ||
202 | head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)]; | |
10c56168 | 203 | cds_hlist_for_each_entry(e, node, head, hlist) { |
f99be407 PMF |
204 | if (!strcmp(name, e->name)) |
205 | return e; | |
206 | } | |
207 | return NULL; | |
208 | } | |
209 | ||
210 | /* | |
211 | * Add the tracepoint to the tracepoint hash table. Must be called with | |
212 | * tracepoints_mutex held. | |
213 | */ | |
214 | static struct tracepoint_entry *add_tracepoint(const char *name) | |
215 | { | |
10c56168 DG |
216 | struct cds_hlist_head *head; |
217 | struct cds_hlist_node *node; | |
f99be407 PMF |
218 | struct tracepoint_entry *e; |
219 | size_t name_len = strlen(name) + 1; | |
220 | u32 hash = jhash(name, name_len-1, 0); | |
221 | ||
222 | head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)]; | |
10c56168 | 223 | cds_hlist_for_each_entry(e, node, head, hlist) { |
f99be407 | 224 | if (!strcmp(name, e->name)) { |
c1f20530 | 225 | DBG("tracepoint %s busy", name); |
f99be407 PMF |
226 | return ERR_PTR(-EEXIST); /* Already there */ |
227 | } | |
228 | } | |
229 | /* | |
1dba3e6c | 230 | * Using zmalloc here to allocate a variable length element. Could |
f99be407 PMF |
231 | * cause some memory fragmentation if overused. |
232 | */ | |
1dba3e6c | 233 | e = zmalloc(sizeof(struct tracepoint_entry) + name_len); |
f99be407 PMF |
234 | if (!e) |
235 | return ERR_PTR(-ENOMEM); | |
236 | memcpy(&e->name[0], name, name_len); | |
9dec086e | 237 | e->probes = NULL; |
f99be407 | 238 | e->refcount = 0; |
10c56168 | 239 | cds_hlist_add_head(&e->hlist, head); |
f99be407 PMF |
240 | return e; |
241 | } | |
242 | ||
243 | /* | |
244 | * Remove the tracepoint from the tracepoint hash table. Must be called with | |
245 | * mutex_lock held. | |
246 | */ | |
247 | static inline void remove_tracepoint(struct tracepoint_entry *e) | |
248 | { | |
10c56168 | 249 | cds_hlist_del(&e->hlist); |
909bc43f | 250 | free(e); |
f99be407 PMF |
251 | } |
252 | ||
253 | /* | |
254 | * Sets the probe callback corresponding to one tracepoint. | |
255 | */ | |
256 | static void set_tracepoint(struct tracepoint_entry **entry, | |
257 | struct tracepoint *elem, int active) | |
258 | { | |
259 | WARN_ON(strcmp((*entry)->name, elem->name) != 0); | |
260 | ||
261 | /* | |
0222e121 | 262 | * rcu_assign_pointer has a cmm_smp_wmb() which makes sure that the new |
f99be407 PMF |
263 | * probe callbacks array is consistent before setting a pointer to it. |
264 | * This array is referenced by __DO_TRACE from | |
0222e121 | 265 | * include/linux/tracepoints.h. A matching cmm_smp_read_barrier_depends() |
f99be407 PMF |
266 | * is used. |
267 | */ | |
9dec086e | 268 | rcu_assign_pointer(elem->probes, (*entry)->probes); |
f36c12ab | 269 | elem->state = active; |
f99be407 PMF |
270 | } |
271 | ||
272 | /* | |
273 | * Disable a tracepoint and its probe callback. | |
274 | * Note: only waiting an RCU period after setting elem->call to the empty | |
275 | * function insures that the original callback is not used anymore. This insured | |
276 | * by preempt_disable around the call site. | |
277 | */ | |
278 | static void disable_tracepoint(struct tracepoint *elem) | |
279 | { | |
f36c12ab | 280 | elem->state = 0; |
9dec086e | 281 | rcu_assign_pointer(elem->probes, NULL); |
f99be407 PMF |
282 | } |
283 | ||
284 | /** | |
285 | * tracepoint_update_probe_range - Update a probe range | |
286 | * @begin: beginning of the range | |
287 | * @end: end of the range | |
288 | * | |
289 | * Updates the probe callback corresponding to a range of tracepoints. | |
290 | */ | |
f218ff28 MD |
291 | void tracepoint_update_probe_range(struct tracepoint * const *begin, |
292 | struct tracepoint * const *end) | |
f99be407 | 293 | { |
f218ff28 | 294 | struct tracepoint * const *iter; |
f99be407 PMF |
295 | struct tracepoint_entry *mark_entry; |
296 | ||
f7b16408 | 297 | pthread_mutex_lock(&tracepoints_mutex); |
f99be407 | 298 | for (iter = begin; iter < end; iter++) { |
f08ebbe2 MD |
299 | if (!*iter) |
300 | continue; /* skip dummy */ | |
f218ff28 MD |
301 | if (!(*iter)->name) { |
302 | disable_tracepoint(*iter); | |
9dec086e NC |
303 | continue; |
304 | } | |
f218ff28 | 305 | mark_entry = get_tracepoint((*iter)->name); |
f99be407 | 306 | if (mark_entry) { |
f218ff28 | 307 | set_tracepoint(&mark_entry, *iter, |
f99be407 PMF |
308 | !!mark_entry->refcount); |
309 | } else { | |
f218ff28 | 310 | disable_tracepoint(*iter); |
f99be407 PMF |
311 | } |
312 | } | |
f7b16408 | 313 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
314 | } |
315 | ||
772030fe PMF |
316 | static void lib_update_tracepoints(void) |
317 | { | |
318 | struct tracepoint_lib *lib; | |
319 | ||
f7b16408 | 320 | //ust// pthread_mutex_lock(&module_mutex); |
0222e121 | 321 | cds_list_for_each_entry(lib, &libs, list) |
772030fe PMF |
322 | tracepoint_update_probe_range(lib->tracepoints_start, |
323 | lib->tracepoints_start + lib->tracepoints_count); | |
f7b16408 | 324 | //ust// pthread_mutex_unlock(&module_mutex); |
772030fe PMF |
325 | } |
326 | ||
f99be407 PMF |
327 | /* |
328 | * Update probes, removing the faulty probes. | |
329 | */ | |
330 | static void tracepoint_update_probes(void) | |
331 | { | |
332 | /* Core kernel tracepoints */ | |
474d745f PMF |
333 | //ust// tracepoint_update_probe_range(__start___tracepoints, |
334 | //ust// __stop___tracepoints); | |
f99be407 | 335 | /* tracepoints in modules. */ |
474d745f | 336 | lib_update_tracepoints(); |
f99be407 PMF |
337 | } |
338 | ||
b979b346 | 339 | static struct tracepoint_probe * |
9dec086e | 340 | tracepoint_add_probe(const char *name, void *probe, void *data) |
f99be407 PMF |
341 | { |
342 | struct tracepoint_entry *entry; | |
b979b346 | 343 | struct tracepoint_probe *old; |
f99be407 PMF |
344 | |
345 | entry = get_tracepoint(name); | |
346 | if (!entry) { | |
347 | entry = add_tracepoint(name); | |
348 | if (IS_ERR(entry)) | |
b979b346 | 349 | return (struct tracepoint_probe *)entry; |
f99be407 | 350 | } |
9dec086e | 351 | old = tracepoint_entry_add_probe(entry, probe, data); |
f99be407 PMF |
352 | if (IS_ERR(old) && !entry->refcount) |
353 | remove_tracepoint(entry); | |
354 | return old; | |
355 | } | |
356 | ||
357 | /** | |
81614639 | 358 | * __tracepoint_probe_register - Connect a probe to a tracepoint |
f99be407 PMF |
359 | * @name: tracepoint name |
360 | * @probe: probe handler | |
361 | * | |
362 | * Returns 0 if ok, error value on error. | |
363 | * The probe address must at least be aligned on the architecture pointer size. | |
364 | */ | |
81614639 | 365 | int __tracepoint_probe_register(const char *name, void *probe, void *data) |
f99be407 PMF |
366 | { |
367 | void *old; | |
368 | ||
f7b16408 | 369 | pthread_mutex_lock(&tracepoints_mutex); |
9dec086e | 370 | old = tracepoint_add_probe(name, probe, data); |
f7b16408 | 371 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
372 | if (IS_ERR(old)) |
373 | return PTR_ERR(old); | |
374 | ||
375 | tracepoint_update_probes(); /* may update entry */ | |
376 | release_probes(old); | |
377 | return 0; | |
378 | } | |
f99be407 | 379 | |
9dec086e | 380 | static void *tracepoint_remove_probe(const char *name, void *probe, void *data) |
f99be407 PMF |
381 | { |
382 | struct tracepoint_entry *entry; | |
383 | void *old; | |
384 | ||
385 | entry = get_tracepoint(name); | |
386 | if (!entry) | |
387 | return ERR_PTR(-ENOENT); | |
9dec086e | 388 | old = tracepoint_entry_remove_probe(entry, probe, data); |
f99be407 PMF |
389 | if (IS_ERR(old)) |
390 | return old; | |
391 | if (!entry->refcount) | |
392 | remove_tracepoint(entry); | |
393 | return old; | |
394 | } | |
395 | ||
396 | /** | |
397 | * tracepoint_probe_unregister - Disconnect a probe from a tracepoint | |
398 | * @name: tracepoint name | |
399 | * @probe: probe function pointer | |
9dec086e | 400 | * @probe: probe data pointer |
f99be407 PMF |
401 | * |
402 | * We do not need to call a synchronize_sched to make sure the probes have | |
403 | * finished running before doing a module unload, because the module unload | |
404 | * itself uses stop_machine(), which insures that every preempt disabled section | |
405 | * have finished. | |
406 | */ | |
81614639 | 407 | int __tracepoint_probe_unregister(const char *name, void *probe, void *data) |
f99be407 PMF |
408 | { |
409 | void *old; | |
410 | ||
f7b16408 | 411 | pthread_mutex_lock(&tracepoints_mutex); |
9dec086e | 412 | old = tracepoint_remove_probe(name, probe, data); |
f7b16408 | 413 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
414 | if (IS_ERR(old)) |
415 | return PTR_ERR(old); | |
416 | ||
417 | tracepoint_update_probes(); /* may update entry */ | |
418 | release_probes(old); | |
419 | return 0; | |
420 | } | |
f99be407 | 421 | |
0222e121 | 422 | static CDS_LIST_HEAD(old_probes); |
f99be407 PMF |
423 | static int need_update; |
424 | ||
425 | static void tracepoint_add_old_probes(void *old) | |
426 | { | |
427 | need_update = 1; | |
428 | if (old) { | |
1e4b909b | 429 | struct tp_probes *tp_probes = _ust_container_of(old, |
f99be407 | 430 | struct tp_probes, probes[0]); |
0222e121 | 431 | cds_list_add(&tp_probes->u.list, &old_probes); |
f99be407 PMF |
432 | } |
433 | } | |
434 | ||
435 | /** | |
436 | * tracepoint_probe_register_noupdate - register a probe but not connect | |
437 | * @name: tracepoint name | |
438 | * @probe: probe handler | |
439 | * | |
440 | * caller must call tracepoint_probe_update_all() | |
441 | */ | |
9dec086e NC |
442 | int tracepoint_probe_register_noupdate(const char *name, void *probe, |
443 | void *data) | |
f99be407 PMF |
444 | { |
445 | void *old; | |
446 | ||
f7b16408 | 447 | pthread_mutex_lock(&tracepoints_mutex); |
9dec086e | 448 | old = tracepoint_add_probe(name, probe, data); |
f99be407 | 449 | if (IS_ERR(old)) { |
f7b16408 | 450 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
451 | return PTR_ERR(old); |
452 | } | |
453 | tracepoint_add_old_probes(old); | |
f7b16408 | 454 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
455 | return 0; |
456 | } | |
474d745f | 457 | //ust// EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate); |
f99be407 PMF |
458 | |
459 | /** | |
460 | * tracepoint_probe_unregister_noupdate - remove a probe but not disconnect | |
461 | * @name: tracepoint name | |
462 | * @probe: probe function pointer | |
463 | * | |
464 | * caller must call tracepoint_probe_update_all() | |
465 | */ | |
9dec086e NC |
466 | int tracepoint_probe_unregister_noupdate(const char *name, void *probe, |
467 | void *data) | |
f99be407 PMF |
468 | { |
469 | void *old; | |
470 | ||
f7b16408 | 471 | pthread_mutex_lock(&tracepoints_mutex); |
9dec086e | 472 | old = tracepoint_remove_probe(name, probe, data); |
f99be407 | 473 | if (IS_ERR(old)) { |
f7b16408 | 474 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
475 | return PTR_ERR(old); |
476 | } | |
477 | tracepoint_add_old_probes(old); | |
f7b16408 | 478 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
479 | return 0; |
480 | } | |
474d745f | 481 | //ust// EXPORT_SYMBOL_GPL(tracepoint_probe_unregister_noupdate); |
f99be407 PMF |
482 | |
483 | /** | |
484 | * tracepoint_probe_update_all - update tracepoints | |
485 | */ | |
486 | void tracepoint_probe_update_all(void) | |
487 | { | |
0222e121 | 488 | CDS_LIST_HEAD(release_probes); |
f99be407 PMF |
489 | struct tp_probes *pos, *next; |
490 | ||
f7b16408 | 491 | pthread_mutex_lock(&tracepoints_mutex); |
f99be407 | 492 | if (!need_update) { |
f7b16408 | 493 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
494 | return; |
495 | } | |
0222e121 MD |
496 | if (!cds_list_empty(&old_probes)) |
497 | cds_list_replace_init(&old_probes, &release_probes); | |
f99be407 | 498 | need_update = 0; |
f7b16408 | 499 | pthread_mutex_unlock(&tracepoints_mutex); |
f99be407 PMF |
500 | |
501 | tracepoint_update_probes(); | |
0222e121 MD |
502 | cds_list_for_each_entry_safe(pos, next, &release_probes, u.list) { |
503 | cds_list_del(&pos->u.list); | |
474d745f PMF |
504 | //ust// call_rcu_sched(&pos->u.rcu, rcu_free_old_probes); |
505 | synchronize_rcu(); | |
909bc43f | 506 | free(pos); |
f99be407 PMF |
507 | } |
508 | } | |
474d745f | 509 | //ust// EXPORT_SYMBOL_GPL(tracepoint_probe_update_all); |
f99be407 | 510 | |
772030fe PMF |
511 | /* |
512 | * Returns 0 if current not found. | |
513 | * Returns 1 if current found. | |
514 | */ | |
515 | int lib_get_iter_tracepoints(struct tracepoint_iter *iter) | |
516 | { | |
517 | struct tracepoint_lib *iter_lib; | |
518 | int found = 0; | |
519 | ||
f7b16408 | 520 | //ust// pthread_mutex_lock(&module_mutex); |
0222e121 | 521 | cds_list_for_each_entry(iter_lib, &libs, list) { |
772030fe PMF |
522 | if (iter_lib < iter->lib) |
523 | continue; | |
524 | else if (iter_lib > iter->lib) | |
525 | iter->tracepoint = NULL; | |
526 | found = tracepoint_get_iter_range(&iter->tracepoint, | |
527 | iter_lib->tracepoints_start, | |
528 | iter_lib->tracepoints_start + iter_lib->tracepoints_count); | |
529 | if (found) { | |
530 | iter->lib = iter_lib; | |
531 | break; | |
532 | } | |
533 | } | |
f7b16408 | 534 | //ust// pthread_mutex_unlock(&module_mutex); |
772030fe PMF |
535 | return found; |
536 | } | |
537 | ||
f99be407 PMF |
538 | /** |
539 | * tracepoint_get_iter_range - Get a next tracepoint iterator given a range. | |
540 | * @tracepoint: current tracepoints (in), next tracepoint (out) | |
541 | * @begin: beginning of the range | |
542 | * @end: end of the range | |
543 | * | |
544 | * Returns whether a next tracepoint has been found (1) or not (0). | |
545 | * Will return the first tracepoint in the range if the input tracepoint is | |
546 | * NULL. | |
547 | */ | |
f218ff28 MD |
548 | int tracepoint_get_iter_range(struct tracepoint * const **tracepoint, |
549 | struct tracepoint * const *begin, struct tracepoint * const *end) | |
f99be407 | 550 | { |
f08ebbe2 | 551 | if (!*tracepoint && begin != end) |
f99be407 | 552 | *tracepoint = begin; |
f08ebbe2 MD |
553 | while (*tracepoint >= begin && *tracepoint < end) { |
554 | if (!**tracepoint) | |
555 | (*tracepoint)++; /* skip dummy */ | |
556 | else | |
557 | return 1; | |
f99be407 | 558 | } |
f99be407 PMF |
559 | return 0; |
560 | } | |
474d745f | 561 | //ust// EXPORT_SYMBOL_GPL(tracepoint_get_iter_range); |
f99be407 PMF |
562 | |
563 | static void tracepoint_get_iter(struct tracepoint_iter *iter) | |
564 | { | |
565 | int found = 0; | |
566 | ||
474d745f PMF |
567 | //ust// /* Core kernel tracepoints */ |
568 | //ust// if (!iter->module) { | |
569 | //ust// found = tracepoint_get_iter_range(&iter->tracepoint, | |
570 | //ust// __start___tracepoints, __stop___tracepoints); | |
571 | //ust// if (found) | |
572 | //ust// goto end; | |
573 | //ust// } | |
574 | /* tracepoints in libs. */ | |
575 | found = lib_get_iter_tracepoints(iter); | |
772030fe | 576 | //ust// end: |
f99be407 PMF |
577 | if (!found) |
578 | tracepoint_iter_reset(iter); | |
579 | } | |
580 | ||
581 | void tracepoint_iter_start(struct tracepoint_iter *iter) | |
582 | { | |
583 | tracepoint_get_iter(iter); | |
584 | } | |
474d745f | 585 | //ust// EXPORT_SYMBOL_GPL(tracepoint_iter_start); |
f99be407 PMF |
586 | |
587 | void tracepoint_iter_next(struct tracepoint_iter *iter) | |
588 | { | |
589 | iter->tracepoint++; | |
590 | /* | |
591 | * iter->tracepoint may be invalid because we blindly incremented it. | |
592 | * Make sure it is valid by marshalling on the tracepoints, getting the | |
593 | * tracepoints from following modules if necessary. | |
594 | */ | |
595 | tracepoint_get_iter(iter); | |
596 | } | |
474d745f | 597 | //ust// EXPORT_SYMBOL_GPL(tracepoint_iter_next); |
f99be407 PMF |
598 | |
599 | void tracepoint_iter_stop(struct tracepoint_iter *iter) | |
600 | { | |
601 | } | |
474d745f | 602 | //ust// EXPORT_SYMBOL_GPL(tracepoint_iter_stop); |
f99be407 PMF |
603 | |
604 | void tracepoint_iter_reset(struct tracepoint_iter *iter) | |
605 | { | |
474d745f | 606 | //ust// iter->module = NULL; |
f99be407 PMF |
607 | iter->tracepoint = NULL; |
608 | } | |
474d745f PMF |
609 | //ust// EXPORT_SYMBOL_GPL(tracepoint_iter_reset); |
610 | ||
611 | //ust// #ifdef CONFIG_MODULES | |
612 | ||
613 | //ust// int tracepoint_module_notify(struct notifier_block *self, | |
614 | //ust// unsigned long val, void *data) | |
615 | //ust// { | |
616 | //ust// struct module *mod = data; | |
617 | //ust// | |
618 | //ust// switch (val) { | |
619 | //ust// case MODULE_STATE_COMING: | |
620 | //ust// tracepoint_update_probe_range(mod->tracepoints, | |
621 | //ust// mod->tracepoints + mod->num_tracepoints); | |
622 | //ust// break; | |
623 | //ust// case MODULE_STATE_GOING: | |
624 | //ust// tracepoint_update_probe_range(mod->tracepoints, | |
625 | //ust// mod->tracepoints + mod->num_tracepoints); | |
626 | //ust// break; | |
627 | //ust// } | |
628 | //ust// return 0; | |
629 | //ust// } | |
630 | ||
631 | //ust// struct notifier_block tracepoint_module_nb = { | |
632 | //ust// .notifier_call = tracepoint_module_notify, | |
633 | //ust// .priority = 0, | |
634 | //ust// }; | |
635 | ||
636 | //ust// static int init_tracepoints(void) | |
637 | //ust// { | |
638 | //ust// return register_module_notifier(&tracepoint_module_nb); | |
639 | //ust// } | |
640 | //ust// __initcall(init_tracepoints); | |
641 | ||
642 | //ust// #endif /* CONFIG_MODULES */ | |
f99be407 | 643 | |
474d745f PMF |
644 | static void (*new_tracepoint_cb)(struct tracepoint *) = NULL; |
645 | ||
646 | void tracepoint_set_new_tracepoint_cb(void (*cb)(struct tracepoint *)) | |
647 | { | |
648 | new_tracepoint_cb = cb; | |
649 | } | |
f99be407 | 650 | |
f218ff28 | 651 | static void new_tracepoints(struct tracepoint * const *start, struct tracepoint * const *end) |
f99be407 | 652 | { |
f218ff28 MD |
653 | if (new_tracepoint_cb) { |
654 | struct tracepoint * const *t; | |
f08ebbe2 MD |
655 | |
656 | for(t = start; t < end; t++) { | |
657 | if (*t) | |
658 | new_tracepoint_cb(*t); | |
474d745f PMF |
659 | } |
660 | } | |
f99be407 | 661 | } |
f99be407 | 662 | |
f218ff28 | 663 | int tracepoint_register_lib(struct tracepoint * const *tracepoints_start, int tracepoints_count) |
474d745f | 664 | { |
b467f7a7 | 665 | struct tracepoint_lib *pl, *iter; |
474d745f | 666 | |
1dba3e6c | 667 | pl = (struct tracepoint_lib *) zmalloc(sizeof(struct tracepoint_lib)); |
474d745f PMF |
668 | |
669 | pl->tracepoints_start = tracepoints_start; | |
670 | pl->tracepoints_count = tracepoints_count; | |
671 | ||
672 | /* FIXME: maybe protect this with its own mutex? */ | |
f7b16408 | 673 | pthread_mutex_lock(&tracepoints_mutex); |
b467f7a7 MD |
674 | /* |
675 | * We sort the libs by struct lib pointer address. | |
676 | */ | |
677 | cds_list_for_each_entry_reverse(iter, &libs, list) { | |
678 | BUG_ON(iter == pl); /* Should never be in the list twice */ | |
679 | if (iter < pl) { | |
680 | /* We belong to the location right after iter. */ | |
681 | cds_list_add(&pl->list, &iter->list); | |
682 | goto lib_added; | |
683 | } | |
684 | } | |
685 | /* We should be added at the head of the list */ | |
0222e121 | 686 | cds_list_add(&pl->list, &libs); |
b467f7a7 | 687 | lib_added: |
f7b16408 | 688 | pthread_mutex_unlock(&tracepoints_mutex); |
474d745f PMF |
689 | |
690 | new_tracepoints(tracepoints_start, tracepoints_start + tracepoints_count); | |
691 | ||
692 | /* FIXME: update just the loaded lib */ | |
693 | lib_update_tracepoints(); | |
694 | ||
f08ebbe2 | 695 | /* tracepoints_count - 1: skip dummy */ |
3b297856 | 696 | DBG("just registered a tracepoints section from %p and having %d tracepoints (minus dummy tracepoints)", tracepoints_start, tracepoints_count); |
9dec086e | 697 | |
474d745f PMF |
698 | return 0; |
699 | } | |
700 | ||
f218ff28 | 701 | int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start) |
474d745f | 702 | { |
24b6668c PMF |
703 | struct tracepoint_lib *lib; |
704 | ||
f7b16408 | 705 | pthread_mutex_lock(&tracepoints_mutex); |
24b6668c | 706 | |
0222e121 | 707 | cds_list_for_each_entry(lib, &libs, list) { |
f218ff28 | 708 | if (lib->tracepoints_start == tracepoints_start) { |
24b6668c | 709 | struct tracepoint_lib *lib2free = lib; |
0222e121 | 710 | cds_list_del(&lib->list); |
24b6668c PMF |
711 | free(lib2free); |
712 | break; | |
713 | } | |
714 | } | |
715 | ||
f7b16408 | 716 | pthread_mutex_unlock(&tracepoints_mutex); |
474d745f PMF |
717 | |
718 | return 0; | |
719 | } |