Rust crate to estimate the 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:
asseembly
inc %rax
inc %rax
inc %rax
inc %rax
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).
This crate currently supports (or is tested on) Linux on x86_64, mips64 and aarch64 instruction sets.
rust
let cpu_frequency_in_mhz = calcmhz::mhz().unwrap();
println!("{} MHz", cpu_frequency_in_mhz);
Full documentation will be available in the docs.rs once this crate is accepted at crates.io.
The files at the cli
directory in the repository provides with a simple command-line
interface to the functionality of this crate.
``` calcmhz --help Command line interface for the calcmhz
Usage: calcmhz [OPTIONS]
Options:
-d, --duration
The aforementioned command line utility is automatically built in the CI pipeline and published in Docker container image format. Visit GitLab Container Registry for latest tags.
Usage example:
sh
podman run -it --rm registry.gitlab.com/tomari/calcmhz:latest
Copyright 2023 Hisanobu Tomari
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.