[x265] [PATCH 3 of 7] threadpool.cpp: utilize all available NUMA nodes for threadpool distribution -> windows system fix
praveen at multicorewareinc.com
praveen at multicorewareinc.com
Fri May 20 13:01:56 CEST 2016
# HG changeset patch
# User Praveen Tiwari <praveen at multicorewareinc.com>
# Date 1463738737 -19800
# Fri May 20 15:35:37 2016 +0530
# Node ID ab1b27a1712d581c32b007f0f72e482f4a83905d
# Parent e988eee2f0dc962b9b94c8cef6f739522bce9afb
threadpool.cpp: utilize all available NUMA nodes for threadpool distribution -> windows system fix
diff -r e988eee2f0dc -r ab1b27a1712d source/common/threadpool.cpp
--- a/source/common/threadpool.cpp Fri May 20 15:35:37 2016 +0530
+++ b/source/common/threadpool.cpp Fri May 20 15:35:37 2016 +0530
@@ -27,6 +27,7 @@
#include "threading.h"
#include <new>
+#include <winnt.h>
#if X86_64
@@ -405,16 +406,15 @@
X265_CHECK(numThreads <= MAX_POOL_THREADS, "a single thread pool cannot have more than MAX_POOL_THREADS threads\n");
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
- m_winCpuMask = 0x0;
- GROUP_AFFINITY groupAffinity;
+ memset(&m_groupAffinity, 0, sizeof(GROUP_AFFINITY));
for (int i = 0; i < getNumaNodeCount(); i++)
{
int numaNode = ((nodeMask >> i) & 0x1U) ? i : -1;
if (numaNode != -1)
- if (GetNumaNodeProcessorMaskEx((USHORT)numaNode, &groupAffinity))
- m_winCpuMask |= groupAffinity.Mask;
+ if (GetNumaNodeProcessorMaskEx((USHORT)numaNode, &m_groupAffinity))
+ break;
}
- m_numaMask = &m_winCpuMask;
+ m_numaMask = &m_groupAffinity.Mask;
#elif HAVE_LIBNUMA
if (numa_available() >= 0)
{
@@ -496,11 +496,16 @@
setThreadNodeAffinity(m_numaMask);
}
-/* static */
void ThreadPool::setThreadNodeAffinity(void *numaMask)
{
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
- if (SetThreadAffinityMask(GetCurrentThread(), *((DWORD_PTR*)numaMask)))
+ UNREFERENCED_PARAMETER(numaMask);
+ GROUP_AFFINITY groupAffinity;
+ memset(&groupAffinity, 0, sizeof(GROUP_AFFINITY));
+ groupAffinity.Group = m_groupAffinity.Group;
+ groupAffinity.Mask = m_groupAffinity.Mask;
+ const PGROUP_AFFINITY affinityPointer = &groupAffinity;
+ if (SetThreadGroupAffinity(GetCurrentThread(), affinityPointer, NULL))
return;
else
x265_log(NULL, X265_LOG_ERROR, "unable to set thread affinity for NUMA node mask\n");
diff -r e988eee2f0dc -r ab1b27a1712d source/common/threadpool.h
--- a/source/common/threadpool.h Fri May 20 15:35:37 2016 +0530
+++ b/source/common/threadpool.h Fri May 20 15:35:37 2016 +0530
@@ -85,7 +85,7 @@
int m_numWorkers;
void* m_numaMask; // node mask in linux, cpu mask in windows
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
- DWORD_PTR m_winCpuMask;
+ GROUP_AFFINITY m_groupAffinity;
#endif
bool m_isActive;
@@ -99,6 +99,7 @@
bool start();
void stopWorkers();
void setCurrentThreadAffinity();
+ void setThreadNodeAffinity(void *numaMask);
int tryAcquireSleepingThread(sleepbitmap_t firstTryBitmap, sleepbitmap_t secondTryBitmap);
int tryBondPeers(int maxPeers, sleepbitmap_t peerBitmap, BondedTaskGroup& master);
@@ -106,7 +107,6 @@
static int getCpuCount();
static int getNumaNodeCount();
- static void setThreadNodeAffinity(void *numaMask);
};
/* Any worker thread may enlist the help of idle worker threads from the same
More information about the x265-devel
mailing list