@@ -4283,7 +4283,11 @@ void BasicCounterState::readAndAggregateTSC(std::shared_ptr<SafeMsrHandle> msr)
4283
4283
uint64 cInvariantTSC = 0 ;
4284
4284
PCM * m = PCM::getInstance ();
4285
4285
const auto cpu_model = m->getCPUModel ();
4286
- if (m->isAtom () == false || cpu_model == PCM::AVOTON) msr->read (IA32_TIME_STAMP_COUNTER, &cInvariantTSC);
4286
+ if (m->isAtom () == false || cpu_model == PCM::AVOTON)
4287
+ {
4288
+ msr->read (IA32_TIME_STAMP_COUNTER, &cInvariantTSC);
4289
+ MSRValues[IA32_TIME_STAMP_COUNTER] = cInvariantTSC;
4290
+ }
4287
4291
else
4288
4292
{
4289
4293
#ifdef _MSC_VER
@@ -4413,14 +4417,22 @@ void BasicCounterState::readAndAggregate(std::shared_ptr<SafeMsrHandle> msr)
4413
4417
readAndAggregateTSC (msr);
4414
4418
4415
4419
// reading core C state counters
4416
- for (int i=0 ; i <= (int )(PCM::MAX_C_STATE) ;++i)
4417
- if (m->coreCStateMsr && m->coreCStateMsr [i])
4418
- msr->read (m->coreCStateMsr [i], &(cCStateResidency[i]));
4420
+ for (int i = 0 ; i <= (int )(PCM::MAX_C_STATE); ++i)
4421
+ {
4422
+ if (m->coreCStateMsr && m->coreCStateMsr [i])
4423
+ {
4424
+ const auto index = m->coreCStateMsr [i];
4425
+ msr->read (index, &(cCStateResidency[i]));
4426
+ MSRValues[index] = cCStateResidency[i];
4427
+ }
4428
+ }
4419
4429
4420
4430
// reading temperature
4421
4431
msr->read (MSR_IA32_THERM_STATUS, &thermStatus);
4432
+ MSRValues[MSR_IA32_THERM_STATUS] = thermStatus;
4422
4433
4423
4434
msr->read (MSR_SMI_COUNT, &cSMICount);
4435
+ MSRValues[MSR_SMI_COUNT] = cSMICount;
4424
4436
4425
4437
InstRetiredAny += checked_uint64 (m->extractCoreFixedCounterValue (cInstRetiredAny), extract_bits (overflows, 32 , 32 ));
4426
4438
CpuClkUnhaltedThread += checked_uint64 (m->extractCoreFixedCounterValue (cCpuClkUnhaltedThread), extract_bits (overflows, 33 , 33 ));
@@ -4657,6 +4669,8 @@ void PCM::programPCU(uint32* PCUCntConf, const uint64 filter)
4657
4669
PCM::ErrorCode PCM::program (const RawPMUConfigs& curPMUConfigs_, const bool silent)
4658
4670
{
4659
4671
if (MSR.empty ()) return PCM::MSRAccessDenied;
4672
+ threadMSRConfig = RawPMUConfig{};
4673
+ packageMSRConfig = RawPMUConfig{};
4660
4674
RawPMUConfigs curPMUConfigs = curPMUConfigs_;
4661
4675
constexpr auto globalRegPos = 0 ;
4662
4676
if (curPMUConfigs.count (" core" ))
@@ -4789,6 +4803,14 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
4789
4803
{
4790
4804
programIIOCounters (events64);
4791
4805
}
4806
+ else if (type == " package_msr" )
4807
+ {
4808
+ packageMSRConfig = pmuConfig.second ;
4809
+ }
4810
+ else if (type == " thread_msr" )
4811
+ {
4812
+ threadMSRConfig = pmuConfig.second ;
4813
+ }
4792
4814
else
4793
4815
{
4794
4816
std::cerr << " ERROR: unrecognized PMU type \" " << type << " \"\n " ;
@@ -5066,6 +5088,28 @@ void PCM::readAndAggregateEnergyCounters(const uint32 socket, CounterStateType &
5066
5088
result.DRAMEnergyStatus += dram_energy_status[socket]->read ();
5067
5089
}
5068
5090
5091
+ template <class CounterStateType >
5092
+ void PCM::readMSRs (std::shared_ptr<SafeMsrHandle> msr, const PCM::RawPMUConfig& msrConfig, CounterStateType& result)
5093
+ {
5094
+ auto read = [&msr, &result](const RawEventConfig & cfg) {
5095
+ const auto index = cfg.first [MSREventPosition::index];
5096
+ if (result.MSRValues .find (index) == result.MSRValues .end ())
5097
+ {
5098
+ uint64 val{ 0 };
5099
+ msr->read (index, &val);
5100
+ result.MSRValues [index] = val;
5101
+ }
5102
+ };
5103
+ for (const auto & cfg : msrConfig.programmable )
5104
+ {
5105
+ read (cfg);
5106
+ }
5107
+ for (const auto & cfg : msrConfig.fixed )
5108
+ {
5109
+ read (cfg);
5110
+ }
5111
+ }
5112
+
5069
5113
template <class CounterStateType >
5070
5114
void PCM::readAndAggregatePackageCStateResidencies (std::shared_ptr<SafeMsrHandle> msr, CounterStateType & result)
5071
5115
{
@@ -5202,6 +5246,7 @@ void PCM::readPackageThermalHeadroom(const uint32 socket, CounterStateType & res
5202
5246
{
5203
5247
uint64 val = 0 ;
5204
5248
MSR[socketRefCore[socket]]->read (MSR_PACKAGE_THERM_STATUS,&val);
5249
+ result.MSRValues [MSR_PACKAGE_THERM_STATUS] = val;
5205
5250
result.ThermalHeadroom = extractThermalHeadroom (val);
5206
5251
}
5207
5252
else
@@ -5257,6 +5302,7 @@ void PCM::getAllCounterStates(SystemCounterState & systemState, std::vector<Sock
5257
5302
{
5258
5303
socketStates[topology[core].socket ].UncoreCounterState ::readAndAggregate (MSR[core]); // read package C state counters
5259
5304
}
5305
+ readMSRs (MSR[core], threadMSRConfig, coreStates[core]);
5260
5306
}
5261
5307
);
5262
5308
asyncCoreResults.push_back (task.get_future ());
@@ -5269,11 +5315,12 @@ void PCM::getAllCounterStates(SystemCounterState & systemState, std::vector<Sock
5269
5315
{
5270
5316
int32 refCore = socketRefCore[s];
5271
5317
if (refCore<0 ) refCore = 0 ;
5272
- std::packaged_task<void ()> task ([this , s, &socketStates]() -> void
5318
+ std::packaged_task<void ()> task ([this , s, &socketStates, refCore ]() -> void
5273
5319
{
5274
5320
readAndAggregateUncoreMCCounters (s, socketStates[s]);
5275
5321
readAndAggregateEnergyCounters (s, socketStates[s]);
5276
5322
readPackageThermalHeadroom (s, socketStates[s]);
5323
+ readMSRs (MSR[refCore], packageMSRConfig, socketStates[s]);
5277
5324
} );
5278
5325
asyncCoreResults.push_back (task.get_future ());
5279
5326
coreTaskQueues[refCore]->push (task);
0 commit comments