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 */
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
;
135 bool tp_entry_callsite_ref
; /* Has a tp_entry took a ref on this callsite */
138 /* coverity[+alloc] */
139 static void *allocate_probes(int count
)
141 struct tp_probes
*p
=
142 zmalloc(count
* sizeof(struct lttng_ust_tracepoint_probe
)
143 + sizeof(struct tp_probes
));
144 return p
== NULL
? NULL
: p
->probes
;
147 /* coverity[+free : arg-0] */
148 static void release_probes(void *old
)
151 struct tp_probes
*tp_probes
= caa_container_of(old
,
152 struct tp_probes
, probes
[0]);
158 static void debug_print_probes(struct tracepoint_entry
*entry
)
162 if (!tracepoint_debug
|| !entry
->probes
)
165 for (i
= 0; entry
->probes
[i
].func
; i
++)
166 DBG("Probe %d : %p", i
, entry
->probes
[i
].func
);
170 tracepoint_entry_add_probe(struct tracepoint_entry
*entry
,
171 void (*probe
)(void), void *data
)
174 struct lttng_ust_tracepoint_probe
*old
, *new;
178 return ERR_PTR(-EINVAL
);
180 debug_print_probes(entry
);
183 /* (N -> N+1), (N != 0, 1) probes */
184 for (nr_probes
= 0; old
[nr_probes
].func
; nr_probes
++)
185 if (old
[nr_probes
].func
== probe
&&
186 old
[nr_probes
].data
== data
)
187 return ERR_PTR(-EEXIST
);
189 /* + 2 : one for new probe, one for NULL func */
190 new = allocate_probes(nr_probes
+ 2);
192 return ERR_PTR(-ENOMEM
);
195 nr_probes
* sizeof(struct lttng_ust_tracepoint_probe
));
196 new[nr_probes
].func
= probe
;
197 new[nr_probes
].data
= data
;
198 new[nr_probes
+ 1].func
= NULL
;
199 entry
->refcount
= nr_probes
+ 1;
201 debug_print_probes(entry
);
206 tracepoint_entry_remove_probe(struct tracepoint_entry
*entry
,
207 void (*probe
)(void), void *data
)
209 int nr_probes
= 0, nr_del
= 0, i
;
210 struct lttng_ust_tracepoint_probe
*old
, *new;
215 return ERR_PTR(-ENOENT
);
217 debug_print_probes(entry
);
218 /* (N -> M), (N > 1, M >= 0) probes */
220 for (nr_probes
= 0; old
[nr_probes
].func
; nr_probes
++) {
221 if (old
[nr_probes
].func
== probe
&&
222 old
[nr_probes
].data
== data
)
227 if (nr_probes
- nr_del
== 0) {
228 /* N -> 0, (N > 1) */
229 entry
->probes
= NULL
;
231 debug_print_probes(entry
);
235 /* N -> M, (N > 1, M > 0) */
237 new = allocate_probes(nr_probes
- nr_del
+ 1);
239 return ERR_PTR(-ENOMEM
);
240 for (i
= 0; old
[i
].func
; i
++)
241 if (old
[i
].func
!= probe
|| old
[i
].data
!= data
)
243 new[nr_probes
- nr_del
].func
= NULL
;
244 entry
->refcount
= nr_probes
- nr_del
;
247 debug_print_probes(entry
);
252 * Get tracepoint if the tracepoint is present in the tracepoint hash table.
253 * Must be called with tracepoint mutex held.
254 * Returns NULL if not present.
256 static struct tracepoint_entry
*get_tracepoint(const char *name
)
258 struct cds_hlist_head
*head
;
259 struct cds_hlist_node
*node
;
260 struct tracepoint_entry
*e
;
261 size_t name_len
= strlen(name
);
264 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
265 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
266 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
268 hash
= jhash(name
, name_len
, 0);
269 head
= &tracepoint_table
[hash
& (TRACEPOINT_TABLE_SIZE
- 1)];
270 cds_hlist_for_each_entry(e
, node
, head
, hlist
) {
271 if (!strncmp(name
, e
->name
, LTTNG_UST_SYM_NAME_LEN
- 1))
278 * Add the tracepoint to the tracepoint hash table. Must be called with
279 * tracepoint mutex held.
281 static struct tracepoint_entry
*add_tracepoint(const char *name
,
282 const char *signature
)
284 struct cds_hlist_head
*head
;
285 struct cds_hlist_node
*node
;
286 struct tracepoint_entry
*e
;
287 size_t name_len
= strlen(name
);
288 size_t sig_len
= strlen(signature
);
289 size_t sig_off
, name_off
;
292 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
293 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
294 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
296 hash
= jhash(name
, name_len
, 0);
297 head
= &tracepoint_table
[hash
& (TRACEPOINT_TABLE_SIZE
- 1)];
298 cds_hlist_for_each_entry(e
, node
, head
, hlist
) {
299 if (!strncmp(name
, e
->name
, LTTNG_UST_SYM_NAME_LEN
- 1)) {
300 DBG("tracepoint %s busy", name
);
301 return ERR_PTR(-EEXIST
); /* Already there */
306 * Using zmalloc here to allocate a variable length elements: name and
307 * signature. Could cause some memory fragmentation if overused.
309 name_off
= sizeof(struct tracepoint_entry
);
310 sig_off
= name_off
+ name_len
+ 1;
312 e
= zmalloc(sizeof(struct tracepoint_entry
) + name_len
+ 1 + sig_len
+ 1);
314 return ERR_PTR(-ENOMEM
);
315 e
->name
= (char *) e
+ name_off
;
316 memcpy(e
->name
, name
, name_len
+ 1);
317 e
->name
[name_len
] = '\0';
319 e
->signature
= (char *) e
+ sig_off
;
320 memcpy(e
->signature
, signature
, sig_len
+ 1);
321 e
->signature
[sig_len
] = '\0';
325 e
->callsite_refcount
= 0;
327 cds_hlist_add_head(&e
->hlist
, head
);
332 * Remove the tracepoint from the tracepoint hash table. Must be called with
333 * tracepoint mutex held.
335 static void remove_tracepoint(struct tracepoint_entry
*e
)
337 cds_hlist_del(&e
->hlist
);
342 * Sets the probe callback corresponding to one tracepoint.
344 static void set_tracepoint(struct tracepoint_entry
**entry
,
345 struct lttng_ust_tracepoint
*elem
, int active
)
347 WARN_ON(strncmp((*entry
)->name
, elem
->name
, LTTNG_UST_SYM_NAME_LEN
- 1) != 0);
349 * Check that signatures match before connecting a probe to a
350 * tracepoint. Warn the user if they don't.
352 if (strcmp(elem
->signature
, (*entry
)->signature
) != 0) {
353 static int warned
= 0;
355 /* Only print once, don't flood console. */
357 WARN("Tracepoint signature mismatch, not enabling one or more tracepoints. Ensure that the tracepoint probes prototypes match the application.");
358 WARN("Tracepoint \"%s\" signatures: call: \"%s\" vs probe: \"%s\".",
359 elem
->name
, elem
->signature
, (*entry
)->signature
);
362 /* Don't accept connecting non-matching signatures. */
367 * rcu_assign_pointer has a cmm_smp_wmb() which makes sure that the new
368 * probe callbacks array is consistent before setting a pointer to it.
369 * This array is referenced by __DO_TRACE from
370 * include/linux/tracepoints.h. A matching cmm_smp_read_barrier_depends()
373 rcu_assign_pointer(elem
->probes
, (*entry
)->probes
);
374 CMM_STORE_SHARED(elem
->state
, active
);
378 * Disable a tracepoint and its probe callback.
379 * Note: only waiting an RCU period after setting elem->call to the empty
380 * function insures that the original callback is not used anymore. This insured
381 * by preempt_disable around the call site.
383 static void disable_tracepoint(struct lttng_ust_tracepoint
*elem
)
385 CMM_STORE_SHARED(elem
->state
, 0);
386 rcu_assign_pointer(elem
->probes
, NULL
);
390 * Add the callsite to the callsite hash table. Must be called with
391 * tracepoint mutex held.
393 static void add_callsite(struct tracepoint_lib
* lib
, struct lttng_ust_tracepoint
*tp
)
395 struct cds_hlist_head
*head
;
396 struct callsite_entry
*e
;
397 const char *name
= tp
->name
;
398 size_t name_len
= strlen(name
);
400 struct tracepoint_entry
*tp_entry
;
402 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
403 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
404 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
406 hash
= jhash(name
, name_len
, 0);
407 head
= &callsite_table
[hash
& (CALLSITE_TABLE_SIZE
- 1)];
408 e
= zmalloc(sizeof(struct callsite_entry
));
410 PERROR("Unable to add callsite for tracepoint \"%s\"", name
);
413 cds_hlist_add_head(&e
->hlist
, head
);
415 cds_list_add(&e
->node
, &lib
->callsites
);
417 tp_entry
= get_tracepoint(name
);
420 tp_entry
->callsite_refcount
++;
421 e
->tp_entry_callsite_ref
= true;
425 * Remove the callsite from the callsite hash table and from lib
426 * callsite list. Must be called with tracepoint mutex held.
428 static void remove_callsite(struct callsite_entry
*e
)
430 struct tracepoint_entry
*tp_entry
;
432 tp_entry
= get_tracepoint(e
->tp
->name
);
434 if (e
->tp_entry_callsite_ref
)
435 tp_entry
->callsite_refcount
--;
436 if (tp_entry
->callsite_refcount
== 0)
437 disable_tracepoint(e
->tp
);
439 cds_hlist_del(&e
->hlist
);
440 cds_list_del(&e
->node
);
445 * Enable/disable all callsites based on the state of a specific
447 * Must be called with tracepoint mutex held.
449 static void tracepoint_sync_callsites(const char *name
)
451 struct cds_hlist_head
*head
;
452 struct cds_hlist_node
*node
;
453 struct callsite_entry
*e
;
454 size_t name_len
= strlen(name
);
456 struct tracepoint_entry
*tp_entry
;
458 tp_entry
= get_tracepoint(name
);
459 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
460 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
461 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
463 hash
= jhash(name
, name_len
, 0);
464 head
= &callsite_table
[hash
& (CALLSITE_TABLE_SIZE
- 1)];
465 cds_hlist_for_each_entry(e
, node
, head
, hlist
) {
466 struct lttng_ust_tracepoint
*tp
= e
->tp
;
468 if (strncmp(name
, tp
->name
, LTTNG_UST_SYM_NAME_LEN
- 1))
471 if (!e
->tp_entry_callsite_ref
) {
472 tp_entry
->callsite_refcount
++;
473 e
->tp_entry_callsite_ref
= true;
475 set_tracepoint(&tp_entry
, tp
,
476 !!tp_entry
->refcount
);
478 disable_tracepoint(tp
);
479 e
->tp_entry_callsite_ref
= false;
485 * tracepoint_update_probe_range - Update a probe range
486 * @begin: beginning of the range
487 * @end: end of the range
489 * Updates the probe callback corresponding to a range of tracepoints.
492 void tracepoint_update_probe_range(struct lttng_ust_tracepoint
* const *begin
,
493 struct lttng_ust_tracepoint
* const *end
)
495 struct lttng_ust_tracepoint
* const *iter
;
496 struct tracepoint_entry
*mark_entry
;
498 for (iter
= begin
; iter
< end
; iter
++) {
500 continue; /* skip dummy */
501 if (!(*iter
)->name
) {
502 disable_tracepoint(*iter
);
505 mark_entry
= get_tracepoint((*iter
)->name
);
507 set_tracepoint(&mark_entry
, *iter
,
508 !!mark_entry
->refcount
);
510 disable_tracepoint(*iter
);
515 static void lib_update_tracepoints(struct tracepoint_lib
*lib
)
517 tracepoint_update_probe_range(lib
->tracepoints_start
,
518 lib
->tracepoints_start
+ lib
->tracepoints_count
);
521 static void lib_register_callsites(struct tracepoint_lib
*lib
)
523 struct lttng_ust_tracepoint
* const *begin
;
524 struct lttng_ust_tracepoint
* const *end
;
525 struct lttng_ust_tracepoint
* const *iter
;
527 begin
= lib
->tracepoints_start
;
528 end
= lib
->tracepoints_start
+ lib
->tracepoints_count
;
530 for (iter
= begin
; iter
< end
; iter
++) {
532 continue; /* skip dummy */
533 if (!(*iter
)->name
) {
536 add_callsite(lib
, *iter
);
540 static void lib_unregister_callsites(struct tracepoint_lib
*lib
)
542 struct callsite_entry
*callsite
, *tmp
;
544 cds_list_for_each_entry_safe(callsite
, tmp
, &lib
->callsites
, node
)
545 remove_callsite(callsite
);
549 * Update probes, removing the faulty probes.
551 static void tracepoint_update_probes(void)
553 struct tracepoint_lib
*lib
;
555 /* tracepoints registered from libraries and executable. */
556 cds_list_for_each_entry(lib
, &libs
, list
)
557 lib_update_tracepoints(lib
);
560 static struct lttng_ust_tracepoint_probe
*
561 tracepoint_add_probe(const char *name
, void (*probe
)(void), void *data
,
562 const char *signature
)
564 struct tracepoint_entry
*entry
;
565 struct lttng_ust_tracepoint_probe
*old
;
567 entry
= get_tracepoint(name
);
569 if (strcmp(entry
->signature
, signature
) != 0) {
570 ERR("Tracepoint and probe signature do not match.");
571 return ERR_PTR(-EINVAL
);
574 entry
= add_tracepoint(name
, signature
);
576 return (struct lttng_ust_tracepoint_probe
*)entry
;
578 old
= tracepoint_entry_add_probe(entry
, probe
, data
);
579 if (IS_ERR(old
) && !entry
->refcount
)
580 remove_tracepoint(entry
);
584 static void tracepoint_release_queue_add_old_probes(void *old
)
586 release_queue_need_update
= 1;
588 struct tp_probes
*tp_probes
= caa_container_of(old
,
589 struct tp_probes
, probes
[0]);
590 cds_list_add(&tp_probes
->u
.list
, &release_queue
);
595 * __tracepoint_probe_register - Connect a probe to a tracepoint
596 * @name: tracepoint name
597 * @probe: probe handler
599 * Returns 0 if ok, error value on error.
600 * The probe address must at least be aligned on the architecture pointer size.
601 * Called with the tracepoint mutex held.
603 int __tracepoint_probe_register(const char *name
, void (*probe
)(void),
604 void *data
, const char *signature
)
609 DBG("Registering probe to tracepoint %s", name
);
611 pthread_mutex_lock(&tracepoint_mutex
);
612 old
= tracepoint_add_probe(name
, probe
, data
, signature
);
618 tracepoint_sync_callsites(name
);
621 pthread_mutex_unlock(&tracepoint_mutex
);
626 * Caller needs to invoke __tracepoint_probe_release_queue() after
627 * calling __tracepoint_probe_register_queue_release() one or multiple
628 * times to ensure it does not leak memory.
630 int __tracepoint_probe_register_queue_release(const char *name
,
631 void (*probe
)(void), void *data
, const char *signature
)
636 DBG("Registering probe to tracepoint %s. Queuing release.", name
);
638 pthread_mutex_lock(&tracepoint_mutex
);
639 old
= tracepoint_add_probe(name
, probe
, data
, signature
);
645 tracepoint_sync_callsites(name
);
646 tracepoint_release_queue_add_old_probes(old
);
648 pthread_mutex_unlock(&tracepoint_mutex
);
652 static void *tracepoint_remove_probe(const char *name
, void (*probe
)(void),
655 struct tracepoint_entry
*entry
;
658 entry
= get_tracepoint(name
);
660 return ERR_PTR(-ENOENT
);
661 old
= tracepoint_entry_remove_probe(entry
, probe
, data
);
664 if (!entry
->refcount
)
665 remove_tracepoint(entry
);
670 * tracepoint_probe_unregister - Disconnect a probe from a tracepoint
671 * @name: tracepoint name
672 * @probe: probe function pointer
673 * @probe: probe data pointer
675 int __tracepoint_probe_unregister(const char *name
, void (*probe
)(void),
681 DBG("Un-registering probe from tracepoint %s", name
);
683 pthread_mutex_lock(&tracepoint_mutex
);
684 old
= tracepoint_remove_probe(name
, probe
, data
);
689 tracepoint_sync_callsites(name
);
692 pthread_mutex_unlock(&tracepoint_mutex
);
697 * Caller needs to invoke __tracepoint_probe_release_queue() after
698 * calling __tracepoint_probe_unregister_queue_release() one or multiple
699 * times to ensure it does not leak memory.
701 int __tracepoint_probe_unregister_queue_release(const char *name
,
702 void (*probe
)(void), void *data
)
707 DBG("Un-registering probe from tracepoint %s. Queuing release.", name
);
709 pthread_mutex_lock(&tracepoint_mutex
);
710 old
= tracepoint_remove_probe(name
, probe
, data
);
715 tracepoint_sync_callsites(name
);
716 tracepoint_release_queue_add_old_probes(old
);
718 pthread_mutex_unlock(&tracepoint_mutex
);
722 void __tracepoint_probe_prune_release_queue(void)
724 CDS_LIST_HEAD(release_probes
);
725 struct tp_probes
*pos
, *next
;
727 DBG("Release queue of unregistered tracepoint probes.");
729 pthread_mutex_lock(&tracepoint_mutex
);
730 if (!release_queue_need_update
)
732 if (!cds_list_empty(&release_queue
))
733 cds_list_replace_init(&release_queue
, &release_probes
);
734 release_queue_need_update
= 0;
736 /* Wait for grace period between all sync_callsites and free. */
739 cds_list_for_each_entry_safe(pos
, next
, &release_probes
, u
.list
) {
740 cds_list_del(&pos
->u
.list
);
744 pthread_mutex_unlock(&tracepoint_mutex
);
747 static void tracepoint_add_old_probes(void *old
)
751 struct tp_probes
*tp_probes
= caa_container_of(old
,
752 struct tp_probes
, probes
[0]);
753 cds_list_add(&tp_probes
->u
.list
, &old_probes
);
758 * tracepoint_probe_register_noupdate - register a probe but not connect
759 * @name: tracepoint name
760 * @probe: probe handler
762 * caller must call tracepoint_probe_update_all()
764 int tracepoint_probe_register_noupdate(const char *name
, void (*probe
)(void),
765 void *data
, const char *signature
)
770 pthread_mutex_lock(&tracepoint_mutex
);
771 old
= tracepoint_add_probe(name
, probe
, data
, signature
);
776 tracepoint_add_old_probes(old
);
778 pthread_mutex_unlock(&tracepoint_mutex
);
783 * tracepoint_probe_unregister_noupdate - remove a probe but not disconnect
784 * @name: tracepoint name
785 * @probe: probe function pointer
787 * caller must call tracepoint_probe_update_all()
788 * Called with the tracepoint mutex held.
790 int tracepoint_probe_unregister_noupdate(const char *name
, void (*probe
)(void),
796 DBG("Un-registering probe from tracepoint %s", name
);
798 pthread_mutex_lock(&tracepoint_mutex
);
799 old
= tracepoint_remove_probe(name
, probe
, data
);
804 tracepoint_add_old_probes(old
);
806 pthread_mutex_unlock(&tracepoint_mutex
);
811 * tracepoint_probe_update_all - update tracepoints
813 void tracepoint_probe_update_all(void)
815 CDS_LIST_HEAD(release_probes
);
816 struct tp_probes
*pos
, *next
;
818 pthread_mutex_lock(&tracepoint_mutex
);
822 if (!cds_list_empty(&old_probes
))
823 cds_list_replace_init(&old_probes
, &release_probes
);
826 tracepoint_update_probes();
827 /* Wait for grace period between update_probes and free. */
829 cds_list_for_each_entry_safe(pos
, next
, &release_probes
, u
.list
) {
830 cds_list_del(&pos
->u
.list
);
834 pthread_mutex_unlock(&tracepoint_mutex
);
837 void tracepoint_set_new_tracepoint_cb(void (*cb
)(struct lttng_ust_tracepoint
*))
839 new_tracepoint_cb
= cb
;
842 static void new_tracepoints(struct lttng_ust_tracepoint
* const *start
,
843 struct lttng_ust_tracepoint
* const *end
)
845 if (new_tracepoint_cb
) {
846 struct lttng_ust_tracepoint
* const *t
;
848 for (t
= start
; t
< end
; t
++) {
850 new_tracepoint_cb(*t
);
855 int tracepoint_register_lib(struct lttng_ust_tracepoint
* const *tracepoints_start
,
856 int tracepoints_count
)
858 struct tracepoint_lib
*pl
, *iter
;
862 pl
= (struct tracepoint_lib
*) zmalloc(sizeof(struct tracepoint_lib
));
864 PERROR("Unable to register tracepoint lib");
867 pl
->tracepoints_start
= tracepoints_start
;
868 pl
->tracepoints_count
= tracepoints_count
;
869 CDS_INIT_LIST_HEAD(&pl
->callsites
);
871 pthread_mutex_lock(&tracepoint_mutex
);
873 * We sort the libs by struct lib pointer address.
875 cds_list_for_each_entry_reverse(iter
, &libs
, list
) {
876 BUG_ON(iter
== pl
); /* Should never be in the list twice */
878 /* We belong to the location right after iter. */
879 cds_list_add(&pl
->list
, &iter
->list
);
883 /* We should be added at the head of the list */
884 cds_list_add(&pl
->list
, &libs
);
886 new_tracepoints(tracepoints_start
, tracepoints_start
+ tracepoints_count
);
887 lib_register_callsites(pl
);
888 lib_update_tracepoints(pl
);
889 pthread_mutex_unlock(&tracepoint_mutex
);
891 DBG("just registered a tracepoints section from %p and having %d tracepoints",
892 tracepoints_start
, tracepoints_count
);
896 for (i
= 0; i
< tracepoints_count
; i
++) {
897 DBG("registered tracepoint: %s", tracepoints_start
[i
]->name
);
904 int tracepoint_unregister_lib(struct lttng_ust_tracepoint
* const *tracepoints_start
)
906 struct tracepoint_lib
*lib
;
908 pthread_mutex_lock(&tracepoint_mutex
);
909 cds_list_for_each_entry(lib
, &libs
, list
) {
910 if (lib
->tracepoints_start
!= tracepoints_start
)
913 cds_list_del(&lib
->list
);
915 * Unregistering a callsite also decreases the
916 * callsite reference count of the corresponding
917 * tracepoint, and disables the tracepoint if
918 * the reference count drops to zero.
920 lib_unregister_callsites(lib
);
921 DBG("just unregistered a tracepoints section from %p",
922 lib
->tracepoints_start
);
926 pthread_mutex_unlock(&tracepoint_mutex
);
931 * Report in debug message whether the compiler correctly supports weak
932 * hidden symbols. This test checks that the address associated with two
933 * weak symbols with hidden visibility is the same when declared within
934 * two compile units part of the same module.
936 static void check_weak_hidden(void)
938 DBG("Your compiler treats weak symbols with hidden visibility for integer objects as %s between compile units part of the same module.",
939 &__tracepoint_test_symbol1
== lttng_ust_tp_check_weak_hidden1() ?
941 "DIFFERENT addresses");
942 DBG("Your compiler treats weak symbols with hidden visibility for pointer objects as %s between compile units part of the same module.",
943 &__tracepoint_test_symbol2
== lttng_ust_tp_check_weak_hidden2() ?
945 "DIFFERENT addresses");
946 DBG("Your compiler treats weak symbols with hidden visibility for 24-byte structure objects as %s between compile units part of the same module.",
947 &__tracepoint_test_symbol3
== lttng_ust_tp_check_weak_hidden3() ?
949 "DIFFERENT addresses");
952 void init_tracepoint(void)
954 if (uatomic_xchg(&initialized
, 1) == 1)
960 void exit_tracepoint(void)
966 * Create the wrapper symbols.
968 #undef tp_rcu_read_lock_bp
969 #undef tp_rcu_read_unlock_bp
970 #undef tp_rcu_dereference_bp
972 void tp_rcu_read_lock_bp(void)
977 void tp_rcu_read_unlock_bp(void)
979 rcu_read_unlock_bp();
982 void *tp_rcu_dereference_sym_bp(void *p
)
984 return rcu_dereference_bp(p
);