Skip to content

Commit

Permalink
Handle TPMI initilization for systems without access to MCFG tables e…
Browse files Browse the repository at this point in the history
….g. docker/VM
  • Loading branch information
ppalucki committed May 27, 2024
1 parent e9a1f39 commit 25d6977
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
37 changes: 21 additions & 16 deletions src/cpucounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TPMIHandle>(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<TPMIHandle>(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)
Expand Down
8 changes: 2 additions & 6 deletions src/pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 25d6977

Please sign in to comment.