From 4ca12b40206f64d32369a78ce443a0dbf5d2b757 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 18 Jun 2014 11:02:09 -0700 Subject: [PATCH] common/WorkQueue: allow io priority to be set for wq Signed-off-by: Sage Weil (cherry picked from commit 5e4b3b1f1cb870f39fc7cfb3adeae93e078d9057) Conflicts: src/common/WorkQueue.cc --- src/common/WorkQueue.cc | 21 +++++++++++++++++++++ src/common/WorkQueue.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/common/WorkQueue.cc b/src/common/WorkQueue.cc index 6b648a780215..452e551646b8 100644 --- a/src/common/WorkQueue.cc +++ b/src/common/WorkQueue.cc @@ -16,6 +16,7 @@ #include "include/types.h" #include "include/utime.h" +#include "common/errno.h" #include "WorkQueue.h" #include "common/config.h" @@ -33,6 +34,8 @@ ThreadPool::ThreadPool(CephContext *cct_, string nm, int n, const char *option) _stop(false), _pause(0), _draining(0), + ioprio_class(-1), + ioprio_priority(-1), _num_threads(n), last_work_queue(0), processing(0) @@ -156,6 +159,11 @@ void ThreadPool::start_threads() WorkThread *wt = new WorkThread(this); ldout(cct, 10) << "start_threads creating and starting " << wt << dendl; _threads.insert(wt); + + int r = wt->set_ioprio(ioprio_class, ioprio_priority); + if (r < 0) + lderr(cct) << " set_ioprio got " << cpp_strerror(r) << dendl; + wt->create(); } } @@ -254,3 +262,16 @@ void ThreadPool::drain(WorkQueue_* wq) _lock.Unlock(); } +void ThreadPool::set_ioprio(int cls, int priority) +{ + Mutex::Locker l(_lock); + ioprio_class = cls; + ioprio_priority = priority; + for (set::iterator p = _threads.begin(); + p != _threads.end(); + ++p) { + int r = (*p)->set_ioprio(cls, priority); + if (r < 0) + lderr(cct) << " set_ioprio got " << cpp_strerror(r) << dendl; + } +} diff --git a/src/common/WorkQueue.h b/src/common/WorkQueue.h index b2742accdce0..6c0b60bc3805 100644 --- a/src/common/WorkQueue.h +++ b/src/common/WorkQueue.h @@ -33,6 +33,7 @@ class ThreadPool : public md_config_obs_t { int _pause; int _draining; Cond _wait_cond; + int ioprio_class, ioprio_priority; public: class TPHandle { @@ -388,6 +389,9 @@ public: void unpause(); /// wait for all work to complete void drain(WorkQueue_* wq = 0); + + /// set io priority + void set_ioprio(int cls, int priority); }; -- 2.47.3