2 * Copyright (C) 2008-2011 Mathieu Desnoyers
3 * Copyright (C) 2009 Pierre-Marc Fournier
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;
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
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
19 * Ported to userspace by Pierre-Marc Fournier.
28 #include <urcu/arch.h>
30 #include <urcu/hlist.h>
31 #include <urcu/uatomic.h>
32 #include <urcu/compiler.h>
33 #include <urcu/system.h>
35 #include <lttng/tracepoint.h>
36 #include <lttng/ust-abi.h> /* for LTTNG_UST_SYM_NAME_LEN */
38 #include <usterr-signal-safe.h>
41 #include "tracepoint-internal.h"
42 #include "lttng-tracer-core.h"
46 /* Test compiler support for weak symbols with hidden visibility. */
47 int __tracepoint_test_symbol1
__attribute__((weak
, visibility("hidden")));
48 void *__tracepoint_test_symbol2
__attribute__((weak
, visibility("hidden")));
51 } __tracepoint_test_symbol3
__attribute__((weak
, visibility("hidden")));
53 /* Set to 1 to enable tracepoint debug output */
54 static const int tracepoint_debug
;
55 static int initialized
;
56 static void (*new_tracepoint_cb
)(struct lttng_ust_tracepoint
*);
59 * tracepoint_mutex nests inside UST mutex.
61 * Note about interaction with fork/clone: UST does not hold the
62 * tracepoint mutex across fork/clone because it is either:
63 * - nested within UST mutex, in which case holding the UST mutex across
65 * - taken by a library constructor, which should never race with a
66 * fork/clone if the application is expected to continue running with
67 * the same memory layout (no following exec()).
69 static pthread_mutex_t tracepoint_mutex
= PTHREAD_MUTEX_INITIALIZER
;
72 * libraries that contain tracepoints (struct tracepoint_lib).
73 * Protected by tracepoint mutex.
75 static CDS_LIST_HEAD(libs
);
78 * The tracepoint mutex protects the library tracepoints, the hash table, and
80 * All calls to the tracepoint API must be protected by the tracepoint mutex,
81 * excepts calls to tracepoint_register_lib and
82 * tracepoint_unregister_lib, which take the tracepoint mutex themselves.
86 * Tracepoint hash table, containing the active tracepoints.
87 * Protected by tracepoint mutex.
89 #define TRACEPOINT_HASH_BITS 12
90 #define TRACEPOINT_TABLE_SIZE (1 << TRACEPOINT_HASH_BITS)
91 static struct cds_hlist_head tracepoint_table
[TRACEPOINT_TABLE_SIZE
];
93 static CDS_LIST_HEAD(old_probes
);
94 static int need_update
;
96 static CDS_LIST_HEAD(release_queue
);
97 static int release_queue_need_update
;
101 * It is used to to delay the free of multiple probes array until a quiescent
103 * Tracepoint entries modifications are protected by the tracepoint mutex.
105 struct tracepoint_entry
{
106 struct cds_hlist_node hlist
;
107 struct lttng_ust_tracepoint_probe
*probes
;
108 int refcount
; /* Number of times armed. 0 if disarmed. */
109 int callsite_refcount
; /* how many libs use this tracepoint */
110 const char *signature
;
116 struct cds_list_head list
;
117 /* Field below only used for call_rcu scheme */
118 /* struct rcu_head head; */
120 struct lttng_ust_tracepoint_probe probes
[0];
124 * Callsite hash table, containing the tracepoint call sites.
125 * Protected by tracepoint mutex.
127 #define CALLSITE_HASH_BITS 12
128 #define CALLSITE_TABLE_SIZE (1 << CALLSITE_HASH_BITS)
129 static struct cds_hlist_head callsite_table
[CALLSITE_TABLE_SIZE
];
131 struct callsite_entry
{
132 struct cds_hlist_node hlist
; /* hash table node */
133 struct cds_list_head node
; /* lib list of callsites node */
134 struct lttng_ust_tracepoint
*tp
;
137 /* coverity[+alloc] */
138 static void *allocate_probes(int count
)
140 struct tp_probes
*p
=
141 zmalloc(count
* sizeof(struct lttng_ust_tracepoint_probe
)
142 + sizeof(struct tp_probes
));
143 return p
== NULL
? NULL
: p
->probes
;
146 /* coverity[+free : arg-0] */
147 static void release_probes(void *old
)
150 struct tp_probes
*tp_probes
= caa_container_of(old
,
151 struct tp_probes
, probes
[0]);
157 static void debug_print_probes(struct tracepoint_entry
*entry
)
161 if (!tracepoint_debug
|| !entry
->probes
)
164 for (i
= 0; entry
->probes
[i
].func
; i
++)
165 DBG("Probe %d : %p", i
, entry
->probes
[i
].func
);
169 tracepoint_entry_add_probe(struct tracepoint_entry
*entry
,
170 void (*probe
)(void), void *data
)
173 struct lttng_ust_tracepoint_probe
*old
, *new;
177 return ERR_PTR(-EINVAL
);
179 debug_print_probes(entry
);
182 /* (N -> N+1), (N != 0, 1) probes */
183 for (nr_probes
= 0; old
[nr_probes
].func
; nr_probes
++)
184 if (old
[nr_probes
].func
== probe
&&
185 old
[nr_probes
].data
== data
)
186 return ERR_PTR(-EEXIST
);
188 /* + 2 : one for new probe, one for NULL func */
189 new = allocate_probes(nr_probes
+ 2);
191 return ERR_PTR(-ENOMEM
);
194 nr_probes
* sizeof(struct lttng_ust_tracepoint_probe
));
195 new[nr_probes
].func
= probe
;
196 new[nr_probes
].data
= data
;
197 new[nr_probes
+ 1].func
= NULL
;
198 entry
->refcount
= nr_probes
+ 1;
200 debug_print_probes(entry
);
205 tracepoint_entry_remove_probe(struct tracepoint_entry
*entry
,
206 void (*probe
)(void), void *data
)
208 int nr_probes
= 0, nr_del
= 0, i
;
209 struct lttng_ust_tracepoint_probe
*old
, *new;
214 return ERR_PTR(-ENOENT
);
216 debug_print_probes(entry
);
217 /* (N -> M), (N > 1, M >= 0) probes */
219 for (nr_probes
= 0; old
[nr_probes
].func
; nr_probes
++) {
220 if (old
[nr_probes
].func
== probe
&&
221 old
[nr_probes
].data
== data
)
226 if (nr_probes
- nr_del
== 0) {
227 /* N -> 0, (N > 1) */
228 entry
->probes
= NULL
;
230 debug_print_probes(entry
);
234 /* N -> M, (N > 1, M > 0) */
236 new = allocate_probes(nr_probes
- nr_del
+ 1);
238 return ERR_PTR(-ENOMEM
);
239 for (i
= 0; old
[i
].func
; i
++)
240 if (old
[i
].func
!= probe
|| old
[i
].data
!= data
)
242 new[nr_probes
- nr_del
].func
= NULL
;
243 entry
->refcount
= nr_probes
- nr_del
;
246 debug_print_probes(entry
);
251 * Get tracepoint if the tracepoint is present in the tracepoint hash table.
252 * Must be called with tracepoint mutex held.
253 * Returns NULL if not present.
255 static struct tracepoint_entry
*get_tracepoint(const char *name
)
257 struct cds_hlist_head
*head
;
258 struct cds_hlist_node
*node
;
259 struct tracepoint_entry
*e
;
260 size_t name_len
= strlen(name
);
263 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
264 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
265 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
267 hash
= jhash(name
, name_len
, 0);
268 head
= &tracepoint_table
[hash
& (TRACEPOINT_TABLE_SIZE
- 1)];
269 cds_hlist_for_each_entry(e
, node
, head
, hlist
) {
270 if (!strncmp(name
, e
->name
, LTTNG_UST_SYM_NAME_LEN
- 1))
277 * Add the tracepoint to the tracepoint hash table. Must be called with
278 * tracepoint mutex held.
280 static struct tracepoint_entry
*add_tracepoint(const char *name
,
281 const char *signature
)
283 struct cds_hlist_head
*head
;
284 struct cds_hlist_node
*node
;
285 struct tracepoint_entry
*e
;
286 size_t name_len
= strlen(name
);
289 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
290 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
291 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
293 hash
= jhash(name
, name_len
, 0);
294 head
= &tracepoint_table
[hash
& (TRACEPOINT_TABLE_SIZE
- 1)];
295 cds_hlist_for_each_entry(e
, node
, head
, hlist
) {
296 if (!strncmp(name
, e
->name
, LTTNG_UST_SYM_NAME_LEN
- 1)) {
297 DBG("tracepoint %s busy", name
);
298 return ERR_PTR(-EEXIST
); /* Already there */
302 * Using zmalloc here to allocate a variable length element. Could
303 * cause some memory fragmentation if overused.
305 e
= zmalloc(sizeof(struct tracepoint_entry
) + name_len
+ 1);
307 return ERR_PTR(-ENOMEM
);
308 memcpy(&e
->name
[0], name
, name_len
+ 1);
309 e
->name
[name_len
] = '\0';
312 e
->callsite_refcount
= 0;
313 e
->signature
= signature
;
314 cds_hlist_add_head(&e
->hlist
, head
);
319 * Remove the tracepoint from the tracepoint hash table. Must be called with
320 * tracepoint mutex held.
322 static void remove_tracepoint(struct tracepoint_entry
*e
)
324 cds_hlist_del(&e
->hlist
);
329 * Sets the probe callback corresponding to one tracepoint.
331 static void set_tracepoint(struct tracepoint_entry
**entry
,
332 struct lttng_ust_tracepoint
*elem
, int active
)
334 WARN_ON(strncmp((*entry
)->name
, elem
->name
, LTTNG_UST_SYM_NAME_LEN
- 1) != 0);
336 * Check that signatures match before connecting a probe to a
337 * tracepoint. Warn the user if they don't.
339 if (strcmp(elem
->signature
, (*entry
)->signature
) != 0) {
340 static int warned
= 0;
342 /* Only print once, don't flood console. */
344 WARN("Tracepoint signature mismatch, not enabling one or more tracepoints. Ensure that the tracepoint probes prototypes match the application.");
345 WARN("Tracepoint \"%s\" signatures: call: \"%s\" vs probe: \"%s\".",
346 elem
->name
, elem
->signature
, (*entry
)->signature
);
349 /* Don't accept connecting non-matching signatures. */
354 * rcu_assign_pointer has a cmm_smp_wmb() which makes sure that the new
355 * probe callbacks array is consistent before setting a pointer to it.
356 * This array is referenced by __DO_TRACE from
357 * include/linux/tracepoints.h. A matching cmm_smp_read_barrier_depends()
360 rcu_assign_pointer(elem
->probes
, (*entry
)->probes
);
361 CMM_STORE_SHARED(elem
->state
, active
);
365 * Disable a tracepoint and its probe callback.
366 * Note: only waiting an RCU period after setting elem->call to the empty
367 * function insures that the original callback is not used anymore. This insured
368 * by preempt_disable around the call site.
370 static void disable_tracepoint(struct lttng_ust_tracepoint
*elem
)
372 CMM_STORE_SHARED(elem
->state
, 0);
373 rcu_assign_pointer(elem
->probes
, NULL
);
377 * Add the callsite to the callsite hash table. Must be called with
378 * tracepoint mutex held.
380 static void add_callsite(struct tracepoint_lib
* lib
, struct lttng_ust_tracepoint
*tp
)
382 struct cds_hlist_head
*head
;
383 struct callsite_entry
*e
;
384 const char *name
= tp
->name
;
385 size_t name_len
= strlen(name
);
387 struct tracepoint_entry
*tp_entry
;
389 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
390 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
391 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
393 hash
= jhash(name
, name_len
, 0);
394 head
= &callsite_table
[hash
& (CALLSITE_TABLE_SIZE
- 1)];
395 e
= zmalloc(sizeof(struct callsite_entry
));
397 PERROR("Unable to add callsite for tracepoint \"%s\"", name
);
400 cds_hlist_add_head(&e
->hlist
, head
);
402 cds_list_add(&e
->node
, &lib
->callsites
);
404 tp_entry
= get_tracepoint(name
);
407 tp_entry
->callsite_refcount
++;
411 * Remove the callsite from the callsite hash table and from lib
412 * callsite list. Must be called with tracepoint mutex held.
414 static void remove_callsite(struct callsite_entry
*e
)
416 struct tracepoint_entry
*tp_entry
;
418 tp_entry
= get_tracepoint(e
->tp
->name
);
420 tp_entry
->callsite_refcount
--;
421 if (tp_entry
->callsite_refcount
== 0)
422 disable_tracepoint(e
->tp
);
424 cds_hlist_del(&e
->hlist
);
425 cds_list_del(&e
->node
);
430 * Enable/disable all callsites based on the state of a specific
432 * Must be called with tracepoint mutex held.
434 static void tracepoint_sync_callsites(const char *name
)
436 struct cds_hlist_head
*head
;
437 struct cds_hlist_node
*node
;
438 struct callsite_entry
*e
;
439 size_t name_len
= strlen(name
);
441 struct tracepoint_entry
*tp_entry
;
443 tp_entry
= get_tracepoint(name
);
444 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
445 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
446 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
448 hash
= jhash(name
, name_len
, 0);
449 head
= &callsite_table
[hash
& (CALLSITE_TABLE_SIZE
- 1)];
450 cds_hlist_for_each_entry(e
, node
, head
, hlist
) {
451 struct lttng_ust_tracepoint
*tp
= e
->tp
;
453 if (strncmp(name
, tp
->name
, LTTNG_UST_SYM_NAME_LEN
- 1))
456 set_tracepoint(&tp_entry
, tp
,
457 !!tp_entry
->refcount
);
459 disable_tracepoint(tp
);
465 * tracepoint_update_probe_range - Update a probe range
466 * @begin: beginning of the range
467 * @end: end of the range
469 * Updates the probe callback corresponding to a range of tracepoints.
472 void tracepoint_update_probe_range(struct lttng_ust_tracepoint
* const *begin
,
473 struct lttng_ust_tracepoint
* const *end
)
475 struct lttng_ust_tracepoint
* const *iter
;
476 struct tracepoint_entry
*mark_entry
;
478 for (iter
= begin
; iter
< end
; iter
++) {
480 continue; /* skip dummy */
481 if (!(*iter
)->name
) {
482 disable_tracepoint(*iter
);
485 mark_entry
= get_tracepoint((*iter
)->name
);
487 set_tracepoint(&mark_entry
, *iter
,
488 !!mark_entry
->refcount
);
490 disable_tracepoint(*iter
);
495 static void lib_update_tracepoints(struct tracepoint_lib
*lib
)
497 tracepoint_update_probe_range(lib
->tracepoints_start
,
498 lib
->tracepoints_start
+ lib
->tracepoints_count
);
501 static void lib_register_callsites(struct tracepoint_lib
*lib
)
503 struct lttng_ust_tracepoint
* const *begin
;
504 struct lttng_ust_tracepoint
* const *end
;
505 struct lttng_ust_tracepoint
* const *iter
;
507 begin
= lib
->tracepoints_start
;
508 end
= lib
->tracepoints_start
+ lib
->tracepoints_count
;
510 for (iter
= begin
; iter
< end
; iter
++) {
512 continue; /* skip dummy */
513 if (!(*iter
)->name
) {
516 add_callsite(lib
, *iter
);
520 static void lib_unregister_callsites(struct tracepoint_lib
*lib
)
522 struct callsite_entry
*callsite
, *tmp
;
524 cds_list_for_each_entry_safe(callsite
, tmp
, &lib
->callsites
, node
)
525 remove_callsite(callsite
);
529 * Update probes, removing the faulty probes.
531 static void tracepoint_update_probes(void)
533 struct tracepoint_lib
*lib
;
535 /* tracepoints registered from libraries and executable. */
536 cds_list_for_each_entry(lib
, &libs
, list
)
537 lib_update_tracepoints(lib
);
540 static struct lttng_ust_tracepoint_probe
*
541 tracepoint_add_probe(const char *name
, void (*probe
)(void), void *data
,
542 const char *signature
)
544 struct tracepoint_entry
*entry
;
545 struct lttng_ust_tracepoint_probe
*old
;
547 entry
= get_tracepoint(name
);
549 entry
= add_tracepoint(name
, signature
);
551 return (struct lttng_ust_tracepoint_probe
*)entry
;
553 old
= tracepoint_entry_add_probe(entry
, probe
, data
);
554 if (IS_ERR(old
) && !entry
->refcount
)
555 remove_tracepoint(entry
);
559 static void tracepoint_release_queue_add_old_probes(void *old
)
561 release_queue_need_update
= 1;
563 struct tp_probes
*tp_probes
= caa_container_of(old
,
564 struct tp_probes
, probes
[0]);
565 cds_list_add(&tp_probes
->u
.list
, &release_queue
);
570 * __tracepoint_probe_register - Connect a probe to a tracepoint
571 * @name: tracepoint name
572 * @probe: probe handler
574 * Returns 0 if ok, error value on error.
575 * The probe address must at least be aligned on the architecture pointer size.
576 * Called with the tracepoint mutex held.
578 int __tracepoint_probe_register(const char *name
, void (*probe
)(void),
579 void *data
, const char *signature
)
584 DBG("Registering probe to tracepoint %s", name
);
586 pthread_mutex_lock(&tracepoint_mutex
);
587 old
= tracepoint_add_probe(name
, probe
, data
, signature
);
593 tracepoint_sync_callsites(name
);
596 pthread_mutex_unlock(&tracepoint_mutex
);
601 * Caller needs to invoke __tracepoint_probe_release_queue() after
602 * calling __tracepoint_probe_register_queue_release() one or multiple
603 * times to ensure it does not leak memory.
605 int __tracepoint_probe_register_queue_release(const char *name
,
606 void (*probe
)(void), void *data
, const char *signature
)
611 DBG("Registering probe to tracepoint %s. Queuing release.", name
);
613 pthread_mutex_lock(&tracepoint_mutex
);
614 old
= tracepoint_add_probe(name
, probe
, data
, signature
);
620 tracepoint_sync_callsites(name
);
621 tracepoint_release_queue_add_old_probes(old
);
623 pthread_mutex_unlock(&tracepoint_mutex
);
627 static void *tracepoint_remove_probe(const char *name
, void (*probe
)(void),
630 struct tracepoint_entry
*entry
;
633 entry
= get_tracepoint(name
);
635 return ERR_PTR(-ENOENT
);
636 old
= tracepoint_entry_remove_probe(entry
, probe
, data
);
639 if (!entry
->refcount
)
640 remove_tracepoint(entry
);
645 * tracepoint_probe_unregister - Disconnect a probe from a tracepoint
646 * @name: tracepoint name
647 * @probe: probe function pointer
648 * @probe: probe data pointer
650 int __tracepoint_probe_unregister(const char *name
, void (*probe
)(void),
656 DBG("Un-registering probe from tracepoint %s", name
);
658 pthread_mutex_lock(&tracepoint_mutex
);
659 old
= tracepoint_remove_probe(name
, probe
, data
);
664 tracepoint_sync_callsites(name
);
667 pthread_mutex_unlock(&tracepoint_mutex
);
672 * Caller needs to invoke __tracepoint_probe_release_queue() after
673 * calling __tracepoint_probe_unregister_queue_release() one or multiple
674 * times to ensure it does not leak memory.
676 int __tracepoint_probe_unregister_queue_release(const char *name
,
677 void (*probe
)(void), void *data
)
682 DBG("Un-registering probe from tracepoint %s. Queuing release.", name
);
684 pthread_mutex_lock(&tracepoint_mutex
);
685 old
= tracepoint_remove_probe(name
, probe
, data
);
690 tracepoint_sync_callsites(name
);
691 tracepoint_release_queue_add_old_probes(old
);
693 pthread_mutex_unlock(&tracepoint_mutex
);
697 void __tracepoint_probe_prune_release_queue(void)
699 CDS_LIST_HEAD(release_probes
);
700 struct tp_probes
*pos
, *next
;
702 DBG("Release queue of unregistered tracepoint probes.");
704 pthread_mutex_lock(&tracepoint_mutex
);
705 if (!release_queue_need_update
)
707 if (!cds_list_empty(&release_queue
))
708 cds_list_replace_init(&release_queue
, &release_probes
);
709 release_queue_need_update
= 0;
711 /* Wait for grace period between all sync_callsites and free. */
714 cds_list_for_each_entry_safe(pos
, next
, &release_probes
, u
.list
) {
715 cds_list_del(&pos
->u
.list
);
719 pthread_mutex_unlock(&tracepoint_mutex
);
722 static void tracepoint_add_old_probes(void *old
)
726 struct tp_probes
*tp_probes
= caa_container_of(old
,
727 struct tp_probes
, probes
[0]);
728 cds_list_add(&tp_probes
->u
.list
, &old_probes
);
733 * tracepoint_probe_register_noupdate - register a probe but not connect
734 * @name: tracepoint name
735 * @probe: probe handler
737 * caller must call tracepoint_probe_update_all()
739 int tracepoint_probe_register_noupdate(const char *name
, void (*probe
)(void),
740 void *data
, const char *signature
)
745 pthread_mutex_lock(&tracepoint_mutex
);
746 old
= tracepoint_add_probe(name
, probe
, data
, signature
);
751 tracepoint_add_old_probes(old
);
753 pthread_mutex_unlock(&tracepoint_mutex
);
758 * tracepoint_probe_unregister_noupdate - remove a probe but not disconnect
759 * @name: tracepoint name
760 * @probe: probe function pointer
762 * caller must call tracepoint_probe_update_all()
763 * Called with the tracepoint mutex held.
765 int tracepoint_probe_unregister_noupdate(const char *name
, void (*probe
)(void),
771 DBG("Un-registering probe from tracepoint %s", name
);
773 pthread_mutex_lock(&tracepoint_mutex
);
774 old
= tracepoint_remove_probe(name
, probe
, data
);
779 tracepoint_add_old_probes(old
);
781 pthread_mutex_unlock(&tracepoint_mutex
);
786 * tracepoint_probe_update_all - update tracepoints
788 void tracepoint_probe_update_all(void)
790 CDS_LIST_HEAD(release_probes
);
791 struct tp_probes
*pos
, *next
;
793 pthread_mutex_lock(&tracepoint_mutex
);
797 if (!cds_list_empty(&old_probes
))
798 cds_list_replace_init(&old_probes
, &release_probes
);
801 tracepoint_update_probes();
802 /* Wait for grace period between update_probes and free. */
804 cds_list_for_each_entry_safe(pos
, next
, &release_probes
, u
.list
) {
805 cds_list_del(&pos
->u
.list
);
809 pthread_mutex_unlock(&tracepoint_mutex
);
812 void tracepoint_set_new_tracepoint_cb(void (*cb
)(struct lttng_ust_tracepoint
*))
814 new_tracepoint_cb
= cb
;
817 static void new_tracepoints(struct lttng_ust_tracepoint
* const *start
,
818 struct lttng_ust_tracepoint
* const *end
)
820 if (new_tracepoint_cb
) {
821 struct lttng_ust_tracepoint
* const *t
;
823 for (t
= start
; t
< end
; t
++) {
825 new_tracepoint_cb(*t
);
830 int tracepoint_register_lib(struct lttng_ust_tracepoint
* const *tracepoints_start
,
831 int tracepoints_count
)
833 struct tracepoint_lib
*pl
, *iter
;
837 pl
= (struct tracepoint_lib
*) zmalloc(sizeof(struct tracepoint_lib
));
839 PERROR("Unable to register tracepoint lib");
842 pl
->tracepoints_start
= tracepoints_start
;
843 pl
->tracepoints_count
= tracepoints_count
;
844 CDS_INIT_LIST_HEAD(&pl
->callsites
);
846 pthread_mutex_lock(&tracepoint_mutex
);
848 * We sort the libs by struct lib pointer address.
850 cds_list_for_each_entry_reverse(iter
, &libs
, list
) {
851 BUG_ON(iter
== pl
); /* Should never be in the list twice */
853 /* We belong to the location right after iter. */
854 cds_list_add(&pl
->list
, &iter
->list
);
858 /* We should be added at the head of the list */
859 cds_list_add(&pl
->list
, &libs
);
861 new_tracepoints(tracepoints_start
, tracepoints_start
+ tracepoints_count
);
862 lib_register_callsites(pl
);
863 lib_update_tracepoints(pl
);
864 pthread_mutex_unlock(&tracepoint_mutex
);
866 DBG("just registered a tracepoints section from %p and having %d tracepoints",
867 tracepoints_start
, tracepoints_count
);
871 for (i
= 0; i
< tracepoints_count
; i
++) {
872 DBG("registered tracepoint: %s", tracepoints_start
[i
]->name
);
879 int tracepoint_unregister_lib(struct lttng_ust_tracepoint
* const *tracepoints_start
)
881 struct tracepoint_lib
*lib
;
883 pthread_mutex_lock(&tracepoint_mutex
);
884 cds_list_for_each_entry(lib
, &libs
, list
) {
885 if (lib
->tracepoints_start
!= tracepoints_start
)
888 cds_list_del(&lib
->list
);
890 * Unregistering a callsite also decreases the
891 * callsite reference count of the corresponding
892 * tracepoint, and disables the tracepoint if
893 * the reference count drops to zero.
895 lib_unregister_callsites(lib
);
896 DBG("just unregistered a tracepoints section from %p",
897 lib
->tracepoints_start
);
901 pthread_mutex_unlock(&tracepoint_mutex
);
906 * Report in debug message whether the compiler correctly supports weak
907 * hidden symbols. This test checks that the address associated with two
908 * weak symbols with hidden visibility is the same when declared within
909 * two compile units part of the same module.
911 static void check_weak_hidden(void)
913 DBG("Your compiler treats weak symbols with hidden visibility for integer objects as %s between compile units part of the same module.",
914 &__tracepoint_test_symbol1
== lttng_ust_tp_check_weak_hidden1() ?
916 "DIFFERENT addresses");
917 DBG("Your compiler treats weak symbols with hidden visibility for pointer objects as %s between compile units part of the same module.",
918 &__tracepoint_test_symbol2
== lttng_ust_tp_check_weak_hidden2() ?
920 "DIFFERENT addresses");
921 DBG("Your compiler treats weak symbols with hidden visibility for 24-byte structure objects as %s between compile units part of the same module.",
922 &__tracepoint_test_symbol3
== lttng_ust_tp_check_weak_hidden3() ?
924 "DIFFERENT addresses");
927 void init_tracepoint(void)
929 if (uatomic_xchg(&initialized
, 1) == 1)
935 void exit_tracepoint(void)
941 * Create the wrapper symbols.
943 #undef tp_rcu_read_lock_bp
944 #undef tp_rcu_read_unlock_bp
945 #undef tp_rcu_dereference_bp
947 void tp_rcu_read_lock_bp(void)
952 void tp_rcu_read_unlock_bp(void)
954 rcu_read_unlock_bp();
957 void *tp_rcu_dereference_sym_bp(void *p
)
959 return rcu_dereference_bp(p
);