On Fri, May 29, 2020 at 02:59:26PM +0200, Niels Möller wrote:
Daniel P. Berrangé berrange@redhat.com writes:
The elapsed time is the same regardless of ncalls, so I'm thinking that the compiler as been clever and optimized bench_nothing() into literally nothing. If I modify it to
static void bench_nothing(void *arg UNUSED) { static int i = 0; i++; return; }
then things work, but of course we're not benchmarking "nothing" anymore.
Maybe simplest to just delete this part of the benchmark? I don't think it's that useful.
After more debugging I found this is due to GCC 10 introdicing the -finline-functions arg at -O2.
Using -fno-inline-functions fixes the problem.
Alternatively adding __attribute__((noinline)) to "time_function" fixes it - nb noinline on "bench_nothing" does NOT fix it.
Alternatively adding assert(ncalls != 0); in the loop in time_function fixes it, because causing GCC to stop inlining it. That's largely luck, but it probably makes sense to have that assert() added regardless as this loop is inherantly susceptible to this wraparound problem as written.
Regards, Daniel