I am profiling some code on three different computers with three different frequencies. I need the frequencies to measure GFLOPs/s. I have some code which does this but it does not account for Turboboost. For example on my 2600k CPU it reports 3.4 GHz but I can see when I run CPUz that my CPU is running at 4.3 GHz (overclocked) for my code which uses all cores.
#include "stdint.h"
#include "stdio.h"
#include "omp.h"
int main() {
int64_t cycles = rdtsc(); double dtime = omp_get_wtime();
//run some code which uses all cores for a while (few ms)
dtime = omp_get_wtime() - dtime;
cycles = rdtsc() - cycles;
double freq = (double)cycles/dtime*1E-9;
printf("freq %.2f GHz\n", freq);
}
__int64 rdtsc() {
#ifdef _WIN32
return __rdtsc();
#else
uint64_t t;
asm volatile ("rdtsc" : "=A"(t));
return t;
#endif
}
I know this question has been asked various times with various answers but it's still not clear to me if this can be done. I don't care about hackers trying to change timers. This code is only for myself. Is it possible to get the actual frequency in code? How is this done on Linux? Every example I have found on linux gives the base frequency (or maybe max) but not the operating frequency under load like CPUz does.
Edit: I found a program, Powertop, for Linux which appears to show the actual operating frequency. Since the source code is available maybe it's possible to figure out how to get the actual frequency in my own code.