Skip to content

Commit 6a47355

Browse files
committed
refactor UBOX PMU code
Change-Id: Id6ae34f8c0fb38d2243cb02a523c9c01dd107888
1 parent 16e270f commit 6a47355

File tree

3 files changed

+65
-69
lines changed

3 files changed

+65
-69
lines changed

src/cpucounters.cpp

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,22 +1926,15 @@ void PCM::initUncoreObjects()
19261926
initUncorePMUsDirect();
19271927
}
19281928

1929-
auto countPMUs = [&](const uint32 s, const int pmu_id)
1930-
{
1931-
size_t count = 0;
1932-
forAllUncorePMUs(s, pmu_id, [&count](UncorePMU&) { ++count; });
1933-
return count;
1934-
};
1935-
1936-
std::cerr << "Info: " << uboxPMUs.size() << " UBOX units detected.\n";
19371929
for (uint32 s = 0; s < (uint32)num_sockets; ++s)
19381930
{
19391931
std::cerr << "Socket " << s << ":" <<
1940-
" " << countPMUs(s, PCU_PMU_ID) << " PCU units detected."
1932+
" " << getMaxNumOfUncorePMUs(PCU_PMU_ID, s) << " PCU units detected."
19411933
" " << ((s < iioPMUs.size()) ? iioPMUs[s].size() : 0) << " IIO units detected."
19421934
" " << ((s < irpPMUs.size()) ? irpPMUs[s].size() : 0) << " IRP units detected."
1943-
" " << countPMUs(s, CBO_PMU_ID) << " CHA/CBO units detected."
1944-
" " << countPMUs(s, MDF_PMU_ID) << " MDF units detected."
1935+
" " << getMaxNumOfUncorePMUs(CBO_PMU_ID, s) << " CHA/CBO units detected."
1936+
" " << getMaxNumOfUncorePMUs(MDF_PMU_ID, s) << " MDF units detected."
1937+
" " << getMaxNumOfUncorePMUs(UBOX_PMU_ID, s) << " UBOX units detected."
19451938
" " << ((s < cxlPMUs.size()) ? cxlPMUs[s].size() : 0) << " CXL units detected."
19461939
"\n";
19471940
}
@@ -1996,53 +1989,62 @@ void PCM::initUncorePMUsDirect()
19961989

19971990
if (IVYTOWN == cpu_model || JAKETOWN == cpu_model)
19981991
{
1999-
uboxPMUs.push_back(
2000-
UncorePMU(
2001-
std::shared_ptr<MSRRegister>(),
1992+
uncorePMUs[s].resize(1);
1993+
std::vector<std::shared_ptr<HWRegister> > CounterControlRegs{
20021994
std::make_shared<MSRRegister>(handle, JKTIVT_UBOX_MSR_PMON_CTL0_ADDR),
2003-
std::make_shared<MSRRegister>(handle, JKTIVT_UBOX_MSR_PMON_CTL1_ADDR),
2004-
std::shared_ptr<MSRRegister>(),
2005-
std::shared_ptr<MSRRegister>(),
1995+
std::make_shared<MSRRegister>(handle, JKTIVT_UBOX_MSR_PMON_CTL1_ADDR)
1996+
},
1997+
CounterValueRegs{
20061998
std::make_shared<MSRRegister>(handle, JKTIVT_UBOX_MSR_PMON_CTR0_ADDR),
2007-
std::make_shared<MSRRegister>(handle, JKTIVT_UBOX_MSR_PMON_CTR1_ADDR),
2008-
std::shared_ptr<MSRRegister>(),
1999+
std::make_shared<MSRRegister>(handle, JKTIVT_UBOX_MSR_PMON_CTR1_ADDR)
2000+
};
2001+
uncorePMUs[s][0][UBOX_PMU_ID].push_back(
2002+
std::make_shared<UncorePMU>(
20092003
std::shared_ptr<MSRRegister>(),
2004+
CounterControlRegs,
2005+
CounterValueRegs,
20102006
std::make_shared<MSRRegister>(handle, JKTIVT_UCLK_FIXED_CTL_ADDR),
20112007
std::make_shared<MSRRegister>(handle, JKTIVT_UCLK_FIXED_CTR_ADDR)
20122008
)
20132009
);
20142010
}
20152011
else if (SPR == cpu_model)
20162012
{
2017-
uboxPMUs.push_back(
2018-
UncorePMU(
2019-
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_BOX_CTL_ADDR),
2013+
uncorePMUs[s].resize(1);
2014+
std::vector<std::shared_ptr<HWRegister> > CounterControlRegs{
20202015
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_CTL0_ADDR),
2021-
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_CTL1_ADDR),
2022-
std::shared_ptr<MSRRegister>(),
2023-
std::shared_ptr<MSRRegister>(),
2016+
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_CTL1_ADDR)
2017+
},
2018+
CounterValueRegs{
20242019
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_CTR0_ADDR),
2025-
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_CTR1_ADDR),
2026-
std::shared_ptr<MSRRegister>(),
2027-
std::shared_ptr<MSRRegister>(),
2020+
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_CTR1_ADDR)
2021+
};
2022+
uncorePMUs[s][0][UBOX_PMU_ID].push_back(
2023+
std::make_shared<UncorePMU>(
2024+
std::make_shared<MSRRegister>(handle, SPR_UBOX_MSR_PMON_BOX_CTL_ADDR),
2025+
CounterControlRegs,
2026+
CounterValueRegs,
20282027
std::make_shared<MSRRegister>(handle, SPR_UCLK_FIXED_CTL_ADDR),
20292028
std::make_shared<MSRRegister>(handle, SPR_UCLK_FIXED_CTR_ADDR)
20302029
)
20312030
);
20322031
}
20332032
else if (isServerCPU() && hasPCICFGUncore())
20342033
{
2035-
uboxPMUs.push_back(
2036-
UncorePMU(
2037-
std::shared_ptr<MSRRegister>(),
2034+
uncorePMUs[s].resize(1);
2035+
std::vector<std::shared_ptr<HWRegister> > CounterControlRegs{
20382036
std::make_shared<MSRRegister>(handle, UBOX_MSR_PMON_CTL0_ADDR),
20392037
std::make_shared<MSRRegister>(handle, UBOX_MSR_PMON_CTL1_ADDR),
2040-
std::shared_ptr<MSRRegister>(),
2041-
std::shared_ptr<MSRRegister>(),
2038+
},
2039+
CounterValueRegs{
20422040
std::make_shared<MSRRegister>(handle, UBOX_MSR_PMON_CTR0_ADDR),
20432041
std::make_shared<MSRRegister>(handle, UBOX_MSR_PMON_CTR1_ADDR),
2042+
};
2043+
uncorePMUs[s][0][UBOX_PMU_ID].push_back(
2044+
std::make_shared<UncorePMU>(
20442045
std::shared_ptr<MSRRegister>(),
2045-
std::shared_ptr<MSRRegister>(),
2046+
CounterControlRegs,
2047+
CounterValueRegs,
20462048
std::make_shared<MSRRegister>(handle, UCLK_FIXED_CTL_ADDR),
20472049
std::make_shared<MSRRegister>(handle, UCLK_FIXED_CTR_ADDR)
20482050
)
@@ -2554,7 +2556,7 @@ void PCM::initUncorePMUsPerf()
25542556
{
25552557
uncorePMUs[s].resize(1);
25562558
populatePerfPMUs(s, enumeratePerfPMUs("pcu", 100), uncorePMUs[s][0][PCU_PMU_ID], false, true);
2557-
populatePerfPMUs(s, enumeratePerfPMUs("ubox", 100), uboxPMUs, true);
2559+
populatePerfPMUs(s, enumeratePerfPMUs("ubox", 100), uncorePMUs[s][0][UBOX_PMU_ID], true);
25582560
populatePerfPMUs(s, enumeratePerfPMUs("cbox", 100), uncorePMUs[s][0][CBO_PMU_ID], false, true, true);
25592561
populatePerfPMUs(s, enumeratePerfPMUs("cha", 200), uncorePMUs[s][0][CBO_PMU_ID], false, true, true);
25602562
populatePerfPMUs(s, enumeratePerfPMUs("mdf", 200), uncorePMUs[s][0][MDF_PMU_ID], false, true, true);
@@ -6590,11 +6592,9 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket)
65906592
}
65916593
}
65926594
}
6593-
for (int i = 0; i < 2 && socket < uboxPMUs.size(); ++i)
6594-
{
6595-
result.UBOXCounter[i] = *(uboxPMUs[socket].counterValue[i]);
6596-
result.UncClocks = getUncoreClocks(socket);
6597-
}
6595+
6596+
readUncoreCounterValues(result, socket, UBOX_PMU_ID);
6597+
result.UncClocks = getUncoreClocks(socket);
65986598

65996599
readUncoreCounterValues(result, socket, PCU_PMU_ID);
66006600

@@ -9347,19 +9347,17 @@ void PCM::programMDF(const uint64* events)
93479347

93489348
void PCM::programUBOX(const uint64* events)
93499349
{
9350-
for (size_t s = 0; (s < uboxPMUs.size()) && MSR.size(); ++s)
9350+
programUncorePMUs(UBOX_PMU_ID, [&events](UncorePMU& pmu)
93519351
{
9352-
uint32 refCore = socketRefCore[s];
9353-
TemporalThreadAffinity tempThreadAffinity(refCore); // speedup trick for Linux
9354-
uboxPMUs[s].initFreeze(UNC_PMON_UNIT_CTL_FRZ_EN);
9352+
pmu.initFreeze(UNC_PMON_UNIT_CTL_FRZ_EN);
93559353

9356-
*uboxPMUs[s].fixedCounterControl = UCLK_FIXED_CTL_EN;
9354+
*pmu.fixedCounterControl = UCLK_FIXED_CTL_EN;
93579355

93589356
if (events)
93599357
{
9360-
PCM::program(uboxPMUs[s], events, events + 2, 0);
9358+
PCM::program(pmu, events, events + 2, 0);
93619359
}
9362-
}
9360+
});
93639361
}
93649362

93659363
void PCM::controlQATTelemetry(uint32 dev, uint32 operation)
@@ -9577,12 +9575,25 @@ uint64 PCM::getUncoreCounterState(const int pmu_id, const size_t socket, const u
95779575
return result;
95789576
}
95799577

9580-
uint64 PCM::getUncoreClocks(const uint32 socket_)
9578+
uint64 PCM::getUncoreClocks(const uint32 socket_id)
95819579
{
95829580
uint64 result = 0;
9583-
if (socket_ < uboxPMUs.size())
9581+
if (socket_id < uncorePMUs.size())
95849582
{
9585-
result = *uboxPMUs[socket_].fixedCounterValue;
9583+
for (auto& d : uncorePMUs[socket_id])
9584+
{
9585+
const auto iter = d.find(UBOX_PMU_ID);
9586+
if (iter != d.end())
9587+
{
9588+
for (auto& pmu : iter->second)
9589+
{
9590+
if (pmu.get())
9591+
{
9592+
result += *pmu->fixedCounterValue;
9593+
}
9594+
}
9595+
}
9596+
}
95869597
}
95879598
return result;
95889599
}

src/cpucounters.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ class PCM_API PCM
648648
CBO_PMU_ID,
649649
MDF_PMU_ID,
650650
PCU_PMU_ID,
651+
UBOX_PMU_ID,
651652
INVALID_PMU_ID
652653
};
653654
private:
@@ -768,7 +769,6 @@ class PCM_API PCM
768769
// TODO: gradually move other PMUs to the uncorePMUs structure
769770
std::vector<std::map<int32, UncorePMU> > iioPMUs;
770771
std::vector<std::map<int32, UncorePMU> > irpPMUs;
771-
std::vector<UncorePMU> uboxPMUs;
772772
std::vector<std::vector<IDX_PMU> > idxPMUs;
773773

774774
double joulesPerEnergyUnit;
@@ -2425,7 +2425,7 @@ class PCM_API PCM
24252425

24262426
bool uncoreFrequencyMetricAvailable() const
24272427
{
2428-
return MSR.empty() == false && uboxPMUs.size() == getNumSockets() && getNumCores() == getNumOnlineCores();
2428+
return MSR.empty() == false && getMaxNumOfUncorePMUs(UBOX_PMU_ID) > 0ULL && getNumCores() == getNumOnlineCores();
24292429
}
24302430

24312431
bool LatencyMetricsAvailable() const
@@ -3042,17 +3042,6 @@ uint64 getUncoreCounter(const int pmu_id, uint32 unit, uint32 counter, const Cou
30423042
return 0ULL;
30433043
}
30443044

3045-
/*! \brief Direct read of UBOX PMU counter (counter meaning depends on the programming: power/performance/etc)
3046-
\param counter counter number
3047-
\param before CPU counter state before the experiment
3048-
\param after CPU counter state after the experiment
3049-
*/
3050-
template <class CounterStateType>
3051-
uint64 getUBOXCounter(uint32 counter, const CounterStateType& before, const CounterStateType& after)
3052-
{
3053-
return after.UBOXCounter[counter] - before.UBOXCounter[counter];
3054-
}
3055-
30563045
/*! \brief Direct read of IIO PMU counter (counter meaning depends on the programming: power/performance/etc)
30573046
\param counter counter number
30583047
\param stack IIO stack number
@@ -3436,7 +3425,6 @@ class ServerUncoreCounterState : public UncoreCounterState
34363425
std::array<std::array<uint64, maxCounters>, maxIIOStacks> IRPCounter;
34373426
std::array<std::array<uint64, maxCounters>, maxCXLPorts> CXLCMCounter;
34383427
std::array<std::array<uint64, maxCounters>, maxCXLPorts> CXLDPCounter;
3439-
std::array<uint64, maxCounters> UBOXCounter;
34403428
std::array<uint64, maxChannels> DRAMClocks;
34413429
std::array<uint64, maxChannels> HBMClocks;
34423430
std::array<std::array<uint64, maxCounters>, maxChannels> MCCounter; // channel X counter
@@ -3462,8 +3450,6 @@ class ServerUncoreCounterState : public UncoreCounterState
34623450
template <class CounterStateType>
34633451
friend uint64 getUncoreCounter(const int pmu_id, uint32 unit, uint32 counter, const CounterStateType& before, const CounterStateType& after);
34643452
template <class CounterStateType>
3465-
friend uint64 getUBOXCounter(uint32 counter, const CounterStateType& before, const CounterStateType& after);
3466-
template <class CounterStateType>
34673453
friend uint64 getIIOCounter(uint32 stack, uint32 counter, const CounterStateType& before, const CounterStateType& after);
34683454
template <class CounterStateType>
34693455
friend uint64 getIRPCounter(uint32 stack, uint32 counter, const CounterStateType& before, const CounterStateType& after);
@@ -3496,7 +3482,6 @@ class ServerUncoreCounterState : public UncoreCounterState
34963482
IRPCounter{{}},
34973483
CXLCMCounter{{}},
34983484
CXLDPCounter{{}},
3499-
UBOXCounter{{}},
35003485
DRAMClocks{{}},
35013486
HBMClocks{{}},
35023487
MCCounter{{}},

src/pcm-raw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ void printTransposed(const PCM::RawPMUConfigs& curPMUConfigs,
16671667
choose(outputType,
16681668
[&]() { printUncoreRows(nullptr, 1U, ""); },
16691669
[&]() { printUncoreRows(nullptr, 1U, type); },
1670-
[&]() { printUncoreRows([](const uint32, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUBOXCounter(i, before, after); }, 1U,
1670+
[&]() { printUncoreRows([](const uint32, const uint32 i, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreCounter(PCM::UBOX_PMU_ID, 0, i, before, after); }, 1U,
16711671
"UncoreClocks", [](const uint32, const ServerUncoreCounterState& before, const ServerUncoreCounterState& after) { return getUncoreClocks(before, after); });
16721672
});
16731673
}
@@ -2037,7 +2037,7 @@ void print(const PCM::RawPMUConfigs& curPMUConfigs,
20372037
choose(outputType,
20382038
[s]() { cout << "SKT" << s << separator; },
20392039
[&event, &i]() { if (event.second.empty()) cout << "UBOXEvent" << i << separator; else cout << event.second << separator; },
2040-
[&]() { cout << getUBOXCounter(i, BeforeUncoreState[s], AfterUncoreState[s]) << separator; });
2040+
[&]() { cout << getUncoreCounter(PCM::UBOX_PMU_ID, 0, i, BeforeUncoreState[s], AfterUncoreState[s]) << separator; });
20412041
++i;
20422042
}
20432043
}

0 commit comments

Comments
 (0)