Make use of hyperthreading for worker threads. Still cap to 16 workers.

This commit is contained in:
Henrik Rydgård 2021-06-13 00:05:18 +02:00
parent 62eadd2dac
commit 1d59560409
2 changed files with 5 additions and 3 deletions

View file

@ -97,15 +97,17 @@ static void WorkerThreadFunc(GlobalThreadContext *global, ThreadContext *thread)
}
}
void ThreadManager::Init(int numRealCores, int numLogicalCores) {
void ThreadManager::Init(int numRealCores, int numLogicalCoresPerCpu) {
if (!global_->threads_.empty()) {
Teardown();
}
numComputeThreads_ = std::min(numRealCores, MAX_CORES_TO_USE);
numComputeThreads_ = std::min(numRealCores * numLogicalCoresPerCpu, MAX_CORES_TO_USE);
int numThreads = numComputeThreads_ + EXTRA_THREADS;
numThreads_ = numThreads;
INFO_LOG(SYSTEM, "ThreadManager::Init(compute threads: %d, all: %d)", numComputeThreads_, numThreads_);
for (int i = 0; i < numThreads; i++) {
ThreadContext *thread = new ThreadContext();
thread->cancelled.store(false);

View file

@ -44,7 +44,7 @@ public:
// The distinction here is to be able to take hyper-threading into account.
// It gets even trickier when you think about mobile chips with BIG/LITTLE, but we'll
// just ignore it and let the OS handle it.
void Init(int numRealCores, int numLogicalCores);
void Init(int numCores, int numLogicalCoresPerCpu);
void EnqueueTask(Task *task, TaskType taskType);
void EnqueueTaskOnThread(int threadNum, Task *task, TaskType taskType);