CMS 3D CMS Logo

Static Public Member Functions

CPUAffinity Class Reference

#include <CPUAffinity.h>

List of all members.

Static Public Member Functions

static bool bindToCurrentCpu ()
static int currentCpu ()
static bool isCpuBound ()

Detailed Description

Definition at line 4 of file CPUAffinity.h.


Member Function Documentation

bool CPUAffinity::bindToCurrentCpu ( ) [static]

Definition at line 78 of file CPUAffinity.cc.

References cond::rpcobimon::current.

Referenced by TimerService::TimerService().

{
  // cpu affinity is currently only supposted on LINUX
#ifdef __linux

  // check if this process is bound to a single CPU, and try to bind to the current one if it's not
  cpu_set_t cpu_set;
  sched_getaffinity(0, sizeof(cpu_set_t), & cpu_set);
  if (CPU_COUNT(& cpu_set) == 1)
    // the process is already bound to a single CPU
    return true;
  
  // this process is not bound, try to bind it to the current CPU
  int current = sched_getcpu();
  CPU_ZERO(& cpu_set);
  CPU_SET(current, & cpu_set);
  sched_setaffinity(0, sizeof(cpu_set_t), & cpu_set); // check for errors ?
  sched_getaffinity(0, sizeof(cpu_set_t), & cpu_set);

  if (CPU_COUNT(& cpu_set) == 1)
    // the process is now bound to a single CPU
    return true;

#endif // __linux

  return false;
}
int CPUAffinity::currentCpu ( ) [static]

Definition at line 51 of file CPUAffinity.cc.

Referenced by TimerService::TimerService().

                            {
  // cpu affinity is currently only supposted on LINUX
#ifdef __linux
  return sched_getcpu();
#else
  return 0;
#endif
}
bool CPUAffinity::isCpuBound ( ) [static]

Definition at line 60 of file CPUAffinity.cc.

Referenced by FastTimerService::preBeginRun().

{
  // cpu affinity is currently only supposted on LINUX
#ifdef __linux

  // check if this process is bound to a single CPU
  cpu_set_t cpu_set;
  sched_getaffinity(0, sizeof(cpu_set_t), & cpu_set);
  if (CPU_COUNT(& cpu_set) == 1)
    // the process is bound to a single CPU
    return true;

#endif // __linux

  return false;
}