فهرست منبع

[FEATURE] Add the ability for ThreadPool and ThreadHive to pin to cores

Panagiotis Christopoulos Charitos 8 سال پیش
والد
کامیت
2cbb5baaa6
5فایلهای تغییر یافته به همراه12 افزوده شده و 12 حذف شده
  1. 2 2
      src/anki/core/App.cpp
  2. 4 4
      src/anki/util/ThreadHive.cpp
  3. 1 1
      src/anki/util/ThreadHive.h
  4. 4 4
      src/anki/util/ThreadPool.cpp
  5. 1 1
      src/anki/util/ThreadPool.h

+ 2 - 2
src/anki/core/App.cpp

@@ -219,8 +219,8 @@ Error App::initInternal(const ConfigSet& config_, AllocAlignedCallback allocCb,
 	//
 	// ThreadPool
 	//
-	m_threadpool = m_heapAlloc.newInstance<ThreadPool>(config.getNumber("core.mainThreadCount"));
-	m_threadHive = m_heapAlloc.newInstance<ThreadHive>(config.getNumber("core.mainThreadCount"), m_heapAlloc);
+	m_threadpool = m_heapAlloc.newInstance<ThreadPool>(config.getNumber("core.mainThreadCount"), true);
+	m_threadHive = m_heapAlloc.newInstance<ThreadHive>(config.getNumber("core.mainThreadCount"), m_heapAlloc, true);
 
 	//
 	// Graphics API

+ 4 - 4
src/anki/util/ThreadHive.cpp

@@ -26,13 +26,13 @@ public:
 	ThreadHive* m_hive;
 
 	/// Constructor
-	Thread(U32 id, ThreadHive* hive)
+	Thread(U32 id, ThreadHive* hive, Bool pinToCores)
 		: m_id(id)
 		, m_thread("anki_threadhive")
 		, m_hive(hive)
 	{
 		ANKI_ASSERT(hive);
-		m_thread.start(this, threadCallback);
+		m_thread.start(this, threadCallback, (pinToCores) ? m_id : -1);
 	}
 
 private:
@@ -71,7 +71,7 @@ public:
 	}
 };
 
-ThreadHive::ThreadHive(U threadCount, GenericMemoryPoolAllocator<U8> alloc)
+ThreadHive::ThreadHive(U threadCount, GenericMemoryPoolAllocator<U8> alloc, Bool pinToCores)
 	: m_slowAlloc(alloc)
 	, m_alloc(alloc.getMemoryPool().getAllocationCallback(),
 		  alloc.getMemoryPool().getAllocationCallbackUserData(),
@@ -81,7 +81,7 @@ ThreadHive::ThreadHive(U threadCount, GenericMemoryPoolAllocator<U8> alloc)
 	m_threads = reinterpret_cast<Thread*>(m_slowAlloc.allocate(sizeof(Thread) * threadCount));
 	for(U i = 0; i < threadCount; ++i)
 	{
-		::new(&m_threads[i]) Thread(i, this);
+		::new(&m_threads[i]) Thread(i, this, pinToCores);
 	}
 }
 

+ 1 - 1
src/anki/util/ThreadHive.h

@@ -50,7 +50,7 @@ public:
 	static const U MAX_THREADS = 32;
 
 	/// Create the hive.
-	ThreadHive(U threadCount, GenericMemoryPoolAllocator<U8> alloc);
+	ThreadHive(U threadCount, GenericMemoryPoolAllocator<U8> alloc, Bool pinToCores = false);
 
 	~ThreadHive();
 

+ 4 - 4
src/anki/util/ThreadPool.cpp

@@ -25,14 +25,14 @@ public:
 	Bool8 m_quit = false;
 
 	/// Constructor
-	ThreadPoolThread(U32 id, ThreadPool* threadpool)
+	ThreadPoolThread(U32 id, ThreadPool* threadpool, Bool pinToCore)
 		: m_id(id)
 		, m_thread("anki_threadpool")
 		, m_task(nullptr)
 		, m_threadpool(threadpool)
 	{
 		ANKI_ASSERT(threadpool);
-		m_thread.start(this, threadCallback);
+		m_thread.start(this, threadCallback, (pinToCore) ? m_id : -1);
 	}
 
 private:
@@ -69,7 +69,7 @@ private:
 
 ThreadPool::DummyTask ThreadPool::m_dummyTask;
 
-ThreadPool::ThreadPool(U32 threadCount)
+ThreadPool::ThreadPool(U32 threadCount, Bool pinToCores)
 	: m_barrier(threadCount + 1)
 {
 	m_threadsCount = threadCount;
@@ -84,7 +84,7 @@ ThreadPool::ThreadPool(U32 threadCount)
 
 	while(threadCount-- != 0)
 	{
-		::new(&m_threads[threadCount]) detail::ThreadPoolThread(threadCount, this);
+		::new(&m_threads[threadCount]) detail::ThreadPoolThread(threadCount, this, pinToCores);
 	}
 }
 

+ 1 - 1
src/anki/util/ThreadPool.h

@@ -51,7 +51,7 @@ public:
 	static constexpr U MAX_THREADS = 32; ///< An absolute limit
 
 	/// Constructor.
-	ThreadPool(U32 threadCount);
+	ThreadPool(U32 threadCount, Bool pinToCores = false);
 
 	~ThreadPool();