uarch-bench
uarch-bench copied to clipboard
Consider making TimerInfo::now() non-static
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 mmap
ed 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).