Skip to contentSkip to conversation

Integrate base-address statedump into lttng-ust

PATCH New Paul Woegerer 2 participants 4 messages Nov 28, 2013 1 message not in the archive Kbuild

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/3 Integrate base-address statedump into lttng-ust

---
 Makefile.am                                        |  3 +-
 liblttng-ust-baddr/Makefile.am                     | 18 +----
 liblttng-ust-baddr/lttng-ust-baddr.c               | 32 +--------
 liblttng-ust-baddr/lttng-ust-baddr.h               | 22 +++++++
 liblttng-ust-baddr/ust_baddr_statedump.h           |  2 +-
 liblttng-ust-dl/Makefile.am                        |  5 +-
 .../ust_baddr.c                                    |  0
 .../ust_baddr.h                                    |  0
 liblttng-ust-dl/ustdl.c                            | 76 ++++++----------------
 liblttng-ust/Makefile.am                           |  1 +
 liblttng-ust/lttng-ust-comm.c                      | 46 ++-----------
 11 files changed, 58 insertions(+), 147 deletions(-)
 create mode 100644 liblttng-ust-baddr/lttng-ust-baddr.h
 rename {liblttng-ust-baddr => liblttng-ust-dl}/ust_baddr.c (100%)
 rename {liblttng-ust-baddr => liblttng-ust-dl}/ust_baddr.h (100%)
Makefile.am +1 -2
index 10b54cb..6fab956 100644
@@ -1,10 +1,9 @@
 ACLOCAL_AMFLAGS = -I config
 
-SUBDIRS = . include snprintf libringbuffer liblttng-ust-comm \
+SUBDIRS = . include snprintf libringbuffer liblttng-ust-comm liblttng-ust-baddr \
 		liblttng-ust \
 		liblttng-ust-ctl \
 		liblttng-ust-fork \
-		liblttng-ust-baddr \
 		liblttng-ust-dl \
 		liblttng-ust-libc-wrapper \
 		liblttng-ust-cyg-profile \
liblttng-ust-baddr/Makefile.am +3 -15
index 0d3cf28..57792f6 100644
@@ -1,20 +1,8 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
-AM_CFLAGS = -fno-strict-aliasing
+AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
+
+noinst_LTLIBRARIES = liblttng-ust-baddr.la
 
-lib_LTLIBRARIES = liblttng-ust-baddr.la
 liblttng_ust_baddr_la_SOURCES = \
 	lttng-ust-baddr.c \
-	ust_baddr.c \
-	ust_baddr.h \
 	ust_baddr_statedump.c \
 	ust_baddr_statedump.h
-liblttng_ust_baddr_la_LIBADD = \
-	-L$(top_builddir)/liblttng-ust/.libs \
-	-llttng-ust
-
-if LTTNG_UST_BUILD_WITH_LIBDL
-liblttng_ust_baddr_la_LIBADD += -ldl
-endif
-if LTTNG_UST_BUILD_WITH_LIBC_DL
-liblttng_ust_baddr_la_LIBADD += -lc
-endif
liblttng-ust-baddr/lttng-ust-baddr.c +2 -30
index a856965..8412233 100644
@@ -22,7 +22,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <limits.h>
 #include <stdlib.h>
@@ -32,38 +31,11 @@
 #include <stdio.h>
 #include "usterr.h"
 
+#include "lttng-ust-baddr.h"
+
 #define TRACEPOINT_DEFINE
-#include "ust_baddr.h"
 #include "ust_baddr_statedump.h"
 
-int
-lttng_ust_push_baddr(void *so_base, const char *so_name)
-{
-	char resolved_path[PATH_MAX];
-	struct stat sostat;
-
-	if (!realpath(so_name, resolved_path)) {
-		ERR("could not resolve path '%s'", so_name);
-		return 0;
-	}
-
-	if (stat(resolved_path, &sostat)) {
-		ERR("could not access file status for %s", resolved_path);
-		return 0;
-	}
-
-	tracepoint(ust_baddr, push,
-		so_base, resolved_path, sostat.st_size, sostat.st_mtime);
-	return 0;
-}
-
-int
-lttng_ust_pop_baddr(void *so_base)
-{
-	tracepoint(ust_baddr, pop, so_base);
-	return 0;
-}
-
 static int
 extract_soinfo_events(struct dl_phdr_info *info, size_t size, void *data)
 {
liblttng-ust-baddr/lttng-ust-baddr.h new file +22 -0
new file mode 100644
index 0000000..e72eb2c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2013  Paul Woegerer <[email protected]>
+ *
+ * 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
+ */
+
+#include <lttng/ust-events.h>
+
+int
+lttng_ust_baddr_statedump(struct lttng_session *session);
liblttng-ust-baddr/ust_baddr_statedump.h +1 -1
index 77a9af4..c509bd4 100644
@@ -35,7 +35,7 @@ extern "C" {
 #include <lttng/ust-events.h>
 
 #define LTTNG_UST_BADDR_STATEDUMP_PROVIDER
-#include <lttng/tracepoint.h>
+#include <tracepoint.h>
 
 TRACEPOINT_EVENT(ust_baddr_statedump, soinfo,
 	TP_ARGS(struct lttng_session *, session, void *, baddr, const char*, sopath, int64_t, size, int64_t, mtime),
liblttng-ust-dl/Makefile.am +4 -1
index c408fdd..352f145 100644
@@ -2,7 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
 lib_LTLIBRARIES = liblttng-ust-dl.la
-liblttng_ust_dl_la_SOURCES = ustdl.c
+liblttng_ust_dl_la_SOURCES = \
+	ustdl.c \
+	ust_baddr.c \
+	ust_baddr.h
 liblttng_ust_dl_la_LIBADD = \
 	$(top_builddir)/liblttng-ust/liblttng-ust.la
 
liblttng-ust-dl/ust_baddr.c renamed from liblttng-ust-baddr/ust_baddr.c +0 -0
similarity index 100%
rename from liblttng-ust-baddr/ust_baddr.c
rename to liblttng-ust-dl/ust_baddr.c
liblttng-ust-dl/ust_baddr.h renamed from liblttng-ust-baddr/ust_baddr.h +0 -0
similarity index 100%
rename from liblttng-ust-baddr/ust_baddr.h
rename to liblttng-ust-dl/ust_baddr.h
liblttng-ust-dl/ustdl.c +20 -56

107 lines not on this page · raw message

liblttng-ust/Makefile.am +1 -0
index a333313..f00fe45 100644
@@ -69,6 +69,7 @@ liblttng_ust_la_LIBADD = \
 	-lurcu-cds \
 	$(top_builddir)/snprintf/libustsnprintf.la \
 	$(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la \
+	$(top_builddir)/liblttng-ust-baddr/liblttng-ust-baddr.la \
 	liblttng-ust-tracepoint.la \
 	liblttng-ust-runtime.la liblttng-ust-support.la
 
liblttng-ust/lttng-ust-comm.c +4 -42

76 lines not on this page · raw message

Signature · 1 line
1.8.4
#2 lore raw

PATCH 2/3 Fix: baddr_statedump deadlock with JUL tracing

In reply to a message not in the archive
---
 liblttng-ust/lttng-ust-comm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
liblttng-ust/lttng-ust-comm.c +3 -1
index 2d3766f..0c7fc65 100644
@@ -1214,10 +1214,12 @@ restart:
 			if (ret) {
 				ERR("Error handling message for %s socket", sock_info->name);
 			} else {
+				int ctor_passed;
 				struct lttng_session *session;
 
+				ctor_passed = sock_info->constructor_sem_posted;
 				session = sock_info->session_enabled;
-				if (session) {
+				if (ctor_passed && session) {
 					sock_info->session_enabled = NULL;
 					lttng_ust_baddr_statedump(session);
 				}
Signature · 1 line
1.8.4
#3 lore raw

PATCH 3/3 Allow suppressing of base-address-state tracing

In reply to a message not in the archive
---
 liblttng-ust-baddr/lttng-ust-baddr.c | 2 ++
 1 file changed, 2 insertions(+)
liblttng-ust-baddr/lttng-ust-baddr.c +2 -0
index 8412233..1e6e08d 100644
@@ -99,6 +99,8 @@ extract_soinfo_events(struct dl_phdr_info *info, size_t size, void *data)
 int
 lttng_ust_baddr_statedump(struct lttng_session *session)
 {
+	if (getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP"))
+		return 0;
 	/*
 	 * Iterate through the list of currently loaded shared objects and
 	 * generate events for loadable segments using extract_soinfo_events
Signature · 1 line
1.8.4
#4 lore raw

Re: [PATCH lttng-ust 0/3] Solve remaining issues with base-address-state tracing

In reply to a message not in the archive

Merged patches 1 and 3, not 2. I also did another commit to move files around and simplify things.

We need to discuss the deadlock fix more thoroughly.

Thanks,

Mathieu

----- Original Message -----

Quoted 72 lines

From: "Paul Woegerer" <[email protected]>
To: [email protected], "mathieu desnoyers" <[email protected]>, [email protected]
Sent: Thursday, November 28, 2013 1:26:51 PM
Subject: [PATCH lttng-ust 0/3] Solve remaining issues with base-address-state tracing

This patch series addresses the remaining issues that were reported against base-address-state tracing. Base-address-state tracing is now fully integrated
into lttng-ust (no separate shared object anymore).

Users that would like to suppress the generation of ust_baddr_statedump events
entirely can now use environment variable LTTNG_UST_WITHOUT_BADDR_STATEDUMP=1.

The deadlock in combination with JUL tracing is also fixed now. It was caused by the fact that JUL tracing causes the static constructor of lttng-ust to be called in the context of dlopen:

To setup JUL tracing the JVM executes:

   System.loadLibrary("lttng-ust-jul-jni");

This effectively dlopen's lttng-ust-jul-jni.so.0 and that will cause the static
ctor of lttng-ust to get executed. Now if the completion of the execution of the lttng-ust ctor depends on someone that tries to acquire a lock on glibc's dl_load_lock we run into a deadlock because the lock is already hold as a side
effect of the dlopen that was initiated by the JVM to load "lttng-ust-jul-jni".
But exactly that happened when base-address-state tracing tries to generate ust_baddr_statedump events on session-enable (e.g. calling dladdr or emitting a
tracepoint all try to acquire the dl_load_lock).

By making the ust_baddr_statedump happen a "little later" so that it cannot block the completion of the static ctor anymore, the deadlock is prevented. Once we know the static ctor will complete for sure we also know that the JVM initiated dlopen that called the static ctor will complete. At that point is is again safe to use calls that involve acquiring dl_load_lock. Making the statedump happen a "little later" is implemented by patch:

Fix: baddr_statedump deadlock with JUL tracing

Paul Woegerer (3):
Integrate base-address statedump into lttng-ust
Fix: baddr_statedump deadlock with JUL tracing
Allow suppressing of base-address-state tracing

 Makefile.am                                        |  3 +-
 liblttng-ust-baddr/Makefile.am                     | 18 +----
 liblttng-ust-baddr/lttng-ust-baddr.c               | 34 ++--------
 liblttng-ust-baddr/lttng-ust-baddr.h               | 22 +++++++
 liblttng-ust-baddr/ust_baddr_statedump.h           |  2 +-
 liblttng-ust-dl/Makefile.am                        |  5 +-
 .../ust_baddr.c                                    |  0
 .../ust_baddr.h                                    |  0
 liblttng-ust-dl/ustdl.c                            | 76
 ++++++----------------
 liblttng-ust/Makefile.am                           |  1 +
 liblttng-ust/lttng-ust-comm.c                      | 50 ++------------
 11 files changed, 63 insertions(+), 148 deletions(-)
 create mode 100644 liblttng-ust-baddr/lttng-ust-baddr.h
 rename {liblttng-ust-baddr => liblttng-ust-dl}/ust_baddr.c (100%)
 rename {liblttng-ust-baddr => liblttng-ust-dl}/ust_baddr.h (100%)

--
1.8.4

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com