Skip to content

Commit

Permalink
PCM_PRINT_TOPOLOGY env variable
Browse files Browse the repository at this point in the history
Change-Id: Ib2d2ba31164aa939ccb644984af5c4b4f025d80e
  • Loading branch information
rdementi committed Oct 20, 2021
1 parent edc6a90 commit b03657d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 56 deletions.
2 changes: 2 additions & 0 deletions ENVVAR_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
`PCM_NO_RDT=1` : don't use RDT metrics for a better interoperation with pqos utility (https://github.com/intel/intel-cmt-cat)

`PCM_USE_RESCTRL=1` : use Linux resctrl driver for RDT metrics

`PCM_PRINT_TOPOLOGY=1` : print detailed CPU topology
117 changes: 61 additions & 56 deletions cpucounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,62 +1173,6 @@ bool PCM::discoverSystemTopology()
//std::cout << std::flush;
fclose(f_cpuinfo);

// produce debug output similar to Intel MPI cpuinfo
#ifdef PCM_DEBUG_TOPOLOGY
std::cerr << "===== Processor identification =====\n";
std::cerr << "Processor Thread Id. Core Id. Tile Id. Package Id.\n";
std::map<uint32, std::vector<uint32> > os_id_by_core, os_id_by_tile, core_id_by_socket;
for(auto it = topology.begin(); it != topology.end(); ++it)
{
std::cerr << std::left << std::setfill(' ')
<< std::setw(16) << it->os_id
<< std::setw(16) << it->thread_id
<< std::setw(16) << it->core_id
<< std::setw(16) << it->tile_id
<< std::setw(16) << it->socket
<< "\n";
if(std::find(core_id_by_socket[it->socket].begin(), core_id_by_socket[it->socket].end(), it->core_id)
== core_id_by_socket[it->socket].end())
core_id_by_socket[it->socket].push_back(it->core_id);
// add socket offset to distinguish cores and tiles from different sockets
os_id_by_core[(it->socket << 15) + it->core_id].push_back(it->os_id);
os_id_by_tile[(it->socket << 15) + it->tile_id].push_back(it->os_id);
}
std::cerr << "===== Placement on packages =====\n";
std::cerr << "Package Id. Core Id. Processors\n";
for(auto pkg = core_id_by_socket.begin(); pkg != core_id_by_socket.end(); ++pkg)
{
auto core_id = pkg->second.begin();
std::cerr << std::left << std::setfill(' ') << std::setw(15) << pkg->first << *core_id;
for(++core_id; core_id != pkg->second.end(); ++core_id)
{
std::cerr << "," << *core_id;
}
std::cerr << "\n";
}
std::cerr << "\n===== Core/Tile sharing =====\n";
std::cerr << "Level Processors\nCore ";
for(auto core = os_id_by_core.begin(); core != os_id_by_core.end(); ++core)
{
auto os_id = core->second.begin();
std::cerr << "(" << *os_id;
for(++os_id; os_id != core->second.end(); ++os_id) {
std::cerr << "," << *os_id;
}
std::cerr << ")";
}
std::cerr << "\nTile / L2$ ";
for(auto core = os_id_by_tile.begin(); core != os_id_by_tile.end(); ++core)
{
auto os_id = core->second.begin();
std::cerr << "(" << *os_id;
for(++os_id; os_id != core->second.end(); ++os_id) {
std::cerr << "," << *os_id;
}
std::cerr << ")";
}
std::cerr << "\n";
#endif // PCM_DEBUG_TOPOLOGY
#elif defined(__FreeBSD__) || defined(__DragonFly__)

size_t size = sizeof(num_cores);
Expand Down Expand Up @@ -1326,6 +1270,67 @@ bool PCM::discoverSystemTopology()

#endif //end of ifdef _MSC_VER

// produce debug output similar to Intel MPI cpuinfo
#ifndef PCM_DEBUG_TOPOLOGY
if (safe_getenv("PCM_PRINT_TOPOLOGY") == "1")
#endif
{
std::cerr << "===== Processor identification =====\n";
std::cerr << "Processor Thread Id. Core Id. Tile Id. Package Id.\n";
std::map<uint32, std::vector<uint32> > os_id_by_core, os_id_by_tile, core_id_by_socket;
for (auto it = topology.begin(); it != topology.end(); ++it)
{
std::cerr << std::left << std::setfill(' ')
<< std::setw(16) << it->os_id
<< std::setw(16) << it->thread_id
<< std::setw(16) << it->core_id
<< std::setw(16) << it->tile_id
<< std::setw(16) << it->socket
<< "\n";
if (std::find(core_id_by_socket[it->socket].begin(), core_id_by_socket[it->socket].end(), it->core_id)
== core_id_by_socket[it->socket].end())
core_id_by_socket[it->socket].push_back(it->core_id);
// add socket offset to distinguish cores and tiles from different sockets
os_id_by_core[(it->socket << 15) + it->core_id].push_back(it->os_id);
os_id_by_tile[(it->socket << 15) + it->tile_id].push_back(it->os_id);
}
std::cerr << "===== Placement on packages =====\n";
std::cerr << "Package Id. Core Id. Processors\n";
for (auto pkg = core_id_by_socket.begin(); pkg != core_id_by_socket.end(); ++pkg)
{
auto core_id = pkg->second.begin();
std::cerr << std::left << std::setfill(' ') << std::setw(15) << pkg->first << *core_id;
for (++core_id; core_id != pkg->second.end(); ++core_id)
{
std::cerr << "," << *core_id;
}
std::cerr << "\n";
}
std::cerr << "\n===== Core/Tile sharing =====\n";
std::cerr << "Level Processors\nCore ";
for (auto core = os_id_by_core.begin(); core != os_id_by_core.end(); ++core)
{
auto os_id = core->second.begin();
std::cerr << "(" << *os_id;
for (++os_id; os_id != core->second.end(); ++os_id) {
std::cerr << "," << *os_id;
}
std::cerr << ")";
}
std::cerr << "\nTile / L2$ ";
for (auto core = os_id_by_tile.begin(); core != os_id_by_tile.end(); ++core)
{
auto os_id = core->second.begin();
std::cerr << "(" << *os_id;
for (++os_id; os_id != core->second.end(); ++os_id) {
std::cerr << "," << *os_id;
}
std::cerr << ")";
}
std::cerr << "\n";
std::cerr << "\n";
}

if(num_cores == 0) {
num_cores = (int32)topology.size();
}
Expand Down

0 comments on commit b03657d

Please sign in to comment.