Skip to content

Commit 2612158

Browse files
authored
Merge pull request #663 from intel/push-2024-01-25
push 2024 01 25
2 parents 1c77ba8 + a6e24d9 commit 2612158

File tree

4 files changed

+89
-15
lines changed

4 files changed

+89
-15
lines changed

src/cpucounters.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,6 +5721,16 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
57215721
{
57225722
programCXLDP(events64);
57235723
}
5724+
else if (strToUncorePMUID(type) != INVALID_PMU_ID)
5725+
{
5726+
const auto pmu_id = strToUncorePMUID(type);
5727+
programUncorePMUs(pmu_id, [&events64, &events, &pmu_id](UncorePMU& pmu)
5728+
{
5729+
uint64 * eventsIter = (uint64 *)events64;
5730+
pmu.initFreeze(UNC_PMON_UNIT_CTL_FRZ_EN);
5731+
PCM::program(pmu, eventsIter, eventsIter + (std::min)(events.programmable.size(), (size_t)ServerUncoreCounterState::maxCounters), UNC_PMON_UNIT_CTL_FRZ_EN);
5732+
});
5733+
}
57245734
else
57255735
{
57265736
std::cerr << "ERROR: unrecognized PMU type \"" << type << "\" when trying to program PMUs.\n";
@@ -6564,9 +6574,7 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket)
65646574
uint32 refCore = socketRefCore[socket];
65656575
TemporalThreadAffinity tempThreadAffinity(refCore);
65666576

6567-
readUncoreCounterValues(result, socket, CBO_PMU_ID);
6568-
6569-
readUncoreCounterValues(result, socket, MDF_PMU_ID);
6577+
readUncoreCounterValues(result, socket);
65706578

65716579
for (uint32 stack = 0; socket < iioPMUs.size() && stack < iioPMUs[socket].size() && stack < ServerUncoreCounterState::maxIIOStacks; ++stack)
65726580
{
@@ -6586,11 +6594,8 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket)
65866594
}
65876595
}
65886596

6589-
readUncoreCounterValues(result, socket, UBOX_PMU_ID);
65906597
result.UncClocks = getUncoreClocks(socket);
65916598

6592-
readUncoreCounterValues(result, socket, PCU_PMU_ID);
6593-
65946599
for (size_t p = 0; p < getNumCXLPorts(socket); ++p)
65956600
{
65966601
for (int i = 0; i < ServerUncoreCounterState::maxCounters && socket < cxlPMUs.size() && size_t(i) < cxlPMUs[socket][p].first.size(); ++i)

src/cpucounters.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,15 @@ class PCM_API PCM
651651
UBOX_PMU_ID,
652652
INVALID_PMU_ID
653653
};
654+
private:
655+
std::unordered_map<std::string, int> strToUncorePMUID_ {
656+
};
657+
public:
658+
UncorePMUIDs strToUncorePMUID(const std::string & type) const
659+
{
660+
const auto iter = strToUncorePMUID_.find(type);
661+
return (iter == strToUncorePMUID_.end()) ? INVALID_PMU_ID : (UncorePMUIDs)iter->second;
662+
}
654663
private:
655664
typedef std::unordered_map<int, UncorePMUArrayType> UncorePMUMapType;
656665
// socket -> die -> pmu map -> pmu ref array
@@ -714,7 +723,7 @@ class PCM_API PCM
714723
}
715724

716725
template <class T>
717-
void readUncoreCounterValues(T& result, const size_t socket, const int pmu_id) const
726+
void readUncoreCounterValues(T& result, const size_t socket) const
718727
{
719728
if (socket < uncorePMUs.size())
720729
{
@@ -723,9 +732,9 @@ class PCM_API PCM
723732
{
724733
TemporalThreadAffinity tempThreadAffinity(socketRefCore[socket]); // speedup trick for Linux
725734

726-
const auto& pmuIter = uncorePMUs[socket][die].find(pmu_id);
727-
if (pmuIter != uncorePMUs[socket][die].end())
735+
for (auto pmuIter = uncorePMUs[socket][die].begin(); pmuIter != uncorePMUs[socket][die].end(); ++pmuIter)
728736
{
737+
const auto & pmu_id = pmuIter->first;
729738
result.Counters[die][pmu_id].resize(pmuIter->second.size());
730739
for (size_t unit = 0; unit < pmuIter->second.size(); ++unit)
731740
{

src/pcm-raw.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ uint32 numTMAEvents(PCM* m)
12391239
return (m->isHWTMAL2Supported() ? 8 : 4);
12401240
}
12411241

1242+
uint32 pmu_type = PCM::INVALID_PMU_ID;
1243+
12421244
void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs,
12431245
PCM* m,
12441246
SystemCounterState& SysBeforeState, SystemCounterState& SysAfterState,
@@ -1719,6 +1721,14 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs,
17191721
[&]() { printUncoreRows([](const uint32 u, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getCXLDPCounter(u, i, before, after); }, ServerUncoreCounterState::maxCXLPorts, "CXLDP");
17201722
});
17211723
}
1724+
else if ((pmu_type = m->strToUncorePMUID(type)) != PCM::INVALID_PMU_ID)
1725+
{
1726+
choose(outputType,
1727+
[&]() { printUncoreRows(nullptr, (uint32) m->getMaxNumOfUncorePMUs(pmu_type), type); },
1728+
[&]() { printUncoreRows(nullptr, (uint32) m->getMaxNumOfUncorePMUs(pmu_type), type); },
1729+
[&]() { printUncoreRows([](const uint32 u, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreCounter(pmu_type, u, i, before, after); }, (uint32)m->getMaxNumOfUncorePMUs(pmu_type), type);
1730+
});
1731+
}
17221732
else
17231733
{
17241734
std::cerr << "ERROR: unrecognized PMU type \"" << type << "\"\n";
@@ -2150,6 +2160,24 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs,
21502160
}
21512161
}
21522162
}
2163+
else if ((pmu_type = m->strToUncorePMUID(type)) != PCM::INVALID_PMU_ID)
2164+
{
2165+
for (uint32 s = 0; s < m->getNumSockets(); ++s)
2166+
{
2167+
for (uint32 unit = 0; unit < m->getMaxNumOfUncorePMUs(pmu_type); ++unit)
2168+
{
2169+
int i = 0;
2170+
for (auto& event : events)
2171+
{
2172+
choose(outputType,
2173+
[s, unit, &type]() { cout << "SKT" << s << type << unit << separator; },
2174+
[&event, &i, &type]() { if (event.second.empty()) cout << type << "Event" << i << separator; else cout << event.second << separator; },
2175+
[&]() { cout << getUncoreCounter(pmu_type, unit, i, BeforeUncoreState[s], AfterUncoreState[s]) << separator; });
2176+
++i;
2177+
}
2178+
}
2179+
}
2180+
}
21532181
else
21542182
{
21552183
std::cerr << "ERROR: unrecognized PMU type \"" << type << "\"\n";

src/uncore_pmu_discovery.h

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,37 @@ class UncorePMUDiscovery
3737
}
3838
return "unknown";
3939
};
40+
union PCICFGAddress
41+
{
42+
uint64 raw;
43+
struct {
44+
uint64 offset:12;
45+
uint64 function:3;
46+
uint64 device:5;
47+
uint64 bus:8;
48+
} fields;
49+
std::string getStr() const
50+
{
51+
std::ostringstream out(std::ostringstream::out);
52+
out << std::hex << fields.bus << ":" << fields.device << "." << fields.function << "@" << fields.offset;
53+
out << std::dec;
54+
return out.str();
55+
}
56+
};
57+
static void printHelper(const accessTypeEnum accessType, const uint64 addr)
58+
{
59+
if (accessType == PCICFG)
60+
{
61+
PCICFGAddress Addr;
62+
Addr.raw = addr;
63+
std::cout << " (" << Addr.getStr() << ")";
64+
}
65+
else
66+
{
67+
std::cout << " (-)";
68+
}
69+
std::cout << " with access type " << std::dec << accessTypeStr(accessType);
70+
}
4071
protected:
4172
struct GlobalPMU
4273
{
@@ -53,9 +84,9 @@ class UncorePMUDiscovery
5384
{
5485
std::cout << "global PMU " <<
5586
" of type " << std::dec << type <<
56-
" globalCtrl: 0x" << std::hex << globalCtrlAddr <<
57-
" with access type " << std::dec << accessTypeStr(accessType) <<
58-
" stride: " << std::dec << stride
87+
" globalCtrl: 0x" << std::hex << globalCtrlAddr;
88+
UncorePMUDiscovery::printHelper((accessTypeEnum)accessType, globalCtrlAddr);
89+
std::cout << " stride: " << std::dec << stride
5990
<< "\n";
6091
}
6192
};
@@ -77,9 +108,10 @@ class UncorePMUDiscovery
77108
std::cout << "unit PMU " <<
78109
" of type " << std::dec << boxType <<
79110
" ID " << boxID <<
80-
" box ctrl: 0x" << std::hex << boxCtrlAddr <<
81-
" width " << std::dec << bitWidth <<
82-
" with access type " << accessTypeStr(accessType) <<
111+
" box ctrl: 0x" << std::hex << boxCtrlAddr;
112+
UncorePMUDiscovery::printHelper((accessTypeEnum)accessType, boxCtrlAddr);
113+
std::cout <<
114+
" width " << bitWidth <<
83115
" numRegs " << numRegs <<
84116
" ctrlOffset " << ctrlOffset <<
85117
" ctrOffset " << ctrOffset <<

0 commit comments

Comments
 (0)