From 12f27fcc49be2a1f444122a185735743c18684f6 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 20 Oct 2020 13:04:27 +0000 Subject: Allow for faster access of thread local variable. This is possible since we do not load our code explicit as dynamic library. Also replace __thread by standard c++ linkage thread_local. --- .../src/vespa/storage/persistence/filestorage/filestormanager.cpp | 8 +++++++- .../src/vespa/storage/persistence/filestorage/filestormanager.h | 2 +- vespalib/src/vespa/vespalib/stllike/string.h | 4 +++- vespamalloc/src/vespamalloc/malloc/threadlist.h | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp index e008e531b90..4b5e25e20a2 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp +++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp @@ -114,7 +114,13 @@ createThreadName(size_t stripeId) { return fmt("PersistenceThread-%zu", stripeId); } -thread_local PersistenceHandler * _G_threadLocalHandler = nullptr; +#ifdef __PIC__ +#define TLS_LINKAGE __attribute__((visibility("hidden"), tls_model("initial-exec"))) +#else +#define TLS_LINKAGE __attribute__((visibility("hidden"), tls_model("local-exec"))) +#endif + +thread_local PersistenceHandler * _G_threadLocalHandler TLS_LINKAGE = nullptr; } diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h index 38df7e752a5..7c952d7f82f 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h +++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h @@ -109,7 +109,7 @@ public: private: void configure(std::unique_ptr config) override; PersistenceHandler & createRegisteredHandler(const ServiceLayerComponent & component); - PersistenceHandler & getThreadLocalHandler(); + VESPA_DLL_LOCAL PersistenceHandler & getThreadLocalHandler(); void replyWithBucketNotFound(api::StorageMessage&, const document::Bucket&); diff --git a/vespalib/src/vespa/vespalib/stllike/string.h b/vespalib/src/vespa/vespalib/stllike/string.h index f1207c1d9b8..1ca0ef1da77 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.h +++ b/vespalib/src/vespa/vespalib/stllike/string.h @@ -7,6 +7,8 @@ #include #include +#define VESPA_DLL_LOCAL __attribute__ ((visibility("hidden"))) + namespace vespalib { /** @@ -567,7 +569,7 @@ private: bool isAllocated() const { return _buf != _stack; } char * buffer() { return _buf; } const char * buffer() const { return _buf; } - void appendAlloc(const void * s, size_type sz) __attribute__((noinline)); + VESPA_DLL_LOCAL void appendAlloc(const void * s, size_type sz) __attribute__((noinline)); void init(const void *s) noexcept { if (__builtin_expect(_sz < StackSize, true)) { _bufferSize = StackSize; diff --git a/vespamalloc/src/vespamalloc/malloc/threadlist.h b/vespamalloc/src/vespamalloc/malloc/threadlist.h index 6e518091f0f..149396a3bff 100644 --- a/vespamalloc/src/vespamalloc/malloc/threadlist.h +++ b/vespamalloc/src/vespamalloc/malloc/threadlist.h @@ -45,10 +45,10 @@ private: std::atomic _threadCountAccum; ThreadPool _threadVector[NUM_THREADS]; AllocPoolT & _allocPool; - static __thread ThreadPool * _myPool TLS_LINKAGE; + static thread_local ThreadPool * _myPool TLS_LINKAGE; }; template -__thread ThreadPoolT * ThreadListT::_myPool TLS_LINKAGE = nullptr; +thread_local ThreadPoolT * ThreadListT::_myPool TLS_LINKAGE = nullptr; } -- cgit v1.2.3