Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle gracefully TPMI initilization fail (with missing MCFG tables) #749

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading