All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found] <51F97688.30704@mentor.com>
@ 2013-07-31 22:00 ` Jérémie Galarneau
       [not found] ` <CA+jJMxsoH8Rz6fwZJOPnG-4xvB2w8GO5eqi0JDtHUy7iM-n2WA@mail.gmail.com>
  1 sibling, 0 replies; 22+ messages in thread
From: Jérémie Galarneau @ 2013-07-31 22:00 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

Hi Stefan,

Please inline your patches in the future as it makes the review process simpler.
There are a number of stylistic problems, mostly misplaced braces.

You can run your patches through the checkpatch.pl script found in
lttng-tools/extras. It will spot most coding-style related problems
right away.

Also, I think lttng-ust-pthread-mutex.c may be a more appropriate name
than pthread.c

Thanks,
Jérémie

On Wed, Jul 31, 2013 at 4:41 PM, Stefan Seefeld
<stefan_seefeld@mentor.com> wrote:
> The attached patch introduces a pthread wrapper library with initial
> instrumentation for pthread_mutex_lock, pthread_mutex_trylock, and
> pthread_mutex_unlock.
> New tracepoints are introduced for each of those. For the lock function,
> two distinct tracepoints are emitted: one before the lock is requested,
> another after it has been acquired.
>
> --
> Stefan Seefeld
> CodeSourcery / Mentor Graphics
> http://www.mentor.com/embedded-software/
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found] ` <CA+jJMxsoH8Rz6fwZJOPnG-4xvB2w8GO5eqi0JDtHUy7iM-n2WA@mail.gmail.com>
@ 2013-08-01  0:17   ` Stefan Seefeld
       [not found]   ` <51F9A917.9010509@seefeld.name>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-01  0:17 UTC (permalink / raw)
  To: lttng-dev

On 07/31/2013 06:00 PM, Jérémie Galarneau wrote:
> Hi Stefan,
>
> Please inline your patches in the future as it makes the review process simpler.
> There are a number of stylistic problems, mostly misplaced braces.
>
> You can run your patches through the checkpatch.pl script found in
> lttng-tools/extras. It will spot most coding-style related problems
> right away.

OK, will do, once the patch is approved functionally.

> Also, I think lttng-ust-pthread-mutex.c may be a more appropriate name
> than pthread.c

Wouldn't that just be redundant ? (And I actually expect the file to
grow instrumentation that's not mutex-specific.)

Thanks,
    Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]   ` <51F9A917.9010509@seefeld.name>
@ 2013-08-01  3:16     ` Jérémie Galarneau
  2013-08-03  1:28     ` Mathieu Desnoyers
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 22+ messages in thread
From: Jérémie Galarneau @ 2013-08-01  3:16 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

On Wed, Jul 31, 2013 at 8:17 PM, Stefan Seefeld <stefan@seefeld.name> wrote:
> On 07/31/2013 06:00 PM, Jérémie Galarneau wrote:
>> Hi Stefan,
>>
>> Please inline your patches in the future as it makes the review process simpler.
>> There are a number of stylistic problems, mostly misplaced braces.
>>
>> You can run your patches through the checkpatch.pl script found in
>> lttng-tools/extras. It will spot most coding-style related problems
>> right away.
>
> OK, will do, once the patch is approved functionally.
>
>> Also, I think lttng-ust-pthread-mutex.c may be a more appropriate name
>> than pthread.c
>
> Wouldn't that just be redundant ? (And I actually expect the file to
> grow instrumentation that's not mutex-specific.)

I'd keep the file name in line with what's already there, namely
lttng-ust-malloc.c.
If you plan on instrumenting other parts of the pthread API,
lttng-ust-pthread.c would make sense.

>
> Thanks,
>     Stefan
>
> --
>
>       ...ich hab' noch einen Koffer in Berlin...
>
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]   ` <51F9A917.9010509@seefeld.name>
  2013-08-01  3:16     ` Jérémie Galarneau
@ 2013-08-03  1:28     ` Mathieu Desnoyers
       [not found]     ` <CA+jJMxv4oS0SbMqUF247jS0s0E+6DfdepNT8yHimY=TULHD+tQ@mail.gmail.com>
       [not found]     ` <20130803012831.GH9033@Krystal>
  3 siblings, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-03  1:28 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan@seefeld.name) wrote:
> On 07/31/2013 06:00 PM, Jérémie Galarneau wrote:
> > Hi Stefan,
> >
> > Please inline your patches in the future as it makes the review process simpler.
> > There are a number of stylistic problems, mostly misplaced braces.
> >
> > You can run your patches through the checkpatch.pl script found in
> > lttng-tools/extras. It will spot most coding-style related problems
> > right away.
> 
> OK, will do, once the patch is approved functionally.

Jeremie is right: incorrect coding style makes the review process harder
for us. Once the coding style is right, we can do the functional review
of the patch more efficiently.

Please resubmit after coding style fixes.

Thanks,

Mathieu

> 
> > Also, I think lttng-ust-pthread-mutex.c may be a more appropriate name
> > than pthread.c
> 
> Wouldn't that just be redundant ? (And I actually expect the file to
> grow instrumentation that's not mutex-specific.)
> 
> Thanks,
>     Stefan
> 
> -- 
> 
>       ...ich hab' noch einen Koffer in Berlin...
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]     ` <CA+jJMxv4oS0SbMqUF247jS0s0E+6DfdepNT8yHimY=TULHD+tQ@mail.gmail.com>
@ 2013-08-03  1:28       ` Mathieu Desnoyers
  0 siblings, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-03  1:28 UTC (permalink / raw)
  To: Jérémie Galarneau; +Cc: lttng-dev

* Jérémie Galarneau (jeremie.galarneau@efficios.com) wrote:
> On Wed, Jul 31, 2013 at 8:17 PM, Stefan Seefeld <stefan@seefeld.name> wrote:
> > On 07/31/2013 06:00 PM, Jérémie Galarneau wrote:
> >> Hi Stefan,
> >>
> >> Please inline your patches in the future as it makes the review process simpler.
> >> There are a number of stylistic problems, mostly misplaced braces.
> >>
> >> You can run your patches through the checkpatch.pl script found in
> >> lttng-tools/extras. It will spot most coding-style related problems
> >> right away.
> >
> > OK, will do, once the patch is approved functionally.
> >
> >> Also, I think lttng-ust-pthread-mutex.c may be a more appropriate name
> >> than pthread.c
> >
> > Wouldn't that just be redundant ? (And I actually expect the file to
> > grow instrumentation that's not mutex-specific.)
> 
> I'd keep the file name in line with what's already there, namely
> lttng-ust-malloc.c.
> If you plan on instrumenting other parts of the pthread API,
> lttng-ust-pthread.c would make sense.

Agreed.

Mathieu

> 
> >
> > Thanks,
> >     Stefan
> >
> > --
> >
> >       ...ich hab' noch einen Koffer in Berlin...
> >
> >
> > _______________________________________________
> > lttng-dev mailing list
> > lttng-dev@lists.lttng.org
> > http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> 
> 
> 
> -- 
> Jérémie Galarneau
> EfficiOS Inc.
> http://www.efficios.com
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]     ` <20130803012831.GH9033@Krystal>
@ 2013-08-05 13:38       ` Stefan Seefeld
       [not found]       ` <51FFAAD7.3000705@seefeld.name>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-05 13:38 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 361 bytes --]

On 08/02/2013 09:28 PM, Mathieu Desnoyers wrote:
> Jeremie is right: incorrect coding style makes the review process harder
> for us. Once the coding style is right, we can do the functional review
> of the patch more efficiently.
>
> Please resubmit after coding style fixes.

See attached.

    Stefan


-- 

      ...ich hab' noch einen Koffer in Berlin...


[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 7498 bytes --]

From cc39cdfbfca6d13121270eb9da3aed97be65586c Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
---
 liblttng-ust-libc-wrapper/Makefile.am         | 12 +++-
 liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 91 +++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_pthread.h       | 76 ++++++++++++++++++++++
 3 files changed, 178 insertions(+), 1 deletion(-)
 create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..d402d53 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	lttng-ust-pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
new file mode 100644
index 0000000..98ce9bf
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	if (!mutex_lock) {
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (!thread_in_trace) {
+		thread_in_trace = 1;
+		tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+		int retval = mutex_lock(mutex);
+		tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+		thread_in_trace = 0;
+		return retval;
+	} else {
+		return mutex_lock(mutex);
+	}
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	if (!mutex_trylock) {
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (!thread_in_trace) {
+		thread_in_trace = 1;
+		int retval = mutex_trylock(mutex);
+		tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+		thread_in_trace = 0;
+		return retval;
+	} else {
+		return mutex_trylock(mutex);
+	}
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	if (!mutex_unlock) {
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (!thread_in_trace) {
+		thread_in_trace = 1;
+		int retval = mutex_unlock(mutex);
+		tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+		thread_in_trace = 0;
+		return retval;
+	} else {
+		return mutex_unlock(mutex);
+	}
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..86275b7
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]       ` <51FFAAD7.3000705@seefeld.name>
@ 2013-08-07  1:32         ` Mathieu Desnoyers
       [not found]         ` <20130807013159.GG19407@Krystal>
  1 sibling, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-07  1:32 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan@seefeld.name) wrote:
> On 08/02/2013 09:28 PM, Mathieu Desnoyers wrote:
> > Jeremie is right: incorrect coding style makes the review process harder
> > for us. Once the coding style is right, we can do the functional review
> > of the patch more efficiently.
> >
> > Please resubmit after coding style fixes.
> 
> See attached.

Thanks,

Please beware that we're not pulling new features during the -rc cycle.
When the patch is deemed ready, it will be good to keep it around for
submission after 2.3-final is released.

comments inlined below,

> 
>     Stefan
> 
> 
> -- 
> 
>       ...ich hab' noch einen Koffer in Berlin...
> 

> From cc39cdfbfca6d13121270eb9da3aed97be65586c Mon Sep 17 00:00:00 2001
> From: Stefan Seefeld <stefan_seefeld@mentor.com>
> Date: Wed, 31 Jul 2013 16:35:31 -0400
> Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.
> 
> Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
> ---
>  liblttng-ust-libc-wrapper/Makefile.am         | 12 +++-
>  liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 91 +++++++++++++++++++++++++++
>  liblttng-ust-libc-wrapper/ust_pthread.h       | 76 ++++++++++++++++++++++
>  3 files changed, 178 insertions(+), 1 deletion(-)
>  create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
>  create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h
> 
> diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
> index 4fdcedb..d402d53 100644
> --- a/liblttng-ust-libc-wrapper/Makefile.am
> +++ b/liblttng-ust-libc-wrapper/Makefile.am
> @@ -1,7 +1,8 @@
>  AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
>  AM_CFLAGS = -fno-strict-aliasing
>  
> -lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
> +lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
> +  liblttng-ust-pthread-wrapper.la
>  liblttng_ust_libc_wrapper_la_SOURCES = \
>  	lttng-ust-malloc.c \
>  	ust_libc.h
> @@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
>  	-L$(top_builddir)/liblttng-ust/.libs \
>  	-llttng-ust
>  
> +liblttng_ust_pthread_wrapper_la_SOURCES = \
> +	lttng-ust-pthread.c \
> +	ust_pthread.h
> +liblttng_ust_pthread_wrapper_la_LIBADD = \
> +	-L$(top_builddir)/liblttng-ust/.libs \
> +	-llttng-ust
> +
>  if LTTNG_UST_BUILD_WITH_LIBDL
>  liblttng_ust_libc_wrapper_la_LIBADD += -ldl
> +liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
>  endif
>  if LTTNG_UST_BUILD_WITH_LIBC_DL
>  liblttng_ust_libc_wrapper_la_LIBADD += -lc
> +liblttng_ust_pthread_wrapper_la_LIBADD += -lc
>  endif
>  
>  noinst_SCRIPTS = run
> diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> new file mode 100644
> index 0000000..98ce9bf
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> @@ -0,0 +1,91 @@
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * 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 _GNU_SOURCE
> +#include <dlfcn.h>
> +#include <pthread.h>
> +
> +#define TRACEPOINT_DEFINE
> +#define TRACEPOINT_CREATE_PROBES
> +#include "ust_pthread.h"
> +
> +static __thread int thread_in_trace;
> +
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_lock)(pthread_mutex_t *);

please add newline.

> +	if (!mutex_lock) {
> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> +		if (!mutex_lock) {
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");

is it possible that fprintf calls pthread_mutex_lock at some point ? If
so, this should be surrounded within thread_in_trace check.

> +			return EINVAL;
> +		}
> +	}
> +	if (!thread_in_trace) {
> +		thread_in_trace = 1;
> +		tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
> +		int retval = mutex_lock(mutex);

please avoid declaring a variable with code. Always do so at the
beginning of a block.

> +		tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
> +		thread_in_trace = 0;
> +		return retval;
> +	} else {
> +		return mutex_lock(mutex);
> +	}

I'd prefer something like:

        if (thread_in_trace) {
                return mutex_lock(mutex);
        }

        thread_in_trace = 1;
        tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
        retval = mutex_lock(mutex);
        tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
        thread_in_trace = 0;
        return retval;

so we can remove a level of indentation by only putting the
special-cases at the beginning in the if (with a return within the true
block).

Similar comments apply throughout this patch.

> +}
> +
> +int pthread_mutex_trylock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_trylock)(pthread_mutex_t *);
> +	if (!mutex_trylock) {
> +		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
> +		if (!mutex_trylock) {
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (!thread_in_trace) {
> +		thread_in_trace = 1;
> +		int retval = mutex_trylock(mutex);
> +		tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
> +		thread_in_trace = 0;
> +		return retval;
> +	} else {
> +		return mutex_trylock(mutex);
> +	}
> +}
> +
> +int pthread_mutex_unlock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_unlock)(pthread_mutex_t *);
> +	if (!mutex_unlock) {
> +		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
> +		if (!mutex_unlock) {
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (!thread_in_trace) {
> +		thread_in_trace = 1;
> +		int retval = mutex_unlock(mutex);
> +		tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
> +		thread_in_trace = 0;
> +		return retval;
> +	} else {
> +		return mutex_unlock(mutex);
> +	}
> +}
> diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
> new file mode 100644
> index 0000000..86275b7
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/ust_pthread.h
> @@ -0,0 +1,76 @@
> +#undef TRACEPOINT_PROVIDER
> +#define TRACEPOINT_PROVIDER ust_pthread
> +
> +#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
> +#define _TRACEPOINT_UST_PTHREAD_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> +	TP_ARGS(pthread_mutex_t *, mutex),
> +	TP_FIELDS(
> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)

I'm curious (and I honestly don't remember): does it work if we put
"void *" as type rather than "unsigned long" here ?

Thanks,

Mathieu

> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +#endif /* _TRACEPOINT_UST_PTHREAD_H */
> +
> +#undef TRACEPOINT_INCLUDE
> +#define TRACEPOINT_INCLUDE "./ust_pthread.h"
> +
> +/* This part must be outside ifdef protection */
> +#include <lttng/tracepoint-event.h>
> +
> +#ifdef __cplusplus
> +}
> +#endif
> -- 
> 1.8.3.1
> 


-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]         ` <20130807013159.GG19407@Krystal>
@ 2013-08-07 13:14           ` Stefan Seefeld
       [not found]           ` <5202482B.2010705@mentor.com>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 13:14 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

Mathieu,

please find attached a revised patch.

On 08/06/2013 09:32 PM, Mathieu Desnoyers wrote:
>
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> +	TP_ARGS(pthread_mutex_t *, mutex),
> +	TP_FIELDS(
> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
> I'm curious (and I honestly don't remember): does it work if we put
> "void *" as type rather than "unsigned long" here ?

It seems to work fine - I applied the suggested change (see the current
patch) and I see the same traces.

    Stefan

-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/


[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 7547 bytes --]

From 6fb45b78dd60045631d3e8e6dab6dd838d9db869 Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
---
 liblttng-ust-libc-wrapper/Makefile.am         | 12 +++-
 liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 97 +++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_pthread.h       | 76 +++++++++++++++++++++
 3 files changed, 184 insertions(+), 1 deletion(-)
 create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..d402d53 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	lttng-ust-pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
new file mode 100644
index 0000000..53230e1
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_lock) {
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_lock(mutex);
+	}
+
+	thread_in_trace = 1;
+	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+	retval = mutex_lock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_trylock) {
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_trylock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_trylock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_unlock) {
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_unlock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_unlock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..86275b7
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]           ` <5202482B.2010705@mentor.com>
@ 2013-08-07 14:05             ` Stefan Seefeld
       [not found]             ` <52025427.5080002@mentor.com>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 14:05 UTC (permalink / raw)
  To: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]

On 08/07/2013 09:14 AM, Stefan Seefeld wrote:
> Mathieu,
>
> please find attached a revised patch.
>
> On 08/06/2013 09:32 PM, Mathieu Desnoyers wrote:
>> +#include <lttng/tracepoint.h>
>> +
>> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
>> +	TP_ARGS(pthread_mutex_t *, mutex),
>> +	TP_FIELDS(
>> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
>> I'm curious (and I honestly don't remember): does it work if we put
>> "void *" as type rather than "unsigned long" here ?
> It seems to work fine - I applied the suggested change (see the current
> patch) and I see the same traces.

Sorry, the patch was incomplete. Here is the complete one (including the
revised ust_pthread.h code.

    Stefan

-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/


[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 7491 bytes --]

From 204a0821918ee826a19ad3e01d1ada69d9ece395 Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
---
 liblttng-ust-libc-wrapper/Makefile.am         | 12 +++-
 liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 97 +++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_pthread.h       | 76 +++++++++++++++++++++
 3 files changed, 184 insertions(+), 1 deletion(-)
 create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..d402d53 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	lttng-ust-pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
new file mode 100644
index 0000000..53230e1
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_lock) {
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_lock(mutex);
+	}
+
+	thread_in_trace = 1;
+	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+	retval = mutex_lock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_trylock) {
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_trylock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_trylock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_unlock) {
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_unlock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_unlock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..a1be974
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]             ` <52025427.5080002@mentor.com>
@ 2013-08-07 14:33               ` Mathieu Desnoyers
       [not found]               ` <20130807143346.GA542@Krystal>
  1 sibling, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-07 14:33 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> On 08/07/2013 09:14 AM, Stefan Seefeld wrote:
> > Mathieu,
> >
> > please find attached a revised patch.
> >
> > On 08/06/2013 09:32 PM, Mathieu Desnoyers wrote:
> >> +#include <lttng/tracepoint.h>
> >> +
> >> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> >> +	TP_ARGS(pthread_mutex_t *, mutex),
> >> +	TP_FIELDS(
> >> +		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
> >> I'm curious (and I honestly don't remember): does it work if we put
> >> "void *" as type rather than "unsigned long" here ?
> > It seems to work fine - I applied the suggested change (see the current
> > patch) and I see the same traces.
> 
> Sorry, the patch was incomplete. Here is the complete one (including the
> revised ust_pthread.h code.

We're getting close with this patch, still a few questions below.

> 
>     Stefan
> 
> -- 
> Stefan Seefeld
> CodeSourcery / Mentor Graphics
> http://www.mentor.com/embedded-software/
> 

> From 204a0821918ee826a19ad3e01d1ada69d9ece395 Mon Sep 17 00:00:00 2001
> From: Stefan Seefeld <stefan_seefeld@mentor.com>
> Date: Wed, 31 Jul 2013 16:35:31 -0400
> Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.
> 
> Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
> ---
>  liblttng-ust-libc-wrapper/Makefile.am         | 12 +++-
>  liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 97 +++++++++++++++++++++++++++
>  liblttng-ust-libc-wrapper/ust_pthread.h       | 76 +++++++++++++++++++++
>  3 files changed, 184 insertions(+), 1 deletion(-)
>  create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
>  create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h
> 
> diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
> index 4fdcedb..d402d53 100644
> --- a/liblttng-ust-libc-wrapper/Makefile.am
> +++ b/liblttng-ust-libc-wrapper/Makefile.am
> @@ -1,7 +1,8 @@
>  AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
>  AM_CFLAGS = -fno-strict-aliasing
>  
> -lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
> +lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
> +  liblttng-ust-pthread-wrapper.la
>  liblttng_ust_libc_wrapper_la_SOURCES = \
>  	lttng-ust-malloc.c \
>  	ust_libc.h
> @@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
>  	-L$(top_builddir)/liblttng-ust/.libs \
>  	-llttng-ust
>  
> +liblttng_ust_pthread_wrapper_la_SOURCES = \
> +	lttng-ust-pthread.c \
> +	ust_pthread.h
> +liblttng_ust_pthread_wrapper_la_LIBADD = \
> +	-L$(top_builddir)/liblttng-ust/.libs \
> +	-llttng-ust
> +
>  if LTTNG_UST_BUILD_WITH_LIBDL
>  liblttng_ust_libc_wrapper_la_LIBADD += -ldl
> +liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
>  endif
>  if LTTNG_UST_BUILD_WITH_LIBC_DL
>  liblttng_ust_libc_wrapper_la_LIBADD += -lc
> +liblttng_ust_pthread_wrapper_la_LIBADD += -lc
>  endif
>  
>  noinst_SCRIPTS = run
> diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> new file mode 100644
> index 0000000..53230e1
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * 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 _GNU_SOURCE
> +#include <dlfcn.h>
> +#include <pthread.h>
> +
> +#define TRACEPOINT_DEFINE
> +#define TRACEPOINT_CREATE_PROBES
> +#include "ust_pthread.h"
> +
> +static __thread int thread_in_trace;
> +
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_lock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_lock) {
> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> +		if (!mutex_lock && !thread_in_trace) {

I'd rather see:

                if (!mutex_lock) {
                        if (thread_in_trace) {
                                abort();
                        }
                        fprintf(stderr, "unable to initialize pthread wrapper library.\n");
                        return EINVAL;
                }

because in that situation, there is not much we can do anyway.

> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_lock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
> +	retval = mutex_lock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_trylock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_trylock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_trylock) {
> +		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
> +		if (!mutex_trylock && !thread_in_trace) {
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_trylock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_trylock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_unlock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_unlock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_unlock) {
> +		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
> +		if (!mutex_unlock && !thread_in_trace) {
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_unlock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_unlock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
> new file mode 100644
> index 0000000..a1be974
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/ust_pthread.h
> @@ -0,0 +1,76 @@
> +#undef TRACEPOINT_PROVIDER
> +#define TRACEPOINT_PROVIDER ust_pthread
> +
> +#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
> +#define _TRACEPOINT_UST_PTHREAD_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> +	TP_ARGS(pthread_mutex_t *, mutex),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)

I think the (void *) cast can be removed here: an implicit cast from
pthread_mutex_t * to void * should be fine.

Thanks,

Mathieu

> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +#endif /* _TRACEPOINT_UST_PTHREAD_H */
> +
> +#undef TRACEPOINT_INCLUDE
> +#define TRACEPOINT_INCLUDE "./ust_pthread.h"
> +
> +/* This part must be outside ifdef protection */
> +#include <lttng/tracepoint-event.h>
> +
> +#ifdef __cplusplus
> +}
> +#endif
> -- 
> 1.8.3.1
> 

> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]               ` <20130807143346.GA542@Krystal>
@ 2013-08-07 15:08                 ` Stefan Seefeld
       [not found]                 ` <520262E8.5010106@mentor.com>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 15:08 UTC (permalink / raw)
  To: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 1174 bytes --]

On 08/07/2013 10:33 AM, Mathieu Desnoyers wrote:
> * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
>
>>
>> +int pthread_mutex_lock(pthread_mutex_t *mutex)
>> +{
>> +	static int (*mutex_lock)(pthread_mutex_t *);
>> +	int retval;
>> +
>> +	if (!mutex_lock) {
>> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
>> +		if (!mutex_lock && !thread_in_trace) {
> I'd rather see:
>
>                 if (!mutex_lock) {
>                         if (thread_in_trace) {
>                                 abort();
>                         }
>                         fprintf(stderr, "unable to initialize pthread wrapper library.\n");
>                         return EINVAL;
>                 }
>
> because in that situation, there is not much we can do anyway.

Agreed.

>> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
>> +	TP_ARGS(pthread_mutex_t *, mutex),
>> +	TP_FIELDS(
>> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> I think the (void *) cast can be removed here: an implicit cast from
> pthread_mutex_t * to void * should be fine.

Adjusted.

    Stefan

-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/


[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 7579 bytes --]

From 5ad78c8b7c24d2c96e55739de32fbf9a353edd9f Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
---
 liblttng-ust-libc-wrapper/Makefile.am         |  12 +++-
 liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 100 ++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_libc.h          |  10 +--
 liblttng-ust-libc-wrapper/ust_pthread.h       |  76 ++++++++++++++++++++
 4 files changed, 192 insertions(+), 6 deletions(-)
 create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..d402d53 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	lttng-ust-pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
new file mode 100644
index 0000000..fff073e
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_lock) {
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock) {
+			if (thread_in_trace) {
+				abort();
+		  }
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_lock(mutex);
+	}
+
+	thread_in_trace = 1;
+	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+	retval = mutex_lock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_trylock) {
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_trylock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_trylock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_unlock) {
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock && !thread_in_trace) {
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_unlock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_unlock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..a1be974
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, (void *) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                 ` <520262E8.5010106@mentor.com>
@ 2013-08-07 15:19                   ` Mathieu Desnoyers
       [not found]                   ` <20130807151903.GA1035@Krystal>
  1 sibling, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-07 15:19 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> On 08/07/2013 10:33 AM, Mathieu Desnoyers wrote:
> > * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> >
> >>
> >> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> >> +{
> >> +	static int (*mutex_lock)(pthread_mutex_t *);
> >> +	int retval;
> >> +
> >> +	if (!mutex_lock) {
> >> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> >> +		if (!mutex_lock && !thread_in_trace) {
> > I'd rather see:
> >
> >                 if (!mutex_lock) {
> >                         if (thread_in_trace) {
> >                                 abort();
> >                         }
> >                         fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> >                         return EINVAL;
> >                 }
> >
> > because in that situation, there is not much we can do anyway.
> 
> Agreed.
> 
> >> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> >> +	TP_ARGS(pthread_mutex_t *, mutex),
> >> +	TP_FIELDS(
> >> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> > I think the (void *) cast can be removed here: an implicit cast from
> > pthread_mutex_t * to void * should be fine.
> 
> Adjusted.
> 
>     Stefan
> 
> -- 
> Stefan Seefeld
> CodeSourcery / Mentor Graphics
> http://www.mentor.com/embedded-software/
> 

> From 5ad78c8b7c24d2c96e55739de32fbf9a353edd9f Mon Sep 17 00:00:00 2001
> From: Stefan Seefeld <stefan_seefeld@mentor.com>
> Date: Wed, 31 Jul 2013 16:35:31 -0400
> Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.
> 
> Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
> ---
>  liblttng-ust-libc-wrapper/Makefile.am         |  12 +++-
>  liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 100 ++++++++++++++++++++++++++
>  liblttng-ust-libc-wrapper/ust_libc.h          |  10 +--
>  liblttng-ust-libc-wrapper/ust_pthread.h       |  76 ++++++++++++++++++++
>  4 files changed, 192 insertions(+), 6 deletions(-)
>  create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
>  create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h
> 
> diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
> index 4fdcedb..d402d53 100644
> --- a/liblttng-ust-libc-wrapper/Makefile.am
> +++ b/liblttng-ust-libc-wrapper/Makefile.am
> @@ -1,7 +1,8 @@
>  AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
>  AM_CFLAGS = -fno-strict-aliasing
>  
> -lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
> +lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
> +  liblttng-ust-pthread-wrapper.la
>  liblttng_ust_libc_wrapper_la_SOURCES = \
>  	lttng-ust-malloc.c \
>  	ust_libc.h
> @@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
>  	-L$(top_builddir)/liblttng-ust/.libs \
>  	-llttng-ust
>  
> +liblttng_ust_pthread_wrapper_la_SOURCES = \
> +	lttng-ust-pthread.c \
> +	ust_pthread.h
> +liblttng_ust_pthread_wrapper_la_LIBADD = \
> +	-L$(top_builddir)/liblttng-ust/.libs \
> +	-llttng-ust
> +
>  if LTTNG_UST_BUILD_WITH_LIBDL
>  liblttng_ust_libc_wrapper_la_LIBADD += -ldl
> +liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
>  endif
>  if LTTNG_UST_BUILD_WITH_LIBC_DL
>  liblttng_ust_libc_wrapper_la_LIBADD += -lc
> +liblttng_ust_pthread_wrapper_la_LIBADD += -lc
>  endif
>  
>  noinst_SCRIPTS = run
> diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> new file mode 100644
> index 0000000..fff073e
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> @@ -0,0 +1,100 @@
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * 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 _GNU_SOURCE
> +#include <dlfcn.h>
> +#include <pthread.h>
> +
> +#define TRACEPOINT_DEFINE
> +#define TRACEPOINT_CREATE_PROBES
> +#include "ust_pthread.h"
> +
> +static __thread int thread_in_trace;
> +
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_lock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_lock) {
> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> +		if (!mutex_lock) {
> +			if (thread_in_trace) {
> +				abort();
> +		  }
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_lock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
> +	retval = mutex_lock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_trylock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_trylock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_trylock) {
> +		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
> +		if (!mutex_trylock && !thread_in_trace) {

I think you forgot to apply the abort() trick everywhere.

> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_trylock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_trylock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_unlock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_unlock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_unlock) {
> +		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
> +		if (!mutex_unlock && !thread_in_trace) {
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_unlock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_unlock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
> new file mode 100644
> index 0000000..a1be974
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/ust_pthread.h
> @@ -0,0 +1,76 @@
> +#undef TRACEPOINT_PROVIDER
> +#define TRACEPOINT_PROVIDER ust_pthread
> +
> +#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
> +#define _TRACEPOINT_UST_PTHREAD_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> +	TP_ARGS(pthread_mutex_t *, mutex),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)

The explicit cast is still there. You possibly forgot to refresh your
patch.

Thanks,

Mathieu

> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, (void *) mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +#endif /* _TRACEPOINT_UST_PTHREAD_H */
> +
> +#undef TRACEPOINT_INCLUDE
> +#define TRACEPOINT_INCLUDE "./ust_pthread.h"
> +
> +/* This part must be outside ifdef protection */
> +#include <lttng/tracepoint-event.h>
> +
> +#ifdef __cplusplus
> +}
> +#endif
> -- 
> 1.8.3.1
> 

> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                   ` <20130807151903.GA1035@Krystal>
@ 2013-08-07 15:42                     ` Stefan Seefeld
       [not found]                     ` <52026AD7.7000103@mentor.com>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 15:42 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 159 bytes --]

Sorry for the incomplete patch. Here is a corrected one.

	Stefan


-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/

[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 7593 bytes --]

From 6fe9a0e8f1db73f688bebc37671d8397bd9094cc Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
---
 liblttng-ust-libc-wrapper/Makefile.am         |  12 ++-
 liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 106 ++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_libc.h          |  10 +--
 liblttng-ust-libc-wrapper/ust_pthread.h       |  76 ++++++++++++++++++
 4 files changed, 198 insertions(+), 6 deletions(-)
 create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..d402d53 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	lttng-ust-pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
new file mode 100644
index 0000000..e72b9b4
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_lock) {
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock) {
+			if (thread_in_trace) {
+				abort();
+			}
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_lock(mutex);
+	}
+
+	thread_in_trace = 1;
+	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+	retval = mutex_lock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_trylock) {
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock) {
+			if (thread_in_trace) {
+				abort();
+			}
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_trylock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_trylock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_unlock) {
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock) {
+			if (thread_in_trace) {
+				abort();
+			}
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_unlock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_unlock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..7d35c3a
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                     ` <52026AD7.7000103@mentor.com>
@ 2013-08-07 15:52                       ` Mathieu Desnoyers
       [not found]                       ` <20130807155228.GC1035@Krystal>
  1 sibling, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-07 15:52 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> Sorry for the incomplete patch. Here is a corrected one.
> 
> 	Stefan

You can add my

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

To you patch changelog.

Can you keep it around and resubmit after we release 2.3-final in a few
weeks ?

Thanks,

Mathieu

> 
> 
> -- 
> Stefan Seefeld
> CodeSourcery / Mentor Graphics
> http://www.mentor.com/embedded-software/

> From 6fe9a0e8f1db73f688bebc37671d8397bd9094cc Mon Sep 17 00:00:00 2001
> From: Stefan Seefeld <stefan_seefeld@mentor.com>
> Date: Wed, 31 Jul 2013 16:35:31 -0400
> Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.
> 
> Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
> ---
>  liblttng-ust-libc-wrapper/Makefile.am         |  12 ++-
>  liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 106 ++++++++++++++++++++++++++
>  liblttng-ust-libc-wrapper/ust_libc.h          |  10 +--
>  liblttng-ust-libc-wrapper/ust_pthread.h       |  76 ++++++++++++++++++
>  4 files changed, 198 insertions(+), 6 deletions(-)
>  create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
>  create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h
> 
> diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
> index 4fdcedb..d402d53 100644
> --- a/liblttng-ust-libc-wrapper/Makefile.am
> +++ b/liblttng-ust-libc-wrapper/Makefile.am
> @@ -1,7 +1,8 @@
>  AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
>  AM_CFLAGS = -fno-strict-aliasing
>  
> -lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
> +lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
> +  liblttng-ust-pthread-wrapper.la
>  liblttng_ust_libc_wrapper_la_SOURCES = \
>  	lttng-ust-malloc.c \
>  	ust_libc.h
> @@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
>  	-L$(top_builddir)/liblttng-ust/.libs \
>  	-llttng-ust
>  
> +liblttng_ust_pthread_wrapper_la_SOURCES = \
> +	lttng-ust-pthread.c \
> +	ust_pthread.h
> +liblttng_ust_pthread_wrapper_la_LIBADD = \
> +	-L$(top_builddir)/liblttng-ust/.libs \
> +	-llttng-ust
> +
>  if LTTNG_UST_BUILD_WITH_LIBDL
>  liblttng_ust_libc_wrapper_la_LIBADD += -ldl
> +liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
>  endif
>  if LTTNG_UST_BUILD_WITH_LIBC_DL
>  liblttng_ust_libc_wrapper_la_LIBADD += -lc
> +liblttng_ust_pthread_wrapper_la_LIBADD += -lc
>  endif
>  
>  noinst_SCRIPTS = run
> diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> new file mode 100644
> index 0000000..e72b9b4
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> @@ -0,0 +1,106 @@
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * 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 _GNU_SOURCE
> +#include <dlfcn.h>
> +#include <pthread.h>
> +
> +#define TRACEPOINT_DEFINE
> +#define TRACEPOINT_CREATE_PROBES
> +#include "ust_pthread.h"
> +
> +static __thread int thread_in_trace;
> +
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_lock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_lock) {
> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> +		if (!mutex_lock) {
> +			if (thread_in_trace) {
> +				abort();
> +			}
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_lock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
> +	retval = mutex_lock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_trylock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_trylock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_trylock) {
> +		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
> +		if (!mutex_trylock) {
> +			if (thread_in_trace) {
> +				abort();
> +			}
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_trylock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_trylock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_unlock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_unlock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_unlock) {
> +		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
> +		if (!mutex_unlock) {
> +			if (thread_in_trace) {
> +				abort();
> +			}
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_unlock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_unlock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
> new file mode 100644
> index 0000000..7d35c3a
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/ust_pthread.h
> @@ -0,0 +1,76 @@
> +#undef TRACEPOINT_PROVIDER
> +#define TRACEPOINT_PROVIDER ust_pthread
> +
> +#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
> +#define _TRACEPOINT_UST_PTHREAD_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> +	TP_ARGS(pthread_mutex_t *, mutex),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +#endif /* _TRACEPOINT_UST_PTHREAD_H */
> +
> +#undef TRACEPOINT_INCLUDE
> +#define TRACEPOINT_INCLUDE "./ust_pthread.h"
> +
> +/* This part must be outside ifdef protection */
> +#include <lttng/tracepoint-event.h>
> +
> +#ifdef __cplusplus
> +}
> +#endif
> -- 
> 1.8.3.1
> 


-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                       ` <20130807155228.GC1035@Krystal>
@ 2013-08-07 16:01                         ` Stefan Seefeld
       [not found]                         ` <52026F42.4050005@mentor.com>
                                           ` (2 subsequent siblings)
  3 siblings, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 16:01 UTC (permalink / raw)
  To: lttng-dev

On 08/07/2013 11:52 AM, Mathieu Desnoyers wrote:
> * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
>> Sorry for the incomplete patch. Here is a corrected one.
>>
>> 	Stefan
> You can add my
>
> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
>
> To you patch changelog.
>
> Can you keep it around and resubmit after we release 2.3-final in a few
> weeks ?

Why can't this be comitted to a devel branch, if it isn't fit to go into
master ? (Also, does this imply that the malloc patch made it into the
2.3 release ?)

    Stefan


-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                         ` <52026F42.4050005@mentor.com>
@ 2013-08-07 16:12                           ` Mathieu Desnoyers
       [not found]                           ` <20130807161241.GB1336@Krystal>
  1 sibling, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-07 16:12 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> On 08/07/2013 11:52 AM, Mathieu Desnoyers wrote:
> > * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> >> Sorry for the incomplete patch. Here is a corrected one.
> >>
> >> 	Stefan
> > You can add my
> >
> > Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> >
> > To you patch changelog.
> >
> > Can you keep it around and resubmit after we release 2.3-final in a few
> > weeks ?
> 
> Why can't this be comitted to a devel branch, if it isn't fit to go into
> master ?

Because master is currently in feature freeze for the 2.3-rc cycle, and
as a maintainer I'm not keeping any devel/staging branch: this
responsibility currently belongs to the contributors. The new features
flow into master between the end of the release candidate cycle (final
version) and the start of the next rc cycle. See the recent discussion
on the release process on lttng-dev for more details. Feedback is
welcome.

> (Also, does this imply that the malloc patch made it into the
> 2.3 release ?)

Yes, the malloc patch made it into the 2.3 release mainly because it's
fixing incomplete coverage of the already existing malloc/free-related
instrumentation.

The difference with pthread instrumentation is that it's really a new
feature in every possible sense of the term: new kind of library
functions are instrumented, new problems may arise, new files are added,
new shared objects are added. This is exactly what we don't want to add
during rc.

Please note that as soon as you get my acked-by, you can consider this
patch accepted. It's just that we don't have the staging branches to
keep them around, nor the manpower to maintain a 3rd branch in parallel
with the current stable+rc.

Thoughts ?

Thanks,

Mathieu

> 
>     Stefan
> 
> 
> -- 
> Stefan Seefeld
> CodeSourcery / Mentor Graphics
> http://www.mentor.com/embedded-software/
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev@lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                           ` <20130807161241.GB1336@Krystal>
@ 2013-08-07 16:25                             ` Stefan Seefeld
       [not found]                             ` <520274F3.3080505@mentor.com>
  1 sibling, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 16:25 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

On 08/07/2013 12:12 PM, Mathieu Desnoyers wrote:

> The difference with pthread instrumentation is that it's really a new
> feature in every possible sense of the term: new kind of library
> functions are instrumented, new problems may arise, new files are added,
> new shared objects are added. This is exactly what we don't want to add
> during rc.

I fully agree.

> Please note that as soon as you get my acked-by, you can consider this
> patch accepted. It's just that we don't have the staging branches to
> keep them around, nor the manpower to maintain a 3rd branch in parallel
> with the current stable+rc.
> 
> Thoughts ?

I understand if it makes things easier for you as maintainer if you ask
contributors to do the rebase before their (approved) patches are to be
merged. But your wording seemed to suggest that I should resend the
actual patch, not regenerate it after rebasing to a future master, which
confused me as in that case I'd need to keep around a free-floating
patch that is neither version-controlled nor archived.

	Stefan


-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                             ` <520274F3.3080505@mentor.com>
@ 2013-08-07 16:31                               ` Mathieu Desnoyers
       [not found]                               ` <20130807163153.GA2194@Krystal>
  1 sibling, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-08-07 16:31 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

* Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> On 08/07/2013 12:12 PM, Mathieu Desnoyers wrote:
> 
> > The difference with pthread instrumentation is that it's really a new
> > feature in every possible sense of the term: new kind of library
> > functions are instrumented, new problems may arise, new files are added,
> > new shared objects are added. This is exactly what we don't want to add
> > during rc.
> 
> I fully agree.
> 
> > Please note that as soon as you get my acked-by, you can consider this
> > patch accepted. It's just that we don't have the staging branches to
> > keep them around, nor the manpower to maintain a 3rd branch in parallel
> > with the current stable+rc.
> > 
> > Thoughts ?
> 
> I understand if it makes things easier for you as maintainer if you ask
> contributors to do the rebase before their (approved) patches are to be
> merged. But your wording seemed to suggest that I should resend the
> actual patch, not regenerate it after rebasing to a future master, which
> confused me as in that case I'd need to keep around a free-floating
> patch that is neither version-controlled nor archived.

I'm OK with contributors rebasing a patch before resubmission, of
course. However, if the rebase required any change at all to the patch,
the "acked-by" tags should be removed, and the fact that it's been
accepted and then rebased (with changes) should be pointed out in the
changelog, ideally with a quick summary of the changes required for the
rebase. This should make the merge process quick and straightforward,
without risks of us missing an issue introduced by the rebase.

Does it make sense ?

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                               ` <20130807163153.GA2194@Krystal>
@ 2013-08-07 16:38                                 ` Stefan Seefeld
  0 siblings, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-08-07 16:38 UTC (permalink / raw)
  To: lttng-dev

On 08/07/2013 12:31 PM, Mathieu Desnoyers wrote:
> * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
>> On 08/07/2013 12:12 PM, Mathieu Desnoyers wrote:
>>
>>> Please note that as soon as you get my acked-by, you can consider this
>>> patch accepted. It's just that we don't have the staging branches to
>>> keep them around, nor the manpower to maintain a 3rd branch in parallel
>>> with the current stable+rc.
>>>
>>> Thoughts ?
>> I understand if it makes things easier for you as maintainer if you ask
>> contributors to do the rebase before their (approved) patches are to be
>> merged. But your wording seemed to suggest that I should resend the
>> actual patch, not regenerate it after rebasing to a future master, which
>> confused me as in that case I'd need to keep around a free-floating
>> patch that is neither version-controlled nor archived.
> I'm OK with contributors rebasing a patch before resubmission, of
> course. However, if the rebase required any change at all to the patch,
> the "acked-by" tags should be removed, and the fact that it's been
> accepted and then rebased (with changes) should be pointed out in the
> changelog, ideally with a quick summary of the changes required for the
> rebase. This should make the merge process quick and straightforward,
> without risks of us missing an issue introduced by the rebase.
>
> Does it make sense ?

OK. You are right, the patch may not actually require any change, given
that it's (mostly) new files.

Thanks,
    Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                       ` <20130807155228.GC1035@Krystal>
  2013-08-07 16:01                         ` Stefan Seefeld
       [not found]                         ` <52026F42.4050005@mentor.com>
@ 2013-09-04 14:01                         ` Stefan Seefeld
       [not found]                         ` <52273D4E.5050304@mentor.com>
  3 siblings, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-09-04 14:01 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

On 2013-08-07 11:52, Mathieu Desnoyers wrote:
> * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
>> Sorry for the incomplete patch. Here is a corrected one.
>>
>> 	Stefan
> 
> You can add my
> 
> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> 
> To you patch changelog.
> 
> Can you keep it around and resubmit after we release 2.3-final in a few
> weeks ?

Mathieu,

please find attached the patch again.

Thanks,
		Stefan


-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 7654 bytes --]

From 6fe9a0e8f1db73f688bebc37671d8397bd9094cc Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
 liblttng-ust-libc-wrapper/Makefile.am         |  12 ++-
 liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 106 ++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_libc.h          |  10 +--
 liblttng-ust-libc-wrapper/ust_pthread.h       |  76 ++++++++++++++++++
 4 files changed, 198 insertions(+), 6 deletions(-)
 create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..d402d53 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	lttng-ust-pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
new file mode 100644
index 0000000..e72b9b4
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_lock) {
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock) {
+			if (thread_in_trace) {
+				abort();
+			}
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_lock(mutex);
+	}
+
+	thread_in_trace = 1;
+	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+	retval = mutex_lock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_trylock) {
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock) {
+			if (thread_in_trace) {
+				abort();
+			}
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_trylock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_trylock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	int retval;
+
+	if (!mutex_unlock) {
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock) {
+			if (thread_in_trace) {
+				abort();
+			}
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if (thread_in_trace) {
+		return mutex_unlock(mutex);
+	}
+
+	thread_in_trace = 1;
+	retval = mutex_unlock(mutex);
+	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+	thread_in_trace = 0;
+	return retval;
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..7d35c3a
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(void *, mutex, mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
       [not found]                         ` <52273D4E.5050304@mentor.com>
@ 2013-09-18 14:19                           ` Mathieu Desnoyers
  0 siblings, 0 replies; 22+ messages in thread
From: Mathieu Desnoyers @ 2013-09-18 14:19 UTC (permalink / raw)
  To: Stefan Seefeld; +Cc: lttng-dev

Merged, thanks !

Mathieu

* Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> On 2013-08-07 11:52, Mathieu Desnoyers wrote:
> > * Stefan Seefeld (stefan_seefeld@mentor.com) wrote:
> >> Sorry for the incomplete patch. Here is a corrected one.
> >>
> >> 	Stefan
> > 
> > You can add my
> > 
> > Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> > 
> > To you patch changelog.
> > 
> > Can you keep it around and resubmit after we release 2.3-final in a few
> > weeks ?
> 
> Mathieu,
> 
> please find attached the patch again.
> 
> Thanks,
> 		Stefan
> 
> 
> -- 
> Stefan Seefeld
> CodeSourcery / Mentor Graphics
> http://www.mentor.com/embedded-software/

> From 6fe9a0e8f1db73f688bebc37671d8397bd9094cc Mon Sep 17 00:00:00 2001
> From: Stefan Seefeld <stefan_seefeld@mentor.com>
> Date: Wed, 31 Jul 2013 16:35:31 -0400
> Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.
> 
> Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
> Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> ---
>  liblttng-ust-libc-wrapper/Makefile.am         |  12 ++-
>  liblttng-ust-libc-wrapper/lttng-ust-pthread.c | 106 ++++++++++++++++++++++++++
>  liblttng-ust-libc-wrapper/ust_libc.h          |  10 +--
>  liblttng-ust-libc-wrapper/ust_pthread.h       |  76 ++++++++++++++++++
>  4 files changed, 198 insertions(+), 6 deletions(-)
>  create mode 100644 liblttng-ust-libc-wrapper/lttng-ust-pthread.c
>  create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h
> 
> diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
> index 4fdcedb..d402d53 100644
> --- a/liblttng-ust-libc-wrapper/Makefile.am
> +++ b/liblttng-ust-libc-wrapper/Makefile.am
> @@ -1,7 +1,8 @@
>  AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
>  AM_CFLAGS = -fno-strict-aliasing
>  
> -lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
> +lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
> +  liblttng-ust-pthread-wrapper.la
>  liblttng_ust_libc_wrapper_la_SOURCES = \
>  	lttng-ust-malloc.c \
>  	ust_libc.h
> @@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
>  	-L$(top_builddir)/liblttng-ust/.libs \
>  	-llttng-ust
>  
> +liblttng_ust_pthread_wrapper_la_SOURCES = \
> +	lttng-ust-pthread.c \
> +	ust_pthread.h
> +liblttng_ust_pthread_wrapper_la_LIBADD = \
> +	-L$(top_builddir)/liblttng-ust/.libs \
> +	-llttng-ust
> +
>  if LTTNG_UST_BUILD_WITH_LIBDL
>  liblttng_ust_libc_wrapper_la_LIBADD += -ldl
> +liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
>  endif
>  if LTTNG_UST_BUILD_WITH_LIBC_DL
>  liblttng_ust_libc_wrapper_la_LIBADD += -lc
> +liblttng_ust_pthread_wrapper_la_LIBADD += -lc
>  endif
>  
>  noinst_SCRIPTS = run
> diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> new file mode 100644
> index 0000000..e72b9b4
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c
> @@ -0,0 +1,106 @@
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * 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 _GNU_SOURCE
> +#include <dlfcn.h>
> +#include <pthread.h>
> +
> +#define TRACEPOINT_DEFINE
> +#define TRACEPOINT_CREATE_PROBES
> +#include "ust_pthread.h"
> +
> +static __thread int thread_in_trace;
> +
> +int pthread_mutex_lock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_lock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_lock) {
> +		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
> +		if (!mutex_lock) {
> +			if (thread_in_trace) {
> +				abort();
> +			}
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_lock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
> +	retval = mutex_lock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_trylock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_trylock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_trylock) {
> +		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
> +		if (!mutex_trylock) {
> +			if (thread_in_trace) {
> +				abort();
> +			}
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_trylock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_trylock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> +
> +int pthread_mutex_unlock(pthread_mutex_t *mutex)
> +{
> +	static int (*mutex_unlock)(pthread_mutex_t *);
> +	int retval;
> +
> +	if (!mutex_unlock) {
> +		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
> +		if (!mutex_unlock) {
> +			if (thread_in_trace) {
> +				abort();
> +			}
> +			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
> +			return EINVAL;
> +		}
> +	}
> +	if (thread_in_trace) {
> +		return mutex_unlock(mutex);
> +	}
> +
> +	thread_in_trace = 1;
> +	retval = mutex_unlock(mutex);
> +	tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
> +	thread_in_trace = 0;
> +	return retval;
> +}
> diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
> new file mode 100644
> index 0000000..7d35c3a
> --- /dev/null
> +++ b/liblttng-ust-libc-wrapper/ust_pthread.h
> @@ -0,0 +1,76 @@
> +#undef TRACEPOINT_PROVIDER
> +#define TRACEPOINT_PROVIDER ust_pthread
> +
> +#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
> +#define _TRACEPOINT_UST_PTHREAD_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * Copyright (C) 2013  Mentor Graphics
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
> +	TP_ARGS(pthread_mutex_t *, mutex),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
> +	TP_ARGS(pthread_mutex_t *, mutex, int, status),
> +	TP_FIELDS(
> +		ctf_integer_hex(void *, mutex, mutex)
> +		ctf_integer(int, status, status)
> +	)
> +)
> +
> +#endif /* _TRACEPOINT_UST_PTHREAD_H */
> +
> +#undef TRACEPOINT_INCLUDE
> +#define TRACEPOINT_INCLUDE "./ust_pthread.h"
> +
> +/* This part must be outside ifdef protection */
> +#include <lttng/tracepoint-event.h>
> +
> +#ifdef __cplusplus
> +}
> +#endif
> -- 
> 1.8.3.1
> 


-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH lttng-ust] Add trace instrumentation for some pthread functions.
@ 2013-07-31 20:41 Stefan Seefeld
  0 siblings, 0 replies; 22+ messages in thread
From: Stefan Seefeld @ 2013-07-31 20:41 UTC (permalink / raw)
  To: lttng-dev

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]

The attached patch introduces a pthread wrapper library with initial
instrumentation for pthread_mutex_lock, pthread_mutex_trylock, and
pthread_mutex_unlock.
New tracepoints are introduced for each of those. For the lock function,
two distinct tracepoints are emitted: one before the lock is requested,
another after it has been acquired.

-- 
Stefan Seefeld
CodeSourcery / Mentor Graphics
http://www.mentor.com/embedded-software/

[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 7474 bytes --]

From 38021db8d2b466856050ed5cdcedb997b0e6aff2 Mon Sep 17 00:00:00 2001
From: Stefan Seefeld <stefan_seefeld@mentor.com>
Date: Wed, 31 Jul 2013 16:35:31 -0400
Subject: [PATCH] Add tracing instrumentation for pthread mutex lock functions.

Signed-off-by: Stefan Seefeld <stefan_seefeld@mentor.com>
---
 liblttng-ust-libc-wrapper/Makefile.am   |  12 +++-
 liblttng-ust-libc-wrapper/pthread.c     | 106 ++++++++++++++++++++++++++++++++
 liblttng-ust-libc-wrapper/ust_pthread.h |  76 +++++++++++++++++++++++
 3 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 liblttng-ust-libc-wrapper/pthread.c
 create mode 100644 liblttng-ust-libc-wrapper/ust_pthread.h

diff --git a/liblttng-ust-libc-wrapper/Makefile.am b/liblttng-ust-libc-wrapper/Makefile.am
index 4fdcedb..78977fe 100644
--- a/liblttng-ust-libc-wrapper/Makefile.am
+++ b/liblttng-ust-libc-wrapper/Makefile.am
@@ -1,7 +1,8 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la
+lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \
+  liblttng-ust-pthread-wrapper.la
 liblttng_ust_libc_wrapper_la_SOURCES = \
 	lttng-ust-malloc.c \
 	ust_libc.h
@@ -9,11 +10,20 @@ liblttng_ust_libc_wrapper_la_LIBADD = \
 	-L$(top_builddir)/liblttng-ust/.libs \
 	-llttng-ust
 
+liblttng_ust_pthread_wrapper_la_SOURCES = \
+	pthread.c \
+	ust_pthread.h
+liblttng_ust_pthread_wrapper_la_LIBADD = \
+	-L$(top_builddir)/liblttng-ust/.libs \
+	-llttng-ust
+
 if LTTNG_UST_BUILD_WITH_LIBDL
 liblttng_ust_libc_wrapper_la_LIBADD += -ldl
+liblttng_ust_pthread_wrapper_la_LIBADD += -ldl
 endif
 if LTTNG_UST_BUILD_WITH_LIBC_DL
 liblttng_ust_libc_wrapper_la_LIBADD += -lc
+liblttng_ust_pthread_wrapper_la_LIBADD += -lc
 endif
 
 noinst_SCRIPTS = run
diff --git a/liblttng-ust-libc-wrapper/pthread.c b/liblttng-ust-libc-wrapper/pthread.c
new file mode 100644
index 0000000..a08aa86
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/pthread.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <pthread.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_pthread.h"
+
+static __thread int thread_in_trace = 0;
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_lock)(pthread_mutex_t *);
+	if (!mutex_lock)
+	{
+		mutex_lock = dlsym(RTLD_NEXT, "pthread_mutex_lock");
+		if (!mutex_lock)
+		{
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if(!thread_in_trace)
+	{
+		thread_in_trace = 1;
+		tracepoint(ust_pthread, pthread_mutex_lock_req, mutex);
+		int retval = mutex_lock(mutex);
+		tracepoint(ust_pthread, pthread_mutex_lock_acq, mutex, retval);
+		thread_in_trace = 0;
+		return retval;
+	}
+	else
+	{
+		return mutex_lock(mutex);
+	}
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_trylock)(pthread_mutex_t *);
+	if (!mutex_trylock)
+	{
+		mutex_trylock = dlsym(RTLD_NEXT, "pthread_mutex_trylock");
+		if (!mutex_trylock)
+		{
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if(!thread_in_trace)
+	{
+		thread_in_trace = 1;
+		int retval = mutex_trylock(mutex);
+		tracepoint(ust_pthread, pthread_mutex_trylock, mutex, retval);
+		thread_in_trace = 0;
+		return retval;
+	}
+	else
+	{
+		return mutex_trylock(mutex);
+	}
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	static int (*mutex_unlock)(pthread_mutex_t *);
+	if (!mutex_unlock)
+	{
+		mutex_unlock = dlsym(RTLD_NEXT, "pthread_mutex_unlock");
+		if (!mutex_unlock)
+		{
+			fprintf(stderr, "unable to initialize pthread wrapper library.\n");
+			return EINVAL;
+		}
+	}
+	if(!thread_in_trace)
+	{
+		thread_in_trace = 1;
+		int retval = mutex_unlock(mutex);
+		tracepoint(ust_pthread, pthread_mutex_unlock, mutex, retval);
+		thread_in_trace = 0;
+		return retval;
+	}
+	else
+	{
+		return mutex_unlock(mutex);
+	}
+}
diff --git a/liblttng-ust-libc-wrapper/ust_pthread.h b/liblttng-ust-libc-wrapper/ust_pthread.h
new file mode 100644
index 0000000..86275b7
--- /dev/null
+++ b/liblttng-ust-libc-wrapper/ust_pthread.h
@@ -0,0 +1,76 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_pthread
+
+#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_PTHREAD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Mentor Graphics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_req,
+	TP_ARGS(pthread_mutex_t *, mutex),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_lock_acq,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_trylock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+TRACEPOINT_EVENT(ust_pthread, pthread_mutex_unlock,
+	TP_ARGS(pthread_mutex_t *, mutex, int, status),
+	TP_FIELDS(
+		ctf_integer_hex(unsigned long, mutex, (unsigned long) mutex)
+		ctf_integer(int, status, status)
+	)
+)
+
+#endif /* _TRACEPOINT_UST_PTHREAD_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_pthread.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.8.3.1


[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2013-09-18 14:19 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <51F97688.30704@mentor.com>
2013-07-31 22:00 ` [PATCH lttng-ust] Add trace instrumentation for some pthread functions Jérémie Galarneau
     [not found] ` <CA+jJMxsoH8Rz6fwZJOPnG-4xvB2w8GO5eqi0JDtHUy7iM-n2WA@mail.gmail.com>
2013-08-01  0:17   ` Stefan Seefeld
     [not found]   ` <51F9A917.9010509@seefeld.name>
2013-08-01  3:16     ` Jérémie Galarneau
2013-08-03  1:28     ` Mathieu Desnoyers
     [not found]     ` <CA+jJMxv4oS0SbMqUF247jS0s0E+6DfdepNT8yHimY=TULHD+tQ@mail.gmail.com>
2013-08-03  1:28       ` Mathieu Desnoyers
     [not found]     ` <20130803012831.GH9033@Krystal>
2013-08-05 13:38       ` Stefan Seefeld
     [not found]       ` <51FFAAD7.3000705@seefeld.name>
2013-08-07  1:32         ` Mathieu Desnoyers
     [not found]         ` <20130807013159.GG19407@Krystal>
2013-08-07 13:14           ` Stefan Seefeld
     [not found]           ` <5202482B.2010705@mentor.com>
2013-08-07 14:05             ` Stefan Seefeld
     [not found]             ` <52025427.5080002@mentor.com>
2013-08-07 14:33               ` Mathieu Desnoyers
     [not found]               ` <20130807143346.GA542@Krystal>
2013-08-07 15:08                 ` Stefan Seefeld
     [not found]                 ` <520262E8.5010106@mentor.com>
2013-08-07 15:19                   ` Mathieu Desnoyers
     [not found]                   ` <20130807151903.GA1035@Krystal>
2013-08-07 15:42                     ` Stefan Seefeld
     [not found]                     ` <52026AD7.7000103@mentor.com>
2013-08-07 15:52                       ` Mathieu Desnoyers
     [not found]                       ` <20130807155228.GC1035@Krystal>
2013-08-07 16:01                         ` Stefan Seefeld
     [not found]                         ` <52026F42.4050005@mentor.com>
2013-08-07 16:12                           ` Mathieu Desnoyers
     [not found]                           ` <20130807161241.GB1336@Krystal>
2013-08-07 16:25                             ` Stefan Seefeld
     [not found]                             ` <520274F3.3080505@mentor.com>
2013-08-07 16:31                               ` Mathieu Desnoyers
     [not found]                               ` <20130807163153.GA2194@Krystal>
2013-08-07 16:38                                 ` Stefan Seefeld
2013-09-04 14:01                         ` Stefan Seefeld
     [not found]                         ` <52273D4E.5050304@mentor.com>
2013-09-18 14:19                           ` Mathieu Desnoyers
2013-07-31 20:41 Stefan Seefeld

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.