A simple library to sample the frequency on single CPU cores. The frequency is sampled by computing the ratio of actual performed cycles to the cycles that have passed in base frequency according to rdtsc.
As buildsystem we use cmake:
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/path/to/install_dir ..
cmake --build . --config Release
cmake --install .To include the library in CMake:
find_package(cpufreqlib
HINTS
/path/to/install_dir/cmake)
target_link_libraries(your_target
PRIVATE cpufreqlib) To sample the current frequency of the current core call:
#include <cpufreqlib.h>
// ...
float base_freq = get_base_cpu_freq_hz(); // get base frequency
// ...
float freq = get_curr_cpu_freq_hz(); // get current frequencyNote that sampling on two SMT threads of the same physical CPU might lead to false measurements