1
votes

Recently I am trying to measure the effect of the cpu scaling. Is it accurate if I use this clock to measure it?

    template<std::intmax_t clock_freq>
    struct rdtsc_clock {
        typedef unsigned long long rep;
        typedef std::ratio<1, clock_freq> period;
        typedef std::chrono::duration<rep, period> duration;
        typedef std::chrono::time_point<rdtsc_clock> time_point;
        static const bool is_steady = true;

        static time_point now() noexcept
        {

            unsigned lo, hi;
            asm volatile("rdtsc" : "=a" (lo), "=d" (hi));

            return time_point(duration(static_cast<rep>(hi) << 32 | lo));
        }
    };

Update:

According to the comment from my another post, I believe redtsc cannot use for measure the effect of cpu frequency scaling because the counter from the redtsc does not affected by the CPU frequency, am i right?

1
How closely do your results match the theoretical results? - paddy
enough to present the effect, and their difference - Bryan Fok
See stackoverflow.com/questions/4509727/… for information on how to see if your RDTSC supports a constant rate clock, independent of power-saving slow down etc.. - Tony Delroy
@TonyD Thanks again Tony. yap, i find constant_tsc tagged in the cpuinfo - Bryan Fok
@TonyD would you like to draw a conclusion, so i can mark as answer? - Bryan Fok

1 Answers

1
votes

From the comment in my another post, in short, redtsc cannot use for measure the effect of cpu frequency scaling because the counter from the redtsc does not affected by the CPU frequency.