Fix T59874: Cycles CPU 25% load only during rendering
The issue was introduced by a Threadripper2 commit back in
ce927e15e0. This boils down to threads inheriting affinity
from the parent thread. It is a question how this slipped
through the review (we definitely run benchmark round).
Quick fix could have been to always set CPU group affinity
in Cycles, and it would work for Windows. On other platforms
we did not have CPU groups API finished.
Ended up making Cycles aware of NUMA topology, so now we
bound threads to a specific NUMA node. This required adding
an external dependency to Cycles, but made some code there
shorter.
This commit is contained in:
@@ -21,10 +21,10 @@
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
thread::thread(function<void()> run_cb, int group)
|
||||
thread::thread(function<void()> run_cb, int node)
|
||||
: run_cb_(run_cb),
|
||||
joined_(false),
|
||||
group_(group)
|
||||
node_(node)
|
||||
{
|
||||
thread_ = std::thread(&thread::run, this);
|
||||
}
|
||||
@@ -39,19 +39,8 @@ thread::~thread()
|
||||
void *thread::run(void *arg)
|
||||
{
|
||||
thread *self = (thread*)(arg);
|
||||
if(self->group_ != -1) {
|
||||
#ifdef _WIN32
|
||||
HANDLE thread_handle = GetCurrentThread();
|
||||
GROUP_AFFINITY group_affinity = { 0 };
|
||||
int num_threads = system_cpu_group_thread_count(self->group_);
|
||||
group_affinity.Group = self->group_;
|
||||
group_affinity.Mask = (num_threads == 64)
|
||||
? -1
|
||||
: (1ull << num_threads) - 1;
|
||||
if(SetThreadGroupAffinity(thread_handle, &group_affinity, NULL) == 0) {
|
||||
fprintf(stderr, "Error setting thread affinity.\n");
|
||||
}
|
||||
#endif
|
||||
if (self->node_ != -1) {
|
||||
system_cpu_run_thread_on_node(self->node_);
|
||||
}
|
||||
self->run_cb_();
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user