ust-tracepoint-event: fix probe creation
[lttng-ust.git] / liblttng-ust / tracepoint.c
CommitLineData
f99be407 1/*
b27f8e75 2 * Copyright (C) 2008-2011 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>
4318ae1b 24#include <lttng/tracepoint.h>
4318ae1b 25#include <lttng/core.h>
b728d87e
MD
26#include <stdint.h>
27#include <stddef.h>
28#include <urcu/arch.h>
b7ea1a1c 29#include <urcu-bp.h>
10c56168 30#include <urcu/hlist.h>
edaa1431 31#include <urcu/uatomic.h>
b728d87e 32#include <urcu/compiler.h>
474d745f 33
4318ae1b 34#include <lttng/usterr-signal-safe.h>
23c8854a 35#include "tracepoint-internal.h"
b751f722 36#include "ltt-tracer-core.h"
596c4223 37#include "jhash.h"
b0c4126f 38
f99be407
PMF
39/* Set to 1 to enable tracepoint debug output */
40static const int tracepoint_debug;
b27f8e75
MD
41static int initialized;
42static void (*new_tracepoint_cb)(struct tracepoint *);
f99be407 43
474d745f 44/* libraries that contain tracepoints (struct tracepoint_lib) */
0222e121 45static CDS_LIST_HEAD(libs);
474d745f 46
f99be407 47/*
17dfb34b
MD
48 * The UST lock protects the library tracepoints, the hash table, and
49 * the library list.
50 * All calls to the tracepoint API must be protected by the UST lock,
51 * excepts calls to tracepoint_register_lib and
52 * tracepoint_unregister_lib, which take the UST lock themselves.
f99be407 53 */
f99be407
PMF
54
55/*
56 * Tracepoint hash table, containing the active tracepoints.
57 * Protected by tracepoints_mutex.
58 */
59#define TRACEPOINT_HASH_BITS 6
60#define TRACEPOINT_TABLE_SIZE (1 << TRACEPOINT_HASH_BITS)
10c56168 61static struct cds_hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE];
f99be407 62
b27f8e75
MD
63static CDS_LIST_HEAD(old_probes);
64static int need_update;
65
f99be407
PMF
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 */
72struct tracepoint_entry {
10c56168 73 struct cds_hlist_node hlist;
b979b346 74 struct tracepoint_probe *probes;
f99be407
PMF
75 int refcount; /* Number of times armed. 0 if disarmed. */
76 char name[0];
77};
78
79struct tp_probes {
80 union {
0222e121 81 struct cds_list_head list;
f99be407 82 } u;
b979b346 83 struct tracepoint_probe probes[0];
f99be407
PMF
84};
85
86static inline void *allocate_probes(int count)
87{
b979b346 88 struct tp_probes *p = zmalloc(count * sizeof(struct tracepoint_probe)
909bc43f 89 + sizeof(struct tp_probes));
f99be407
PMF
90 return p == NULL ? NULL : p->probes;
91}
92
f99be407
PMF
93static inline void release_probes(void *old)
94{
95 if (old) {
b728d87e 96 struct tp_probes *tp_probes = caa_container_of(old,
f99be407 97 struct tp_probes, probes[0]);
474d745f 98 synchronize_rcu();
909bc43f 99 free(tp_probes);
f99be407
PMF
100 }
101}
102
103static void debug_print_probes(struct tracepoint_entry *entry)
104{
105 int i;
106
9dec086e 107 if (!tracepoint_debug || !entry->probes)
f99be407
PMF
108 return;
109
9dec086e
NC
110 for (i = 0; entry->probes[i].func; i++)
111 DBG("Probe %d : %p", i, entry->probes[i].func);
f99be407
PMF
112}
113
114static void *
9dec086e
NC
115tracepoint_entry_add_probe(struct tracepoint_entry *entry,
116 void *probe, void *data)
f99be407
PMF
117{
118 int nr_probes = 0;
b979b346 119 struct tracepoint_probe *old, *new;
f99be407
PMF
120
121 WARN_ON(!probe);
122
123 debug_print_probes(entry);
9dec086e 124 old = entry->probes;
f99be407
PMF
125 if (old) {
126 /* (N -> N+1), (N != 0, 1) probes */
9dec086e
NC
127 for (nr_probes = 0; old[nr_probes].func; nr_probes++)
128 if (old[nr_probes].func == probe &&
129 old[nr_probes].data == data)
f99be407
PMF
130 return ERR_PTR(-EEXIST);
131 }
132 /* + 2 : one for new probe, one for NULL func */
133 new = allocate_probes(nr_probes + 2);
134 if (new == NULL)
135 return ERR_PTR(-ENOMEM);
136 if (old)
b979b346 137 memcpy(new, old, nr_probes * sizeof(struct tracepoint_probe));
9dec086e
NC
138 new[nr_probes].func = probe;
139 new[nr_probes].data = data;
140 new[nr_probes + 1].func = NULL;
f99be407 141 entry->refcount = nr_probes + 1;
9dec086e 142 entry->probes = new;
f99be407
PMF
143 debug_print_probes(entry);
144 return old;
145}
146
147static void *
9dec086e
NC
148tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe,
149 void *data)
f99be407
PMF
150{
151 int nr_probes = 0, nr_del = 0, i;
b979b346 152 struct tracepoint_probe *old, *new;
f99be407 153
9dec086e 154 old = entry->probes;
f99be407
PMF
155
156 if (!old)
157 return ERR_PTR(-ENOENT);
158
159 debug_print_probes(entry);
160 /* (N -> M), (N > 1, M >= 0) probes */
9dec086e 161 for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
c66428ac
DG
162 if (!probe ||
163 (old[nr_probes].func == probe &&
9dec086e 164 old[nr_probes].data == data))
f99be407
PMF
165 nr_del++;
166 }
167
168 if (nr_probes - nr_del == 0) {
169 /* N -> 0, (N > 1) */
9dec086e 170 entry->probes = NULL;
f99be407
PMF
171 entry->refcount = 0;
172 debug_print_probes(entry);
173 return old;
174 } else {
175 int j = 0;
176 /* N -> M, (N > 1, M > 0) */
177 /* + 1 for NULL */
178 new = allocate_probes(nr_probes - nr_del + 1);
179 if (new == NULL)
180 return ERR_PTR(-ENOMEM);
9dec086e
NC
181 for (i = 0; old[i].func; i++)
182 if (probe &&
183 (old[i].func != probe || old[i].data != data))
f99be407 184 new[j++] = old[i];
9dec086e 185 new[nr_probes - nr_del].func = NULL;
f99be407 186 entry->refcount = nr_probes - nr_del;
9dec086e 187 entry->probes = new;
f99be407
PMF
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 */
198static struct tracepoint_entry *get_tracepoint(const char *name)
199{
10c56168
DG
200 struct cds_hlist_head *head;
201 struct cds_hlist_node *node;
f99be407 202 struct tracepoint_entry *e;
23c8854a 203 uint32_t hash = jhash(name, strlen(name), 0);
f99be407
PMF
204
205 head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)];
10c56168 206 cds_hlist_for_each_entry(e, node, head, hlist) {
f99be407
PMF
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 */
217static struct tracepoint_entry *add_tracepoint(const char *name)
218{
10c56168
DG
219 struct cds_hlist_head *head;
220 struct cds_hlist_node *node;
f99be407
PMF
221 struct tracepoint_entry *e;
222 size_t name_len = strlen(name) + 1;
23c8854a 223 uint32_t hash = jhash(name, name_len-1, 0);
f99be407
PMF
224
225 head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)];
10c56168 226 cds_hlist_for_each_entry(e, node, head, hlist) {
f99be407 227 if (!strcmp(name, e->name)) {
c1f20530 228 DBG("tracepoint %s busy", name);
f99be407
PMF
229 return ERR_PTR(-EEXIST); /* Already there */
230 }
231 }
232 /*
1dba3e6c 233 * Using zmalloc here to allocate a variable length element. Could
f99be407
PMF
234 * cause some memory fragmentation if overused.
235 */
1dba3e6c 236 e = zmalloc(sizeof(struct tracepoint_entry) + name_len);
f99be407
PMF
237 if (!e)
238 return ERR_PTR(-ENOMEM);
239 memcpy(&e->name[0], name, name_len);
9dec086e 240 e->probes = NULL;
f99be407 241 e->refcount = 0;
10c56168 242 cds_hlist_add_head(&e->hlist, head);
f99be407
PMF
243 return e;
244}
245
246/*
247 * Remove the tracepoint from the tracepoint hash table. Must be called with
17dfb34b 248 * ust_lock held.
f99be407
PMF
249 */
250static inline void remove_tracepoint(struct tracepoint_entry *e)
251{
10c56168 252 cds_hlist_del(&e->hlist);
909bc43f 253 free(e);
f99be407
PMF
254}
255
256/*
257 * Sets the probe callback corresponding to one tracepoint.
258 */
259static void set_tracepoint(struct tracepoint_entry **entry,
260 struct tracepoint *elem, int active)
261{
262 WARN_ON(strcmp((*entry)->name, elem->name) != 0);
263
264 /*
0222e121 265 * rcu_assign_pointer has a cmm_smp_wmb() which makes sure that the new
f99be407
PMF
266 * probe callbacks array is consistent before setting a pointer to it.
267 * This array is referenced by __DO_TRACE from
0222e121 268 * include/linux/tracepoints.h. A matching cmm_smp_read_barrier_depends()
f99be407
PMF
269 * is used.
270 */
9dec086e 271 rcu_assign_pointer(elem->probes, (*entry)->probes);
f36c12ab 272 elem->state = active;
f99be407
PMF
273}
274
275/*
276 * Disable a tracepoint and its probe callback.
277 * Note: only waiting an RCU period after setting elem->call to the empty
278 * function insures that the original callback is not used anymore. This insured
279 * by preempt_disable around the call site.
280 */
281static void disable_tracepoint(struct tracepoint *elem)
282{
f36c12ab 283 elem->state = 0;
9dec086e 284 rcu_assign_pointer(elem->probes, NULL);
f99be407
PMF
285}
286
287/**
288 * tracepoint_update_probe_range - Update a probe range
289 * @begin: beginning of the range
290 * @end: end of the range
291 *
292 * Updates the probe callback corresponding to a range of tracepoints.
293 */
b27f8e75 294static
f218ff28
MD
295void tracepoint_update_probe_range(struct tracepoint * const *begin,
296 struct tracepoint * const *end)
f99be407 297{
f218ff28 298 struct tracepoint * const *iter;
f99be407
PMF
299 struct tracepoint_entry *mark_entry;
300
f99be407 301 for (iter = begin; iter < end; iter++) {
f08ebbe2
MD
302 if (!*iter)
303 continue; /* skip dummy */
f218ff28
MD
304 if (!(*iter)->name) {
305 disable_tracepoint(*iter);
9dec086e
NC
306 continue;
307 }
f218ff28 308 mark_entry = get_tracepoint((*iter)->name);
f99be407 309 if (mark_entry) {
f218ff28 310 set_tracepoint(&mark_entry, *iter,
f99be407
PMF
311 !!mark_entry->refcount);
312 } else {
f218ff28 313 disable_tracepoint(*iter);
f99be407
PMF
314 }
315 }
f99be407
PMF
316}
317
772030fe
PMF
318static void lib_update_tracepoints(void)
319{
320 struct tracepoint_lib *lib;
321
b27f8e75 322 cds_list_for_each_entry(lib, &libs, list) {
772030fe
PMF
323 tracepoint_update_probe_range(lib->tracepoints_start,
324 lib->tracepoints_start + lib->tracepoints_count);
b27f8e75 325 }
772030fe
PMF
326}
327
f99be407
PMF
328/*
329 * Update probes, removing the faulty probes.
330 */
331static void tracepoint_update_probes(void)
332{
b27f8e75 333 /* tracepoints registered from libraries and executable. */
474d745f 334 lib_update_tracepoints();
f99be407
PMF
335}
336
b979b346 337static struct tracepoint_probe *
9dec086e 338tracepoint_add_probe(const char *name, void *probe, void *data)
f99be407
PMF
339{
340 struct tracepoint_entry *entry;
b979b346 341 struct tracepoint_probe *old;
f99be407
PMF
342
343 entry = get_tracepoint(name);
344 if (!entry) {
345 entry = add_tracepoint(name);
346 if (IS_ERR(entry))
b979b346 347 return (struct tracepoint_probe *)entry;
f99be407 348 }
9dec086e 349 old = tracepoint_entry_add_probe(entry, probe, data);
f99be407
PMF
350 if (IS_ERR(old) && !entry->refcount)
351 remove_tracepoint(entry);
352 return old;
353}
354
355/**
81614639 356 * __tracepoint_probe_register - Connect a probe to a tracepoint
f99be407
PMF
357 * @name: tracepoint name
358 * @probe: probe handler
359 *
360 * Returns 0 if ok, error value on error.
361 * The probe address must at least be aligned on the architecture pointer size.
17dfb34b 362 * Called with the UST lock held.
f99be407 363 */
81614639 364int __tracepoint_probe_register(const char *name, void *probe, void *data)
f99be407
PMF
365{
366 void *old;
367
9dec086e 368 old = tracepoint_add_probe(name, probe, data);
f99be407
PMF
369 if (IS_ERR(old))
370 return PTR_ERR(old);
371
372 tracepoint_update_probes(); /* may update entry */
373 release_probes(old);
374 return 0;
375}
f99be407 376
9dec086e 377static void *tracepoint_remove_probe(const char *name, void *probe, void *data)
f99be407
PMF
378{
379 struct tracepoint_entry *entry;
380 void *old;
381
382 entry = get_tracepoint(name);
383 if (!entry)
384 return ERR_PTR(-ENOENT);
9dec086e 385 old = tracepoint_entry_remove_probe(entry, probe, data);
f99be407
PMF
386 if (IS_ERR(old))
387 return old;
388 if (!entry->refcount)
389 remove_tracepoint(entry);
390 return old;
391}
392
393/**
394 * tracepoint_probe_unregister - Disconnect a probe from a tracepoint
395 * @name: tracepoint name
396 * @probe: probe function pointer
9dec086e 397 * @probe: probe data pointer
f99be407 398 *
17dfb34b 399 * Called with the UST lock held.
f99be407 400 */
81614639 401int __tracepoint_probe_unregister(const char *name, void *probe, void *data)
f99be407
PMF
402{
403 void *old;
404
f280cb51
MD
405 fprintf(stderr, "TEST REGISTER %s\n", name);
406
9dec086e 407 old = tracepoint_remove_probe(name, probe, data);
f99be407
PMF
408 if (IS_ERR(old))
409 return PTR_ERR(old);
410
411 tracepoint_update_probes(); /* may update entry */
412 release_probes(old);
413 return 0;
414}
f99be407 415
f99be407
PMF
416static void tracepoint_add_old_probes(void *old)
417{
418 need_update = 1;
419 if (old) {
b728d87e 420 struct tp_probes *tp_probes = caa_container_of(old,
f99be407 421 struct tp_probes, probes[0]);
0222e121 422 cds_list_add(&tp_probes->u.list, &old_probes);
f99be407
PMF
423 }
424}
425
426/**
427 * tracepoint_probe_register_noupdate - register a probe but not connect
428 * @name: tracepoint name
429 * @probe: probe handler
430 *
431 * caller must call tracepoint_probe_update_all()
17dfb34b 432 * Called with the UST lock held.
f99be407 433 */
9dec086e
NC
434int tracepoint_probe_register_noupdate(const char *name, void *probe,
435 void *data)
f99be407
PMF
436{
437 void *old;
438
9dec086e 439 old = tracepoint_add_probe(name, probe, data);
f99be407 440 if (IS_ERR(old)) {
f99be407
PMF
441 return PTR_ERR(old);
442 }
443 tracepoint_add_old_probes(old);
f99be407
PMF
444 return 0;
445}
f99be407
PMF
446
447/**
448 * tracepoint_probe_unregister_noupdate - remove a probe but not disconnect
449 * @name: tracepoint name
450 * @probe: probe function pointer
451 *
452 * caller must call tracepoint_probe_update_all()
17dfb34b 453 * Called with the UST lock held.
f99be407 454 */
9dec086e
NC
455int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
456 void *data)
f99be407
PMF
457{
458 void *old;
459
9dec086e 460 old = tracepoint_remove_probe(name, probe, data);
f99be407 461 if (IS_ERR(old)) {
f99be407
PMF
462 return PTR_ERR(old);
463 }
464 tracepoint_add_old_probes(old);
f99be407
PMF
465 return 0;
466}
f99be407
PMF
467
468/**
469 * tracepoint_probe_update_all - update tracepoints
17dfb34b 470 * Called with the UST lock held.
f99be407
PMF
471 */
472void tracepoint_probe_update_all(void)
473{
0222e121 474 CDS_LIST_HEAD(release_probes);
f99be407
PMF
475 struct tp_probes *pos, *next;
476
f99be407 477 if (!need_update) {
f99be407
PMF
478 return;
479 }
0222e121
MD
480 if (!cds_list_empty(&old_probes))
481 cds_list_replace_init(&old_probes, &release_probes);
f99be407 482 need_update = 0;
f99be407
PMF
483
484 tracepoint_update_probes();
0222e121
MD
485 cds_list_for_each_entry_safe(pos, next, &release_probes, u.list) {
486 cds_list_del(&pos->u.list);
474d745f 487 synchronize_rcu();
909bc43f 488 free(pos);
f99be407
PMF
489 }
490}
f99be407 491
772030fe
PMF
492/*
493 * Returns 0 if current not found.
494 * Returns 1 if current found.
b27f8e75
MD
495 *
496 * Called with tracepoint mutex held
772030fe
PMF
497 */
498int lib_get_iter_tracepoints(struct tracepoint_iter *iter)
499{
500 struct tracepoint_lib *iter_lib;
501 int found = 0;
502
0222e121 503 cds_list_for_each_entry(iter_lib, &libs, list) {
772030fe
PMF
504 if (iter_lib < iter->lib)
505 continue;
506 else if (iter_lib > iter->lib)
507 iter->tracepoint = NULL;
508 found = tracepoint_get_iter_range(&iter->tracepoint,
509 iter_lib->tracepoints_start,
510 iter_lib->tracepoints_start + iter_lib->tracepoints_count);
511 if (found) {
512 iter->lib = iter_lib;
513 break;
514 }
515 }
772030fe
PMF
516 return found;
517}
518
f99be407
PMF
519/**
520 * tracepoint_get_iter_range - Get a next tracepoint iterator given a range.
521 * @tracepoint: current tracepoints (in), next tracepoint (out)
522 * @begin: beginning of the range
523 * @end: end of the range
524 *
525 * Returns whether a next tracepoint has been found (1) or not (0).
526 * Will return the first tracepoint in the range if the input tracepoint is
527 * NULL.
b27f8e75 528 * Called with tracepoint mutex held.
f99be407 529 */
f218ff28
MD
530int tracepoint_get_iter_range(struct tracepoint * const **tracepoint,
531 struct tracepoint * const *begin, struct tracepoint * const *end)
f99be407 532{
f08ebbe2 533 if (!*tracepoint && begin != end)
f99be407 534 *tracepoint = begin;
f08ebbe2
MD
535 while (*tracepoint >= begin && *tracepoint < end) {
536 if (!**tracepoint)
537 (*tracepoint)++; /* skip dummy */
538 else
539 return 1;
f99be407 540 }
f99be407
PMF
541 return 0;
542}
f99be407 543
b27f8e75
MD
544/*
545 * Called with tracepoint mutex held.
546 */
f99be407
PMF
547static void tracepoint_get_iter(struct tracepoint_iter *iter)
548{
549 int found = 0;
550
474d745f
PMF
551 /* tracepoints in libs. */
552 found = lib_get_iter_tracepoints(iter);
f99be407
PMF
553 if (!found)
554 tracepoint_iter_reset(iter);
555}
556
17dfb34b
MD
557/*
558 * Called with UST lock held.
559 */
f99be407
PMF
560void tracepoint_iter_start(struct tracepoint_iter *iter)
561{
562 tracepoint_get_iter(iter);
563}
f99be407 564
b27f8e75 565/*
17dfb34b 566 * Called with UST lock held.
b27f8e75 567 */
f99be407
PMF
568void tracepoint_iter_next(struct tracepoint_iter *iter)
569{
570 iter->tracepoint++;
571 /*
572 * iter->tracepoint may be invalid because we blindly incremented it.
573 * Make sure it is valid by marshalling on the tracepoints, getting the
574 * tracepoints from following modules if necessary.
575 */
576 tracepoint_get_iter(iter);
577}
f99be407 578
17dfb34b
MD
579/*
580 * Called with UST lock held.
581 */
f99be407
PMF
582void tracepoint_iter_stop(struct tracepoint_iter *iter)
583{
584}
f99be407
PMF
585
586void tracepoint_iter_reset(struct tracepoint_iter *iter)
587{
f99be407
PMF
588 iter->tracepoint = NULL;
589}
474d745f
PMF
590
591void tracepoint_set_new_tracepoint_cb(void (*cb)(struct tracepoint *))
592{
593 new_tracepoint_cb = cb;
594}
f99be407 595
f218ff28 596static void new_tracepoints(struct tracepoint * const *start, struct tracepoint * const *end)
f99be407 597{
f218ff28
MD
598 if (new_tracepoint_cb) {
599 struct tracepoint * const *t;
f08ebbe2 600
b27f8e75 601 for (t = start; t < end; t++) {
f08ebbe2
MD
602 if (*t)
603 new_tracepoint_cb(*t);
474d745f
PMF
604 }
605 }
f99be407 606}
f99be407 607
b27f8e75
MD
608int tracepoint_register_lib(struct tracepoint * const *tracepoints_start,
609 int tracepoints_count)
474d745f 610{
b467f7a7 611 struct tracepoint_lib *pl, *iter;
474d745f 612
edaa1431
MD
613 init_tracepoint();
614
1dba3e6c 615 pl = (struct tracepoint_lib *) zmalloc(sizeof(struct tracepoint_lib));
474d745f
PMF
616
617 pl->tracepoints_start = tracepoints_start;
618 pl->tracepoints_count = tracepoints_count;
619
17dfb34b 620 ust_lock();
b467f7a7
MD
621 /*
622 * We sort the libs by struct lib pointer address.
623 */
624 cds_list_for_each_entry_reverse(iter, &libs, list) {
625 BUG_ON(iter == pl); /* Should never be in the list twice */
626 if (iter < pl) {
627 /* We belong to the location right after iter. */
628 cds_list_add(&pl->list, &iter->list);
629 goto lib_added;
630 }
631 }
632 /* We should be added at the head of the list */
0222e121 633 cds_list_add(&pl->list, &libs);
b467f7a7 634lib_added:
474d745f
PMF
635 new_tracepoints(tracepoints_start, tracepoints_start + tracepoints_count);
636
b27f8e75 637 /* TODO: update just the loaded lib */
474d745f 638 lib_update_tracepoints();
17dfb34b 639 ust_unlock();
474d745f 640
1fcf7ad7
MD
641 DBG("just registered a tracepoints section from %p and having %d tracepoints",
642 tracepoints_start, tracepoints_count);
9dec086e 643
474d745f
PMF
644 return 0;
645}
646
f218ff28 647int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start)
474d745f 648{
24b6668c
PMF
649 struct tracepoint_lib *lib;
650
17dfb34b 651 ust_lock();
0222e121 652 cds_list_for_each_entry(lib, &libs, list) {
f218ff28 653 if (lib->tracepoints_start == tracepoints_start) {
24b6668c 654 struct tracepoint_lib *lib2free = lib;
0222e121 655 cds_list_del(&lib->list);
24b6668c
PMF
656 free(lib2free);
657 break;
658 }
659 }
17dfb34b 660 ust_unlock();
474d745f
PMF
661
662 return 0;
663}
b27f8e75 664
edaa1431 665void init_tracepoint(void)
b27f8e75 666{
edaa1431
MD
667 if (uatomic_xchg(&initialized, 1) == 1)
668 return;
5e96a467 669 init_usterr();
b27f8e75
MD
670}
671
edaa1431 672void exit_tracepoint(void)
b27f8e75 673{
17dfb34b 674 initialized = 0;
b27f8e75 675}
This page took 0.061238 seconds and 4 git commands to generate.