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