diff options
-rw-r--r-- | fastos/src/vespa/fastos/thread.cpp | 6 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/thread.h | 28 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_thread.cpp | 78 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_thread.h | 15 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.h | 1 |
6 files changed, 18 insertions, 112 deletions
diff --git a/fastos/src/vespa/fastos/thread.cpp b/fastos/src/vespa/fastos/thread.cpp index d172977b222..3850c14fb26 100644 --- a/fastos/src/vespa/fastos/thread.cpp +++ b/fastos/src/vespa/fastos/thread.cpp @@ -14,10 +14,9 @@ // FastOS_ThreadPool // ---------------------------------------------------------------------- -FastOS_ThreadPool::FastOS_ThreadPool(int stackSize, int maxThreads) +FastOS_ThreadPool::FastOS_ThreadPool(int , int maxThreads) : _startedThreadsCount(0), _closeFlagMutex(), - _stackSize(stackSize), _closeCalledFlag(false), _freeMutex(), _liveMutex(), @@ -255,7 +254,6 @@ void FastOS_ThreadInterface::Hook () dispatchedGuard.unlock(); // END lock if(!finished) { - PreEntry(); deleteOnCompletion = _owner->DeleteOnCompletion(); _owner->Run(this, _startArg); @@ -331,7 +329,7 @@ FastOS_ThreadInterface *FastOS_ThreadInterface::CreateThread(FastOS_ThreadPool * { FastOS_ThreadInterface *thread = new FastOS_Thread(pool); - if(!thread->Initialize(pool->GetStackSize(), pool->GetStackGuardSize())) { + if(!thread->Initialize()) { delete(thread); thread = nullptr; } diff --git a/fastos/src/vespa/fastos/thread.h b/fastos/src/vespa/fastos/thread.h index a8cf12825eb..d42987640b4 100644 --- a/fastos/src/vespa/fastos/thread.h +++ b/fastos/src/vespa/fastos/thread.h @@ -38,15 +38,8 @@ class FastOS_ThreadPool friend class FastOS_ThreadInterface; private: - FastOS_ThreadPool(const FastOS_ThreadPool&); - FastOS_ThreadPool& operator=(const FastOS_ThreadPool&); - int _startedThreadsCount; std::mutex _closeFlagMutex; - /** - * The stack size for threads in this pool. - */ - const int _stackSize; bool _closeCalledFlag; // Always lock in this order @@ -136,6 +129,8 @@ private: FastOS_ThreadInterface **listHead); public: + FastOS_ThreadPool(const FastOS_ThreadPool&) = delete; + FastOS_ThreadPool& operator=(const FastOS_ThreadPool&) = delete; /** * Create a threadpool that can hold a maximum of [maxThreads] threads. * @param stackSize The stack size for threads in this pool should @@ -165,14 +160,6 @@ public: FastOS_ThreadInterface *NewThread (FastOS_Runnable *owner, void *arg=nullptr); /** - * Get the stack size used for threads in this pool. - * @return Stack size in bytes. - */ - int GetStackSize() const { return _stackSize; } - - int GetStackGuardSize() const { return 0; } - - /** * Close the threadpool. This involves setting the break flag on * all active threads, and waiting for them to finish. Once Close * is called, no more threads can be allocated from the thread @@ -271,18 +258,11 @@ protected: void Dispatch (FastOS_Runnable *owner, void *arg); /** - * This method is called prior to invoking @ref FastOS_Runnable::Run(). - * Usually this involves setting operating system thread attributes, - * and is handled by each operating specific subclass. - */ - virtual void PreEntry ()=0; - - /** * Initializes a thread. This includes creating the operating system - * socket handle and setting it up and making it ready to be dispatched. + * thread handle and setting it up and making it ready to be dispatched. * @return Boolean success/failure */ - virtual bool Initialize (int stackSize, int stackGuardSize)=0; + virtual bool Initialize ()=0; /** * Used to store thread invocation arguments. These are passed along diff --git a/fastos/src/vespa/fastos/unix_thread.cpp b/fastos/src/vespa/fastos/unix_thread.cpp index f2098cc6345..621505b7e02 100644 --- a/fastos/src/vespa/fastos/unix_thread.cpp +++ b/fastos/src/vespa/fastos/unix_thread.cpp @@ -1,90 +1,24 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "thread.h" -#include <atomic> -#include <thread> -#include <unistd.h> -#include <limits.h> -#ifdef __linux__ -extern "C" { size_t __pthread_get_minstack(const pthread_attr_t *); } -#endif - -namespace { -#ifdef __linux__ - std::atomic_size_t _G_nextCpuId(0); -#endif - volatile size_t _G_maxNumCpus=0; // Non zero means use cpu pinning. -} - -bool FastOS_UNIX_Thread::InitializeClass () -{ - if (getenv("VESPA_PIN_THREAD_TO_CORE") != nullptr) { - _G_maxNumCpus = std::thread::hardware_concurrency(); - fprintf(stderr, "Will pin threads to CPU. Using %ld cores\n", _G_maxNumCpus); - if (getenv("VESPA_MAX_CORES") != nullptr) { - size_t maxCores = strtoul(getenv("VESPA_MAX_CORES"), nullptr, 0); - fprintf(stderr, "Will limit to %ld", maxCores); - if (maxCores < _G_maxNumCpus) { - _G_maxNumCpus = maxCores; - } - } - } - return true; -} - -bool FastOS_UNIX_Thread::CleanupClass () -{ - return true; -} - -bool FastOS_UNIX_Thread::Initialize (int /*stackSize*/, int stackGuardSize) +bool FastOS_UNIX_Thread::Initialize () { - bool rc=false; - pthread_attr_t attr; pthread_attr_init(&attr); - pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); -#ifdef __linux__ - if (_G_maxNumCpus > 0) { - int cpuid = _G_nextCpuId.fetch_add(1)%_G_maxNumCpus; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - CPU_SET(cpuid, &cpuset); - int retval = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset); - if (retval != 0) { - fprintf(stderr, "Pinning FAILURE retval = %d, errno=%d sizeof(cpuset_t)=%ld cpuid(%d)\n", retval, errno, sizeof(cpuset), cpuid); - } - } -#endif - - if (stackGuardSize != 0) { - pthread_attr_setguardsize(&attr, stackGuardSize); - } pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - rc = (0 == pthread_create(&_handle, &attr, FastOS_ThreadHook, this)); - if (rc) - _handleValid = true; - + _handleValid = (0 == pthread_create(&_handle, &attr, FastOS_ThreadHook, this)); pthread_attr_destroy(&attr); - return rc; -} - -void FastOS_UNIX_Thread::PreEntry () -{ + return _handleValid; } FastOS_UNIX_Thread::~FastOS_UNIX_Thread() { - void *value; + if (!_handleValid) return; - // Wait for thread library cleanup to complete. - if (_handleValid) { - value = nullptr; - pthread_join(_handle, &value); - } + void *value = nullptr; + pthread_join(_handle, &value); } FastOS_ThreadId FastOS_UNIX_Thread::GetThreadId () const noexcept diff --git a/fastos/src/vespa/fastos/unix_thread.h b/fastos/src/vespa/fastos/unix_thread.h index b2f666060ca..c3c757e3fd9 100644 --- a/fastos/src/vespa/fastos/unix_thread.h +++ b/fastos/src/vespa/fastos/unix_thread.h @@ -13,28 +13,21 @@ class FastOS_UNIX_Thread : public FastOS_ThreadInterface { -private: - FastOS_UNIX_Thread(const FastOS_UNIX_Thread &); - FastOS_UNIX_Thread& operator=(const FastOS_UNIX_Thread &); - protected: pthread_t _handle; bool _handleValid; - bool Initialize (int stackSize, int stackGuardSize) override; - void PreEntry () override; - + bool Initialize () override; public: - static bool InitializeClass (); - static bool CleanupClass (); - + FastOS_UNIX_Thread(const FastOS_UNIX_Thread &) = delete; + FastOS_UNIX_Thread& operator=(const FastOS_UNIX_Thread &) = delete; FastOS_UNIX_Thread(FastOS_ThreadPool *pool) : FastOS_ThreadInterface(pool), _handle(), _handleValid(false) {} - ~FastOS_UNIX_Thread(); + ~FastOS_UNIX_Thread() override; FastOS_ThreadId GetThreadId () const noexcept override; static bool CompareThreadIds (FastOS_ThreadId a, FastOS_ThreadId b); diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h index f8036ad4a92..4b15c3503f3 100644 --- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h +++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h @@ -27,7 +27,7 @@ public: ~FlushMeta(); const vespalib::string & getName() const { return _name; } const vespalib::string& handler_name() const { return _handler_name; } - vespalib::system_time getStart() const { return vespalib::system_clock::now() - std::chrono::duration_cast<vespalib::system_time::duration>(elapsed()); } + vespalib::system_time getStart() const { return vespalib::to_utc(_timer.get_start()); } vespalib::duration elapsed() const { return _timer.elapsed(); } uint32_t getId() const { return _id; } bool operator < (const FlushMeta & rhs) const { return _id < rhs._id; } diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index 783831b5171..2355b269fa5 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -84,6 +84,7 @@ private: public: Timer() : _start(steady_clock::now()) {} ~Timer(); + steady_time get_start() const { return _start; } duration elapsed() const { return (steady_clock::now() - _start); } static void waitAtLeast(duration dur, bool busyWait); }; |