X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Ftracepoint.c;h=8d41d97a7793c79f56a9a1d9cc51c4f9b2f60fd6;hb=f27f1026353ae61083b7a2221f912b0299095a04;hp=ce7dbbb283947f608978d4948c2df62656f1275a;hpb=a58c831a07058055a6e14d09d0e5a3f40f47eae3;p=lttng-ust.git diff --git a/liblttng-ust/tracepoint.c b/liblttng-ust/tracepoint.c index ce7dbbb2..8d41d97a 100644 --- a/liblttng-ust/tracepoint.c +++ b/liblttng-ust/tracepoint.c @@ -1,21 +1,9 @@ /* + * SPDX-License-Identifier: LGPL-2.1-only + * * Copyright (C) 2008-2011 Mathieu Desnoyers * Copyright (C) 2009 Pierre-Marc Fournier * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * * Ported to userspace by Pierre-Marc Fournier. */ @@ -33,10 +21,10 @@ #include #include -#include /* for LTTNG_UST_SYM_NAME_LEN */ +#include /* for LTTNG_UST_ABI_SYM_NAME_LEN */ #include -#include +#include #include "tracepoint-internal.h" #include "lttng-tracer-core.h" @@ -60,15 +48,6 @@ static int initialized; */ static int tracepoint_destructors_state = 1; -/* - * Expose the now deprecated symbol __tracepoints__disable_destructors for - * backward compatibility of applications built against old versions of - * lttng-ust. We need to keep __tracepoints__disable_destructors up to date - * within the new destructor disabling API because old applications read this - * symbol directly. - */ -int __tracepoints__disable_destructors __attribute__((weak)); - static void (*new_tracepoint_cb)(struct lttng_ust_tracepoint *); /* @@ -151,86 +130,6 @@ struct callsite_entry { bool tp_entry_callsite_ref; /* Has a tp_entry took a ref on this callsite */ }; -static int tracepoint_v1_api_used; -static void (*lttng_ust_liburcu_bp_synchronize_rcu)(void); -static void (*lttng_ust_liburcu_bp_rcu_read_lock)(void); -static void (*lttng_ust_liburcu_bp_rcu_read_unlock)(void); -void (*lttng_ust_liburcu_bp_before_fork)(void); -void (*lttng_ust_liburcu_bp_after_fork_parent)(void); -void (*lttng_ust_liburcu_bp_after_fork_child)(void); - -static bool lttng_ust_tracepoint_v1_used(void) -{ - return uatomic_read(&tracepoint_v1_api_used); -} - -static void lttng_ust_tracepoint_set_v1_used(void) -{ - if (!lttng_ust_tracepoint_v1_used()) { - /* - * Perform dlsym here rather than lazily on first use to - * eliminate nesting of dynamic loader lock (used within - * dlsym) inside the ust lock. - */ - if (!lttng_ust_liburcu_bp_synchronize_rcu) { - lttng_ust_liburcu_bp_synchronize_rcu = URCU_FORCE_CAST(void (*)(void), - dlsym(RTLD_DEFAULT, "synchronize_rcu_bp")); - /* - * Allow legacy applications compiled without - * _LGPL_SOURCE to use v1 API. Those are not - * required to be linked against liburcu-bp, - * so in those situations the liburcu-bp symbols - * are not present in the global symbol table, - * and we do not need to call urcu-bp - * synchronize. - * - * However, nothing prevents a _LGPL_SOURCE - * instrumented library loaded afterwards to - * require liburcu-bp, so we need to check again - * in that situation. - */ - if (!lttng_ust_liburcu_bp_synchronize_rcu) - return; - } - if (!lttng_ust_liburcu_bp_before_fork) { - lttng_ust_liburcu_bp_before_fork = URCU_FORCE_CAST(void (*)(void), - dlsym(RTLD_DEFAULT, "rcu_bp_before_fork")); - if (!lttng_ust_liburcu_bp_before_fork) - abort(); - } - if (!lttng_ust_liburcu_bp_after_fork_parent) { - lttng_ust_liburcu_bp_after_fork_parent = URCU_FORCE_CAST(void (*)(void), - dlsym(RTLD_DEFAULT, "rcu_bp_after_fork_parent")); - if (!lttng_ust_liburcu_bp_after_fork_parent) - abort(); - } - if (!lttng_ust_liburcu_bp_after_fork_child) { - lttng_ust_liburcu_bp_after_fork_child = URCU_FORCE_CAST(void (*)(void), - dlsym(RTLD_DEFAULT, "rcu_bp_after_fork_child")); - if (!lttng_ust_liburcu_bp_after_fork_child) - abort(); - } - if (!lttng_ust_liburcu_bp_rcu_read_lock) { - lttng_ust_liburcu_bp_rcu_read_lock = URCU_FORCE_CAST(void (*)(void), - dlsym(RTLD_DEFAULT, "rcu_read_lock_bp")); - if (!lttng_ust_liburcu_bp_rcu_read_lock) - abort(); - } - if (!lttng_ust_liburcu_bp_rcu_read_unlock) { - lttng_ust_liburcu_bp_rcu_read_unlock = URCU_FORCE_CAST(void (*)(void), - dlsym(RTLD_DEFAULT, "rcu_read_unlock_bp")); - if (!lttng_ust_liburcu_bp_rcu_read_unlock) - abort(); - } - - /* Fixup URCU bp TLS. */ - lttng_ust_liburcu_bp_rcu_read_lock(); - lttng_ust_liburcu_bp_rcu_read_unlock(); - - uatomic_set(&tracepoint_v1_api_used, 1); - } -} - /* coverity[+alloc] */ static void *allocate_probes(int count) { @@ -246,7 +145,7 @@ static void release_probes(void *old) if (old) { struct tp_probes *tp_probes = caa_container_of(old, struct tp_probes, probes[0]); - lttng_ust_synchronize_trace(); + lttng_ust_urcu_synchronize_rcu(); free(tp_probes); } } @@ -357,14 +256,14 @@ static struct tracepoint_entry *get_tracepoint(const char *name) size_t name_len = strlen(name); uint32_t hash; - if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) { - WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1); - name_len = LTTNG_UST_SYM_NAME_LEN - 1; + if (name_len > LTTNG_UST_ABI_SYM_NAME_LEN - 1) { + WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_ABI_SYM_NAME_LEN - 1); + name_len = LTTNG_UST_ABI_SYM_NAME_LEN - 1; } hash = jhash(name, name_len, 0); head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)]; cds_hlist_for_each_entry(e, node, head, hlist) { - if (!strncmp(name, e->name, LTTNG_UST_SYM_NAME_LEN - 1)) + if (!strncmp(name, e->name, LTTNG_UST_ABI_SYM_NAME_LEN - 1)) return e; } return NULL; @@ -385,14 +284,14 @@ static struct tracepoint_entry *add_tracepoint(const char *name, size_t sig_off, name_off; uint32_t hash; - if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) { - WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1); - name_len = LTTNG_UST_SYM_NAME_LEN - 1; + if (name_len > LTTNG_UST_ABI_SYM_NAME_LEN - 1) { + WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_ABI_SYM_NAME_LEN - 1); + name_len = LTTNG_UST_ABI_SYM_NAME_LEN - 1; } hash = jhash(name, name_len, 0); head = &tracepoint_table[hash & (TRACEPOINT_TABLE_SIZE - 1)]; cds_hlist_for_each_entry(e, node, head, hlist) { - if (!strncmp(name, e->name, LTTNG_UST_SYM_NAME_LEN - 1)) { + if (!strncmp(name, e->name, LTTNG_UST_ABI_SYM_NAME_LEN - 1)) { DBG("tracepoint %s busy", name); return ERR_PTR(-EEXIST); /* Already there */ } @@ -440,7 +339,7 @@ static void remove_tracepoint(struct tracepoint_entry *e) static void set_tracepoint(struct tracepoint_entry **entry, struct lttng_ust_tracepoint *elem, int active) { - WARN_ON(strncmp((*entry)->name, elem->name, LTTNG_UST_SYM_NAME_LEN - 1) != 0); + WARN_ON(strncmp((*entry)->name, elem->name, LTTNG_UST_ABI_SYM_NAME_LEN - 1) != 0); /* * Check that signatures match before connecting a probe to a * tracepoint. Warn the user if they don't. @@ -495,9 +394,9 @@ static void add_callsite(struct tracepoint_lib * lib, struct lttng_ust_tracepoin uint32_t hash; struct tracepoint_entry *tp_entry; - if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) { - WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1); - name_len = LTTNG_UST_SYM_NAME_LEN - 1; + if (name_len > LTTNG_UST_ABI_SYM_NAME_LEN - 1) { + WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_ABI_SYM_NAME_LEN - 1); + name_len = LTTNG_UST_ABI_SYM_NAME_LEN - 1; } hash = jhash(name, name_len, 0); head = &callsite_table[hash & (CALLSITE_TABLE_SIZE - 1)]; @@ -552,16 +451,16 @@ static void tracepoint_sync_callsites(const char *name) struct tracepoint_entry *tp_entry; tp_entry = get_tracepoint(name); - if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) { - WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1); - name_len = LTTNG_UST_SYM_NAME_LEN - 1; + if (name_len > LTTNG_UST_ABI_SYM_NAME_LEN - 1) { + WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_ABI_SYM_NAME_LEN - 1); + name_len = LTTNG_UST_ABI_SYM_NAME_LEN - 1; } hash = jhash(name, name_len, 0); head = &callsite_table[hash & (CALLSITE_TABLE_SIZE - 1)]; cds_hlist_for_each_entry(e, node, head, hlist) { struct lttng_ust_tracepoint *tp = e->tp; - if (strncmp(name, tp->name, LTTNG_UST_SYM_NAME_LEN - 1)) + if (strncmp(name, tp->name, LTTNG_UST_ABI_SYM_NAME_LEN - 1)) continue; if (tp_entry) { if (!e->tp_entry_callsite_ref) { @@ -720,10 +619,10 @@ end: /* * Caller needs to invoke __tracepoint_probe_release_queue() after - * calling __tracepoint_probe_register_queue_release() one or multiple + * calling lttng_ust_tp_probe_register_queue_release() one or multiple * times to ensure it does not leak memory. */ -int __tracepoint_probe_register_queue_release(const char *name, +int lttng_ust_tp_probe_register_queue_release(const char *name, void (*probe)(void), void *data, const char *signature) { void *old; @@ -791,10 +690,10 @@ end: /* * Caller needs to invoke __tracepoint_probe_release_queue() after - * calling __tracepoint_probe_unregister_queue_release() one or multiple + * calling lttng_ust_tp_probe_unregister_queue_release() one or multiple * times to ensure it does not leak memory. */ -int __tracepoint_probe_unregister_queue_release(const char *name, +int lttng_ust_tp_probe_unregister_queue_release(const char *name, void (*probe)(void), void *data) { void *old; @@ -815,7 +714,7 @@ end: return ret; } -void __tracepoint_probe_prune_release_queue(void) +void lttng_ust_tp_probe_prune_release_queue(void) { CDS_LIST_HEAD(release_probes); struct tp_probes *pos, *next; @@ -830,7 +729,7 @@ void __tracepoint_probe_prune_release_queue(void) release_queue_need_update = 0; /* Wait for grace period between all sync_callsites and free. */ - lttng_ust_synchronize_trace(); + lttng_ust_urcu_synchronize_rcu(); cds_list_for_each_entry_safe(pos, next, &release_probes, u.list) { cds_list_del(&pos->u.list); @@ -921,7 +820,7 @@ void tracepoint_probe_update_all(void) tracepoint_update_probes(); /* Wait for grace period between update_probes and free. */ - lttng_ust_synchronize_trace(); + lttng_ust_urcu_synchronize_rcu(); cds_list_for_each_entry_safe(pos, next, &release_probes, u.list) { cds_list_del(&pos->u.list); free(pos); @@ -960,12 +859,12 @@ static void new_tracepoints(struct lttng_ust_tracepoint * const *start, * against recent liblttng-ust headers require a recent liblttng-ust * runtime for those tracepoints to be taken into account. */ -int tracepoint_register_lib2(struct lttng_ust_tracepoint * const *tracepoints_start, +int tracepoint_register_lib(struct lttng_ust_tracepoint * const *tracepoints_start, int tracepoints_count) { struct tracepoint_lib *pl, *iter; - init_tracepoint(); + lttng_ust_tp_init(); pl = (struct tracepoint_lib *) zmalloc(sizeof(struct tracepoint_lib)); if (!pl) { @@ -998,7 +897,7 @@ lib_added: DBG("just registered a tracepoints section from %p and having %d tracepoints", tracepoints_start, tracepoints_count); - if (ust_debug()) { + if (ust_err_debug_enabled()) { int i; for (i = 0; i < tracepoints_count; i++) { @@ -1009,15 +908,7 @@ lib_added: return 0; } -/* Exposed for backward compatibility with old instrumented applications. */ -int tracepoint_register_lib(struct lttng_ust_tracepoint * const *tracepoints_start, - int tracepoints_count) -{ - lttng_ust_tracepoint_set_v1_used(); - return tracepoint_register_lib2(tracepoints_start, tracepoints_count); -} - -int tracepoint_unregister_lib2(struct lttng_ust_tracepoint * const *tracepoints_start) +int tracepoint_unregister_lib(struct lttng_ust_tracepoint * const *tracepoints_start) { struct tracepoint_lib *lib; @@ -1043,13 +934,6 @@ int tracepoint_unregister_lib2(struct lttng_ust_tracepoint * const *tracepoints_ return 0; } -/* Exposed for backward compatibility with old instrumented applications. */ -int tracepoint_unregister_lib(struct lttng_ust_tracepoint * const *tracepoints_start) -{ - lttng_ust_tracepoint_set_v1_used(); - return tracepoint_unregister_lib2(tracepoints_start); -} - /* * Report in debug message whether the compiler correctly supports weak * hidden symbols. This test checks that the address associated with two @@ -1072,15 +956,15 @@ static void check_weak_hidden(void) "DIFFERENT addresses"); } -void init_tracepoint(void) +void lttng_ust_tp_init(void) { if (uatomic_xchg(&initialized, 1) == 1) return; - init_usterr(); + ust_err_init(); check_weak_hidden(); } -void exit_tracepoint(void) +void lttng_ust_tp_exit(void) { initialized = 0; } @@ -1131,32 +1015,3 @@ int tp_get_destructors_state(void) { return uatomic_read(&tracepoint_destructors_state); } - -void lttng_ust_synchronize_trace(void) -{ - lttng_ust_urcu_synchronize_rcu(); - /* - * For legacy tracepoint instrumentation, also wait for urcu-bp - * grace period. - */ - if (lttng_ust_liburcu_bp_synchronize_rcu) - lttng_ust_liburcu_bp_synchronize_rcu(); -} - -/* - * Create the wrapper symbols for legacy v1 API. - */ -void tp_rcu_read_lock_bp(void) -{ - lttng_ust_urcu_read_lock(); -} - -void tp_rcu_read_unlock_bp(void) -{ - lttng_ust_urcu_read_unlock(); -} - -void *tp_rcu_dereference_sym_bp(void *p) -{ - return lttng_ust_rcu_dereference(p); -}