Skip to content

Commit 3b17a62

Browse files
authored
Merge pull request #890 from intel/push-2024-12-11
Push 2024 12 11
2 parents f584c88 + fc087d6 commit 3b17a62

File tree

6 files changed

+263
-67
lines changed

6 files changed

+263
-67
lines changed

src/cpucounters.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,29 +1444,19 @@ bool PCM::discoverSystemTopology()
14441444
}
14451445
if(num_sockets == 0) {
14461446
num_sockets = (int32)(std::max)(socketIdMap.size(), (size_t)1);
1447+
// std::cerr << " num_sockets = " << num_sockets << "\n";
14471448
}
14481449

14491450
socketIdMap_type::iterator s = socketIdMap.begin();
14501451
for (uint32 sid = 0; s != socketIdMap.end(); ++s)
14511452
{
14521453
s->second = sid++;
1453-
// first is apic id, second is logical socket id
1454-
systemTopology->addSocket( s->first, s->second );
14551454
}
14561455

1457-
for (int32 cid = 0; cid < num_cores; ++cid)
1458-
{
1459-
//std::cerr << "Cid: " << cid << "\n";
1460-
systemTopology->addThread( cid, topology[cid] );
1461-
}
1462-
1463-
// All threads are here now so we can set the refCore for a socket
1464-
for ( auto& socket : systemTopology->sockets() )
1465-
socket->setRefCore();
1466-
14671456
// use map to change apic socket id to the logical socket id
14681457
for (int i = 0; (i < (int)num_cores) && (!socketIdMap.empty()); ++i)
14691458
{
1459+
// std::cerr << "socket_id: " << topology[i].socket_id << ", socketIdMap tells me: " << socketIdMap[topology[i].socket_id] << "\n";
14701460
if(isCoreOnline((int32)i))
14711461
topology[i].socket_id = socketIdMap[topology[i].socket_id];
14721462
}
@@ -1483,14 +1473,30 @@ bool PCM::discoverSystemTopology()
14831473
{
14841474
for (int i = 0; i < (int)num_cores; ++i)
14851475
{
1486-
if (topology[i].socket_id == topology[0].socket_id && topology[i].core_id == topology[0].core_id)
1476+
if (topology[i].isSameCore( topology[0] ))
14871477
++threads_per_core;
14881478
}
14891479
assert(threads_per_core != 0);
14901480
}
14911481
if(num_phys_cores_per_socket == 0 && num_cores == num_online_cores) num_phys_cores_per_socket = num_cores / num_sockets / threads_per_core;
14921482
if(num_online_cores == 0) num_online_cores = num_cores;
14931483

1484+
s = socketIdMap.begin();
1485+
for (; s != socketIdMap.end(); ++s)
1486+
{
1487+
systemTopology->addSocket( s->second );
1488+
}
1489+
1490+
for (int32 cid = 0; cid < num_cores; ++cid)
1491+
{
1492+
//std::cerr << "Cid: " << cid << "\n";
1493+
systemTopology->addThread( cid, topology[cid] );
1494+
}
1495+
1496+
// All threads are here now so we can set the refCore for a socket
1497+
for ( auto& socket : systemTopology->sockets() )
1498+
socket->setRefCore();
1499+
14941500
int32 i = 0;
14951501

14961502
socketRefCore.resize(num_sockets, -1);
@@ -3421,11 +3427,11 @@ void PCM::destroyMSR()
34213427

34223428
PCM::~PCM()
34233429
{
3430+
deleteAndNullify(systemTopology);
34243431
if (instance)
34253432
{
34263433
destroyMSR();
34273434
instance = NULL;
3428-
deleteAndNullify(systemTopology);
34293435
}
34303436
}
34313437

src/pcm-sensor-server.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ class PrometheusPrinter : Visitor
645645
}
646646

647647
virtual void dispatch( Core* c ) override {
648-
addToHierarchy( std::string( "core=\"" ) + std::to_string( c->coreID() ) + "\"" );
648+
addToHierarchy( std::string( "core=\"" ) + std::to_string( c->dieGroupID()*256 + c->dieID()*64 + c->tileID()*16 + c->moduleID()*4 + c->coreID() ) + "\"" );
649649
auto vec = c->threads();
650650
iterateVectorAndCallAccept( vec );
651651

@@ -801,6 +801,7 @@ class PrometheusPrinter : Visitor
801801
}
802802
removeFromHierarchy();
803803
}
804+
804805
void printSystemCounterState( SystemCounterState const& before, SystemCounterState const& after ) {
805806
addToHierarchy( "source=\"uncore\"" );
806807
PCM* pcm = PCM::getInstance();
@@ -3759,6 +3760,7 @@ int mainThrows(int argc, char * argv[]) {
37593760
bool useRealtimePriority = false;
37603761
#endif
37613762
bool forceRTMAbortMode = false;
3763+
bool printTopology = false;
37623764
unsigned short port = 0;
37633765
unsigned short debug_level = 0;
37643766
std::string certificateFile;
@@ -3774,7 +3776,12 @@ int mainThrows(int argc, char * argv[]) {
37743776
MainLoop mainLoop;
37753777
std::string ev_file_name;
37763778

3777-
if ( argc > 1 ) {
3779+
const char* PPTEnv = std::getenv( "PCMSENSORSERVER_PRINT_TOPOLOGY" );
3780+
if ( PPTEnv ) {
3781+
if ( *PPTEnv == '1' ) {
3782+
printTopology = true;
3783+
}
3784+
} else if ( argc > 1 ) {
37783785
std::string arg_value;
37793786

37803787
for ( int i=1; i < argc; ++i ) {
@@ -3901,7 +3908,7 @@ int mainThrows(int argc, char * argv[]) {
39013908
}
39023909
}
39033910

3904-
#ifdef __linux__
3911+
#ifdef __linux__
39053912
// check kernel version for driver dependency.
39063913
if (accel != ACCEL_NOCONFIG)
39073914
{
@@ -4035,6 +4042,17 @@ int mainThrows(int argc, char * argv[]) {
40354042

40364043
accs_->programAccelCounters();
40374044
}
4045+
if ( printTopology ) {
4046+
TopologyPrinter* tp = new TopologyPrinter();
4047+
tp->dispatch( PCM::getInstance()->getSystemTopology() );
4048+
std::vector<std::string> & tpData = tp->topologyDataStrings();
4049+
std::sort( tpData.begin(), tpData.end(), TopologyStringCompare );
4050+
for( auto& line: tpData ) {
4051+
std::cout << line << "\n";
4052+
}
4053+
deleteAndNullify( tp );
4054+
exit( 0 );
4055+
}
40384056
#if defined (USE_SSL)
40394057
if ( useSSL ) {
40404058
if ( port == 0 )

src/simdjson

Submodule simdjson updated 82 files

src/topology.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ UncoreCounterState ClientUncore::uncoreCounterState( void ) const
3030
return ucs;
3131
}
3232

33-
Socket::Socket( PCM* m, int32 apicID, int32 logicalID )
34-
: pcm_(m), refCore_(nullptr), apicID_(apicID), logicalID_(logicalID)
33+
Socket::Socket( PCM* m, int32 logicalID )
34+
: pcm_(m), refCore_(nullptr), logicalID_(logicalID)
3535
{
3636
if ( pcm_->isServerCPU() )
3737
uncore_ = new ServerUncore( pcm_, logicalID );
@@ -102,4 +102,16 @@ void Aggregator::dispatch( SystemRoot const& syp ) {
102102
readAccelCounters(sycs_);
103103
}
104104

105+
bool TopologyStringCompare( const std::string& topology1, const std::string& topology2 ) {
106+
if ( topology1.size() == 0 ) return true;
107+
if ( topology2.size() == 0 ) return false;
108+
109+
int topo1asint, topo2asint;
110+
std::stringstream ss1(topology1);
111+
std::stringstream ss2(topology2);
112+
ss1 >> topo1asint;
113+
ss2 >> topo2asint;
114+
return topo1asint < topo2asint;
115+
}
116+
105117
}// namespace pcm

0 commit comments

Comments
 (0)