travisdowns / uarch-bench

A benchmark for low-level CPU micro-architectural features
MIT License
686 stars 63 forks source link

Consider making TimerInfo::now() non-static #62

Open travisdowns opened 6 years ago

travisdowns commented 6 years ago

Currently, each TIMER implementation should implement a static now() method, which is used in the core of the benchmark loop in order to take time (or PMU or whatever other metric) snapshots before and after the code-under-test runs.

This is fine for timers that are "stateless" like rdtsc or clock_gettime or whatever, but it's kind of incompatible with ones like PerfTimer which set up state inside the timer object (in this case, representing the mmaped page for each configured counter), and so whose now() method in principle must be non-static. As a workaround for PerfTimer, it uses static (global) data which assumes there is only one PerfTimer object and otherwise violates all kinds of good coding principles.

We could just make this method non-static and rely on the compiler to optimize it "as if static" for implementations that don't actually need this. We'd also want to check the code quality for things like PerfTimer which use instance data. Other solutions are possible, such as passing the Timer object to a static now as a parameter (admittedly almost the same thing).