Skip to content

Commit f92b55c

Browse files
ppaluckirdementi
authored andcommitted
Handle TPMI initilization for systems without access to MCFG tables e.g. docker/VM
1 parent cb95e32 commit f92b55c

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/cpucounters.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,26 +1969,31 @@ void PCM::initUncoreObjects()
19691969
initUncorePMUsDirect();
19701970
}
19711971

1972-
// TPMIHandle::setVerbose(true);
1973-
if (TPMIHandle::getNumInstances() == (size_t)num_sockets)
1974-
{
1975-
// std::cerr << "DEBUG: TPMIHandle::getNumInstances(): " << TPMIHandle::getNumInstances() << "\n";
1976-
UFSStatus.resize(num_sockets);
1977-
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
1978-
{
1979-
try {
1980-
TPMIHandle h(s, UFS_ID, UFS_FABRIC_CLUSTER_OFFSET * sizeof(uint64));
1981-
// std::cerr << "DEBUG: Socket " << s << " dies: " << h.getNumEntries() << "\n";
1982-
for (size_t die = 0; die < h.getNumEntries(); ++die)
1972+
//TPMIHandle::setVerbose(true);
1973+
try {
1974+
if (TPMIHandle::getNumInstances() == (size_t)num_sockets)
1975+
{
1976+
// std::cerr << "DEBUG: TPMIHandle::getNumInstances(): " << TPMIHandle::getNumInstances() << "\n";
1977+
UFSStatus.resize(num_sockets);
1978+
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
1979+
{
1980+
try {
1981+
TPMIHandle h(s, UFS_ID, UFS_FABRIC_CLUSTER_OFFSET * sizeof(uint64));
1982+
// std::cerr << "DEBUG: Socket " << s << " dies: " << h.getNumEntries() << "\n";
1983+
for (size_t die = 0; die < h.getNumEntries(); ++die)
1984+
{
1985+
const auto clusterOffset = extract_bits(h.read64(die), 0, 7);
1986+
UFSStatus[s].push_back(std::make_shared<TPMIHandle>(s, UFS_ID, (clusterOffset + UFS_STATUS)* sizeof(uint64)));
1987+
}
1988+
} catch (std::exception & e)
19831989
{
1984-
const auto clusterOffset = extract_bits(h.read64(die), 0, 7);
1985-
UFSStatus[s].push_back(std::make_shared<TPMIHandle>(s, UFS_ID, (clusterOffset + UFS_STATUS)* sizeof(uint64)));
1990+
std::cerr << "ERROR: Could not open UFS TPMI register on socket " << s << ". Uncore frequency metrics will be unavailable. Excaption details: " << e.what() << "\n";
19861991
}
1987-
} catch (std::exception & )
1988-
{
1989-
std::cerr << "ERROR: Could not open UFS TPMI register on socket " << s << ". Uncore frequency metrics will be unavailable.\n";
19901992
}
19911993
}
1994+
} catch (std::exception & e)
1995+
{
1996+
std::cerr << "ERROR: Could not initialize TPMI. Uncore frequency metrics will be unavailable. Exception details: " << e.what() << "\n";
19921997
}
19931998

19941999
for (uint32 s = 0; s < (uint32)num_sockets; ++s)

src/pci.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ PciHandleM::PciHandleM(uint32 bus_, uint32 device_, uint32 function_) :
477477
fd = handle;
478478

479479
int mcfg_handle = PciHandle::openMcfgTable();
480-
if (mcfg_handle < 0) throw std::exception();
480+
if (mcfg_handle < 0) throw std::runtime_error("Cannot open any of /[pcm]/sys/firmware/acpi/tables/MCFG* files!");
481481

482482
int32 result = ::pread(mcfg_handle, (void *)&base_addr, sizeof(uint64), 44);
483483

@@ -569,11 +569,7 @@ void PciHandleMM::readMCFG()
569569
return; // already initialized
570570

571571
int mcfg_handle = PciHandle::openMcfgTable();
572-
573-
if (mcfg_handle < 0)
574-
{
575-
throw std::exception();
576-
}
572+
if (mcfg_handle < 0) throw std::runtime_error("cannot open any of /[pcm]/sys/firmware/acpi/tables/MCFG* files!");
577573

578574
ssize_t read_bytes = ::read(mcfg_handle, (void *)&mcfgHeader, sizeof(MCFGHeader));
579575

0 commit comments

Comments
 (0)