diff options
| author | 2022-07-16 23:14:38 -0700 | |
|---|---|---|
| committer | 2022-07-16 23:14:38 -0700 | |
| commit | 8ca8281f4f2d4050ec4eb67db422d5ceb3cabb3a (patch) | |
| tree | 10fc191d058f7d057cbe41bc875054080774893d /src/common/x64/cpu_detect.cpp | |
| parent | Merge pull request #8593 from merryhime/ranged-setting-T (diff) | |
| parent | guard against div-by-zero (diff) | |
| download | yuzu-8ca8281f4f2d4050ec4eb67db422d5ceb3cabb3a.tar.gz yuzu-8ca8281f4f2d4050ec4eb67db422d5ceb3cabb3a.tar.xz yuzu-8ca8281f4f2d4050ec4eb67db422d5ceb3cabb3a.zip | |
Merge pull request #8543 from BreadFish64/use_tsc_from_caps
common/x64: Use TSC clock rate from CPUID when available
Diffstat (limited to 'src/common/x64/cpu_detect.cpp')
| -rw-r--r-- | src/common/x64/cpu_detect.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp index 322aa1f08..1a27532d4 100644 --- a/src/common/x64/cpu_detect.cpp +++ b/src/common/x64/cpu_detect.cpp | |||
| @@ -161,6 +161,22 @@ static CPUCaps Detect() { | |||
| 161 | caps.invariant_tsc = Common::Bit<8>(cpu_id[3]); | 161 | caps.invariant_tsc = Common::Bit<8>(cpu_id[3]); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | if (max_std_fn >= 0x15) { | ||
| 165 | __cpuid(cpu_id, 0x15); | ||
| 166 | caps.tsc_crystal_ratio_denominator = cpu_id[0]; | ||
| 167 | caps.tsc_crystal_ratio_numerator = cpu_id[1]; | ||
| 168 | caps.crystal_frequency = cpu_id[2]; | ||
| 169 | // Some CPU models might not return a crystal frequency. | ||
| 170 | // The CPU model can be detected to use the values from turbostat | ||
| 171 | // https://github.com/torvalds/linux/blob/master/tools/power/x86/turbostat/turbostat.c#L5569 | ||
| 172 | // but it's easier to just estimate the TSC tick rate for these cases. | ||
| 173 | if (caps.tsc_crystal_ratio_denominator) { | ||
| 174 | caps.tsc_frequency = static_cast<u64>(caps.crystal_frequency) * | ||
| 175 | caps.tsc_crystal_ratio_numerator / | ||
| 176 | caps.tsc_crystal_ratio_denominator; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 164 | if (max_std_fn >= 0x16) { | 180 | if (max_std_fn >= 0x16) { |
| 165 | __cpuid(cpu_id, 0x16); | 181 | __cpuid(cpu_id, 0x16); |
| 166 | caps.base_frequency = cpu_id[0]; | 182 | caps.base_frequency = cpu_id[0]; |