summaryrefslogtreecommitdiffstats
path: root/storageframework
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2022-02-16 08:55:49 +0000
committerGeir Storli <geirst@yahooinc.com>2022-02-16 08:55:49 +0000
commit133945f36bbee0be51153e60410b03d88b7a16f9 (patch)
tree1d3c4e8b297a63d7c60cc13a2b572d391b185412 /storageframework
parent80bf8df285a1ecf1f5f253eeb4e49f600fcbad9a (diff)
Support setting cpu category on storageframework threads.
Diffstat (limited to 'storageframework')
-rw-r--r--storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp13
-rw-r--r--storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h6
-rw-r--r--storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp5
-rw-r--r--storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h3
-rw-r--r--storageframework/src/vespa/storageframework/generic/component/component.cpp5
-rw-r--r--storageframework/src/vespa/storageframework/generic/component/component.h7
-rw-r--r--storageframework/src/vespa/storageframework/generic/thread/threadpool.h5
-rw-r--r--storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp2
8 files changed, 33 insertions, 13 deletions
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp
index f5deb25f983..f4dacb7ccc3 100644
--- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp
+++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp
@@ -14,7 +14,8 @@ ThreadImpl::ThreadImpl(ThreadPoolImpl& pool,
vespalib::stringref id,
vespalib::duration waitTime,
vespalib::duration maxProcessTime,
- int ticksBeforeWait)
+ int ticksBeforeWait,
+ std::optional<vespalib::CpuUsage::Category> cpu_category)
: Thread(id),
_pool(pool),
_runnable(runnable),
@@ -23,7 +24,8 @@ ThreadImpl::ThreadImpl(ThreadPoolImpl& pool,
_tickDataPtr(0),
_interrupted(false),
_joined(false),
- _thread(*this)
+ _thread(*this),
+ _cpu_category(cpu_category)
{
_tickData[_tickDataPtr]._lastTick = pool.getClock().getMonotonicTime();
_thread.start(_pool.getThreadPool());
@@ -38,7 +40,12 @@ ThreadImpl::~ThreadImpl()
void
ThreadImpl::run()
{
- _runnable.run(*this);
+ if (_cpu_category.has_value()) {
+ auto usage = vespalib::CpuUsage::use(_cpu_category.value());
+ _runnable.run(*this);
+ } else {
+ _runnable.run(*this);
+ }
_pool.unregisterThread(*this);
_joined = true;
}
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h
index 3a24b79bda8..0757c5cdf1a 100644
--- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h
+++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h
@@ -3,9 +3,11 @@
#pragma once
#include <vespa/storageframework/generic/thread/threadpool.h>
+#include <vespa/vespalib/util/cpu_usage.h>
#include <vespa/vespalib/util/document_runnable.h>
#include <array>
#include <atomic>
+#include <optional>
namespace storage::framework::defaultimplementation {
@@ -51,12 +53,14 @@ class ThreadImpl : public Thread
std::atomic<bool> _interrupted;
bool _joined;
BackendThread _thread;
+ std::optional<vespalib::CpuUsage::Category> _cpu_category;
void run();
public:
ThreadImpl(ThreadPoolImpl&, Runnable&, vespalib::stringref id, vespalib::duration waitTime,
- vespalib::duration maxProcessTime, int ticksBeforeWait);
+ vespalib::duration maxProcessTime, int ticksBeforeWait,
+ std::optional<vespalib::CpuUsage::Category> cpu_category);
~ThreadImpl();
bool interrupted() const override;
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp
index 7846c917631..7711eddf51c 100644
--- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp
+++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.cpp
@@ -48,13 +48,14 @@ ThreadPoolImpl::~ThreadPoolImpl()
Thread::UP
ThreadPoolImpl::startThread(Runnable& runnable, vespalib::stringref id, vespalib::duration waitTime,
- vespalib::duration maxProcessTime, int ticksBeforeWait)
+ vespalib::duration maxProcessTime, int ticksBeforeWait,
+ std::optional<vespalib::CpuUsage::Category> cpu_category)
{
std::lock_guard lock(_threadVectorLock);
if (_stopping) {
throw IllegalStateException("Threadpool is stopping", VESPA_STRLOC);
}
- auto thread = std::make_unique<ThreadImpl>(*this, runnable, id, waitTime, maxProcessTime, ticksBeforeWait);
+ auto thread = std::make_unique<ThreadImpl>(*this, runnable, id, waitTime, maxProcessTime, ticksBeforeWait, cpu_category);
_threads.push_back(thread.get());
return thread;
}
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h
index dc80803b57f..d6053a2f128 100644
--- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h
+++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadpoolimpl.h
@@ -22,7 +22,8 @@ public:
~ThreadPoolImpl() override;
Thread::UP startThread(Runnable&, vespalib::stringref id, vespalib::duration waitTime,
- vespalib::duration maxProcessTime, int ticksBeforeWait) override;
+ vespalib::duration maxProcessTime, int ticksBeforeWait,
+ std::optional<vespalib::CpuUsage::Category> cpu_category) override;
void visitThreads(ThreadVisitor&) const override;
void registerThread(ThreadImpl&);
diff --git a/storageframework/src/vespa/storageframework/generic/component/component.cpp b/storageframework/src/vespa/storageframework/generic/component/component.cpp
index 82ca40f780d..f45e1a0b839 100644
--- a/storageframework/src/vespa/storageframework/generic/component/component.cpp
+++ b/storageframework/src/vespa/storageframework/generic/component/component.cpp
@@ -89,10 +89,11 @@ Component::getThreadPool() const
// Helper functions for components wanting to start a single thread.
Thread::UP
-Component::startThread(Runnable& runnable, vespalib::duration waitTime, vespalib::duration maxProcessTime, int ticksBeforeWait)
+Component::startThread(Runnable& runnable, vespalib::duration waitTime, vespalib::duration maxProcessTime,
+ int ticksBeforeWait, std::optional<vespalib::CpuUsage::Category> cpu_category)
{
return getThreadPool().startThread(runnable, getName(), waitTime,
- maxProcessTime, ticksBeforeWait);
+ maxProcessTime, ticksBeforeWait, cpu_category);
}
void
diff --git a/storageframework/src/vespa/storageframework/generic/component/component.h b/storageframework/src/vespa/storageframework/generic/component/component.h
index b7d07243f73..45cf30d1902 100644
--- a/storageframework/src/vespa/storageframework/generic/component/component.h
+++ b/storageframework/src/vespa/storageframework/generic/component/component.h
@@ -71,7 +71,9 @@
#include <vespa/storageframework/generic/thread/runnable.h>
#include <vespa/storageframework/generic/thread/thread.h>
#include <vespa/storageframework/generic/clock/clock.h>
+#include <vespa/vespalib/util/cpu_usage.h>
#include <atomic>
+#include <optional>
namespace storage::framework {
@@ -115,7 +117,7 @@ class Component : private ManagedComponent
void close() override;
public:
- typedef std::unique_ptr<Component> UP;
+ using UP = std::unique_ptr<Component>;
Component(ComponentRegister&, vespalib::stringref name);
virtual ~Component();
@@ -180,7 +182,8 @@ public:
Thread::UP startThread(Runnable&,
vespalib::duration maxProcessTime = vespalib::duration::zero(),
vespalib::duration waitTime = vespalib::duration::zero(),
- int ticksBeforeWait = 1);
+ int ticksBeforeWait = 1,
+ std::optional<vespalib::CpuUsage::Category> cpu_category = {});
// Check upgrade flag settings. Note that this flag may change at any time.
// Thus the results of these functions should not be cached.
diff --git a/storageframework/src/vespa/storageframework/generic/thread/threadpool.h b/storageframework/src/vespa/storageframework/generic/thread/threadpool.h
index 7a8ff47f669..a490a6f8511 100644
--- a/storageframework/src/vespa/storageframework/generic/thread/threadpool.h
+++ b/storageframework/src/vespa/storageframework/generic/thread/threadpool.h
@@ -16,6 +16,8 @@
#include <vespa/storageframework/generic/thread/runnable.h>
#include <vespa/storageframework/generic/thread/thread.h>
#include <vespa/storageframework/generic/clock/time.h>
+#include <vespa/vespalib/util/cpu_usage.h>
+#include <optional>
#include <vector>
namespace storage::framework {
@@ -88,7 +90,8 @@ struct ThreadPool {
vespalib::stringref id,
vespalib::duration waitTime,
vespalib::duration maxProcessTime,
- int ticksBeforeWait) = 0;
+ int ticksBeforeWait,
+ std::optional<vespalib::CpuUsage::Category> cpu_category) = 0;
virtual void visitThreads(ThreadVisitor&) const = 0;
};
diff --git a/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp b/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp
index 867247c1d68..626680f0a95 100644
--- a/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp
+++ b/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp
@@ -171,7 +171,7 @@ public:
ost.str(),
_waitTime.load(std::memory_order_relaxed),
_maxProcessTime.load(std::memory_order_relaxed),
- _ticksBeforeWait.load(std::memory_order_relaxed))));
+ _ticksBeforeWait.load(std::memory_order_relaxed), {})));
}
}