diff --git a/src/pcm-raw.cpp b/src/pcm-raw.cpp index a92751e3..8bfdd02b 100644 --- a/src/pcm-raw.cpp +++ b/src/pcm-raw.cpp @@ -1877,10 +1877,11 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs, } else if (type == "ubox") { + const auto numPMUs = (uint32)m->getMaxNumOfUncorePMUs(PCM::UBOX_PMU_ID); choose(outputType, - [&]() { printUncoreRows(nullptr, 1U, ""); }, - [&]() { printUncoreRows(nullptr, 1U, type); }, - [&]() { printUncoreRows([](const uint32, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreCounter(PCM::UBOX_PMU_ID, 0, i, before, after); }, 1U, + [&]() { printUncoreRows(nullptr, numPMUs, ""); }, + [&]() { printUncoreRows(nullptr, numPMUs, type); }, + [&]() { printUncoreRows([](const uint32 u, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreCounter(PCM::UBOX_PMU_ID, u, i, before, after); }, numPMUs, "UncoreClocks", [](const uint32, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreClocks(before, after); }); }); } @@ -2260,14 +2261,17 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, [&fixedEvents]() { cout << "UncoreClocks" << fixedEvents[0].second << separator; }, [&]() { cout << getUncoreClocks(BeforeUncoreState[s], AfterUncoreState[s]) << separator; }); } - int i = 0; - for (auto& event : events) + for (uint32 u = 0; u < m->getMaxNumOfUncorePMUs(PCM::UBOX_PMU_ID); ++u) { - choose(outputType, - [s]() { cout << "SKT" << s << separator; }, - [&event, &i]() { if (event.second.empty()) cout << "UBOXEvent" << i << separator; else cout << event.second << separator; }, - [&]() { cout << getUncoreCounter(PCM::UBOX_PMU_ID, 0, i, BeforeUncoreState[s], AfterUncoreState[s]) << separator; }); - ++i; + int i = 0; + for (auto& event : events) + { + choose(outputType, + [s, u]() { cout << "SKT" << s << "U" << u << separator; }, + [&event, &i]() { if (event.second.empty()) cout << "UBOXEvent" << i << separator; else cout << event.second << separator; }, + [&]() { cout << getUncoreCounter(PCM::UBOX_PMU_ID, u, i, BeforeUncoreState[s], AfterUncoreState[s]) << separator; }); + ++i; + } } } } diff --git a/src/uncore_pmu_discovery.cpp b/src/uncore_pmu_discovery.cpp index 62e47516..fd968ef4 100644 --- a/src/uncore_pmu_discovery.cpp +++ b/src/uncore_pmu_discovery.cpp @@ -15,35 +15,74 @@ UncorePMUDiscovery::UncorePMUDiscovery() { return; } - auto processTables = [this](const uint64 bar, const VSEC &) + const auto debug = (safe_getenv("PCM_DEBUG_PMU_DISCOVERY") == std::string("1")); + + auto processTables = [this, &debug](const uint64 bar, const VSEC & vsec) { - constexpr size_t UncoreDiscoverySize = 3UL; - union UncoreGlobalDiscovery { - GlobalPMU pmu; - uint64 table[UncoreDiscoverySize]; - }; - UncoreGlobalDiscovery global; - mmio_memcpy(global.table, bar, UncoreDiscoverySize * sizeof(uint64), true); - globalPMUs.push_back(global.pmu); - union UncoreUnitDiscovery { - BoxPMU pmu; - uint64 table[UncoreDiscoverySize]; - }; - UncoreUnitDiscovery unit; - const auto step = global.pmu.stride * 8; - BoxPMUMap boxPMUMap; - for (size_t u = 0; u < global.pmu.maxUnits; ++u) - { - mmio_memcpy(unit.table, bar + (u+1) * step, UncoreDiscoverySize * sizeof(uint64), true); - if (unit.table[0] == 0 && unit.table[1] == 0) + try { + DBG(2, "Uncore discovery detection. Reading from bar 0x", std::hex, bar, std::dec); + constexpr size_t UncoreDiscoverySize = 3UL; + union UncoreGlobalDiscovery { + GlobalPMU pmu; + uint64 table[UncoreDiscoverySize]; + }; + UncoreGlobalDiscovery global; + mmio_memcpy(global.table, bar, UncoreDiscoverySize * sizeof(uint64), true); + globalPMUs.push_back(global.pmu); + if (debug) { - // invalid entry - continue; + std::cerr << "Read global.pmu from 0x" << std::hex << bar << std::dec << "\n"; + global.pmu.print(); + std::cout.flush(); + } + union UncoreUnitDiscovery { + BoxPMU pmu; + uint64 table[UncoreDiscoverySize]; + }; + UncoreUnitDiscovery unit; + const auto step = global.pmu.stride * 8; + BoxPMUMap boxPMUMap; + for (size_t u = 0; u < global.pmu.maxUnits; ++u) + { + mmio_memcpy(unit.table, bar + (u + 1) * step, UncoreDiscoverySize * sizeof(uint64), true); + if (debug) + { + std::cerr << "Read unit.pmu " << u << " from 0x" << std::hex << (bar + (u + 1) * step) << std::dec << "\n"; + unit.pmu.print(); + std::cout.flush(); + } + if (unit.table[0] == 0 && unit.table[1] == 0) + { + if (debug) + { + std::cerr << "Invalid entry\n"; + } + // invalid entry + continue; + } + // unit.pmu.print(); + boxPMUMap[unit.pmu.boxType].push_back(unit.pmu); } - // unit.pmu.print(); - boxPMUMap[unit.pmu.boxType].push_back(unit.pmu); + boxPMUs.push_back(boxPMUMap); + } + catch (const std::exception & e) + { + std::cerr << "WARNING: enumeration of devices in UncorePMUDiscovery failed on bar 0x" + << std::hex << bar << "\n" << e.what() << "\n" << + " CAP_ID: 0x" << vsec.fields.cap_id << "\n" << + " CAP_VERSION: 0x" << vsec.fields.cap_version << "\n" << + " CAP_NEXT: 0x" << vsec.fields.cap_next << "\n" << + " VSEC_ID: 0x" << vsec.fields.vsec_id << "\n" << + " VSEC_VERSION: 0x" << vsec.fields.vsec_version << "\n" << + " VSEC_LENGTH: 0x" << vsec.fields.vsec_length << "\n" << + " ENTRY_ID: 0x" << vsec.fields.entryID << "\n" << + " NUM_ENTRIES: 0x" << vsec.fields.NumEntries << "\n" << + " ENTRY_SIZE: 0x" << vsec.fields.EntrySize << "\n" << + " TBIR: 0x" << vsec.fields.tBIR << "\n" << + " ADDRESS: 0x" << vsec.fields.Address << + std::dec << "\n"; + std::cerr << "INFO: discovery has " << boxPMUs.size() << " entries\n"; } - boxPMUs.push_back(boxPMUMap); }; try { processDVSEC([](const VSEC & vsec) diff --git a/src/uncore_pmu_discovery.h b/src/uncore_pmu_discovery.h index 9d9f089d..7caddf7e 100644 --- a/src/uncore_pmu_discovery.h +++ b/src/uncore_pmu_discovery.h @@ -92,6 +92,9 @@ class UncorePMUDiscovery " globalCtrl: 0x" << std::hex << globalCtrlAddr; UncorePMUDiscovery::printHelper((accessTypeEnum)accessType, globalCtrlAddr); std::cout << " stride: " << std::dec << stride + << " maxUnits: " << maxUnits + << " statusOffset: " << statusOffset + << " numStatus: " << numStatus << "\n"; } };