8 #ifndef CPUASYNCHCOUNTER_HEADER 9 #define CPUASYNCHCOUNTER_HEADER 20 #define DELAY 1 // in seconds 24 void * UpdateCounters(
void *);
33 pthread_t UpdateThread;
34 pthread_mutex_t CounterMutex;
36 friend void * UpdateCounters(
void *);
46 if (status != PCM::Success)
48 std::cerr <<
"\nCannot access CPU counters. Try to run 'pcm 1' to check the PMU access status.\n\n";
67 pthread_mutex_init(&CounterMutex, NULL);
68 pthread_create(&UpdateThread, NULL, UpdateCounters,
this);
72 pthread_cancel(UpdateThread);
73 if (pthread_mutex_destroy(&CounterMutex) != 0) std::cerr <<
"pthread_mutex_destroy failed\n";
84 uint32 getNumSockets()
87 uint32 getQPILinksPerSocket()
92 uint32 getSocketId(uint32 c)
97 const char * getXpi() {
101 template <
typename T, T func(CoreCounterState const &)>
104 pthread_mutex_lock(&CounterMutex);
105 T value = func(cstates2[core]);
106 pthread_mutex_unlock(&CounterMutex);
109 template <
typename T, T func(CoreCounterState const &, CoreCounterState const &)>
112 pthread_mutex_lock(&CounterMutex);
113 T value = func(cstates1[core], cstates2[core]);
114 pthread_mutex_unlock(&CounterMutex);
118 template <
typename T, T func(
int, CoreCounterState const &, CoreCounterState const &)>
119 T get(
int param, uint32 core)
121 pthread_mutex_lock(&CounterMutex);
122 T value = func(param, cstates1[core], cstates2[core]);
123 pthread_mutex_unlock(&CounterMutex);
127 template <
typename T, T func(SocketCounterState const &)>
128 T getSocket(uint32 socket)
130 pthread_mutex_lock(&CounterMutex);
131 T value = func(skstates2[socket]);
132 pthread_mutex_unlock(&CounterMutex);
136 template <
typename T, T func(SocketCounterState const &, SocketCounterState const &)>
137 T getSocket(uint32 socket)
139 pthread_mutex_lock(&CounterMutex);
140 T value = func(skstates1[socket], skstates2[socket]);
141 pthread_mutex_unlock(&CounterMutex);
145 template <
typename T, T func(
int, SocketCounterState const &, SocketCounterState const &)>
146 T getSocket(
int param, uint32 socket)
148 pthread_mutex_lock(&CounterMutex);
149 T value = func(param, skstates1[socket], skstates2[socket]);
150 pthread_mutex_unlock(&CounterMutex);
154 template <
typename T, T func(u
int32, u
int32, SystemCounterState const &, SystemCounterState const &)>
155 T getSocket(uint32 socket, uint32 param)
157 pthread_mutex_lock(&CounterMutex);
158 T value = func(socket, param, sstate1, sstate2);
159 pthread_mutex_unlock(&CounterMutex);
163 template <
typename T, T func(SystemCounterState const &, SystemCounterState const &)>
166 pthread_mutex_lock(&CounterMutex);
167 T value = func(sstate1, sstate2);
168 pthread_mutex_unlock(&CounterMutex);
172 template <
typename T, T func(
int, SystemCounterState const &, SystemCounterState const &)>
173 T getSystem(
int param)
175 pthread_mutex_lock(&CounterMutex);
176 T value = func(param, sstate1, sstate2);
177 pthread_mutex_unlock(&CounterMutex);
182 void * UpdateCounters(
void * state)
187 if (pthread_mutex_lock(&(s->CounterMutex)) != 0) std::cerr <<
"pthread_mutex_lock failed\n";
188 for (uint32 core = 0; core < s->m->
getNumCores(); ++core) {
189 s->cstates1[core] = std::move(s->cstates2[core]);
193 for (uint32 socket = 0; socket < s->m->
getNumSockets(); ++socket) {
194 s->skstates1[socket] = std::move(s->skstates2[socket]);
198 s->sstate1 = std::move(s->sstate2);
201 if (pthread_mutex_unlock(&(s->CounterMutex)) != 0) std::cerr <<
"pthread_mutex_unlock failed\n";
uint32 getNumCores() const
Reads number of logical cores in the system.
Definition: cpucounters.cpp:5448
Definition: memoptest.cpp:24
uint64 getQPILinksPerSocket() const
Returns the number of Intel(r) Quick Path Interconnect(tm) links per socket.
Definition: cpucounters.h:1457
SystemCounterState getSystemCounterState()
Reads the counter state of the system.
Definition: cpucounters.cpp:4957
(Logical) core-wide counter state
Definition: cpucounters.h:2925
CoreCounterState getCoreCounterState(uint32 core)
Reads the counter state of a (logical) core.
Definition: cpucounters.cpp:5441
Socket-wide counter state.
Definition: cpucounters.h:2938
Definition: cpuasynchcounter.h:26
ErrorCode
Return codes (e.g. for program(..) method)
Definition: cpucounters.h:697
CPU Performance Monitor.
Definition: cpucounters.h:543
static PCM * getInstance()
Returns PCM object.
Definition: cpucounters.cpp:239
Main CPU counters header.
SocketCounterState getSocketCounterState(uint32 socket)
Reads the counter state of a socket.
Definition: cpucounters.cpp:5315
System-wide counter state.
Definition: cpucounters.h:2978
uint32 getNumSockets() const
Reads number of sockets (CPUs) in the system.
Definition: cpucounters.cpp:5458
SocketCounterState getSocketCounterState(uint32 socket)
Reads the counter state of a socket.
Definition: cpucounters.cpp:4240
CoreCounterState getCoreCounterState(uint32 core)
Reads the counter state of a (logical) core.
Definition: cpucounters.cpp:4248
int32 getSocketId(uint32 core_id) const
Determines socket of given core.
Definition: cpucounters.h:1453
void cleanup(const bool silent=false)
Cleanups resources and stops performance counting.
Definition: cpucounters.cpp:4112