-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPerformanceCounter.h
83 lines (67 loc) · 2.49 KB
/
PerformanceCounter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* PerformanceCounter.h
*
* Created on: 25/mag/2011
* Author: paolo
*/
#ifndef PERFORMANCECOUNTER_H_
#define PERFORMANCECOUNTER_H_
#include "Processor.h"
#include "MSRObject.h"
class PerformanceCounter {
protected:
//On Family 11h BKDG Manual (doc. 41256 Rev. 3.00) see chapter 3.12, page 224 for reference
PROCESSORMASK cpuMask;
char perfCounterSlot[MAX_CORES];
unsigned char slot;
unsigned char maxslots;
unsigned short int eventSelect; //Event selection
unsigned char counterMask; //Counter Mask
unsigned char unitMask; //Usually set to 0, can be used to select a sub-event
bool invertCntMask; //Invert counter mask, check reference for explanation
bool enableAPICInterrupt; //Enables an APIC Interrupt when a counter overflows
bool edgeDetect; //0 means Level Detect, 1 means Edge Detect
bool countOsMode; //Counts events happening in OS Mode
bool countUserMode; //Counts events happening in User Mode
unsigned int pesrReg; //Base PESR Register for the CPU
unsigned int percReg; //Base PERC Register for the CPU
unsigned char offset; //Register offset from the base register
bool enabled; //Only used in case of fetch() method. Do not use it elsewhere
unsigned int getPESRReg(unsigned char slot);
unsigned int getPERCReg(unsigned char slot);
MSRObject *snapshotRegister;
public:
PerformanceCounter(PROCESSORMASK cpuMask, DWORD slot, DWORD maxslots);
bool program ();
bool fetch(DWORD cpuIndex);
bool enable ();
bool disable ();
bool takeSnapshot ();
uint64_t getCounter (DWORD cpuIndex);
unsigned int findAvailableSlot ();
unsigned int findFreeSlot ();
virtual ~PerformanceCounter();
bool getEnabled () const;
bool getCountUserMode() const;
unsigned char getCounterMask() const;
PROCESSORMASK getCpuMask() const;
bool getEdgeDetect() const;
bool getEnableAPICInterrupt() const;
unsigned short int getEventSelect() const;
bool getInvertCntMask() const;
unsigned char getSlot() const;
unsigned char getUnitMask() const;
void setCountUserMode(bool countUserMode);
void setCounterMask(unsigned char counterMask);
void setCpuMask(PROCESSORMASK cpuMask);
void setEdgeDetect(bool edgeDetect);
void setEnableAPICInterrupt(bool enableAPICInterrupt);
void setEventSelect(unsigned short int eventSelect);
void setInvertCntMask(bool invertCntMask);
void setSlot(unsigned char slot);
void setUnitMask(unsigned char unitMask);
bool getCountOsMode() const;
void setCountOsMode(bool countOsMode);
void setMaxSlots(unsigned char maxslots);
};
#endif /* PERFORMANCECOUNTER_H_ */