the mysterious cairo-perf (was: Re: [cairo] [PATCH] Performance patch for bo intersections)

Carl Worth cworth at
Sat Dec 16 08:27:09 PST 2006

On Sat, 16 Dec 2006 00:09:14 -0500, Behdad Esfahbod wrote:
> Yes, this happens a lot.  Basically anything that runs for shorter than
> a few seconds cannot be considered accurate.

I don't buy that. I've gotten very reliable results from tests that
run shorter than one second. Here's the writeup I did on how I was
determining reliability for short measurements:

> Also note that gettimeofday() has a limited accuracy. A few years
> ago I added some timing to glxgears, and I observed gettimeofday()
> return the same value before and after a frame redraw.

Yes, gettimeofday has limited precision, and it can also have
significant overhead, (since it's a system call). That's why
cairo-perf doesn't use gettimeofday except as a last resort. Instead,
we got code from liboil to query CPU performance counters. For
example, this uses "rdtsc" with inline assembly on i386 Posix
platforms. We've also got powerpc, alpha, and s390 support for Posix
systems as well, (again, thanks to liboil).

So the raw timing values that cairo-perf records and calculates with
are all just in units of whatever these counters return. We have a
pretty cheesy mechanism for estimating the frequency of that counter,
(using gettimeofday on either side of a usleep), but that's just for
formatting human-readable millisecond times for the reports---the
estimated frequency isn't used to determine speedup and slowdown at

> Adding a sched_yield() fixed it there, but you probably don't want to do that :).

We actually do have a sched_yield in cairo-perf, just before grabbing
the "before" value from the CPU counter before running each
iteration. Adding that did help a lot.

As usual, if anybody has suggestions for improving the reliability of
our timing, I'd love to see them.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url :

More information about the cairo mailing list