Skip to content

Commit 0be6ac8

Browse files
authored
Merge pull request #166 from intel-innersource/rdementi/edp-compat2
rdementi/edp compat
2 parents 95e961c + 64c587c commit 0be6ac8

File tree

6 files changed

+192
-83
lines changed

6 files changed

+192
-83
lines changed

scripts/convert_edp_list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22

3-
cat "$1" | sed '0,/^#.*group/d' | head -n -1 | dos2unix
3+
cat "$1" | sed '0,/^#.*[gG][rR][oO][uU][pP]/d' | head -n -1 | dos2unix
44

src/cpucounters.cpp

Lines changed: 94 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ bool PCM::detectModel()
527527

528528
pcm_cpuid(7, 0, cpuinfo);
529529

530+
std::cerr << "\n===== Processor information =====\n";
531+
530532
#ifdef __linux__
531533
auto checkLinuxCpuinfoFlag = [](const std::string& flag) -> bool
532534
{
@@ -1279,69 +1281,6 @@ bool PCM::discoverSystemTopology()
12791281

12801282
#endif //end of ifdef _MSC_VER
12811283

1282-
// produce debug output similar to Intel MPI cpuinfo
1283-
#ifndef PCM_DEBUG_TOPOLOGY
1284-
if (safe_getenv("PCM_PRINT_TOPOLOGY") == "1")
1285-
#endif
1286-
{
1287-
std::cerr << "===== Processor identification =====\n";
1288-
std::cerr << "Processor Thread Id. Core Id. Tile Id. Package Id. Core Type. Native CPU Model.\n";
1289-
std::map<uint32, std::vector<uint32> > os_id_by_core, os_id_by_tile, core_id_by_socket;
1290-
for (auto it = topology.begin(); it != topology.end(); ++it)
1291-
{
1292-
std::cerr << std::left << std::setfill(' ')
1293-
<< std::setw(16) << it->os_id
1294-
<< std::setw(16) << it->thread_id
1295-
<< std::setw(16) << it->core_id
1296-
<< std::setw(16) << it->tile_id
1297-
<< std::setw(16) << it->socket
1298-
<< std::setw(16) << it->getCoreTypeStr()
1299-
<< std::setw(16) << it->native_cpu_model
1300-
<< "\n";
1301-
if (std::find(core_id_by_socket[it->socket].begin(), core_id_by_socket[it->socket].end(), it->core_id)
1302-
== core_id_by_socket[it->socket].end())
1303-
core_id_by_socket[it->socket].push_back(it->core_id);
1304-
// add socket offset to distinguish cores and tiles from different sockets
1305-
os_id_by_core[(it->socket << 15) + it->core_id].push_back(it->os_id);
1306-
os_id_by_tile[(it->socket << 15) + it->tile_id].push_back(it->os_id);
1307-
}
1308-
std::cerr << "===== Placement on packages =====\n";
1309-
std::cerr << "Package Id. Core Id. Processors\n";
1310-
for (auto pkg = core_id_by_socket.begin(); pkg != core_id_by_socket.end(); ++pkg)
1311-
{
1312-
auto core_id = pkg->second.begin();
1313-
std::cerr << std::left << std::setfill(' ') << std::setw(15) << pkg->first << *core_id;
1314-
for (++core_id; core_id != pkg->second.end(); ++core_id)
1315-
{
1316-
std::cerr << "," << *core_id;
1317-
}
1318-
std::cerr << "\n";
1319-
}
1320-
std::cerr << "\n===== Core/Tile sharing =====\n";
1321-
std::cerr << "Level Processors\nCore ";
1322-
for (auto core = os_id_by_core.begin(); core != os_id_by_core.end(); ++core)
1323-
{
1324-
auto os_id = core->second.begin();
1325-
std::cerr << "(" << *os_id;
1326-
for (++os_id; os_id != core->second.end(); ++os_id) {
1327-
std::cerr << "," << *os_id;
1328-
}
1329-
std::cerr << ")";
1330-
}
1331-
std::cerr << "\nTile / L2$ ";
1332-
for (auto core = os_id_by_tile.begin(); core != os_id_by_tile.end(); ++core)
1333-
{
1334-
auto os_id = core->second.begin();
1335-
std::cerr << "(" << *os_id;
1336-
for (++os_id; os_id != core->second.end(); ++os_id) {
1337-
std::cerr << "," << *os_id;
1338-
}
1339-
std::cerr << ")";
1340-
}
1341-
std::cerr << "\n";
1342-
std::cerr << "\n";
1343-
}
1344-
13451284
if(num_cores == 0) {
13461285
num_cores = (int32)topology.size();
13471286
}
@@ -2091,6 +2030,10 @@ class CoreTaskQueue
20912030
}
20922031
};
20932032

2033+
std::ofstream* PCM::outfile = nullptr; // output file stream
2034+
std::streambuf* PCM::backup_ofile = nullptr; // backup of original output = cout
2035+
std::streambuf* PCM::backup_ofile_cerr = nullptr; // backup of original output = cerr
2036+
20942037
PCM::PCM() :
20952038
cpu_family(-1),
20962039
cpu_model(-1),
@@ -2145,8 +2088,6 @@ PCM::PCM() :
21452088
forceRTMAbortMode(false),
21462089
mode(INVALID_MODE),
21472090
canUsePerf(false),
2148-
outfile(NULL),
2149-
backup_ofile(NULL),
21502091
run_state(1),
21512092
needToRestoreNMIWatchdog(false)
21522093
{
@@ -2182,8 +2123,19 @@ PCM::PCM() :
21822123

21832124
showSpecControlMSRs();
21842125

2126+
#ifndef PCM_DEBUG_TOPOLOGY
2127+
if (safe_getenv("PCM_PRINT_TOPOLOGY") == "1")
2128+
#endif
2129+
{
2130+
printDetailedSystemTopology();
2131+
}
2132+
21852133
initEnergyMonitoring();
21862134

2135+
#ifndef PCM_SILENT
2136+
std::cerr << "\n";
2137+
#endif
2138+
21872139
initUncoreObjects();
21882140

21892141
initRDT();
@@ -2200,6 +2152,74 @@ PCM::PCM() :
22002152
{
22012153
coreTaskQueues.push_back(std::make_shared<CoreTaskQueue>(i));
22022154
}
2155+
2156+
#ifndef PCM_SILENT
2157+
std::cerr << "\n";
2158+
#endif
2159+
}
2160+
2161+
void PCM::printDetailedSystemTopology()
2162+
{
2163+
// produce debug output similar to Intel MPI cpuinfo
2164+
if (true)
2165+
{
2166+
std::cerr << "\n===== Processor topology =====\n";
2167+
std::cerr << "OS_Processor Thread_Id Core_Id Tile_Id Package_Id Core_Type Native_CPU_Model\n";
2168+
std::map<uint32, std::vector<uint32> > os_id_by_core, os_id_by_tile, core_id_by_socket;
2169+
for (auto it = topology.begin(); it != topology.end(); ++it)
2170+
{
2171+
std::cerr << std::left << std::setfill(' ')
2172+
<< std::setw(16) << it->os_id
2173+
<< std::setw(16) << it->thread_id
2174+
<< std::setw(16) << it->core_id
2175+
<< std::setw(16) << it->tile_id
2176+
<< std::setw(16) << it->socket
2177+
<< std::setw(16) << it->getCoreTypeStr()
2178+
<< std::setw(16) << it->native_cpu_model
2179+
<< "\n";
2180+
if (std::find(core_id_by_socket[it->socket].begin(), core_id_by_socket[it->socket].end(), it->core_id)
2181+
== core_id_by_socket[it->socket].end())
2182+
core_id_by_socket[it->socket].push_back(it->core_id);
2183+
// add socket offset to distinguish cores and tiles from different sockets
2184+
os_id_by_core[(it->socket << 15) + it->core_id].push_back(it->os_id);
2185+
os_id_by_tile[(it->socket << 15) + it->tile_id].push_back(it->os_id);
2186+
}
2187+
std::cerr << "===== Placement on packages =====\n";
2188+
std::cerr << "Package Id. Core Id. Processors\n";
2189+
for (auto pkg = core_id_by_socket.begin(); pkg != core_id_by_socket.end(); ++pkg)
2190+
{
2191+
auto core_id = pkg->second.begin();
2192+
std::cerr << std::left << std::setfill(' ') << std::setw(15) << pkg->first << *core_id;
2193+
for (++core_id; core_id != pkg->second.end(); ++core_id)
2194+
{
2195+
std::cerr << "," << *core_id;
2196+
}
2197+
std::cerr << "\n";
2198+
}
2199+
std::cerr << "\n===== Core/Tile sharing =====\n";
2200+
std::cerr << "Level Processors\nCore ";
2201+
for (auto core = os_id_by_core.begin(); core != os_id_by_core.end(); ++core)
2202+
{
2203+
auto os_id = core->second.begin();
2204+
std::cerr << "(" << *os_id;
2205+
for (++os_id; os_id != core->second.end(); ++os_id) {
2206+
std::cerr << "," << *os_id;
2207+
}
2208+
std::cerr << ")";
2209+
}
2210+
std::cerr << "\nTile / L2$ ";
2211+
for (auto core = os_id_by_tile.begin(); core != os_id_by_tile.end(); ++core)
2212+
{
2213+
auto os_id = core->second.begin();
2214+
std::cerr << "(" << *os_id;
2215+
for (++os_id; os_id != core->second.end(); ++os_id) {
2216+
std::cerr << "," << *os_id;
2217+
}
2218+
std::cerr << ")";
2219+
}
2220+
std::cerr << "\n";
2221+
std::cerr << "\n";
2222+
}
22032223
}
22042224

22052225
void PCM::enableJKTWorkaround(bool enable)
@@ -3855,11 +3875,16 @@ void PCM::cleanupRDT(const bool silent)
38553875
if (!silent) std::cerr << " Freeing up all RMIDs\n";
38563876
}
38573877

3858-
void PCM::setOutput(const std::string filename)
3878+
void PCM::setOutput(const std::string filename, const bool cerrToo)
38593879
{
38603880
outfile = new std::ofstream(filename.c_str());
38613881
backup_ofile = std::cout.rdbuf();
38623882
std::cout.rdbuf(outfile->rdbuf());
3883+
if (cerrToo)
3884+
{
3885+
backup_ofile_cerr = std::cerr.rdbuf();
3886+
std::cerr.rdbuf(outfile->rdbuf());
3887+
}
38633888
}
38643889

38653890
void PCM::restoreOutput()
@@ -3868,6 +3893,9 @@ void PCM::restoreOutput()
38683893
if(backup_ofile)
38693894
std::cout.rdbuf(backup_ofile);
38703895

3896+
if (backup_ofile_cerr)
3897+
std::cerr.rdbuf(backup_ofile_cerr);
3898+
38713899
// close output file
38723900
if(outfile)
38733901
outfile->close();

src/cpucounters.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ class PCM_API PCM
674674
return (pkgCStateMsr != NULL && state <= ((int)MAX_C_STATE) && pkgCStateMsr[state] != 0);
675675
}
676676

677-
//! \brief Redirects output destination to provided file, instead of std::cout
678-
void setOutput(const std::string filename);
677+
//! \brief Redirects output destination to provided file, instead of std::cout and std::cerr (optional)
678+
static void setOutput(const std::string filename, const bool cerrToo = false);
679679

680680
//! \brief Restores output, closes output file if opened
681681
void restoreOutput();
@@ -884,8 +884,9 @@ class PCM_API PCM
884884
PERF_TOPDOWN_GROUP_LEADER_COUNTER = PERF_TOPDOWN_SLOTS_POS
885885
};
886886
#endif
887-
std::ofstream * outfile; // output file stream
888-
std::streambuf * backup_ofile; // backup of original output = cout
887+
static std::ofstream * outfile; // output file stream
888+
static std::streambuf * backup_ofile; // backup of original output = cout
889+
static std::streambuf * backup_ofile_cerr; // backup of original output = cerr
889890
int run_state; // either running (1) or sleeping (0)
890891

891892
bool needToRestoreNMIWatchdog;
@@ -1032,6 +1033,9 @@ class PCM_API PCM
10321033
return *systemTopology;
10331034
}
10341035

1036+
//! prints detailed system topology
1037+
void printDetailedSystemTopology();
1038+
10351039
/*!
10361040
\brief checks if QOS monitoring support present
10371041

0 commit comments

Comments
 (0)