1

The command rdtsc should be reliable source of time if the "TscInvariant" CPUID feature is enabled (see for example this link). On a dynamic frequency rescaling context, a reliable source of time cannot be a reliable source of cycles.

On TsCInvariant-enabled CPUs: is there a way to have a reliable way to just measure cycles?

diegor
  • 542
  • 2
  • 15
  • 2
    Yes, use performance counters, that's what they're for. It's possible to set things up so `rdpmc` is usable from user-space (and counting an even like core cycles) if you really want it to work similarly to `rdtsc`. It's usually easier to put your benchmark in an executable by itself with enough repeat count to dominate startup overhead, though, then you can just `perf stat` it. – Peter Cordes Dec 31 '19 at 10:49
  • 1
    @PeterCordes, great thanks! The option perf stat/wrapper is a bit cumbersome when working with MPI. I am giving rdpmc a shot, I am following the approach provided by Dr. Bandwidth here https://software.intel.com/en-us/forums/software-tuning-performance-optimization-platform-monitoring/topic/595214 . – diegor Dec 31 '19 at 11:14
  • If your algorithm doesn't have a big startup or cleanup phase, you *can* probably still use `perf stat`. It can attach to a PID so you could have your MPI workers fork/exec `perf stat`. Often the signal you're looking for is still visible with a bit of "noise" from imperfect measurement conditions, as long as the code under test doesn't optimize away your repeat loop or whatever. – Peter Cordes Dec 31 '19 at 11:21
  • Apologies to the OP for this digression. @PeterCordes, you invariably offer such insightful contributions. I am curious why you often choose to do so in comments, rather than formal solutions. Rather than speculating, I'd much prefer to get it from 'the horse's' mouth. – Ghii Velte Jan 01 '20 at 23:52
  • @GhiiVelte: I didn't feel like my comment was a complete answer if I didn't take the time to look up *how* to set up RDPMC for use from user-space and program a counter to count something. I don't want to post "fastest gun in the west" answers that only partially answer the question, and sometimes I'm not interested in digging up the extra details I've already looked into previous but don't have at my fingertips. – Peter Cordes Jan 02 '20 at 03:13
  • 1
    @GhiiVelte: When I leave a quick comment instead of answering, it's a low effort way to nudge further comments / discussion in the "right" (I hope) direction. Or hopefully someone feeling more ambitious can take my comment and turn that into a real answer. Or maybe if I get back to it, I'll do that myself, but I've started and not finished so many answers (either because I get bored or run out of time and don't get back to it) that leaving a comment at least helps some. – Peter Cordes Jan 02 '20 at 04:44
  • 1
    @PeterCordes: Thank you! I appreciate your sincerity and clarity, and I do understand completely. We have similar interests, and I relatively little time to spend here; so I frequently find myself in this situation: where I come to a question thinking I have the definitive answer, but then spy it in your comments. *Without* this reassurance, I tend to feel that building an answer thereon would be duplicative, redundant, or even plagiaristic, and so simply leave it at that. *Knowing* that this is your attitude, I will often be *delighted* to act on your *'nudge'*. Cheers! – Ghii Velte Jan 03 '20 at 00:38
  • @GhiiVelte: It's not rare to see answers that include the phrase "as @ somebody mentioned in comments" and then expand on that idea, for at least a section of the answer. I used to write more answers, but now that I've been around for longer it's more common that I can see what the answer would be, but it's something I've already explained pieces of in previous answers and don't think it would be fun to write again. That's the other part of why I'd probably get bored writing an answer. – Peter Cordes Jan 03 '20 at 05:25

0 Answers0