I have /cgroup/cpuset/set1. set1 has 2-5,8. I want to bind a process to that cpuset and then pin a thread in that process to, say, core 4. The name of the cpuset and the thread
Call the following Function and pass whatever core ID you want to pass. Also from wherever you call this function do check its return value to be 1.
short CorePin(int coreID)
{
short status=0;
int nThreads = std::thread::hardware_concurrency();
//std::cout< nThreads)
{
std::cout<<"Invalid CORE ID"<<"\n";
return status;
}
CPU_SET(coreID,&set);
if(sched_setaffinity(0, sizeof(cpu_set_t), &set) < 0)
{
std::cout<<"Unable to Set Affinity"<<"\n";
return -1;
}
return 1;
}