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 &)>
111 pthread_mutex_lock(&CounterMutex);
112 T value = func(cstates2[core]);
113 pthread_mutex_unlock(&CounterMutex);
116 template <
typename T, T func(CoreCounterState const &, CoreCounterState const &)>
119 pthread_mutex_lock(&CounterMutex);
120 T value = func(cstates1[core], cstates2[core]);
121 pthread_mutex_unlock(&CounterMutex);
125 template <
typename T, T func(
int, CoreCounterState const &, CoreCounterState const &)>
126 T get(
int param, uint32 core)
128 pthread_mutex_lock(&CounterMutex);
129 T value = func(param, cstates1[core], cstates2[core]);
130 pthread_mutex_unlock(&CounterMutex);
134 template <
typename T, T func(SocketCounterState const &)>
135 T getSocket(uint32 socket)
137 pthread_mutex_lock(&CounterMutex);
138 T value = func(skstates2[socket]);
139 pthread_mutex_unlock(&CounterMutex);
143 template <
typename T, T func(SocketCounterState const &, SocketCounterState const &)>
144 T getSocket(uint32 socket)
146 pthread_mutex_lock(&CounterMutex);
147 T value = func(skstates1[socket], skstates2[socket]);
148 pthread_mutex_unlock(&CounterMutex);
152 template <
typename T, T func(
int, SocketCounterState const &, SocketCounterState const &)>
153 T getSocket(
int param, uint32 socket)
155 pthread_mutex_lock(&CounterMutex);
156 T value = func(param, skstates1[socket], skstates2[socket]);
157 pthread_mutex_unlock(&CounterMutex);
161 template <
typename T, T func(u
int32, u
int32, SystemCounterState const &, SystemCounterState const &)>
162 T getSocket(uint32 socket, uint32 param)
164 pthread_mutex_lock(&CounterMutex);
165 T value = func(socket, param, sstate1, sstate2);
166 pthread_mutex_unlock(&CounterMutex);
170 template <
typename T, T func(SystemCounterState const &, SystemCounterState const &)>
173 pthread_mutex_lock(&CounterMutex);
174 T value = func(sstate1, sstate2);
175 pthread_mutex_unlock(&CounterMutex);
179 template <
typename T, T func(
int, SystemCounterState const &, SystemCounterState const &)>
180 T getSystem(
int param)
182 pthread_mutex_lock(&CounterMutex);
183 T value = func(param, sstate1, sstate2);
184 pthread_mutex_unlock(&CounterMutex);
189 void * UpdateCounters(
void * state)
194 pthread_mutex_lock(&(s->CounterMutex));
195 for (uint32 core = 0; core < s->m->
getNumCores(); ++core) {
196 s->cstates1[core] = s->cstates2[core];
200 for (uint32 socket = 0; socket < s->m->
getNumSockets(); ++socket) {
201 s->skstates1[socket] = s->skstates2[socket];
205 s->sstate1 = s->sstate2;
208 pthread_mutex_unlock(&(s->CounterMutex));
Definition: memoptest.cpp:35
Socket-wide counter state.
Definition: cpucounters.h:2289
SocketCounterState getSocketCounterState(uint32 socket)
Reads the counter state of a socket.
Definition: cpucounters.cpp:3981
SystemCounterState getSystemCounterState()
Reads the counter state of the system.
Definition: cpucounters.cpp:3701
Definition: cpuasynchcounter.h:37
System-wide counter state.
Definition: cpucounters.h:2308
uint32 getNumSockets() const
Reads number of sockets (CPUs) in the system.
Definition: cpucounters.cpp:4116
CoreCounterState getCoreCounterState(uint32 core)
Reads the counter state of a (logical) core.
Definition: cpucounters.cpp:3296
Main CPU counters header.
SocketCounterState getSocketCounterState(uint32 socket)
Reads the counter state of a socket.
Definition: cpucounters.cpp:3288
uint32 getNumCores() const
Reads number of logical cores in the system.
Definition: cpucounters.cpp:4106
CPU Performance Monitor.
Definition: cpucounters.h:481
CoreCounterState getCoreCounterState(uint32 core)
Reads the counter state of a (logical) core.
Definition: cpucounters.cpp:4099
(Logical) core-wide counter state
Definition: cpucounters.h:2281
ErrorCode
Return codes (e.g. for program(..) method)
Definition: cpucounters.h:615
static PCM * getInstance()
Returns PCM object.
Definition: cpucounters.cpp:259