Add customizable per-platform affinity for content and pool threads

This commit is contained in:
Wojtek Figat
2025-07-29 10:41:41 +02:00
parent 17c0892ff1
commit 99323c1d2f
4 changed files with 27 additions and 10 deletions

View File

@@ -4,8 +4,13 @@
#include "Engine/Core/Config.h"
// Amount of content loading threads per single physical CPU core
// Amount of content loading threads per single logical CPU core
#ifndef LOADING_THREAD_PER_LOGICAL_CORE
#define LOADING_THREAD_PER_LOGICAL_CORE 0.5f
#endif
// Enables pinning loading threads to the logical CPU cores with affinity mask
//#define LOADING_THREAD_AFFINITY_MASK(thread) (1 << (thread + 1))
// Enables additional assets metadata verification
#define ASSETS_LOADING_EXTRA_VERIFICATION (BUILD_DEBUG || USE_EDITOR)

View File

@@ -129,17 +129,17 @@ bool ContentService::Init()
LOG(Info, "Creating {0} content loading threads...", count);
MainLoadThread = New<LoadingThread>();
ThisLoadThread = MainLoadThread;
LoadThreads.EnsureCapacity(count);
LoadThreads.Resize(count);
for (int32 i = 0; i < count; i++)
{
auto thread = New<LoadingThread>();
LoadThreads[i] = thread;
if (thread->Start(String::Format(TEXT("Load Thread {0}"), i)))
{
LOG(Fatal, "Cannot spawn content thread {0}/{1}", i, count);
Delete(thread);
return true;
}
LoadThreads.Add(thread);
}
return false;
@@ -339,6 +339,9 @@ int32 LoadingThread::Run()
return -1;
}
#endif
#ifdef LOADING_THREAD_AFFINITY_MASK
Platform::SetThreadAffinityMask(LOADING_THREAD_AFFINITY_MASK(LoadThreads.Find(this)));
#endif
ContentLoadTask* task;
ThisLoadThread = this;