@@ -3448,11 +3448,11 @@ uint64 RDTSC();
3448
3448
void PCM::computeNominalFrequency ()
3449
3449
{
3450
3450
const int ref_core = 0 ;
3451
- uint64 before = 0 , after = 0 ;
3452
- MSR[ref_core]-> read (IA32_TIME_STAMP_COUNTER, &before );
3453
- MySleepMs ( 1000 );
3454
- MSR[ref_core]-> read (IA32_TIME_STAMP_COUNTER, & after);
3455
- nominal_frequency = after-before ;
3451
+ const uint64 before = getInvariantTSC_Fast (ref_core) ;
3452
+ MySleepMs ( 100 );
3453
+ const uint64 after = getInvariantTSC_Fast (ref_core );
3454
+ nominal_frequency = 10ULL *( after-before );
3455
+ std::cerr << " WARNING: Core nominal frequency has to be estimated \n " ;
3456
3456
}
3457
3457
std::string PCM::getCPUBrandString ()
3458
3458
{
@@ -4095,6 +4095,18 @@ bool PCM::supportsRTM() const
4095
4095
return (info.reg .ebx & (0x1 << 11 )) ? true : false ;
4096
4096
}
4097
4097
4098
+ bool PCM::supportsRDTSCP () const
4099
+ {
4100
+ static int supports = -1 ;
4101
+ if (supports < 0 )
4102
+ {
4103
+ PCM_CPUID_INFO info;
4104
+ pcm_cpuid (0x80000001 , info);
4105
+ supports = (info.reg .edx & (0x1 << 27 )) ? 1 : 0 ;
4106
+ }
4107
+ return 1 == supports;
4108
+ }
4109
+
4098
4110
#ifdef __APPLE__
4099
4111
4100
4112
uint32 PCM::getNumInstances ()
@@ -4215,12 +4227,24 @@ bool PCM::decrementInstanceSemaphore()
4215
4227
4216
4228
uint64 PCM::getTickCount (uint64 multiplier, uint32 core)
4217
4229
{
4218
- return (multiplier * getInvariantTSC ( CoreCounterState (), getCoreCounterState ( core) )) / getNominalFrequency ();
4230
+ return (multiplier * getInvariantTSC_Fast ( core)) / getNominalFrequency ();
4219
4231
}
4220
4232
4221
- uint64 PCM::getTickCountRDTSCP (uint64 multiplier )
4233
+ uint64 PCM::getInvariantTSC_Fast (uint32 core )
4222
4234
{
4223
- return (multiplier*RDTSCP ())/getNominalFrequency ();
4235
+ if (supportsRDTSCP ())
4236
+ {
4237
+ TemporalThreadAffinity aff (core);
4238
+ return RDTSCP ();
4239
+ }
4240
+ else if (core < MSR.size ())
4241
+ {
4242
+ uint64 cInvariantTSC = 0 ;
4243
+ MSR[core]->read (IA32_TIME_STAMP_COUNTER, &cInvariantTSC);
4244
+ if (cInvariantTSC) return cInvariantTSC;
4245
+ }
4246
+ std::cerr << " ERROR: cannot read time stamp counter\n " ;
4247
+ return 0ULL ;
4224
4248
}
4225
4249
4226
4250
SystemCounterState getSystemCounterState ()
@@ -4292,7 +4316,7 @@ void BasicCounterState::readAndAggregateTSC(std::shared_ptr<SafeMsrHandle> msr)
4292
4316
const auto cpu_model = m->getCPUModel ();
4293
4317
if (m->isAtom () == false || cpu_model == PCM::AVOTON)
4294
4318
{
4295
- msr->read (IA32_TIME_STAMP_COUNTER, &cInvariantTSC );
4319
+ cInvariantTSC = m-> getInvariantTSC_Fast ( msr->getCoreId () );
4296
4320
MSRValues[IA32_TIME_STAMP_COUNTER] = cInvariantTSC;
4297
4321
}
4298
4322
else
@@ -5544,7 +5568,7 @@ ServerUncoreCounterState PCM::getServerUncoreCounterState(uint32 socket)
5544
5568
// std::cout << "Energy status: " << val << "\n";
5545
5569
MSR[refCore]->read (MSR_PACKAGE_THERM_STATUS,&val);
5546
5570
result.PackageThermalHeadroom = extractThermalHeadroom (val);
5547
- MSR[refCore]-> read (IA32_TIME_STAMP_COUNTER, & result.InvariantTSC );
5571
+ result.InvariantTSC = getInvariantTSC_Fast (refCore );
5548
5572
readAndAggregatePackageCStateResidencies (MSR[refCore], result);
5549
5573
}
5550
5574
// std::cout << std::flush;
0 commit comments