Skip to content

Commit b4d0abc

Browse files
committed
pcm-raw: add pmt raw events
1 parent a61bd86 commit b4d0abc

File tree

6 files changed

+143
-2
lines changed

6 files changed

+143
-2
lines changed

src/cpucounters.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5713,6 +5713,7 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
57135713
packageMSRConfig = RawPMUConfig{};
57145714
pcicfgConfig = RawPMUConfig{};
57155715
mmioConfig = RawPMUConfig{};
5716+
pmtConfig = RawPMUConfig{};
57165717
RawPMUConfigs curPMUConfigs = curPMUConfigs_;
57175718
constexpr auto globalRegPos = 0ULL;
57185719
PCM::ExtendedCustomCoreEventDescription conf;
@@ -5982,6 +5983,29 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
59825983
addLocations(mmioConfig.programmable);
59835984
addLocations(mmioConfig.fixed);
59845985
}
5986+
else if (type == "pmt")
5987+
{
5988+
pmtConfig = pmuConfig.second;
5989+
auto addLocations = [this](const std::vector<RawEventConfig>& configs) {
5990+
for (const auto& c : configs)
5991+
{
5992+
if (PMTRegisterLocations.find(c.first) == PMTRegisterLocations.end())
5993+
{
5994+
// add locations
5995+
std::vector<PMTRegisterEncoding> locations;
5996+
const auto UID = c.first[PMTEventPosition::UID];
5997+
for (size_t inst = 0; inst < TelemetryArray::numInstances(UID); ++inst)
5998+
{
5999+
locations.push_back(std::make_shared<TelemetryArray>(UID, inst));
6000+
// std::cout << "PMTRegisterLocations: UID: 0x" << std::hex << UID << " inst: " << std::dec << inst << std::endl;
6001+
}
6002+
PMTRegisterLocations[c.first] = locations;
6003+
}
6004+
}
6005+
};
6006+
addLocations(pmtConfig.programmable);
6007+
addLocations(pmtConfig.fixed);
6008+
}
59856009
else if (type == "cxlcm")
59866010
{
59876011
programCXLCM(events64);
@@ -6466,6 +6490,44 @@ void PCM::readMMIORegisters(SystemCounterState& systemState)
64666490
}
64676491
}
64686492

6493+
void PCM::readPMTRegisters(SystemCounterState& systemState)
6494+
{
6495+
for (auto & p: PMTRegisterLocations)
6496+
{
6497+
for (auto & t: p.second)
6498+
{
6499+
if (t.get())
6500+
{
6501+
t->load();
6502+
}
6503+
}
6504+
}
6505+
auto read = [this, &systemState](const RawEventConfig& cfg) {
6506+
const RawEventEncoding& reEnc = cfg.first;
6507+
systemState.PMTValues[reEnc].clear();
6508+
const auto lsb = reEnc[PMTEventPosition::lsb];
6509+
const auto msb = reEnc[PMTEventPosition::msb];
6510+
const auto offset = reEnc[PMTEventPosition::offset];
6511+
// std::cout << "PMTValues: " << std::hex << reEnc[PMTEventPosition::UID] << std::dec << std::endl;
6512+
for (auto& reg : PMTRegisterLocations[reEnc])
6513+
{
6514+
if (reg.get())
6515+
{
6516+
systemState.PMTValues[reEnc].push_back(reg->get(offset, lsb, msb));
6517+
// std::cout << "PMTValues: " << std::hex << reEnc[PMTEventPosition::UID] << " " << std::dec << reg->get(offset, lsb, msb) << std::endl;
6518+
}
6519+
}
6520+
};
6521+
for (const auto& cfg : pmtConfig.programmable)
6522+
{
6523+
read(cfg);
6524+
}
6525+
for (const auto& cfg : pmtConfig.fixed)
6526+
{
6527+
read(cfg);
6528+
}
6529+
}
6530+
64696531
void PCM::readQPICounters(SystemCounterState & result)
64706532
{
64716533
// read QPI counters
@@ -6671,6 +6733,7 @@ void PCM::getAllCounterStates(SystemCounterState & systemState, std::vector<Sock
66716733
readQPICounters(systemState);
66726734
readPCICFGRegisters(systemState);
66736735
readMMIORegisters(systemState);
6736+
readPMTRegisters(systemState);
66746737
}
66756738

66766739
for (auto & ar : asyncCoreResults)

src/cpucounters.h

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ class PCM_API PCM
12171217
void readQPICounters(SystemCounterState & counterState);
12181218
void readPCICFGRegisters(SystemCounterState& result);
12191219
void readMMIORegisters(SystemCounterState& result);
1220+
void readPMTRegisters(SystemCounterState& result);
12201221
void reportQPISpeed() const;
12211222
void readCoreCounterConfig(const bool complainAboutMSR = false);
12221223
void readCPUMicrocodeLevel();
@@ -1568,9 +1569,46 @@ class PCM_API PCM
15681569
&& a[MMIOEventPosition::membar_bits2] == b[MMIOEventPosition::membar_bits2];
15691570
}
15701571
};
1572+
struct PMTEventPosition
1573+
{
1574+
enum constants
1575+
{
1576+
UID = PCICFGEventPosition::deviceID,
1577+
offset = PCICFGEventPosition::offset,
1578+
type = PCICFGEventPosition::type,
1579+
lsb = 3,
1580+
msb = 4
1581+
};
1582+
};
1583+
struct PMTRegisterEncodingHash
1584+
{
1585+
std::size_t operator()(const RawEventEncoding & e) const
1586+
{
1587+
return std::hash<uint64>{}(e[PMTEventPosition::UID]);
1588+
}
1589+
};
1590+
struct PMTRegisterEncodingHash2
1591+
{
1592+
std::size_t operator()(const RawEventEncoding & e) const
1593+
{
1594+
std::size_t h1 = std::hash<uint64>{}(e[PMTEventPosition::UID]);
1595+
std::size_t h2 = std::hash<uint64>{}(e[PMTEventPosition::offset]);
1596+
std::size_t h3 = std::hash<uint64>{}(e[PMTEventPosition::lsb]);
1597+
return h1 ^ (h2 << 1ULL) ^ (h3 << 2ULL);
1598+
}
1599+
};
1600+
struct PMTRegisterEncodingCmp
1601+
{
1602+
bool operator ()(const RawEventEncoding& a, const RawEventEncoding& b) const
1603+
{
1604+
return a[PMTEventPosition::UID] == b[PMTEventPosition::UID];
1605+
}
1606+
};
1607+
typedef std::shared_ptr<TelemetryArray> PMTRegisterEncoding; // TelemetryArray shared ptr
15711608
private:
15721609
std::unordered_map<RawEventEncoding, std::vector<PCICFGRegisterEncoding>, PCICFGRegisterEncodingHash, PCICFGRegisterEncodingCmp> PCICFGRegisterLocations{};
15731610
std::unordered_map<RawEventEncoding, std::vector<MMIORegisterEncoding>, MMIORegisterEncodingHash, MMIORegisterEncodingCmp> MMIORegisterLocations{};
1611+
std::unordered_map<RawEventEncoding, std::vector<PMTRegisterEncoding>, PMTRegisterEncodingHash, PMTRegisterEncodingCmp> PMTRegisterLocations{};
15741612
public:
15751613

15761614
TopologyEntry::CoreType getCoreType(const unsigned coreID) const
@@ -1861,7 +1899,7 @@ class PCM_API PCM
18611899
}
18621900
return false;
18631901
}
1864-
RawPMUConfig threadMSRConfig{}, packageMSRConfig{}, pcicfgConfig{}, mmioConfig{};
1902+
RawPMUConfig threadMSRConfig{}, packageMSRConfig{}, pcicfgConfig{}, mmioConfig{}, pmtConfig{};
18651903
public:
18661904

18671905
//! \brief Reads CPU family
@@ -3743,13 +3781,15 @@ class SystemCounterState : public SocketCounterState
37433781
friend class PCM;
37443782
friend std::vector<uint64> getPCICFGEvent(const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
37453783
friend std::vector<uint64> getMMIOEvent(const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
3784+
friend std::vector<uint64> getPMTEvent(const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
37463785

37473786
std::vector<std::vector<uint64> > incomingQPIPackets; // each 64 byte
37483787
std::vector<std::vector<uint64> > outgoingQPIFlits; // idle or data/non-data flits depending on the architecture
37493788
std::vector<std::vector<uint64> > TxL0Cycles;
37503789
uint64 uncoreTSC;
37513790
std::unordered_map<PCM::RawEventEncoding, std::vector<uint64> , PCM::PCICFGRegisterEncodingHash, PCM::PCICFGRegisterEncodingCmp> PCICFGValues{};
37523791
std::unordered_map<PCM::RawEventEncoding, std::vector<uint64>, PCM::MMIORegisterEncodingHash, PCM::MMIORegisterEncodingCmp> MMIOValues{};
3792+
std::unordered_map<PCM::RawEventEncoding, std::vector<uint64>, PCM::PMTRegisterEncodingHash2> PMTValues{};
37533793

37543794
protected:
37553795
void readAndAggregate(std::shared_ptr<SafeMsrHandle> handle)
@@ -5100,6 +5140,11 @@ inline std::vector<uint64> getMMIOEvent(const PCM::RawEventEncoding& eventEnc, c
51005140
return getRegisterEvent(eventEnc, before.MMIOValues, after.MMIOValues);
51015141
}
51025142

5143+
inline std::vector<uint64> getPMTEvent(const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after)
5144+
{
5145+
return getRegisterEvent(eventEnc, before.PMTValues, after.PMTValues);
5146+
}
5147+
51035148
template <class CounterStateType>
51045149
uint64 getMSREvent(const uint64& index, const PCM::MSRType& type, const CounterStateType& before, const CounterStateType& after)
51055150
{

src/pcm-raw.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,18 @@ std::string getMMIOEventString(const PCM::RawEventEncoding& eventEnc, const std:
12501250
return c.str();
12511251
}
12521252

1253+
std::string getPMTEventString(const PCM::RawEventEncoding& eventEnc, const std::string& type)
1254+
{
1255+
std::stringstream c;
1256+
c << type << ":0x" << std::hex <<
1257+
eventEnc[PCM::PMTEventPosition::UID] <<
1258+
":0x" << eventEnc[PCM::PMTEventPosition::offset] <<
1259+
":0x" << eventEnc[PCM::PMTEventPosition::lsb] <<
1260+
":0x" << eventEnc[PCM::PMTEventPosition::msb] <<
1261+
":" << getTypeString(eventEnc[PCM::PMTEventPosition::type]);
1262+
return c.str();
1263+
}
1264+
12531265
typedef std::string(*getEventStringFunc)(const PCM::RawEventEncoding& eventEnc, const std::string& type);
12541266
typedef std::vector<uint64>(getEventFunc)(const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
12551267

@@ -1639,6 +1651,10 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs,
16391651
{
16401652
printRegisterRows(getMMIOEventString, getMMIOEvent);
16411653
}
1654+
else if (type == "pmt")
1655+
{
1656+
printRegisterRows(getPMTEventString, getPMTEvent);
1657+
}
16421658
else if (type == "m3upi")
16431659
{
16441660
choose(outputType,
@@ -2055,6 +2071,10 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs,
20552071
{
20562072
printRegisters(getMMIOEventString, getMMIOEvent);
20572073
}
2074+
else if (type == "pmt")
2075+
{
2076+
printRegisters(getPMTEventString, getPMTEvent);
2077+
}
20582078
else if (type == "ubox")
20592079
{
20602080
for (uint32 s = 0; s < m->getNumSockets(); ++s)

src/pmt.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <unordered_map>
99
#include <iostream>
1010

11+
#ifdef __linux__
12+
#include <unistd.h>
13+
#endif
14+
1115
namespace pcm {
1216

1317
#ifdef __linux__
@@ -68,7 +72,12 @@ class TelemetryArrayLinux : public TelemetryArrayInterface
6872
}
6973
static size_t numInstances(const size_t uid)
7074
{
71-
return getTelemetryFiles().at(uid).size();
75+
auto t = getTelemetryFiles();
76+
if (t.find(uid) == t.end())
77+
{
78+
return 0;
79+
}
80+
return t.at(uid).size();
7281
}
7382
virtual ~TelemetryArrayLinux() override
7483
{

src/utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ bool isRegisterEvent(const std::string & pmu)
946946
{
947947
if (pmu == "mmio"
948948
|| pmu == "pcicfg"
949+
|| pmu == "pmt"
949950
|| pmu == "package_msr"
950951
|| pmu == "thread_msr")
951952
{

src/utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include <map>
3737
#include <unordered_map>
3838

39+
#ifdef __linux__
40+
#include <unistd.h>
41+
#endif
3942

4043
namespace pcm {
4144
std::string safe_getenv(const char* env);

0 commit comments

Comments
 (0)