Skip to content

Commit

Permalink
add warning if TSC is not invariant
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 715345083
  • Loading branch information
jan-wassenberg authored and copybara-github committed Jan 14, 2025
1 parent 84b9f61 commit 4e00e25
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hwy/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ void Cpuid(const uint32_t level, const uint32_t count,
bool HasRDTSCP() {
uint32_t abcd[4];
Cpuid(0x80000001U, 0, abcd); // Extended feature flags
return (abcd[3] & (1u << 27)) != 0; // RDTSCP
if ((abcd[3] & (1u << 27)) == 0) return false; // RDTSCP

Cpuid(0x80000007U, 0, abcd);
if ((abcd[3] & (1u << 8)) == 0) {
HWY_WARN("TSC not constant/invariant, may vary frequency or jump.");
}
return true;
}

#endif // HWY_ARCH_X86
Expand Down

0 comments on commit 4e00e25

Please sign in to comment.