16 #ifndef WIDTH_EXTENDER_HEADER_
17 #define WIDTH_EXTENDER_HEADER_
34 DWORD WINAPI WatchDogProc(LPVOID state);
36 void * WatchDogProc(
void * state);
44 virtual uint64 operator() () = 0;
56 msr->read(msr_addr,&value);
65 uint64 operator() () {
return clientBW->getImcReads(); }
72 uint64 operator() () {
return clientBW->getImcWrites(); }
79 uint64 operator() () {
return clientBW->getIoRequests(); }
88 pthread_t UpdateThread;
89 pthread_mutex_t CounterMutex;
93 uint64 extended_value;
94 uint64 last_raw_value;
99 uint64 internal_read()
101 if (
this==NULL)
return 0;
102 uint64 result = 0, new_raw_value = 0;
104 WaitForSingleObject(CounterMutex,INFINITE);
106 pthread_mutex_lock(&CounterMutex);
108 new_raw_value = (*raw_counter)();
109 if(new_raw_value < last_raw_value)
111 extended_value += ((1ULL<<32ULL)-last_raw_value) + new_raw_value;
115 extended_value += (new_raw_value-last_raw_value);
118 last_raw_value = new_raw_value;
120 result = extended_value;
122 ReleaseMutex(CounterMutex);
124 pthread_mutex_unlock(&CounterMutex);
132 last_raw_value = (*raw_counter)();
133 extended_value = last_raw_value;
136 CounterMutex = CreateMutex(NULL,FALSE,NULL);
137 UpdateThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)WatchDogProc,
this,0,NULL);
139 pthread_mutex_init(&CounterMutex, NULL);
140 pthread_create(&UpdateThread, NULL, WatchDogProc,
this);
146 TerminateThread(UpdateThread,0);
147 CloseHandle(UpdateThread);
148 CloseHandle(CounterMutex);
150 pthread_cancel(UpdateThread);
151 pthread_mutex_destroy(&CounterMutex);
153 if(raw_counter)
delete raw_counter;
158 return internal_read();
Definition: width_extender.h:42
Definition: width_extender.h:68
Interface to access client bandwidth counters.
Main CPU counters header.
Definition: width_extender.h:75
Definition: width_extender.h:39
Definition: client_bw.h:40
Definition: width_extender.h:61
Definition: width_extender.h:48