This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/intern/cycles/util/util_thread.cpp
Sergey Sharybin 826d7adde7 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.
2018-12-27 19:12:59 +01:00

62 lines
1.2 KiB
C++

/*
* Copyright 2011-2016 Blender Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "util/util_thread.h"
#include "util/util_system.h"
#include "util/util_windows.h"
CCL_NAMESPACE_BEGIN
thread::thread(function<void()> run_cb, int node)
: run_cb_(run_cb),
joined_(false),
node_(node)
{
thread_ = std::thread(&thread::run, this);
}
thread::~thread()
{
if(!joined_) {
join();
}
}
void *thread::run(void *arg)
{
thread *self = (thread*)(arg);
if (self->node_ != -1) {
system_cpu_run_thread_on_node(self->node_);
}
self->run_cb_();
return NULL;
}
bool thread::join()
{
joined_ = true;
try {
thread_.join();
return true;
}
catch (const std::system_error&) {
return false;
}
}
CCL_NAMESPACE_END