CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions
CPUAffinity Class Reference

#include <CPUAffinity.h>

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.

Referenced by TimerService::TimerService().

79 {
80  // cpu affinity is currently only supposted on LINUX
81 #ifdef __linux
82 
83  // check if this process is bound to a single CPU, and try to bind to the current one if it's not
84  cpu_set_t cpu_set;
85  sched_getaffinity(0, sizeof(cpu_set_t), & cpu_set);
86  if (CPU_COUNT(& cpu_set) == 1)
87  // the process is already bound to a single CPU
88  return true;
89 
90  // this process is not bound, try to bind it to the current CPU
91  int current = sched_getcpu();
92  CPU_ZERO(& cpu_set);
93  CPU_SET(current, & cpu_set);
94  sched_setaffinity(0, sizeof(cpu_set_t), & cpu_set); // check for errors ?
95  sched_getaffinity(0, sizeof(cpu_set_t), & cpu_set);
96 
97  if (CPU_COUNT(& cpu_set) == 1)
98  // the process is now bound to a single CPU
99  return true;
100 
101 #endif // __linux
102 
103  return false;
104 }
int CPUAffinity::currentCpu ( )
static

Definition at line 51 of file CPUAffinity.cc.

Referenced by TimerService::TimerService().

51  {
52  // cpu affinity is currently only supposted on LINUX
53 #ifdef __linux
54  return sched_getcpu();
55 #else
56  return 0;
57 #endif
58 }
bool CPUAffinity::isCpuBound ( )
static

Definition at line 60 of file CPUAffinity.cc.

61 {
62  // cpu affinity is currently only supposted on LINUX
63 #ifdef __linux
64 
65  // check if this process is bound to a single CPU
66  cpu_set_t cpu_set;
67  sched_getaffinity(0, sizeof(cpu_set_t), & cpu_set);
68  if (CPU_COUNT(& cpu_set) == 1)
69  // the process is bound to a single CPU
70  return true;
71 
72 #endif // __linux
73 
74  return false;
75 }