18 #ifndef CPUASYNCHCOUNTER_HEADER
19 #define CPUASYNCHCOUNTER_HEADER
30 #define DELAY 1 // in seconds
35 void * UpdateCounters(
void *);
44 pthread_t UpdateThread;
45 pthread_mutex_t CounterMutex;
47 friend void * UpdateCounters(
void *);
57 if(status != PCM::Success)
59 cout <<
"\nCan not access CPU counters. Try to run pcm.x 1 to check the PMU access status.\n" << endl;
68 for (uint32 i = 0; i < m->getNumCores(); ++i) {
73 for (uint32 i = 0; i < m->getNumSockets(); ++i) {
78 pthread_mutex_init(&CounterMutex, NULL);
79 pthread_create(&UpdateThread, NULL, UpdateCounters,
this);
83 pthread_cancel(UpdateThread);
84 pthread_mutex_destroy(&CounterMutex);
93 {
return m->getNumCores(); }
95 uint32 getNumSockets()
96 {
return m->getNumSockets(); }
98 uint32 getQPILinksPerSocket()
100 return m->getQPILinksPerSocket();
103 uint32 getSocketId(uint32 c)
105 return m->getSocketId(c);
108 template <
typename T, T func(CoreCounterState const &, CoreCounterState const &)>
111 pthread_mutex_lock(&CounterMutex);
112 T value = func(cstates1[core], cstates2[core]);
113 pthread_mutex_unlock(&CounterMutex);
117 template <
typename T, T func(
int, CoreCounterState const &, CoreCounterState const &)>
118 T get(
int param, uint32 core)
120 pthread_mutex_lock(&CounterMutex);
121 T value = func(param, cstates1[core], cstates2[core]);
122 pthread_mutex_unlock(&CounterMutex);
126 template <
typename T, T func(SocketCounterState const &, SocketCounterState const &)>
127 T getSocket(uint32 socket)
129 pthread_mutex_lock(&CounterMutex);
130 T value = func(skstates1[socket], skstates2[socket]);
131 pthread_mutex_unlock(&CounterMutex);
135 template <
typename T, T func(
int, SocketCounterState const &, SocketCounterState const &)>
136 T getSocket(
int param, uint32 socket)
138 pthread_mutex_lock(&CounterMutex);
139 T value = func(param, skstates1[socket], skstates2[socket]);
140 pthread_mutex_unlock(&CounterMutex);
144 template <
typename T, T func(u
int32, u
int32, SystemCounterState const &, SystemCounterState const &)>
145 T getSocket(uint32 socket, uint32 param)
147 pthread_mutex_lock(&CounterMutex);
148 T value = func(socket, param, sstate1, sstate2);
149 pthread_mutex_unlock(&CounterMutex);
153 template <
typename T, T func(SystemCounterState const &, SystemCounterState const &)>
156 pthread_mutex_lock(&CounterMutex);
157 T value = func(sstate1, sstate2);
158 pthread_mutex_unlock(&CounterMutex);
162 template <
typename T, T func(
int, SystemCounterState const &, SystemCounterState const &)>
163 T getSystem(
int param)
165 pthread_mutex_lock(&CounterMutex);
166 T value = func(param, sstate1, sstate2);
167 pthread_mutex_unlock(&CounterMutex);
173 void * UpdateCounters(
void * state)
178 pthread_mutex_lock(&(s->CounterMutex));
179 for (uint32 core = 0; core < s->m->
getNumCores(); ++core) {
180 s->cstates1[core] = s->cstates2[core];
184 for (uint32 socket = 0; socket < s->m->
getNumSockets(); ++socket) {
185 s->skstates1[socket] = s->skstates2[socket];
189 s->sstate1 = s->sstate2;
192 pthread_mutex_unlock(&(s->CounterMutex));
Definition: memoptest.cpp:35
Socket-wide counter state.
Definition: cpucounters.h:1339
SocketCounterState getSocketCounterState(uint32 socket)
Reads the counter state of a socket.
Definition: cpucounters.cpp:3234
SystemCounterState getSystemCounterState()
Reads the counter state of the system.
Definition: cpucounters.cpp:2998
Definition: cpuasynchcounter.h:37
System-wide counter state.
Definition: cpucounters.h:1358
uint32 getNumSockets()
Reads number of sockets (CPUs) in the system.
Definition: cpucounters.cpp:3313
CoreCounterState getCoreCounterState(uint32 core)
Reads the counter state of a (logical) core.
Definition: cpucounters.cpp:2673
Main CPU counters header.
SocketCounterState getSocketCounterState(uint32 socket)
Reads the counter state of a socket.
Definition: cpucounters.cpp:2665
uint32 getNumCores()
Reads number of logical cores in the system.
Definition: cpucounters.cpp:3303
CPU Performance Monitor.
Definition: cpucounters.h:212
CoreCounterState getCoreCounterState(uint32 core)
Reads the counter state of a (logical) core.
Definition: cpucounters.cpp:3296
(Logical) core-wide counter state
Definition: cpucounters.h:1331
ErrorCode
Return codes (e.g. for program(..) method)
Definition: cpucounters.h:323
static PCM * getInstance()
Returns PCM object.
Definition: cpucounters.cpp:196