From 25d69776c0d3cc8ce3666644c2161b6ac0b71358 Mon Sep 17 00:00:00 2001 From: Pawel Palucki Date: Mon, 27 May 2024 17:02:38 -0100 Subject: [PATCH] Handle TPMI initilization for systems without access to MCFG tables e.g. docker/VM --- src/cpucounters.cpp | 37 +++++++++++++++++++++---------------- src/pci.cpp | 8 ++------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/cpucounters.cpp b/src/cpucounters.cpp index 66b84b56..48a25844 100644 --- a/src/cpucounters.cpp +++ b/src/cpucounters.cpp @@ -1969,26 +1969,31 @@ void PCM::initUncoreObjects() initUncorePMUsDirect(); } - // TPMIHandle::setVerbose(true); - if (TPMIHandle::getNumInstances() == (size_t)num_sockets) - { - // std::cerr << "DEBUG: TPMIHandle::getNumInstances(): " << TPMIHandle::getNumInstances() << "\n"; - UFSStatus.resize(num_sockets); - for (uint32 s = 0; s < (uint32)num_sockets; ++s) - { - try { - TPMIHandle h(s, UFS_ID, UFS_FABRIC_CLUSTER_OFFSET * sizeof(uint64)); - // std::cerr << "DEBUG: Socket " << s << " dies: " << h.getNumEntries() << "\n"; - for (size_t die = 0; die < h.getNumEntries(); ++die) + //TPMIHandle::setVerbose(true); + try { + if (TPMIHandle::getNumInstances() == (size_t)num_sockets) + { + // std::cerr << "DEBUG: TPMIHandle::getNumInstances(): " << TPMIHandle::getNumInstances() << "\n"; + UFSStatus.resize(num_sockets); + for (uint32 s = 0; s < (uint32)num_sockets; ++s) + { + try { + TPMIHandle h(s, UFS_ID, UFS_FABRIC_CLUSTER_OFFSET * sizeof(uint64)); + // std::cerr << "DEBUG: Socket " << s << " dies: " << h.getNumEntries() << "\n"; + for (size_t die = 0; die < h.getNumEntries(); ++die) + { + const auto clusterOffset = extract_bits(h.read64(die), 0, 7); + UFSStatus[s].push_back(std::make_shared(s, UFS_ID, (clusterOffset + UFS_STATUS)* sizeof(uint64))); + } + } catch (std::exception & e) { - const auto clusterOffset = extract_bits(h.read64(die), 0, 7); - UFSStatus[s].push_back(std::make_shared(s, UFS_ID, (clusterOffset + UFS_STATUS)* sizeof(uint64))); + std::cerr << "ERROR: Could not open UFS TPMI register on socket " << s << ". Uncore frequency metrics will be unavailable. Excaption details: " << e.what() << "\n"; } - } catch (std::exception & ) - { - std::cerr << "ERROR: Could not open UFS TPMI register on socket " << s << ". Uncore frequency metrics will be unavailable.\n"; } } + } catch (std::exception & e) + { + std::cerr << "ERROR: Could not initialize TPMI. Uncore frequency metrics will be unavailable. Exception details: " << e.what() << "\n"; } for (uint32 s = 0; s < (uint32)num_sockets; ++s) diff --git a/src/pci.cpp b/src/pci.cpp index 3afcbbfd..f2e30306 100644 --- a/src/pci.cpp +++ b/src/pci.cpp @@ -477,7 +477,7 @@ PciHandleM::PciHandleM(uint32 bus_, uint32 device_, uint32 function_) : fd = handle; int mcfg_handle = PciHandle::openMcfgTable(); - if (mcfg_handle < 0) throw std::exception(); + if (mcfg_handle < 0) throw std::runtime_error("Cannot open any of /[pcm]/sys/firmware/acpi/tables/MCFG* files!"); int32 result = ::pread(mcfg_handle, (void *)&base_addr, sizeof(uint64), 44); @@ -569,11 +569,7 @@ void PciHandleMM::readMCFG() return; // already initialized int mcfg_handle = PciHandle::openMcfgTable(); - - if (mcfg_handle < 0) - { - throw std::exception(); - } + if (mcfg_handle < 0) throw std::runtime_error("cannot open any of /[pcm]/sys/firmware/acpi/tables/MCFG* files!"); ssize_t read_bytes = ::read(mcfg_handle, (void *)&mcfgHeader, sizeof(MCFGHeader));