From: Mathieu Desnoyers Date: Thu, 19 Oct 2017 13:27:27 +0000 (-0400) Subject: Use initial-exec TLS model X-Git-Tag: v2.11.0-rc1~45 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=553bbf7f38652084ed7966c7817b8ccb372b14e1;p=lttng-ust.git Use initial-exec TLS model Use initial-exec TLS model for TLS variables. Those are faster, and signal-handler-safe. Link: https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter8-20.html Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes Signed-off-by: Mathieu Desnoyers --- diff --git a/configure.ac b/configure.ac index e2acfa90..08ca3b65 100644 --- a/configure.ac +++ b/configure.ac @@ -225,26 +225,22 @@ AM_CONDITIONAL([HAVE_DLINFO], [test "x${ac_cv_have_decl_RTLD_DI_LINKMAP}" = "xye AC_CHECK_HEADERS([urcu-bp.h], [], [AC_MSG_ERROR([Cannot find [URCU] headers (urcu-bp.h). Use [CPPFLAGS]=-Idir to specify their location. This error can also occur when the liburcu package's configure script has not been run.])]) +# URCU library version needed or newer +m4_define([WRONG_LIBURCU_MSG], [Userspace RCU (liburcu) >= 0.11.0 is needed]) + +#Macro added in urcu 0.6.6 +AC_CHECK_DECL([caa_likely], [], + [AC_MSG_ERROR([WRONG_LIBURCU_MSG])], [[#include ]]) +#Macro added in urcu 0.11.0 +AC_CHECK_DECL([DEFINE_URCU_TLS_IE], [], + [AC_MSG_ERROR([WRONG_LIBURCU_MSG])], [[#include ]] +) + # urcu-cds - check that URCU Concurrent Data Structure lib is available to compilation # Part of Userspace RCU library 0.7.2 or better. AC_CHECK_LIB([urcu-cds], [_cds_lfht_new], [], [AC_MSG_ERROR([Cannot find liburcu-cds lib, part of Userspace RCU 0.7 or better. Use [LDFLAGS]=-Ldir to specify its location.])]) -AC_MSG_CHECKING([caa_likely()]) -AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ - #include - void fct(void) - { - if (caa_likely(1)) { - } - } -]])], [ - AC_MSG_RESULT([yes]) -], [ - AC_MSG_RESULT([no]) - AC_MSG_ERROR([Please upgrade your version of liburcu to 0.6.6 or better]) -]) - # urcu - check that URCU lib is available to compilation AC_CHECK_LIB([urcu-bp], [synchronize_rcu_bp], [], [AC_MSG_ERROR([Cannot find liburcu-bp lib. Use [LDFLAGS]=-Ldir to specify its location.])]) diff --git a/liblttng-ust-comm/lttng-ust-fd-tracker.c b/liblttng-ust-comm/lttng-ust-fd-tracker.c index 5a763ff2..04ae2391 100644 --- a/liblttng-ust-comm/lttng-ust-fd-tracker.c +++ b/liblttng-ust-comm/lttng-ust-fd-tracker.c @@ -65,7 +65,7 @@ static pthread_mutex_t ust_safe_guard_fd_mutex = PTHREAD_MUTEX_INITIALIZER; * Track whether we are within lttng-ust or application, for close * system call override by LD_PRELOAD library. */ -static DEFINE_URCU_TLS(int, thread_fd_tracking); +static DEFINE_URCU_TLS_IE(int, thread_fd_tracking); /* fd_set used to book keep fd being used by lttng-ust. */ static fd_set *lttng_fd_set; diff --git a/liblttng-ust-java-agent/jni/common/lttng_ust_context.c b/liblttng-ust-java-agent/jni/common/lttng_ust_context.c index 3bed11ec..e9b6da28 100644 --- a/liblttng-ust-java-agent/jni/common/lttng_ust_context.c +++ b/liblttng-ust-java-agent/jni/common/lttng_ust_context.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "helper.h" #include "lttng_ust_context.h" @@ -56,7 +57,7 @@ struct lttng_ust_jni_ctx_entry { } __attribute__((packed)); /* TLS passing context info from JNI to callbacks. */ -__thread struct lttng_ust_jni_tls lttng_ust_context_info_tls; +DECLARE_URCU_TLS_IE(struct lttng_ust_jni_tls, lttng_ust_context_info_tls); static const char *get_ctx_string_at_offset(int32_t offset) { diff --git a/liblttng-ust-java-agent/jni/common/lttng_ust_context.h b/liblttng-ust-java-agent/jni/common/lttng_ust_context.h index 415f7de2..8ea43e1a 100644 --- a/liblttng-ust-java-agent/jni/common/lttng_ust_context.h +++ b/liblttng-ust-java-agent/jni/common/lttng_ust_context.h @@ -19,6 +19,8 @@ #ifndef LIBLTTNG_UST_JAVA_AGENT_JNI_COMMON_LTTNG_UST_CONTEXT_H_ #define LIBLTTNG_UST_JAVA_AGENT_JNI_COMMON_LTTNG_UST_CONTEXT_H_ +#include + struct lttng_ust_jni_ctx_entry; struct lttng_ust_jni_tls { @@ -28,6 +30,6 @@ struct lttng_ust_jni_tls { int32_t ctx_strings_len; }; -extern __thread struct lttng_ust_jni_tls lttng_ust_context_info_tls; +extern DECLARE_URCU_TLS(struct lttng_ust_jni_tls, lttng_ust_context_info_tls); #endif /* LIBLTTNG_UST_JAVA_AGENT_JNI_COMMON_LTTNG_UST_CONTEXT_H_ */ diff --git a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c index f3e1e19e..f30a2c69 100644 --- a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c +++ b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c @@ -95,7 +95,7 @@ void ust_malloc_spin_unlock(pthread_mutex_t *lock) #define calloc static_calloc #define pthread_mutex_lock ust_malloc_spin_lock #define pthread_mutex_unlock ust_malloc_spin_unlock -static DEFINE_URCU_TLS(int, malloc_nesting); +static DEFINE_URCU_TLS_IE(int, malloc_nesting); #undef ust_malloc_spin_unlock #undef ust_malloc_spin_lock #undef calloc diff --git a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c index 7836ffa0..6554a47a 100644 --- a/liblttng-ust-libc-wrapper/lttng-ust-pthread.c +++ b/liblttng-ust-libc-wrapper/lttng-ust-pthread.c @@ -23,6 +23,7 @@ * libc. */ #include +#include #include #include @@ -31,7 +32,7 @@ #define TP_IP_PARAM ip #include "ust_pthread.h" -static __thread int thread_in_trace; +static DEFINE_URCU_TLS_IE(int, thread_in_trace); int pthread_mutex_lock(pthread_mutex_t *mutex) { diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index b6e69501..4b8da28f 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -38,7 +38,7 @@ * thread. */ typedef char procname_array[17]; -static DEFINE_URCU_TLS(procname_array, cached_procname); +static DEFINE_URCU_TLS_IE(procname_array, cached_procname); static inline char *wrapper_getprocname(void) diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index f28e470a..8c9bbec5 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -34,7 +34,7 @@ * We cache the result to ensure we don't trigger a system call for * each event. */ -static DEFINE_URCU_TLS(pid_t, cached_vtid); +static DEFINE_URCU_TLS_IE(pid_t, cached_vtid); /* * Upon fork or clone, the TID assigned to our thread is not the same as diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 511b9cf4..eec049b3 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -86,7 +86,7 @@ static int initialized; static pthread_mutex_t ust_mutex = PTHREAD_MUTEX_INITIALIZER; /* Allow nesting the ust_mutex within the same thread. */ -static DEFINE_URCU_TLS(int, ust_mutex_nest); +static DEFINE_URCU_TLS_IE(int, ust_mutex_nest); /* * ust_exit_mutex protects thread_active variable wrt thread exit. It diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 331639f1..396b0064 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -118,7 +118,7 @@ struct switch_offsets { switch_old_end:1; }; -DEFINE_URCU_TLS(unsigned int, lib_ring_buffer_nesting); +DEFINE_URCU_TLS_IE(unsigned int, lib_ring_buffer_nesting); /* * wakeup_fd_mutex protects wakeup fd use by timer from concurrent diff --git a/tests/test-app-ctx/hello.c b/tests/test-app-ctx/hello.c index 197df21e..f2859a7a 100644 --- a/tests/test-app-ctx/hello.c +++ b/tests/test-app-ctx/hello.c @@ -26,6 +26,7 @@ #include #include #include +#include /* * Work-around inet.h missing struct mmsghdr forward declaration, with * triggers a warning when system files warnings are enabled. @@ -43,7 +44,7 @@ struct mmsghdr; #include #include -static __thread unsigned int test_count; +static DEFINE_URCU_TLS_IE(unsigned int, test_count); void test_inc_count(void) {