ThreadPool的allocThreadPools主要功能是:
创建线程池,并计算出来jobprovider的个数和workthread的个数。
其中numaNode的结构如下:
NUMA体系结构中多了Node的概念,这个概念其实是用来解决core的分组的问题,具体参见下图来理解(图中的OS CPU可以理解thread,那么core就没有在图中画出),从图中可以看出每个Socket里有两个node,共有4个socket,每个socket 2个node,每个node中有8个thread,总共4(Socket)× 2(Node)× 8 (4core × 2 Thread) = 64个thread
需要计算出来每个node的线程数目,每个node创建一个threadpool。
ThreadPool* ThreadPool::allocThreadPools(x265_param* p, int& numPools, bool isThreadsReserved)
{
enum { MAX_NODE_NUM = 127 };
int cpusPerNode[MAX_NODE_NUM + 1];
int threadsPerPool[MAX_NODE_NUM + 2];
uint64_t nodeMaskPerPool[MAX_NODE_NUM + 2];
int totalNumThreads = 0;
memset(cpusPerNode, 0, sizeof(cpusPerNode));
memset(threadsPerPool, 0, sizeof(threadsPerPool));
memset(nodeMaskPerPool, 0, sizeof(nodeMaskPerPool));
int numNumaNodes = X265_MIN(getNumaNodeCount(), MAX_NODE_NUM);
bool bNumaSupport = false;
cpusPerNode[0] = getCpuCount();
if (bNumaSupport && p->logLevel >= X265_LOG_DEBUG)
for (int i = 0; i < numNumaNodes; i++)
x265_log(p, X265_LOG_DEBUG, "detected NUMA node %d with %d logical cores\n", i, cpusPerNode[i]);
/* limit threads based on param->numaPools
* For windows because threads can't be allocated to live across sockets
* changing the default behavior to be per-socket pools -- FIXME */
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN7
if (!p->numaPools || (strcmp(p->numaPools, "NULL") == 0 || strcmp(p->numaPools, "*") == 0 || strcmp(p->numaPools, "") == 0))
{
char poolString[50] = "";
for (int i = 0; i < numNumaNodes; i++)
{
char nextCount[10] = "";
if (i)
sprintf(nextCount, ",%d", cpusPerNode[i]);
else
sprintf(nextCount, "%d", cpusPerNode[i]);