Skip to content

Commit 6deb088

Browse files
authored
Merge pull request #190 from intel-innersource/188-disable-enable-nmi-watchdog-just-once-not-for-each-programcleanup-call
reduce overhead for multigroups by skipping full cleanup
2 parents b83a93a + 60f2e2c commit 6deb088

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/cpucounters.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,6 @@ PCM::PCM() :
20762076
pkgMinimumPower(-1),
20772077
pkgMaximumPower(-1),
20782078
systemTopology(new SystemRoot(this)),
2079-
programmed_pmu(false),
20802079
joulesPerEnergyUnit(0),
20812080
#ifdef __linux__
20822081
resctrl(*this),
@@ -2413,6 +2412,7 @@ PCM::ErrorCode PCM::program(const PCM::ProgramMode mode_, const void * parameter
24132412
ExtendedCustomCoreEventDescription * pExtDesc = (ExtendedCustomCoreEventDescription *)parameter_;
24142413

24152414
#ifdef PCM_USE_PERF
2415+
closePerfHandles(silent);
24162416
if (!silent) std::cerr << "Trying to use Linux perf events...\n";
24172417
const char * no_perf_env = std::getenv("PCM_NO_PERF");
24182418
if (no_perf_env != NULL && std::string(no_perf_env) == std::string("1"))
@@ -2463,7 +2463,7 @@ PCM::ErrorCode PCM::program(const PCM::ProgramMode mode_, const void * parameter
24632463
}
24642464
#endif
24652465

2466-
if (true)
2466+
if (programmed_core_pmu == false)
24672467
{
24682468
if((canUsePerf == false) && PMUinUse())
24692469
{
@@ -2742,8 +2742,6 @@ PCM::ErrorCode PCM::program(const PCM::ProgramMode mode_, const void * parameter
27422742
}
27432743
#endif
27442744

2745-
programmed_pmu = true;
2746-
27472745
lastProgrammedCustomCounters.clear();
27482746
lastProgrammedCustomCounters.resize(num_cores);
27492747
core_global_ctrl_value = 0ULL;
@@ -2776,6 +2774,8 @@ PCM::ErrorCode PCM::program(const PCM::ProgramMode mode_, const void * parameter
27762774
}
27772775
}
27782776

2777+
programmed_core_pmu = true;
2778+
27792779
if (canUsePerf && !silent)
27802780
{
27812781
std::cerr << "Successfully programmed on-core PMU using Linux perf\n";
@@ -3808,9 +3808,9 @@ const char * PCM::getUArchCodename(const int32 cpu_model_param) const
38083808
return "unknown";
38093809
}
38103810

3811-
void PCM::cleanupPMU(const bool silent)
3812-
{
38133811
#ifdef PCM_USE_PERF
3812+
void PCM::closePerfHandles(const bool silent)
3813+
{
38143814
if (canUsePerf)
38153815
{
38163816
auto cleanOne = [this](PerfEventHandleContainer & cont)
@@ -3833,6 +3833,17 @@ void PCM::cleanupPMU(const bool silent)
38333833
perfEventTaskHandle.clear();
38343834

38353835
if (!silent) std::cerr << " Closed perf event handles\n";
3836+
}
3837+
}
3838+
#endif
3839+
3840+
void PCM::cleanupPMU(const bool silent)
3841+
{
3842+
programmed_core_pmu = false;
3843+
#ifdef PCM_USE_PERF
3844+
closePerfHandles(silent);
3845+
if (canUsePerf)
3846+
{
38363847
return;
38373848
}
38383849
#endif

src/cpucounters.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ class PCM_API PCM
600600
std::string errorMessage;
601601

602602
static PCM * instance;
603-
bool programmed_pmu;
603+
bool programmed_core_pmu{false};
604604
std::vector<std::shared_ptr<SafeMsrHandle> > MSR;
605605
std::vector<std::shared_ptr<ServerPCICFGUncore> > server_pcicfg_uncore;
606606
std::vector<UncorePMU> pcuPMUs;
@@ -863,6 +863,7 @@ class PCM_API PCM
863863
PerfEventHandleContainer perfEventHandle;
864864
std::vector<PerfEventHandleContainer> perfEventTaskHandle;
865865
void readPerfData(uint32 core, std::vector<uint64> & data);
866+
void closePerfHandles(const bool silent = false);
866867

867868
enum {
868869
PERF_INST_RETIRED_POS = 0,

src/pcm-raw.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,11 +2147,7 @@ int main(int argc, char* argv[])
21472147
//cout << "Called sleep function for " << dec << fixed << delay_ms << " ms\n";
21482148

21492149
printAll(group, m, BeforeState, AfterState, BeforeUncoreState, AfterUncoreState, BeforeSocketState, AfterSocketState, PMUConfigs, groupNr == nGroups);
2150-
if (nGroups > 1)
2151-
{
2152-
m->cleanup(true);
2153-
}
2154-
else
2150+
if (nGroups == 1)
21552151
{
21562152
std::swap(BeforeState, AfterState);
21572153
std::swap(BeforeSocketState, AfterSocketState);

0 commit comments

Comments
 (0)