diff --git a/src/cpucounters.cpp b/src/cpucounters.cpp index a937ccff..9e7158eb 100644 --- a/src/cpucounters.cpp +++ b/src/cpucounters.cpp @@ -5721,6 +5721,16 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile { programCXLDP(events64); } + else if (strToUncorePMUID(type) != INVALID_PMU_ID) + { + const auto pmu_id = strToUncorePMUID(type); + programUncorePMUs(pmu_id, [&events64, &events, &pmu_id](UncorePMU& pmu) + { + uint64 * eventsIter = (uint64 *)events64; + pmu.initFreeze(UNC_PMON_UNIT_CTL_FRZ_EN); + PCM::program(pmu, eventsIter, eventsIter + (std::min)(events.programmable.size(), (size_t)ServerUncoreCounterState::maxCounters), UNC_PMON_UNIT_CTL_FRZ_EN); + }); + } else { std::cerr << "ERROR: unrecognized PMU type \"" << type << "\" when trying to program PMUs.\n"; @@ -6564,9 +6574,7 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket) uint32 refCore = socketRefCore[socket]; TemporalThreadAffinity tempThreadAffinity(refCore); - readUncoreCounterValues(result, socket, CBO_PMU_ID); - - readUncoreCounterValues(result, socket, MDF_PMU_ID); + readUncoreCounterValues(result, socket); for (uint32 stack = 0; socket < iioPMUs.size() && stack < iioPMUs[socket].size() && stack < ServerUncoreCounterState::maxIIOStacks; ++stack) { @@ -6586,11 +6594,8 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket) } } - readUncoreCounterValues(result, socket, UBOX_PMU_ID); result.UncClocks = getUncoreClocks(socket); - readUncoreCounterValues(result, socket, PCU_PMU_ID); - for (size_t p = 0; p < getNumCXLPorts(socket); ++p) { for (int i = 0; i < ServerUncoreCounterState::maxCounters && socket < cxlPMUs.size() && size_t(i) < cxlPMUs[socket][p].first.size(); ++i) diff --git a/src/cpucounters.h b/src/cpucounters.h index 7bf216a9..386d380f 100644 --- a/src/cpucounters.h +++ b/src/cpucounters.h @@ -651,6 +651,15 @@ class PCM_API PCM UBOX_PMU_ID, INVALID_PMU_ID }; +private: + std::unordered_map strToUncorePMUID_ { + }; +public: + UncorePMUIDs strToUncorePMUID(const std::string & type) const + { + const auto iter = strToUncorePMUID_.find(type); + return (iter == strToUncorePMUID_.end()) ? INVALID_PMU_ID : (UncorePMUIDs)iter->second; + } private: typedef std::unordered_map UncorePMUMapType; // socket -> die -> pmu map -> pmu ref array @@ -714,7 +723,7 @@ class PCM_API PCM } template - void readUncoreCounterValues(T& result, const size_t socket, const int pmu_id) const + void readUncoreCounterValues(T& result, const size_t socket) const { if (socket < uncorePMUs.size()) { @@ -723,9 +732,9 @@ class PCM_API PCM { TemporalThreadAffinity tempThreadAffinity(socketRefCore[socket]); // speedup trick for Linux - const auto& pmuIter = uncorePMUs[socket][die].find(pmu_id); - if (pmuIter != uncorePMUs[socket][die].end()) + for (auto pmuIter = uncorePMUs[socket][die].begin(); pmuIter != uncorePMUs[socket][die].end(); ++pmuIter) { + const auto & pmu_id = pmuIter->first; result.Counters[die][pmu_id].resize(pmuIter->second.size()); for (size_t unit = 0; unit < pmuIter->second.size(); ++unit) { diff --git a/src/pcm-raw.cpp b/src/pcm-raw.cpp index 47b9f78c..cf94734f 100644 --- a/src/pcm-raw.cpp +++ b/src/pcm-raw.cpp @@ -1239,6 +1239,8 @@ uint32 numTMAEvents(PCM* m) return (m->isHWTMAL2Supported() ? 8 : 4); } +uint32 pmu_type = PCM::INVALID_PMU_ID; + void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs, PCM* m, SystemCounterState& SysBeforeState, SystemCounterState& SysAfterState, @@ -1719,6 +1721,14 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs, [&]() { printUncoreRows([](const uint32 u, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getCXLDPCounter(u, i, before, after); }, ServerUncoreCounterState::maxCXLPorts, "CXLDP"); }); } + else if ((pmu_type = m->strToUncorePMUID(type)) != PCM::INVALID_PMU_ID) + { + choose(outputType, + [&]() { printUncoreRows(nullptr, (uint32) m->getMaxNumOfUncorePMUs(pmu_type), type); }, + [&]() { printUncoreRows(nullptr, (uint32) m->getMaxNumOfUncorePMUs(pmu_type), type); }, + [&]() { printUncoreRows([](const uint32 u, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreCounter(pmu_type, u, i, before, after); }, (uint32)m->getMaxNumOfUncorePMUs(pmu_type), type); + }); + } else { std::cerr << "ERROR: unrecognized PMU type \"" << type << "\"\n"; @@ -2150,6 +2160,24 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs, } } } + else if ((pmu_type = m->strToUncorePMUID(type)) != PCM::INVALID_PMU_ID) + { + for (uint32 s = 0; s < m->getNumSockets(); ++s) + { + for (uint32 unit = 0; unit < m->getMaxNumOfUncorePMUs(pmu_type); ++unit) + { + int i = 0; + for (auto& event : events) + { + choose(outputType, + [s, unit, &type]() { cout << "SKT" << s << type << unit << separator; }, + [&event, &i, &type]() { if (event.second.empty()) cout << type << "Event" << i << separator; else cout << event.second << separator; }, + [&]() { cout << getUncoreCounter(pmu_type, unit, i, BeforeUncoreState[s], AfterUncoreState[s]) << separator; }); + ++i; + } + } + } + } else { std::cerr << "ERROR: unrecognized PMU type \"" << type << "\"\n"; diff --git a/src/uncore_pmu_discovery.h b/src/uncore_pmu_discovery.h index c8766c90..dc050fa2 100644 --- a/src/uncore_pmu_discovery.h +++ b/src/uncore_pmu_discovery.h @@ -37,6 +37,37 @@ class UncorePMUDiscovery } return "unknown"; }; + union PCICFGAddress + { + uint64 raw; + struct { + uint64 offset:12; + uint64 function:3; + uint64 device:5; + uint64 bus:8; + } fields; + std::string getStr() const + { + std::ostringstream out(std::ostringstream::out); + out << std::hex << fields.bus << ":" << fields.device << "." << fields.function << "@" << fields.offset; + out << std::dec; + return out.str(); + } + }; + static void printHelper(const accessTypeEnum accessType, const uint64 addr) + { + if (accessType == PCICFG) + { + PCICFGAddress Addr; + Addr.raw = addr; + std::cout << " (" << Addr.getStr() << ")"; + } + else + { + std::cout << " (-)"; + } + std::cout << " with access type " << std::dec << accessTypeStr(accessType); + } protected: struct GlobalPMU { @@ -53,9 +84,9 @@ class UncorePMUDiscovery { std::cout << "global PMU " << " of type " << std::dec << type << - " globalCtrl: 0x" << std::hex << globalCtrlAddr << - " with access type " << std::dec << accessTypeStr(accessType) << - " stride: " << std::dec << stride + " globalCtrl: 0x" << std::hex << globalCtrlAddr; + UncorePMUDiscovery::printHelper((accessTypeEnum)accessType, globalCtrlAddr); + std::cout << " stride: " << std::dec << stride << "\n"; } }; @@ -77,9 +108,10 @@ class UncorePMUDiscovery std::cout << "unit PMU " << " of type " << std::dec << boxType << " ID " << boxID << - " box ctrl: 0x" << std::hex << boxCtrlAddr << - " width " << std::dec << bitWidth << - " with access type " << accessTypeStr(accessType) << + " box ctrl: 0x" << std::hex << boxCtrlAddr; + UncorePMUDiscovery::printHelper((accessTypeEnum)accessType, boxCtrlAddr); + std::cout << + " width " << bitWidth << " numRegs " << numRegs << " ctrlOffset " << ctrlOffset << " ctrOffset " << ctrOffset <<