Skip to content

Commit c5f21f9

Browse files
authored
Merge pull request #261 from intel-innersource/rdementi-2022-08-23
Rdementi 2022 08 23
2 parents 7e80d61 + 9b4fbc8 commit c5f21f9

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/cpucounters.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,10 +3264,11 @@ PCM::ErrorCode PCM::programCoreCounters(const int i /* core */,
32643264
}
32653265
}
32663266
EventSelectRegister reg;
3267-
setEvent(reg, eventSel, umask);
3267+
reg.fields.event_select = eventSel;
3268+
reg.fields.umask = umask;
32683269
perf_event_attr e = PCM_init_perf_event_attr();
32693270
e.type = PERF_TYPE_RAW;
3270-
e.config = (1ULL << 63ULL) + reg.value;
3271+
e.config = reg.value;
32713272
// std::cerr << "Programming perf event " << std::hex << e.config << "\n";
32723273
if (programPerfEvent(e, event.second, std::string("event ") + event.first + " " + eventDesc) == false)
32733274
{
@@ -4288,6 +4289,7 @@ void PCM::readPerfData(uint32 core, std::vector<uint64> & outData)
42884289
}
42894290
uint64 data[1 + PERF_MAX_COUNTERS];
42904291
const int32 bytes2read = sizeof(uint64) * (1 + num_counters);
4292+
assert(num_counters <= PERF_MAX_COUNTERS);
42914293
int result = ::read(perfEventHandle[core][leader], data, bytes2read);
42924294
// data layout: nr counters; counter 0, counter 1, counter 2,...
42934295
if (result != bytes2read)
@@ -4300,7 +4302,17 @@ void PCM::readPerfData(uint32 core, std::vector<uint64> & outData)
43004302
std::cerr << "Number of counters read from perf is wrong. Elements read: " << data[0] << "\n";
43014303
}
43024304
else
4303-
{ // copy all counters, they start from position 1 in data
4305+
{
4306+
/*
4307+
if (core == 0)
4308+
{
4309+
std::unique_lock<std::mutex> _(instanceCreationMutex);
4310+
std::cerr << "DEBUG: perf raw: " << std::dec;
4311+
for (uint32 p=0; p < (1 + num_counters) ; ++p) std::cerr << data[p] << " ";
4312+
std::cerr << "\n";
4313+
}
4314+
*/
4315+
// copy all counters, they start from position 1 in data
43044316
std::copy((data + 1), (data + 1) + data[0], outData.begin());
43054317
}
43064318
};
@@ -4385,7 +4397,7 @@ void BasicCounterState::readAndAggregate(std::shared_ptr<SafeMsrHandle> msr)
43854397
cBackendBoundSlots = perfData[m->perfTopDownPos[PCM::PERF_TOPDOWN_BACKEND_POS]];
43864398
cRetiringSlots = perfData[m->perfTopDownPos[PCM::PERF_TOPDOWN_RETIRING_POS]];
43874399
cAllSlotsRaw = perfData[m->perfTopDownPos[PCM::PERF_TOPDOWN_SLOTS_POS]];
4388-
// if (core_id == 0) std::cout << "DEBUG: "<< cAllSlotsRaw << " " << cFrontendBoundSlots << " " << cBadSpeculationSlots << " " << cBackendBoundSlots << " " << cRetiringSlots << std::endl;
4400+
// if (core_id == 0) std::cout << "DEBUG: All: "<< cAllSlotsRaw << " FE: " << cFrontendBoundSlots << " BAD-SP: " << cBadSpeculationSlots << " BE: " << cBackendBoundSlots << " RET: " << cRetiringSlots << std::endl;
43894401
}
43904402
}
43914403
else

src/cpucounters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ class PCM_API PCM
870870
PERF_TOPDOWN_RETIRING_POS = PERF_TOPDOWN_SLOTS_POS + 4
871871
};
872872

873-
std::unordered_map<int, int> perfTopDownPos;
873+
std::array<int, (PERF_TOPDOWN_RETIRING_POS + 1)> perfTopDownPos;
874874

875875
enum {
876876
PERF_GROUP_LEADER_COUNTER = PERF_INST_RETIRED_POS,

0 commit comments

Comments
 (0)