From 16686bab71cd99d277497e3f09ba41d9293a591d Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Tue, 28 May 2024 17:32:51 +0800 Subject: [PATCH] Enable increasing/decreasing compute threads. --- src/kernel/Executor.cc | 16 ++++++++++------ src/kernel/Executor.h | 4 ++++ src/manager/WFGlobal.cc | 2 +- src/manager/WFGlobal.h | 12 +++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/kernel/Executor.cc b/src/kernel/Executor.cc index 25804faf..efb731d1 100644 --- a/src/kernel/Executor.cc +++ b/src/kernel/Executor.cc @@ -52,12 +52,6 @@ void ExecQueue::deinit() int Executor::init(size_t nthreads) { - if (nthreads == 0) - { - errno = EINVAL; - return -1; - } - this->thrdpool = thrdpool_create(nthreads, 0); if (this->thrdpool) return 0; @@ -152,3 +146,13 @@ int Executor::request(ExecSession *session, ExecQueue *queue) return -!entry; } +int Executor::increase_thread() +{ + return thrdpool_increase(this->thrdpool); +} + +int Executor::decrease_thread() +{ + return thrdpool_decrease(this->thrdpool); +} + diff --git a/src/kernel/Executor.h b/src/kernel/Executor.h index 05ab50e0..0b84c9b8 100644 --- a/src/kernel/Executor.h +++ b/src/kernel/Executor.h @@ -67,6 +67,10 @@ public: int request(ExecSession *session, ExecQueue *queue); +public: + int increase_thread(); + int decrease_thread(); + private: struct __thrdpool *thrdpool; diff --git a/src/manager/WFGlobal.cc b/src/manager/WFGlobal.cc index abea7bc1..638be5cd 100644 --- a/src/manager/WFGlobal.cc +++ b/src/manager/WFGlobal.cc @@ -421,7 +421,7 @@ private: { int compute_threads = WFGlobal::get_global_settings()->compute_threads; - if (compute_threads <= 0) + if (compute_threads < 0) compute_threads = sysconf(_SC_NPROCESSORS_ONLN); if (compute_executor_.init(compute_threads) < 0) diff --git a/src/manager/WFGlobal.h b/src/manager/WFGlobal.h index f4805ed6..4b813164 100644 --- a/src/manager/WFGlobal.h +++ b/src/manager/WFGlobal.h @@ -54,7 +54,7 @@ struct WFGlobalSettings int dns_threads; int poller_threads; int handler_threads; - int compute_threads; ///< auto-set by system CPU number if value<=0 + int compute_threads; ///< auto-set by system CPU number if value<0 int fio_max_events; const char *resolv_conf_path; const char *hosts_path; @@ -124,6 +124,16 @@ public: static const char *get_error_string(int state, int error); + static bool increase_compute_thread() + { + return WFGlobal::get_compute_executor()->increase_thread() == 0; + } + + static bool decrease_compute_thread() + { + return WFGlobal::get_compute_executor()->decrease_thread() == 0; + } + // Internal usage only public: static bool is_scheduler_created();