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