Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix locking to secure affinity update #2530

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xmrstak/backend/amd/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void minethd::work_main()

order_fix.set_value();
std::unique_lock<std::mutex> lck(thd_aff_set);
lck.release();
lck.unlock();
std::this_thread::yield();

cryptonight_ctx* cpu_ctx;
Expand Down
2 changes: 1 addition & 1 deletion xmrstak/backend/cpu/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ void minethd::multiway_work_main()

order_fix.set_value();
std::unique_lock<std::mutex> lck(thd_aff_set);
lck.release();
lck.unlock();
std::this_thread::yield();

cryptonight_ctx* ctx[MAX_N];
Expand Down
11 changes: 7 additions & 4 deletions xmrstak/backend/nvidia/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ minethd::minethd(miner_work& pWork, size_t iNo, const jconf::thd_cfg& cfg)
ctx.memMode = cfg.memMode;
this->affinity = cfg.cpu_aff;

std::unique_lock<std::mutex> lck(thd_aff_set);
std::future<void> numa_guard = numa_promise.get_future();
thread_work_guard = thread_work_promise.get_future();

Expand All @@ -92,14 +93,15 @@ minethd::minethd(miner_work& pWork, size_t iNo, const jconf::thd_cfg& cfg)
* without concurrent threads (CUDA driver is less occupied).
*/
numa_guard.wait();

if(this->affinity >= 0) //-1 means no affinity
if(!cpu::minethd::thd_setaffinity(oWorkThd.native_handle(), affinity))
printer::inst()->print_msg(L1, "WARNING setting affinity failed.");
}

void minethd::start_mining()
{
thread_work_promise.set_value();
if(this->affinity >= 0) //-1 means no affinity
if(!cpu::minethd::thd_setaffinity(oWorkThd.native_handle(), affinity))
printer::inst()->print_msg(L1, "WARNING setting affinity failed.");
}

bool minethd::self_test()
Expand Down Expand Up @@ -194,7 +196,8 @@ void minethd::work_main()

// numa memory bind and gpu memory is initialized
numa_promise.set_value();

std::unique_lock<std::mutex> lck(thd_aff_set);
lck.unlock();
std::this_thread::yield();
// wait until all NVIDIA devices are initialized
thread_work_guard.wait();
Expand Down
1 change: 1 addition & 0 deletions xmrstak/backend/nvidia/minethd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class minethd : public iBackend

std::promise<void> numa_promise;
std::promise<void> thread_work_promise;
std::mutex thd_aff_set;

// block thread until all NVIDIA GPUs are initialized
std::future<void> thread_work_guard;
Expand Down