[x265] [PATCH] ThreadPool.cpp: fix core count for windows machines

praveen at multicorewareinc.com praveen at multicorewareinc.com
Tue May 17 15:37:40 CEST 2016


# HG changeset patch
# User Praveen Tiwari <praveen at multicorewareinc.com>
# Date 1463492196 -19800
#      Tue May 17 19:06:36 2016 +0530
# Node ID 372fc5b12ed6003f8784702956ccf7203ea68a2e
# Parent  e5b5bdc3c154f908706fb75e006f9abf9b3de96f
ThreadPool.cpp: fix core count for windows machines

diff -r e5b5bdc3c154 -r 372fc5b12ed6 source/common/threadpool.cpp
--- a/source/common/threadpool.cpp	Sat May 14 07:29:46 2016 +0530
+++ b/source/common/threadpool.cpp	Tue May 17 19:06:36 2016 +0530
@@ -27,6 +27,7 @@
 #include "threading.h"
 
 #include <new>
+#include <winnt.h>
 
 #if X86_64
 
@@ -64,6 +65,18 @@
 # define strcasecmp _stricmp
 #endif
 
+uint64_t bitCount(uint64_t value)
+{
+    uint64_t count = 0;
+    while (value > 0)             // until all bits are zero
+    {
+        if ((value & 1) == 1)     // check lower bit
+            count++;
+        value >>= 1;              // shift bits, removing lower bit
+    }
+    return count;
+}
+
 namespace X265_NS {
 // x265 private namespace
 
@@ -238,7 +251,6 @@
     memset(nodeMaskPerPool, 0, sizeof(nodeMaskPerPool));
 
     int numNumaNodes = X265_MIN(getNumaNodeCount(), MAX_NODE_NUM);
-    int cpuCount = getCpuCount();
     bool bNumaSupport = false;
 
 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7 
@@ -248,20 +260,28 @@
 #endif
 
 
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
+    PGROUP_AFFINITY groupAffinityPointer = new GROUP_AFFINITY;
+    for (int i = 0; i < numNumaNodes; i++)
+    {
+        GetNumaNodeProcessorMaskEx((UCHAR)i, groupAffinityPointer);
+        cpusPerNode[i] = (int)bitCount(groupAffinityPointer->Mask);
+    }
+    delete groupAffinityPointer;
+#elif HAVE_LIBNUMA
+    int cpuCount = getCpuCount();
     for (int i = 0; i < cpuCount; i++)
     {
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7 
-        UCHAR node;
-        if (GetNumaProcessorNode((UCHAR)i, &node))
-            cpusPerNode[X265_MIN(node, (UCHAR)MAX_NODE_NUM)]++;
-        else
-#elif HAVE_LIBNUMA
         if (bNumaSupport >= 0)
             cpusPerNode[X265_MIN(numa_node_of_cpu(i), MAX_NODE_NUM)]++;
-        else
+    }
+#elif
+    int cpuCount = getCpuCount();
+    for (int i = 0; i < cpuCount; i++)
+    {
+        cpusPerNode[0]++;
+    }
 #endif
-            cpusPerNode[0]++;
-    }
 
     if (bNumaSupport && p->logLevel >= X265_LOG_DEBUG)
         for (int i = 0; i < numNumaNodes; i++)


More information about the x265-devel mailing list