From 2db1d513904b6dda3644a84a221bae074ee93b66 Mon Sep 17 00:00:00 2001 From: "Jean M. Cyr" Date: Mon, 21 Jan 2019 19:01:19 -0500 Subject: [PATCH] Lower the compiler background thread priority. --- libethash-cl/CLMiner.cpp | 14 ++++++++++++++ libethash-cuda/CUDAMiner.cpp | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libethash-cl/CLMiner.cpp b/libethash-cl/CLMiner.cpp index 00b299c3a..976e19294 100644 --- a/libethash-cl/CLMiner.cpp +++ b/libethash-cl/CLMiner.cpp @@ -870,7 +870,21 @@ void CLMiner::asyncCompile() { auto saveName = getThreadName(); setThreadName(name().c_str()); + +#if defined(__linux__) + // Non Posix hack to lower compile thread's priority. Under POSIX + // the nice value is a process attribute, under Linux it's a thread + // attribute + if (nice(5) == -1) + cllog << "Unable to lower compiler priority."; +#endif +#ifdef WIN32 + if (!SetThreadPriority(m_compileThread->native_handle(), THREAD_PRIORITY_BELOW_NORMAL)) + cllog << "Unable to lower compiler priority."; +#endif + compileKernel(m_nextProgpowPeriod, m_nextProgram, m_nextSearchKernel); + setThreadName(saveName.c_str()); } diff --git a/libethash-cuda/CUDAMiner.cpp b/libethash-cuda/CUDAMiner.cpp index ea2e5334d..6b3907565 100644 --- a/libethash-cuda/CUDAMiner.cpp +++ b/libethash-cuda/CUDAMiner.cpp @@ -332,10 +332,23 @@ void CUDAMiner::enumDevices(std::map& _DevicesCollecti void CUDAMiner::asyncCompile() { - cuCtxSetCurrent(m_context); auto saveName = getThreadName(); setThreadName(name().c_str()); +#if defined(__linux__) + // Non Posix hack to lower compile thread's priority. Under POSIX + // the nice value is a process attribute, under Linux it's a thread + // attribute + if (nice(5) == -1) + cudalog << "Unable to lower compiler priority."; +#endif +#ifdef WIN32 + if (!SetThreadPriority(m_compileThread->native_handle(), THREAD_PRIORITY_BELOW_NORMAL)) + cudalog << "Unable to lower compiler priority."; +#endif + + cuCtxSetCurrent(m_context); + compileKernel(m_nextProgpowPeriod, m_epochContext.dagNumItems / 2, m_kernel[m_kernelCompIx]); setThreadName(saveName.c_str());