From b791df09bcb5fcf19d4f4cfe5ad4169d87503a74 Mon Sep 17 00:00:00 2001 From: "Dementiev, Roman" Date: Mon, 22 Sep 2025 13:20:28 +0200 Subject: [PATCH 1/5] PMU discovery: don't fail on error, print warning and continue Change-Id: If5930428706b7e11b2a3edc522f212ef6c13e99f --- src/uncore_pmu_discovery.cpp | 70 +++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/src/uncore_pmu_discovery.cpp b/src/uncore_pmu_discovery.cpp index 62e47516..af3992f5 100644 --- a/src/uncore_pmu_discovery.cpp +++ b/src/uncore_pmu_discovery.cpp @@ -15,35 +15,55 @@ UncorePMUDiscovery::UncorePMUDiscovery() { return; } - auto processTables = [this](const uint64 bar, const VSEC &) + auto processTables = [this](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 { + 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) { - // invalid entry - continue; + mmio_memcpy(unit.table, bar + (u + 1) * step, UncoreDiscoverySize * sizeof(uint64), true); + if (unit.table[0] == 0 && unit.table[1] == 0) + { + // 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 (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) From fb437c98fff4b1564725d172de7d000b680cca4f Mon Sep 17 00:00:00 2001 From: Roman Dementiev Date: Mon, 22 Sep 2025 13:45:58 +0200 Subject: [PATCH 2/5] Update src/uncore_pmu_discovery.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/uncore_pmu_discovery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uncore_pmu_discovery.cpp b/src/uncore_pmu_discovery.cpp index af3992f5..662f93fd 100644 --- a/src/uncore_pmu_discovery.cpp +++ b/src/uncore_pmu_discovery.cpp @@ -46,7 +46,7 @@ UncorePMUDiscovery::UncorePMUDiscovery() } boxPMUs.push_back(boxPMUMap); } - catch (std::exception & e) + catch (const std::exception & e) { std::cerr << "WARNING: enumeration of devices in UncorePMUDiscovery failed on bar 0x" << std::hex << bar << "\n" << e.what() << "\n" << From 7e6965ac85e9bdba0704225a8d033d7bb84a36b2 Mon Sep 17 00:00:00 2001 From: "Dementiev, Roman" Date: Tue, 23 Sep 2025 16:29:56 +0200 Subject: [PATCH 3/5] pcm-raw: enable >1 UBOX counters Change-Id: I81517f0145c04cf511c20c15c08a6d6c028b3dcb --- src/pcm-raw.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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; + } } } } From 0c39947adb55a77efaee809500ea08f35203b251 Mon Sep 17 00:00:00 2001 From: "Dementiev, Roman" Date: Fri, 26 Sep 2025 08:51:07 +0200 Subject: [PATCH 4/5] add PCM_DEBUG_PMU_DISCOVERY capability Change-Id: Ifce75a0aa806f6ebc1f40cf7cf45485c31115951 --- src/uncore_pmu_discovery.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/uncore_pmu_discovery.cpp b/src/uncore_pmu_discovery.cpp index 662f93fd..fd968ef4 100644 --- a/src/uncore_pmu_discovery.cpp +++ b/src/uncore_pmu_discovery.cpp @@ -15,9 +15,12 @@ UncorePMUDiscovery::UncorePMUDiscovery() { return; } - auto processTables = [this](const uint64 bar, const VSEC & vsec) + const auto debug = (safe_getenv("PCM_DEBUG_PMU_DISCOVERY") == std::string("1")); + + auto processTables = [this, &debug](const uint64 bar, const VSEC & vsec) { try { + DBG(2, "Uncore discovery detection. Reading from bar 0x", std::hex, bar, std::dec); constexpr size_t UncoreDiscoverySize = 3UL; union UncoreGlobalDiscovery { GlobalPMU pmu; @@ -26,6 +29,12 @@ UncorePMUDiscovery::UncorePMUDiscovery() UncoreGlobalDiscovery global; mmio_memcpy(global.table, bar, UncoreDiscoverySize * sizeof(uint64), true); globalPMUs.push_back(global.pmu); + if (debug) + { + 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]; @@ -36,8 +45,18 @@ UncorePMUDiscovery::UncorePMUDiscovery() 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; } From 35ffd18e68c43fa01b87616b8b88351b9542f97d Mon Sep 17 00:00:00 2001 From: "Dementiev, Roman" Date: Fri, 26 Sep 2025 10:51:10 +0200 Subject: [PATCH 5/5] print more fields GlobalPMU Change-Id: If448cb04e501d5b5b072a4175ec32eea8ecec241 --- src/uncore_pmu_discovery.h | 3 +++ 1 file changed, 3 insertions(+) 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"; } };