From f0cc794d37abf59b4b8079612c7aa03dc305d92f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 16 Dec 2013 08:36:06 -0500 Subject: [PATCH] Fix: baddr_statedump tracepoint registration Make sure that the ust_baddr_statedump probe is registered prior to using the tracepoint in lttng_ust_baddr_statedump(). This fix solves the issue that in rare cases the very first ust_baddr_statedump events were missing. Use a reference counting approach that allows constructors/destructors of the probe to be called many times, as long as the number of calls to constructor matches the number of calls to destructor. Reported-by: Paul Woegerer Signed-off-by: Mathieu Desnoyers --- include/lttng/ust-tracepoint-event.h | 12 ++++++++++++ liblttng-ust/Makefile.am | 1 - liblttng-ust/lttng-ust-baddr.c | 4 ++++ liblttng-ust/ust_baddr_statedump.c | 22 ---------------------- 4 files changed, 16 insertions(+), 23 deletions(-) delete mode 100644 liblttng-ust/ust_baddr_statedump.c diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index be580307..eb6b2ea4 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -685,6 +685,8 @@ static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PR .minor = LTTNG_UST_PROVIDER_MINOR, }; +static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER); + /* * Stage 9 of tracepoint event generation. * @@ -692,6 +694,8 @@ static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PR * * Generate the constructor as an externally visible symbol for use when * linking the probe statically. + * + * Register refcount is protected by libc dynamic loader mutex. */ /* Reset all macros within TRACEPOINT_EVENT */ @@ -703,6 +707,10 @@ _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) { int ret; + if (_TP_COMBINE_TOKENS(__probe_register_refcount___, + TRACEPOINT_PROVIDER)++) { + return; + } /* * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a * static inline function that ensures every probe PROVIDER @@ -724,6 +732,10 @@ _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); static void _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) { + if (--_TP_COMBINE_TOKENS(__probe_register_refcount___, + TRACEPOINT_PROVIDER)) { + return; + } lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); } diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index b165c321..e9022d8a 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -37,7 +37,6 @@ liblttng_ust_runtime_la_SOURCES = \ lttng-hash-helper.h \ lttng-ust-baddr.c \ lttng-ust-baddr.h \ - ust_baddr_statedump.c \ ust_baddr_statedump.h \ tracepoint-internal.h \ clock.h \ diff --git a/liblttng-ust/lttng-ust-baddr.c b/liblttng-ust/lttng-ust-baddr.c index b7843e24..90ffe688 100644 --- a/liblttng-ust/lttng-ust-baddr.c +++ b/liblttng-ust/lttng-ust-baddr.c @@ -36,6 +36,8 @@ #include "lttng-ust-baddr.h" #define TRACEPOINT_DEFINE +#define TRACEPOINT_CREATE_PROBES +#define TP_SESSION_CHECK #include "ust_baddr_statedump.h" struct extract_data { @@ -199,10 +201,12 @@ void lttng_ust_baddr_statedump_init(void) { __tracepoints__init(); __tracepoints__ptrs_init(); + __lttng_events_init__ust_baddr_statedump(); } void lttng_ust_baddr_statedump_destroy(void) { + __lttng_events_exit__ust_baddr_statedump(); __tracepoints__ptrs_destroy(); __tracepoints__destroy(); } diff --git a/liblttng-ust/ust_baddr_statedump.c b/liblttng-ust/ust_baddr_statedump.c deleted file mode 100644 index 9097008c..00000000 --- a/liblttng-ust/ust_baddr_statedump.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2013 Paul Woegerer - * - * 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; either - * version 2.1 of the License, or (at your option) any later version. - * - * 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 - */ - -#define _LGPL_SOURCE -#define TRACEPOINT_CREATE_PROBES -#define TP_SESSION_CHECK -#include "ust_baddr_statedump.h" -- 2.34.1