aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorEvan Klitzke <evan@eklitzke.org>2018-03-06 12:50:20 -0500
committerEvan Klitzke <evan@eklitzke.org>2018-03-26 15:59:41 -0700
commitd54874d795a523d7cad5f4a9f4270145e56238f8 (patch)
treef39d91af0b1506f87c94c75aebf8e901530c70bc /src/util.cpp
parent0a018431c447bbf18bdaa6a1037aad6a87c1294a (diff)
downloadbitcoin-d54874d795a523d7cad5f4a9f4270145e56238f8.tar.xz
Set SCHED_BATCH priority on the loadblk thread.
While reading another PR I saw a mention of #6358. The use case for SCHED_BATCH is to hint to the kernel that the thread is running a non-interactive workload that consumes a lot of CPU time. This is helpful on desktop machines where the loadblk thread can interfere with interactive applications. More details can be found in the sched(7) man page.
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 494d5c4eaf..842d4f6e19 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -31,6 +31,7 @@
#include <algorithm>
#include <fcntl.h>
+#include <sched.h>
#include <sys/resource.h>
#include <sys/stat.h>
@@ -966,3 +967,17 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
{
return fs::absolute(path, GetDataDir(net_specific));
}
+
+int ScheduleBatchPriority(void)
+{
+#ifdef SCHED_BATCH
+ const static sched_param param{.sched_priority = 0};
+ if (int ret = pthread_setschedparam(0, SCHED_BATCH, &param)) {
+ LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno));
+ return ret;
+ }
+ return 0;
+#else
+ return 1;
+#endif
+}