diff --git a/src/cpucounters.cpp b/src/cpucounters.cpp index 5368fe61..34e2a70d 100644 --- a/src/cpucounters.cpp +++ b/src/cpucounters.cpp @@ -359,7 +359,7 @@ bool PCM::isHWTMAL1Supported() const void PCM::readCPUMicrocodeLevel() { if (MSR.empty()) return; - const int ref_core = 0; + const int32 ref_core = socketRefCore[0]; TemporalThreadAffinity affinity(ref_core); if (affinity.supported() && isCoreOnline(ref_core)) { // see "Update Signature and Verification" and "Determining the Signature" @@ -1110,7 +1110,22 @@ bool PCM::discoverSystemTopology() }; std::unordered_map topologyDomainMap; { - TemporalThreadAffinity aff0(0); + const int32 maxTopoDomainAff = 1<<16; + int32 topoDomainAff = -1; + + for (int32 core = 0; core < maxTopoDomainAff; ++core) + { + try { + TemporalThreadAffinity _(core); + topoDomainAff = core; + } + catch (...) + { + } + if (topoDomainAff != -1) break; + } + + TemporalThreadAffinity _(topoDomainAff); if (initCoreMasks(smtMaskWidth, coreMaskWidth, l2CacheMaskShift, l3CacheMaskShift) == false) { @@ -4637,7 +4652,7 @@ uint64 RDTSC(); void PCM::computeNominalFrequency() { - const int ref_core = 0; + const int32 ref_core = socketRefCore[0]; const uint64 before = getInvariantTSC_Fast(ref_core); MySleepMs(100); const uint64 after = getInvariantTSC_Fast(ref_core); @@ -4809,11 +4824,11 @@ void PCM::computeQPISpeedBeckton(int core_nr) MSR[core_nr]->read(R_MSR_PMON_CTR0, &startFlits); const uint64 timerGranularity = 1000000ULL; // mks - uint64 startTSC = getTickCount(timerGranularity, (uint32) core_nr); + uint64 startTSC = getTickCount(timerGranularity, core_nr); uint64 endTSC; do { - endTSC = getTickCount(timerGranularity, (uint32) core_nr); + endTSC = getTickCount(timerGranularity, core_nr); } while (endTSC - startTSC < 200000ULL); // spin for 200 ms uint64 endFlits = 0; @@ -5401,8 +5416,9 @@ int convertUnknownToInt(size_t size, char* value) #endif -uint64 PCM::getTickCount(uint64 multiplier, uint32 core) +uint64 PCM::getTickCount(uint64 multiplier, int32 core) { + if (core == -1) core = socketRefCore[0]; return (multiplier * getInvariantTSC_Fast(core)) / getNominalFrequency(); } diff --git a/src/cpucounters.h b/src/cpucounters.h index b3e60ab5..90b5ecf9 100644 --- a/src/cpucounters.h +++ b/src/cpucounters.h @@ -2304,9 +2304,9 @@ class PCM_API PCM } //! \brief Return TSC timer value in time units //! \param multiplier use 1 for seconds, 1000 for ms, 1000000 for mks, etc (default is 1000: ms) - //! \param core core to read on-chip TSC value (default is 0) + //! \param core core to read on-chip TSC value (default is -1: socketRefCore[0]) //! \return time counter value - uint64 getTickCount(uint64 multiplier = 1000 /* ms */, uint32 core = 0); + uint64 getTickCount(uint64 multiplier = 1000 /* ms */, int32 core = -1); uint64 getInvariantTSC_Fast(uint32 core = 0);