How to benchmark on multi-core processors

Posted by Pascal Cuoq on Stack Overflow See other posts from Stack Overflow or by Pascal Cuoq
Published on 2010-05-08T15:48:43Z Indexed on 2010/05/08 15:58 UTC
Read the original article Hit count: 269

I am looking for ways to perform micro-benchmarks on multi-core processors.

Context:

At about the same time desktop processors introduced out-of-order execution that made performance hard to predict, they, perhaps not coincidentally, also introduced special instructions to get very precise timings. Example of these instructions are rdtsc on x86 and rftb on PowerPC. These instructions gave timings that were more precise than could ever be allowed by a system call, allowed programmers to micro-benchmark their hearts out, for better or for worse.

On a yet more modern processor with several cores, some of which sleep some of the time, the counters are not synchronized between cores. We are told that rdtsc is no longer safe to use for benchmarking, but I must have been dozing off when we were explained the alternative solutions.

Question:

Some systems may save and restore the performance counter and provide an API call to read the proper sum. If you know what this call is for any operating system, please let us know in an answer.

Some systems may allow to turn off cores, leaving only one running. I know Mac OS X Leopard does when the right Preference Pane is installed from the Developers Tools. Do you think that this make rdtsc safe to use again?

More context:

Please assume I know what I am doing when trying to do a micro-benchmark. If you are of the opinion that if an optimization's gains cannot be measured by timing the whole application, it's not worth optimizing, I agree with you, but

  1. I cannot time the whole application until the alternative data structure is finished, which will take a long time. In fact, if the micro-benchmark were not promising, I could decide to give up on the implementation now;

  2. I need figures to provide in a publication whose deadline I have no control over.

© Stack Overflow or respective owner

Related posts about benchmarking

Related posts about micro-benchmark