easy_profiler icon indicating copy to clipboard operation
easy_profiler copied to clipboard

calculate_cpu_frequency

Open amesgames opened this issue 5 years ago • 1 comments

I am having difficulty interpreting the result of calculate_cpu_frequency(). I ran the main_clock.cpp sample code and produce this output:

`std::chrono::steady_clock: 0.012 usec std::chrono::high_resolution_clock: 0.017 usec std::chrono::system_clock: 0.018 usec

rdtsc: 0.003 usec

syscall(SYS_clock_gettime, CLOCK_MONOTONIC): 0.125134 usec syscall(SYS_clock_gettime, CLOCK_REALTIME): 0.127601 usec syscall(SYS_clock_gettime, CLOCK_MONOTONIC_RAW): 0.12472 usec syscall(SYS_clock_gettime, CLOCK_MONOTONIC_COARSE): 0 usec syscall(SYS_clock_gettime, CLOCK_REALTIME_COARSE): 0 usec

clock_gettime(CLOCK_MONOTONIC): 0.011697 usec clock_gettime(CLOCK_REALTIME): 0.014974 usec clock_gettime(CLOCK_MONOTONIC_RAW): 0.12744 usec clock_gettime(CLOCK_MONOTONIC_COARSE): 0 usec clock_gettime(CLOCK_REALTIME_COARSE): 0 usec

gettimeofday(): 0.009 usec`

Should I expect that rdtsc should be in the ballpark of the other values?

The value I get when I call calculate_cpu_frequency() tends to be around 2,208,000. Following is my clock speed as reported by lscpu | grep MHz:

CPU MHz: 900.073 CPU max MHz: 4100.0000 CPU min MHz: 800.0000

Is calculate_cpu_frequency() supposed to return ticks per second?

amesgames avatar Jan 17 '19 01:01 amesgames

Hi @amesgames

I'm very sorry for the delay...

I'm trying to remember... I think main_clock.cpp is a bit outdated, but your interpretation is right. rdtsc is the best choise for the most platforms, but there is a low probability that it could give incorrect results if a task has switched from one cpu-core to another one (generally speaking - you will see that execution time of your task suddenly increased to abnormal huge value, which would also lead to visual artifacts in profiler_gui). If this happened, you probably should try another timer type (currently we offer std::chrono::high_resolution_clock and std::chrono::steady_clock).

COARSE timers check is redundant.
You got surprising results for gettimeofday() :)

Yes, calculate_cpu_frequency() supposed to return ticks per second, but output value depends on your cpu energy management settings. It executes cpu-effective cycle (tries to load cpu to 100%) and measures ticks wasted in it, but it will give you an average value if your cpu is in energy saving mode.

@yse , please correct me if I'm wrong

cas4ey avatar Feb 20 '19 15:02 cas4ey