From d51652f7ee9f3214b62c17441913168115ab4c9e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 1 Mar 2012 12:09:40 -0500 Subject: [PATCH] Fix: fixup ringbuffer tls at constructor by forcing read Signed-off-by: Mathieu Desnoyers --- liblttng-ust/lttng-ust-comm.c | 2 ++ libringbuffer/Makefile.am | 2 +- libringbuffer/ring_buffer_frontend.c | 9 +++++++++ libringbuffer/tlsfixup.h | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 libringbuffer/tlsfixup.h diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index ba69f5ff..2f2c783b 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -46,6 +46,7 @@ #include "tracepoint-internal.h" #include "ltt-tracer-core.h" #include "compat.h" +#include "../libringbuffer/tlsfixup.h" /* * Has lttng ust comm constructor been called ? @@ -833,6 +834,7 @@ void __attribute__((constructor)) lttng_ust_init(void) * the ust lock. */ lttng_fixup_event_tls(); + lttng_fixup_ringbuffer_tls(); /* * We want precise control over the order in which we construct diff --git a/libringbuffer/Makefile.am b/libringbuffer/Makefile.am index 9bd85868..b5b0ebd1 100644 --- a/libringbuffer/Makefile.am +++ b/libringbuffer/Makefile.am @@ -11,7 +11,7 @@ libringbuffer_la_SOURCES = \ api.h \ backend.h backend_internal.h backend_types.h \ frontend_api.h frontend.h frontend_internal.h frontend_types.h \ - nohz.h vatomic.h + nohz.h vatomic.h tlsfixup.h libringbuffer_la_LIBADD = \ -lpthread \ diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 28e959ba..0ae3d72f 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -53,6 +53,7 @@ #include "backend.h" #include "frontend.h" #include "shm.h" +#include "tlsfixup.h" #include "../liblttng-ust/compat.h" /* For ENODATA */ #ifndef max @@ -1508,3 +1509,11 @@ int lib_ring_buffer_reserve_slow(struct lttng_ust_lib_ring_buffer_ctx *ctx) ctx->buf_offset = offsets.begin + offsets.pre_header_padding; return 0; } + +/* + * Force a read (imply TLS fixup for dlopen) of TLS variables. + */ +void lttng_fixup_ringbuffer_tls(void) +{ + asm volatile ("" : : "m" (lib_ring_buffer_nesting)); +} diff --git a/libringbuffer/tlsfixup.h b/libringbuffer/tlsfixup.h new file mode 100644 index 00000000..84ba889e --- /dev/null +++ b/libringbuffer/tlsfixup.h @@ -0,0 +1,14 @@ +#ifndef _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H +#define _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H + +/* + * libringbuffer/tlsfixup.h + * + * Copyright 2011 (c) - Mathieu Desnoyers + * + * Dual LGPL v2.1/GPL v2 license. + */ + +void lttng_fixup_ringbuffer_tls(void); + +#endif /* _LTTNG_UST_LIB_RINGBUFFER_TLS_FIXUP_H */ -- 2.34.1