Skip to content

Commit 0df446a

Browse files
soramichiopcm
authored andcommitted
Do not pass garbage values to perf_event_open (#98)
* Do not pass garbage values to perf_event_open * Use an array with a pre-defined size for regs
1 parent 324ae73 commit 0df446a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pcm-core.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C" {
6363
SystemCounterState SysBeforeState, SysAfterState;
6464
std::vector<CoreCounterState> BeforeState, AfterState;
6565
std::vector<SocketCounterState> DummySocketStates;
66-
EventSelectRegister regs[4];
66+
EventSelectRegister regs[PERF_MAX_COUNTERS];
6767
PCM::ExtendedCustomCoreEventDescription conf;
6868

6969
int pcm_c_build_core_event(uint8_t idx, const char * argv)
@@ -290,16 +290,12 @@ int main(int argc, char * argv[])
290290
int calibrated = PCM_CALIBRATION_INTERVAL - 2; // keeps track is the clock calibration needed
291291
unsigned int numberOfIterations = 0; // number of iterations
292292
string program = string(argv[0]);
293-
EventSelectRegister regs[4];
293+
EventSelectRegister regs[PERF_MAX_COUNTERS];
294294
PCM::ExtendedCustomCoreEventDescription conf;
295295
bool show_partial_core_output = false;
296296
std::bitset<MAX_CORES> ycores;
297297

298-
// Occasionally the memory is not properly nulled because counters appear to
299-
// be programmed even without given arguments so making really sure
300-
memset( &regs, 0, sizeof(regs) );
301-
302-
PCM * m = PCM::getInstance();
298+
PCM * m = PCM::getInstance();
303299

304300
conf.fixedCfg = NULL; // default
305301
conf.nGPCounters = m->getMaxCustomCoreEvents();

types.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ typedef signed int int32;
5050
#define IA32_PERFEVTSEL2_ADDR (IA32_PERFEVTSEL0_ADDR + 2)
5151
#define IA32_PERFEVTSEL3_ADDR (IA32_PERFEVTSEL0_ADDR + 3)
5252

53-
#define PERF_MAX_COUNTERS (11)
53+
#define PERF_MAX_FIXED_COUNTERS (3)
54+
#define PERF_MAX_CUSTOM_COUNTERS (8)
55+
#define PERF_MAX_COUNTERS (PERF_MAX_FIXED_COUNTERS + PERF_MAX_CUSTOM_COUNTERS)
5456

5557
#define IA32_DEBUGCTL (0x1D9)
5658

@@ -319,6 +321,8 @@ struct EventSelectRegister
319321
} fields;
320322
uint64 value;
321323
};
324+
325+
EventSelectRegister() : value(0) {}
322326
};
323327

324328

0 commit comments

Comments
 (0)