Crate calcmhz

source ·
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:

ISALinuxmacOSWindows(MSVC)
aarch64
arm
i586
i686
mips
mips64
powerpc
powerpc64
riscv64
s390xnot yet
sparc
sparc64
x86_64

Structs§

Enums§

  • The error type for estimation functions.

Constants§

Functions§

  • 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 than min_duration the function tries to adjust the number of loops to meet the minimum duration requirement.
  • 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.