This commit is contained in:
Wojtek Figat
2021-06-12 19:35:27 +02:00
parent 41ad835d86
commit 47af31a8c4
3 changed files with 20 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ bool ProfilerCPU::Enabled = false;
ProfilerCPU::EventBuffer::EventBuffer()
{
_capacity = Math::RoundUpToPowerOf2(10 * 1000);
_capacity = 8192;
_capacityMask = _capacity - 1;
_data = NewArray<Event>(_capacity);
_head = 0;

View File

@@ -20,6 +20,7 @@
// JOB_SYSTEM_USE_MUTEX=0, enqueue=300-700 cycles, dequeue=10-16 cycles
// So using RingBuffer+Mutex+Signals is better than moodycamel::ConcurrentQueue
#define JOB_SYSTEM_ENABLED 1
#define JOB_SYSTEM_USE_MUTEX 1
#define JOB_SYSTEM_USE_STATS 0
@@ -32,6 +33,8 @@
#include "ConcurrentQueue.h"
#endif
#if JOB_SYSTEM_ENABLED
class JobSystemService : public EngineService
{
public:
@@ -201,11 +204,14 @@ int32 JobSystemThread::Run()
return 0;
}
#endif
int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
{
PROFILE_CPU();
if (jobCount <= 0)
return 0;
#if JOB_SYSTEM_ENABLED
#if JOB_SYSTEM_USE_STATS
const auto start = Platform::GetTimeCycles();
#endif
@@ -234,15 +240,23 @@ int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
JobsSignal.NotifyAll();
return label;
#else
for (int32 i = 0; i < jobCount; i++)
job(i);
return 0;
#endif
}
void JobSystem::Wait()
{
#if JOB_SYSTEM_ENABLED
Wait(Platform::AtomicRead(&NextLabel));
#endif
}
void JobSystem::Wait(int64 label)
{
#if JOB_SYSTEM_ENABLED
PROFILE_CPU();
// Early out
@@ -262,4 +276,5 @@ void JobSystem::Wait(int64 label)
LOG(Info, "Job average dequeue time: {0} cycles", DequeueSum / DequeueCount);
DequeueSum = DequeueCount = 0;
#endif
#endif
}

View File

@@ -69,7 +69,8 @@ public:
return result;
}
void GetValues(Array<T>& result) const
template<typename AllocationType = HeapAllocation>
void GetValues(Array<T, AllocationType>& result) const
{
result.EnsureCapacity(MaxThreads);
for (int32 i = 0; i < MaxThreads; i++)
@@ -134,7 +135,8 @@ public:
}
}
void GetNotNullValues(Array<T*>& result) const
template<typename AllocationType = HeapAllocation>
void GetNotNullValues(Array<T*, AllocationType>& result) const
{
result.EnsureCapacity(MaxThreads);
for (int32 i = 0; i < MaxThreads; i++)