Commit a0740fd0 authored by BRAMAS Berenger's avatar BRAMAS Berenger

update binding functions

parent ed64767a
......@@ -15,6 +15,8 @@ namespace FBinding {
#if defined(linux) || defined(__linux__) || defined(unix) || defined(__unix__)
#define FBINDING_ENABLE
#else
#define cpu_set_t int
#endif
inline long GetThreadBinding(){
......@@ -27,17 +29,38 @@ inline long GetThreadBinding(){
// Get the affinity
FAssertLF(sched_getaffinity(tid, sizeof(mask), (cpu_set_t*)&mask) != -1);
long cpus = 0;
for(size_t idxCpu = 0 ; idxCpu < sizeof(long)*8-1 ; ++idxCpu){
if(CPU_ISSET(idxCpu, &mask)){
cpus |= (1 << idxCpu);
if(CPU_COUNT(&mask) == 1){
int proc = 0;
while(proc != sizeof(cpu_set_t)*8){
if(CPU_ISSET(proc, &mask)){
return proc;
}
proc += 1;
}
}
return cpus;
#endif
return -1;
}
inline cpu_set_t GetSystemBinding(){
cpu_set_t mask;
#ifdef FBINDING_ENABLE
CPU_ZERO(&mask);
// We need the thread pid (even if we are in openmp)
pid_t tid = (pid_t) syscall(SYS_gettid);
// Get the affinity
FAssertLF(sched_getaffinity(tid, sizeof(mask), (cpu_set_t*)&mask) != -1);
#endif
return mask;
}
inline void ApplySystemBinding(cpu_set_t set){
#ifdef FBINDING_ENABLE
pid_t tid = (pid_t) syscall(SYS_gettid);
FAssertLF(sched_setaffinity(tid, sizeof(set), &set) != -1);
#endif
}
inline void SetThreadBinding(const int procId){
#ifdef FBINDING_ENABLE
cpu_set_t set;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment