Expand description
Estimates CPU (processor) core frequency.
Estimates the CPU frequency by measuring the time it takes to run a sequence of instructions in a dependency chain. The instruction sequence is written in assembly like this:
addi a1,a1,1
addi a1,a1,1
addi a1,a1,1
addi a1,a1,1
This method does not use performance counters (other than the wall clock), and the estimated frequency is likely to be the boosted frequency if such a feature is available on the system, subject to temperature and/or other conditions.
While this method of frequency estimation works most of the time, there are a number of known example of microarchitectures where this measurement reports half the actual operating frequency (e.g. IBM POWER7 and POWER8). There is also an example of microarchitecture where this program reports double the frequency: Pentium 4. It runs ALUs at double the frequency.
This crate currently supports following platforms:
ISA | Linux | macOS | Windows(MSVC) |
---|---|---|---|
aarch64 | ☑ | ☑ | ☑ |
arm | ☑ | ||
i586 | ☑ | ☑ | |
i686 | ☑ | ☑ | |
mips | ☑ | ||
mips64 | ☑ | ||
powerpc | ☑ | ||
powerpc64 | ☑ | ||
riscv64 | ☑ | ||
s390x | not yet | ||
sparc | ☑ | ||
sparc64 | ☑ | ||
x86_64 | ☑ | ☑ | ☑ |
Structs§
- Estimation
- Result of estimation.
Enums§
- Error
- The error type for estimation functions.
Constants§
- REASONABLE_
INITIAL_ LOOPS - Reasonable value for use as the initial number of loops. 10000.
- REASONABLE_
MIN_ DURATION - Reasonable duration for the estimation. 500ms.
Functions§
- estimate_
mhz - Runs the measurement instruction sequence and returns the estimated CPU frequency.
The initial number of loops is specified in the
loops
argument. If the elapsed time is shorter thanmin_duration
the function tries to adjust the number of loops to meet the minimum duration requirement. - mhz
- Convenience function that is used when all that is required is the CPU frequency.
Uses reasonable defaults for
estimate_mhz
and returns just the CPU frequency.