From: Michael Jeanson Date: Wed, 14 Apr 2021 18:55:30 +0000 (-0400) Subject: Move liblttng-ust-pthread-wrapper to 'src/lib/' X-Git-Tag: v2.13.0-rc1~92 X-Git-Url: http://git.liburcu.org/?a=commitdiff_plain;h=3aa28d2301d8b9c1f7eef509e3de42bca2abbffe;p=lttng-ust.git Move liblttng-ust-pthread-wrapper to 'src/lib/' Change-Id: Id38841b2338de290f7dc9ec68c10411031fc3d58 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/.gitignore b/.gitignore index f409ce70..326795a7 100644 --- a/.gitignore +++ b/.gitignore @@ -143,6 +143,7 @@ cscope.* /src/lib/lttng-ust-java-agent/jni/log4j/Makefile /src/lib/lttng-ust-java/Makefile /src/lib/lttng-ust-libc-wrapper/Makefile +/src/lib/lttng-ust-pthread-wrapper/Makefile /src/lib/lttng-ust-tracepoint/Makefile /src/lib/lttng-ust-python-agent/Makefile /src/lib/Makefile diff --git a/configure.ac b/configure.ac index be707b0f..54b00dcc 100644 --- a/configure.ac +++ b/configure.ac @@ -537,6 +537,7 @@ AC_CONFIG_FILES([ src/lib/lttng-ust-java-agent/Makefile src/lib/lttng-ust-java/Makefile src/lib/lttng-ust-libc-wrapper/Makefile + src/lib/lttng-ust-pthread-wrapper/Makefile src/lib/lttng-ust-tracepoint/Makefile src/lib/lttng-ust/Makefile src/lib/lttng-ust-python-agent/Makefile diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 49fbd75d..fbd12358 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -8,7 +8,8 @@ SUBDIRS = \ lttng-ust-fd \ lttng-ust-fork \ lttng-ust-cyg-profile \ - lttng-ust-libc-wrapper + lttng-ust-libc-wrapper \ + lttng-ust-pthread-wrapper if ENABLE_UST_DL SUBDIRS += lttng-ust-dl diff --git a/src/lib/lttng-ust-libc-wrapper/Makefile.am b/src/lib/lttng-ust-libc-wrapper/Makefile.am index f3fcee69..0507e4df 100644 --- a/src/lib/lttng-ust-libc-wrapper/Makefile.am +++ b/src/lib/lttng-ust-libc-wrapper/Makefile.am @@ -2,8 +2,7 @@ AM_CFLAGS += -I$(srcdir) -fno-strict-aliasing -lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la \ - liblttng-ust-pthread-wrapper.la +lib_LTLIBRARIES = liblttng-ust-libc-wrapper.la liblttng_ust_libc_wrapper_la_SOURCES = \ lttng-ust-malloc.c \ @@ -15,15 +14,5 @@ liblttng_ust_libc_wrapper_la_LIBADD = \ liblttng_ust_libc_wrapper_la_LDFLAGS = -version-info $(LTTNG_UST_LIBRARY_VERSION) -liblttng_ust_pthread_wrapper_la_SOURCES = \ - lttng-ust-pthread.c \ - ust_pthread.h - -liblttng_ust_pthread_wrapper_la_LIBADD = \ - $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ - $(DL_LIBS) - -liblttng_ust_pthread_wrapper_la_LDFLAGS = -version-info $(LTTNG_UST_LIBRARY_VERSION) - dist_noinst_SCRIPTS = run EXTRA_DIST = README diff --git a/src/lib/lttng-ust-libc-wrapper/lttng-ust-pthread.c b/src/lib/lttng-ust-libc-wrapper/lttng-ust-pthread.c deleted file mode 100644 index c6633fe8..00000000 --- a/src/lib/lttng-ust-libc-wrapper/lttng-ust-pthread.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * - * Copyright (C) 2013 Mentor Graphics - */ - -/* - * Do _not_ define _LGPL_SOURCE because we don't want to create a - * circular dependency loop between this malloc wrapper, liburcu and - * libc. - */ - -/* Has to be included first to override dlfcn.h */ -#include - -#include "common/macros.h" -#include - -#define TRACEPOINT_DEFINE -#define TRACEPOINT_CREATE_PROBES -#define TP_IP_PARAM ip -#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(lttng_ust_pthread, pthread_mutex_lock_req, mutex, - LTTNG_UST_CALLER_IP()); - retval = mutex_lock(mutex); - tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex, - retval, LTTNG_UST_CALLER_IP()); - 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(lttng_ust_pthread, pthread_mutex_trylock, mutex, - retval, LTTNG_UST_CALLER_IP()); - 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(lttng_ust_pthread, pthread_mutex_unlock, mutex, - retval, LTTNG_UST_CALLER_IP()); - thread_in_trace = 0; - return retval; -} diff --git a/src/lib/lttng-ust-libc-wrapper/ust_pthread.h b/src/lib/lttng-ust-libc-wrapper/ust_pthread.h deleted file mode 100644 index 4fdc11aa..00000000 --- a/src/lib/lttng-ust-libc-wrapper/ust_pthread.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2013 Mentor Graphics - */ - -#undef TRACEPOINT_PROVIDER -#define TRACEPOINT_PROVIDER lttng_ust_pthread - -#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ) -#define _TRACEPOINT_UST_PTHREAD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_lock_req, - TP_ARGS(pthread_mutex_t *, mutex, void *, ip), - TP_FIELDS( - ctf_integer_hex(void *, mutex, mutex) - ctf_unused(ip) - ) -) - -TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_lock_acq, - TP_ARGS(pthread_mutex_t *, mutex, int, status, void *, ip), - TP_FIELDS( - ctf_integer_hex(void *, mutex, mutex) - ctf_integer(int, status, status) - ctf_unused(ip) - ) -) - -TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_trylock, - TP_ARGS(pthread_mutex_t *, mutex, int, status, void *, ip), - TP_FIELDS( - ctf_integer_hex(void *, mutex, mutex) - ctf_integer(int, status, status) - ctf_unused(ip) - ) -) - -TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_unlock, - TP_ARGS(pthread_mutex_t *, mutex, int, status, void *, ip), - TP_FIELDS( - ctf_integer_hex(void *, mutex, mutex) - ctf_integer(int, status, status) - ctf_unused(ip) - ) -) - -#endif /* _TRACEPOINT_UST_PTHREAD_H */ - -#undef TRACEPOINT_INCLUDE -#define TRACEPOINT_INCLUDE "./ust_pthread.h" - -/* This part must be outside ifdef protection */ -#include - -#ifdef __cplusplus -} -#endif diff --git a/src/lib/lttng-ust-pthread-wrapper/Makefile.am b/src/lib/lttng-ust-pthread-wrapper/Makefile.am new file mode 100644 index 00000000..3edb72a7 --- /dev/null +++ b/src/lib/lttng-ust-pthread-wrapper/Makefile.am @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: LGPL-2.1-only + +AM_CFLAGS += -I$(srcdir) -fno-strict-aliasing + +lib_LTLIBRARIES = liblttng-ust-pthread-wrapper.la + +liblttng_ust_pthread_wrapper_la_SOURCES = \ + lttng-ust-pthread.c \ + ust_pthread.h + +liblttng_ust_pthread_wrapper_la_LIBADD = \ + $(top_builddir)/src/lib/lttng-ust/liblttng-ust.la \ + $(DL_LIBS) + +liblttng_ust_pthread_wrapper_la_LDFLAGS = -version-info $(LTTNG_UST_LIBRARY_VERSION) diff --git a/src/lib/lttng-ust-pthread-wrapper/lttng-ust-pthread.c b/src/lib/lttng-ust-pthread-wrapper/lttng-ust-pthread.c new file mode 100644 index 00000000..c6633fe8 --- /dev/null +++ b/src/lib/lttng-ust-pthread-wrapper/lttng-ust-pthread.c @@ -0,0 +1,107 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * Copyright (C) 2013 Mentor Graphics + */ + +/* + * Do _not_ define _LGPL_SOURCE because we don't want to create a + * circular dependency loop between this malloc wrapper, liburcu and + * libc. + */ + +/* Has to be included first to override dlfcn.h */ +#include + +#include "common/macros.h" +#include + +#define TRACEPOINT_DEFINE +#define TRACEPOINT_CREATE_PROBES +#define TP_IP_PARAM ip +#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(lttng_ust_pthread, pthread_mutex_lock_req, mutex, + LTTNG_UST_CALLER_IP()); + retval = mutex_lock(mutex); + tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex, + retval, LTTNG_UST_CALLER_IP()); + 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(lttng_ust_pthread, pthread_mutex_trylock, mutex, + retval, LTTNG_UST_CALLER_IP()); + 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(lttng_ust_pthread, pthread_mutex_unlock, mutex, + retval, LTTNG_UST_CALLER_IP()); + thread_in_trace = 0; + return retval; +} diff --git a/src/lib/lttng-ust-pthread-wrapper/ust_pthread.h b/src/lib/lttng-ust-pthread-wrapper/ust_pthread.h new file mode 100644 index 00000000..4fdc11aa --- /dev/null +++ b/src/lib/lttng-ust-pthread-wrapper/ust_pthread.h @@ -0,0 +1,64 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2013 Mentor Graphics + */ + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER lttng_ust_pthread + +#if !defined(_TRACEPOINT_UST_PTHREAD_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_PTHREAD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_lock_req, + TP_ARGS(pthread_mutex_t *, mutex, void *, ip), + TP_FIELDS( + ctf_integer_hex(void *, mutex, mutex) + ctf_unused(ip) + ) +) + +TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_lock_acq, + TP_ARGS(pthread_mutex_t *, mutex, int, status, void *, ip), + TP_FIELDS( + ctf_integer_hex(void *, mutex, mutex) + ctf_integer(int, status, status) + ctf_unused(ip) + ) +) + +TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_trylock, + TP_ARGS(pthread_mutex_t *, mutex, int, status, void *, ip), + TP_FIELDS( + ctf_integer_hex(void *, mutex, mutex) + ctf_integer(int, status, status) + ctf_unused(ip) + ) +) + +TRACEPOINT_EVENT(lttng_ust_pthread, pthread_mutex_unlock, + TP_ARGS(pthread_mutex_t *, mutex, int, status, void *, ip), + TP_FIELDS( + ctf_integer_hex(void *, mutex, mutex) + ctf_integer(int, status, status) + ctf_unused(ip) + ) +) + +#endif /* _TRACEPOINT_UST_PTHREAD_H */ + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./ust_pthread.h" + +/* This part must be outside ifdef protection */ +#include + +#ifdef __cplusplus +} +#endif