From 93081eb1f64ccda849b3988237035bb4945d817e Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 20 Dec 2021 12:05:17 +0100 Subject: [PATCH] GhostRidere: set correct priority for helper threads Fixes #2825 --- src/backend/cpu/CpuWorker.cpp | 2 +- src/crypto/ghostrider/ghostrider.cpp | 14 +++++++++----- src/crypto/ghostrider/ghostrider.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 32a7a6be6..5a6ae8fa5 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -100,7 +100,7 @@ xmrig::CpuWorker::CpuWorker(size_t id, const CpuLaunchData &data) : } # ifdef XMRIG_ALGO_GHOSTRIDER - m_ghHelper = ghostrider::create_helper_thread(affinity(), data.affinities); + m_ghHelper = ghostrider::create_helper_thread(affinity(), data.priority, data.affinities); # endif } diff --git a/src/crypto/ghostrider/ghostrider.cpp b/src/crypto/ghostrider/ghostrider.cpp index 9f403d3aa..43a721097 100644 --- a/src/crypto/ghostrider/ghostrider.cpp +++ b/src/crypto/ghostrider/ghostrider.cpp @@ -166,7 +166,7 @@ static struct AlgoTune struct HelperThread { - HelperThread(hwloc_bitmap_t cpu_set, bool is8MB) : m_cpuSet(cpu_set), m_is8MB(is8MB) + HelperThread(hwloc_bitmap_t cpu_set, int priority, bool is8MB) : m_cpuSet(cpu_set), m_priority(priority), m_is8MB(is8MB) { uv_mutex_init(&m_mutex); uv_cond_init(&m_cond); @@ -241,6 +241,8 @@ struct HelperThread } } + Platform::setThreadPriority(m_priority); + uv_mutex_lock(&m_mutex); m_ready = true; @@ -268,6 +270,7 @@ struct HelperThread volatile bool m_ready = false; volatile bool m_finished = false; hwloc_bitmap_t m_cpuSet = {}; + int m_priority = -1; bool m_is8MB = false; std::thread* m_thread = nullptr; @@ -297,6 +300,7 @@ void benchmark() } Platform::setThreadAffinity(thread_index1); + Platform::setThreadPriority(3); constexpr uint32_t N = 1U << 21; @@ -375,7 +379,7 @@ void benchmark() hwloc_bitmap_t helper_set = hwloc_bitmap_alloc(); hwloc_bitmap_set(helper_set, thread_index2); - HelperThread* helper = new HelperThread(helper_set, false); + HelperThread* helper = new HelperThread(helper_set, 3, false); for (uint32_t algo = 0; algo < 6; ++algo) { for (uint64_t step : { 1, 2, 4}) { @@ -465,7 +469,7 @@ static inline bool findByType(hwloc_obj_t obj, hwloc_obj_type_t type, func lambd } -HelperThread* create_helper_thread(int64_t cpu_index, const std::vector& affinities) +HelperThread* create_helper_thread(int64_t cpu_index, int priority, const std::vector& affinities) { #ifndef XMRIG_ARM hwloc_bitmap_t helper_cpu_set = hwloc_bitmap_alloc(); @@ -520,7 +524,7 @@ HelperThread* create_helper_thread(int64_t cpu_index, const std::vector }); if (hwloc_bitmap_weight(helper_cpu_set) > 0) { - return new HelperThread(helper_cpu_set, is8MB); + return new HelperThread(helper_cpu_set, priority, is8MB); } } } @@ -761,7 +765,7 @@ void hash_octa(const uint8_t* data, size_t size, uint8_t* output, cryptonight_ct void benchmark() {} -HelperThread* create_helper_thread(int64_t, const std::vector&) { return nullptr; } +HelperThread* create_helper_thread(int64_t, int, const std::vector&) { return nullptr; } void destroy_helper_thread(HelperThread*) {} diff --git a/src/crypto/ghostrider/ghostrider.h b/src/crypto/ghostrider/ghostrider.h index 081e4f6f1..e6c08df1b 100644 --- a/src/crypto/ghostrider/ghostrider.h +++ b/src/crypto/ghostrider/ghostrider.h @@ -39,7 +39,7 @@ namespace ghostrider struct HelperThread; void benchmark(); -HelperThread* create_helper_thread(int64_t cpu_index, const std::vector& affinities); +HelperThread* create_helper_thread(int64_t cpu_index, int priority, const std::vector& affinities); void destroy_helper_thread(HelperThread* t); void hash_octa(const uint8_t* data, size_t size, uint8_t* output, cryptonight_ctx** ctx, HelperThread* helper, bool verbose = true);