Add a name to JobManager (#5576)

* Add a name to JobManager, all worker threads use that name to label their threads

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* update with PR feedback, changed to use AZStd::fixed_string::format

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Fix copy paste errors using local variable names

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>
This commit is contained in:
rgba16f
2021-11-12 13:15:41 -06:00
committed by GitHub
parent cb93bafc4f
commit 57adfd795e
8 changed files with 19 additions and 4 deletions
@@ -62,6 +62,7 @@ namespace AZ
, m_alignment(alignment) , m_alignment(alignment)
{ {
JobManagerDesc jobDesc; JobManagerDesc jobDesc;
jobDesc.m_jobManagerName = "Full File Decompressor";
u32 numThreads = AZ::GetMin(maxNumJobs, AZStd::thread::hardware_concurrency()); u32 numThreads = AZ::GetMin(maxNumJobs, AZStd::thread::hardware_concurrency());
for (u32 i = 0; i < numThreads; ++i) for (u32 i = 0; i < numThreads; ++i)
{ {
@@ -14,6 +14,7 @@
#include <AzCore/std/parallel/thread.h> #include <AzCore/std/parallel/thread.h>
#include <AzCore/std/parallel/lock.h> #include <AzCore/std/parallel/lock.h>
#include <AzCore/std/functional.h> #include <AzCore/std/functional.h>
#include <AzCore/std/string/fixed_string.h>
#include <AzCore/Debug/Profiler.h> #include <AzCore/Debug/Profiler.h>
@@ -83,7 +84,7 @@ AZ_THREAD_LOCAL JobManagerWorkStealing::ThreadInfo* JobManagerWorkStealing::m_cu
JobManagerWorkStealing::JobManagerWorkStealing(const JobManagerDesc& desc) JobManagerWorkStealing::JobManagerWorkStealing(const JobManagerDesc& desc)
: m_isAsynchronous(!desc.m_workerThreads.empty()) : m_isAsynchronous(!desc.m_workerThreads.empty())
, m_workerThreads(AZStd::move(CreateWorkerThreads(desc.m_workerThreads))) , m_workerThreads(AZStd::move(CreateWorkerThreads(desc)))
{ {
//allow workers to begin processing after they have all been created, needed to wait since they may access each others queues //allow workers to begin processing after they have all been created, needed to wait since they may access each others queues
m_initSemaphore.release(static_cast<unsigned int>(desc.m_workerThreads.size())); m_initSemaphore.release(static_cast<unsigned int>(desc.m_workerThreads.size()));
@@ -618,8 +619,9 @@ JobManagerWorkStealing::ThreadInfo* JobManagerWorkStealing::FindCurrentThreadInf
return info; return info;
} }
JobManagerWorkStealing::ThreadList JobManagerWorkStealing::CreateWorkerThreads(const JobManagerDesc::DescList& workerDescList) JobManagerWorkStealing::ThreadList JobManagerWorkStealing::CreateWorkerThreads(const JobManagerDesc& jmDesc)
{ {
const JobManagerDesc::DescList& workerDescList = jmDesc.m_workerThreads;
ThreadList workerThreads(workerDescList.size()); ThreadList workerThreads(workerDescList.size());
m_threads.reserve(workerDescList.size()); m_threads.reserve(workerDescList.size());
@@ -632,8 +634,12 @@ JobManagerWorkStealing::ThreadList JobManagerWorkStealing::CreateWorkerThreads(c
info->m_owningManager = this; info->m_owningManager = this;
info->m_workerId = iThread; info->m_workerId = iThread;
AZStd::fixed_string<128> threadName = AZStd::fixed_string<128>::format(
"%s worker thread %d",
jmDesc.m_jobManagerName[0] != '\0' ? jmDesc.m_jobManagerName : "AZ JobManager",
iThread);
AZStd::thread_desc threadDesc; AZStd::thread_desc threadDesc;
threadDesc.m_name = "AZ JobManager worker thread"; threadDesc.m_name = threadName.c_str();
threadDesc.m_cpuId = desc.m_cpuId; threadDesc.m_cpuId = desc.m_cpuId;
threadDesc.m_priority = desc.m_priority; threadDesc.m_priority = desc.m_priority;
if (desc.m_stackSize != 0) if (desc.m_stackSize != 0)
@@ -115,7 +115,7 @@ namespace AZ
void ProcessJobsAssist(ThreadInfo* info, Job* suspendedJob, AZStd::atomic<bool>* notifyFlag); void ProcessJobsAssist(ThreadInfo* info, Job* suspendedJob, AZStd::atomic<bool>* notifyFlag);
void ProcessJobsSynchronous(ThreadInfo* info, Job* suspendedJob, AZStd::atomic<bool>* notifyFlag); void ProcessJobsSynchronous(ThreadInfo* info, Job* suspendedJob, AZStd::atomic<bool>* notifyFlag);
void ProcessJobsInternal(ThreadInfo* info, Job* suspendedJob, AZStd::atomic<bool>* notifyFlag); void ProcessJobsInternal(ThreadInfo* info, Job* suspendedJob, AZStd::atomic<bool>* notifyFlag);
ThreadList CreateWorkerThreads(const JobManagerDesc::DescList& workerDescList); ThreadList CreateWorkerThreads(const JobManagerDesc& jmDesc);
#ifndef AZ_MONOLITHIC_BUILD #ifndef AZ_MONOLITHIC_BUILD
ThreadInfo* CrossModuleFindAndSetWorkerThreadInfo() const; ThreadInfo* CrossModuleFindAndSetWorkerThreadInfo() const;
#endif #endif
@@ -51,6 +51,7 @@ namespace AZ
JobManagerBus::Handler::BusConnect(); JobManagerBus::Handler::BusConnect();
JobManagerDesc desc; JobManagerDesc desc;
desc.m_jobManagerName = "Default JobManager";
JobManagerThreadDesc threadDesc; JobManagerThreadDesc threadDesc;
int numberOfWorkerThreads = m_numberOfWorkerThreads; int numberOfWorkerThreads = m_numberOfWorkerThreads;
@@ -51,6 +51,8 @@ namespace AZ
{ {
JobManagerDesc() {} JobManagerDesc() {}
const char* m_jobManagerName = "";
using DescList = AZStd::fixed_vector<JobManagerThreadDesc, 64>; using DescList = AZStd::fixed_vector<JobManagerThreadDesc, 64>;
DescList m_workerThreads; ///< List of worker threads to create DescList m_workerThreads; ///< List of worker threads to create
}; };
@@ -160,6 +160,7 @@ namespace AWSCore
// If m_firstThreadCPU isn't -1, then each thread will be // If m_firstThreadCPU isn't -1, then each thread will be
// assigned to a specific CPU starting with the specified CPU. // assigned to a specific CPU starting with the specified CPU.
AZ::JobManagerDesc jobManagerDesc{}; AZ::JobManagerDesc jobManagerDesc{};
jobManagerDesc.m_jobManagerName = "AWSCore JobManager";
AZ::JobManagerThreadDesc threadDesc(m_firstThreadCPU, m_threadPriority, m_threadStackSize); AZ::JobManagerThreadDesc threadDesc(m_firstThreadCPU, m_threadPriority, m_threadStackSize);
for (int i = 0; i < m_threadCount; ++i) for (int i = 0; i < m_threadCount; ++i)
{ {
@@ -101,6 +101,8 @@ namespace ImageProcessingAtom
void ImagePreview::InitializeJobSettings() void ImagePreview::InitializeJobSettings()
{ {
AZ::JobManagerDesc desc; AZ::JobManagerDesc desc;
desc.m_jobManagerName = "ImagePreview";
AZ::JobManagerThreadDesc threadDesc; AZ::JobManagerThreadDesc threadDesc;
desc.m_workerThreads.push_back(threadDesc); desc.m_workerThreads.push_back(threadDesc);
// Check to ensure these have not already been initialized. // Check to ensure these have not already been initialized.
@@ -123,6 +123,8 @@ namespace AZ
// Prepare to create a cancellable job. // Prepare to create a cancellable job.
AZ::JobManagerDesc desc; AZ::JobManagerDesc desc;
desc.m_jobManagerName = "AssetCollectionAsyncLoader";
AZ::JobManagerThreadDesc threadDesc; AZ::JobManagerThreadDesc threadDesc;
desc.m_workerThreads.push_back(threadDesc); desc.m_workerThreads.push_back(threadDesc);
m_jobManager = AZStd::make_unique<AZ::JobManager>(desc); m_jobManager = AZStd::make_unique<AZ::JobManager>(desc);