Linux kernel 找出defualt pthread affinity策略,然后是Linux内核2.6.32

Linux kernel 找出defualt pthread affinity策略,然后是Linux内核2.6.32,linux-kernel,pthreads,scheduled-tasks,affinity,hyperthreading,Linux Kernel,Pthreads,Scheduled Tasks,Affinity,Hyperthreading,我试图找出在HT系统中创建pthread时,科学Linux内核2.6.32遵循的默认关联策略是什么。有办法知道吗?在pthreads创建中,没有对affinity的调用,因此我猜affinity将留给操作系统使用。不确定这是否有帮助,但下面是一些使用pthread API获取和设置线程affinity的代码: // nail down this thread so it will only run on a specific CPU cpu_set_t tCPUSet; CPU_ZERO(&am

我试图找出在HT系统中创建pthread时,科学Linux内核2.6.32遵循的默认关联策略是什么。有办法知道吗?在pthreads创建中,没有对affinity的调用,因此我猜affinity将留给操作系统使用。

不确定这是否有帮助,但下面是一些使用pthread API获取和设置线程affinity的代码:

// nail down this thread so it will only run on a specific CPU
cpu_set_t tCPUSet;
CPU_ZERO(&tCPUSet);
CPU_SET(ENCODE_LEFT_THREAD_CPU, &tCPUSet);
nReturnCode = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &tCPUSet);
if (nReturnCode == -1)  {
    pLogFile->Write(LOG_ERR, "ERROR: encodeLeftThread(): pthread_setaffinity() failed, %s, exiting thread... ", strerror(errno));
    nThreadReturnValue = THREAD_CPU_AFFINITY_ERRORS;
    pthread_exit((void *)&nThreadReturnValue);
}

CPU_ZERO(&tCPUSet);
nReturnCode = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &tCPUSet);
if (nReturnCode == -1)  {
    pLogFile->Write(LOG_ERR, "ERROR: encodeLeftThread(): 2nd pthread_getaffinity() failed, %s, exiting thread... ", strerror(errno));
    nThreadReturnValue = THREAD_CPU_AFFINITY_ERRORS;
    pthread_exit((void *)&nThreadReturnValue);
}

sCPUs.clear();
sCPUs.append("    new left thread CPU affinity: ");
if (bInitLog)  {
    for (int i = 0; i < CPU_SETSIZE; i++)  {
        if (CPU_ISSET(i, &tCPUSet))  {
            sCPUs.append(" ");
            char c = '0' + i;
            sCPUs = sCPUs + c;
        }
    }
}
if (bInitLog) pLogFile->Write(LOG_DEBUG, "%s ", sCPUs.c_str());
//确定此线程,使其仅在特定CPU上运行
cpu设置tCPUSet;
CPU_ZERO(&TcpSet);
CPU设置(编码左线程CPU和tCPUSet);
nReturnCode=pthread_setaffinity_np(pthread_self()、sizeof(cpu_set)&tCPUSet);
如果(nReturnCode==-1){
pLogFile->Write(LOG_ERR,“错误:encodeLeftThread():pthread_setaffinity()失败,%s,正在退出线程…”,strerror(errno));
nThreadReturnValue=线程\u CPU\u相关性\u错误;
pthread_exit((void*)&nThreadReturnValue);
}
CPU_ZERO(&TcpSet);
nReturnCode=pthread\u getaffinity\u np(pthread\u self()、sizeof(cpu\u set)&tCPUSet);
如果(nReturnCode==-1){
pLogFile->Write(LOG_ERR,“错误:encodeLeftThread():第二个pthread_getaffinity()失败,%s,正在退出线程…”,strerror(errno));
nThreadReturnValue=线程\u CPU\u相关性\u错误;
pthread_exit((void*)&nThreadReturnValue);
}
sCPUs.clear();
append(“新的左线程CPU关联:”);
if(bInitLog){
对于(int i=0;iWrite(LOG_DEBUG,“%s”,sCPUs.c_str());

@Andres Gonzalez谢谢你,它绝对有用