/*
+ * 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.
*/
#include <stdio.h>
#include <urcu/arch.h>
-#include <urcu-bp.h>
+#include <lttng/urcu/urcu-ust.h>
#include <urcu/hlist.h>
#include <urcu/uatomic.h>
#include <urcu/compiler.h>
/* Set to 1 to enable tracepoint debug output */
static const int tracepoint_debug;
static int initialized;
+
+/*
+ * If tracepoint_destructors_state = 1, tracepoint destructors are
+ * enabled. They are disabled otherwise.
+ */
+static int tracepoint_destructors_state = 1;
+
static void (*new_tracepoint_cb)(struct lttng_ust_tracepoint *);
/*
if (old) {
struct tp_probes *tp_probes = caa_container_of(old,
struct tp_probes, probes[0]);
- synchronize_rcu();
+ lttng_ust_synchronize_trace();
free(tp_probes);
}
}
* include/linux/tracepoints.h. A matching cmm_smp_read_barrier_depends()
* is used.
*/
- rcu_assign_pointer(elem->probes, (*entry)->probes);
+ lttng_ust_rcu_assign_pointer(elem->probes, (*entry)->probes);
CMM_STORE_SHARED(elem->state, active);
}
static void disable_tracepoint(struct lttng_ust_tracepoint *elem)
{
CMM_STORE_SHARED(elem->state, 0);
- rcu_assign_pointer(elem->probes, NULL);
+ lttng_ust_rcu_assign_pointer(elem->probes, NULL);
}
/*
release_queue_need_update = 0;
/* Wait for grace period between all sync_callsites and free. */
- synchronize_rcu();
+ lttng_ust_synchronize_trace();
cds_list_for_each_entry_safe(pos, next, &release_probes, u.list) {
cds_list_del(&pos->u.list);
tracepoint_update_probes();
/* Wait for grace period between update_probes and free. */
- synchronize_rcu();
+ lttng_ust_synchronize_trace();
cds_list_for_each_entry_safe(pos, next, &release_probes, u.list) {
cds_list_del(&pos->u.list);
free(pos);
}
}
+/*
+ * tracepoint_{un,}register_lib is meant to be looked up by instrumented
+ * applications through dlsym(). If found, those can register their
+ * tracepoints, else those tracepoints will not be available for
+ * tracing. The number at the end of those symbols acts as a major
+ * version for tracepoints.
+ *
+ * Older instrumented applications should still work with newer
+ * liblttng-ust, but it is fine that instrumented applications compiled
+ * against recent liblttng-ust headers require a recent liblttng-ust
+ * runtime for those tracepoints to be taken into account.
+ */
int tracepoint_register_lib(struct lttng_ust_tracepoint * const *tracepoints_start,
- int tracepoints_count)
+ int tracepoints_count)
{
struct tracepoint_lib *pl, *iter;
/*
* Create the wrapper symbols.
*/
-#undef tp_rcu_read_lock_bp
-#undef tp_rcu_read_unlock_bp
-#undef tp_rcu_dereference_bp
+#undef tp_rcu_read_lock
+#undef tp_rcu_read_unlock
+#undef tp_rcu_dereference
-void tp_rcu_read_lock_bp(void)
+void tp_rcu_read_lock(void)
{
- rcu_read_lock_bp();
+ lttng_ust_urcu_read_lock();
}
-void tp_rcu_read_unlock_bp(void)
+void tp_rcu_read_unlock(void)
+{
+ lttng_ust_urcu_read_unlock();
+}
+
+void *tp_rcu_dereference_sym(void *p)
+{
+ return lttng_ust_rcu_dereference(p);
+}
+
+/*
+ * Programs that have threads that survive after they exit, and therefore call
+ * library destructors, should disable the tracepoint destructors by calling
+ * tp_disable_destructors(). This will leak the tracepoint
+ * instrumentation library shared object, leaving its teardown to the operating
+ * system process teardown.
+ *
+ * To access and/or modify this value, users need to use a combination of
+ * dlopen(3) and dlsym(3) to get an handle on the
+ * tp_disable_destructors and tp_get_destructors_state symbols below.
+ */
+void tp_disable_destructors(void)
+{
+ uatomic_set(&tracepoint_destructors_state, 0);
+}
+
+/*
+ * Returns 1 if the destructors are enabled and should be executed.
+ * Returns 0 if the destructors are disabled.
+ */
+int tp_get_destructors_state(void)
{
- rcu_read_unlock_bp();
+ return uatomic_read(&tracepoint_destructors_state);
}
-void *tp_rcu_dereference_sym_bp(void *p)
+void lttng_ust_synchronize_trace(void)
{
- return rcu_dereference_bp(p);
+ lttng_ust_urcu_synchronize_rcu();
}