diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-19 14:33:15 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-19 14:54:04 +0000 |
commit | 5cabc15d86ef3d823626115b76715a589e147fb3 (patch) | |
tree | b0de117397a15b57bf5c0b31ef389865677a732a | |
parent | 701ae22e4b334d3fe9fcca3b9aac95c4cf3d613e (diff) |
Stacksize is no longer in use.
-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 |
4 files changed, 16 insertions, 111 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); |