BYTE.com > Features > 2006
Testing Times
By Richard Vaughan
(Testing Times
: Page 1 of 1 )
The film Fantastic Voyage demonstrates microscopy through a provocative premise--the miniaturization of the observer. Appealing as this is, however, it would not yield definitive knowledge of biological processes because the behaviour of, say, a single blood cell does not reflect the properties of blood as a whole. Similarly, the RDTSC machine-instruction, supported by Intel processors from the Pentium onwards, proffers microscopy of time, in that it allows the number of cycles consumed during execution of a section of code to be determined exactly. However, the use of RDTSC is by no means simple, and a number of often-subtle issues must be observed if accurate, consistent, and representative results are to be gathered.
Using RDTSC
The RDTSC instruction lets applications determine the number of machine cycles that have elapsed since the CPU was powered up, and places a 64-bit value in EDX:EAX. Subtracting the value obtained just before a code sequence from that obtained once the sequence has completed yields the number of cycles consumed between the two points, and the figure can then be divided by the clock frequency to yield elapsed real-time if desired. Given this, Listing One should yield the number of cycles required to construct an instance of a simple class (note this reads just the lower 32 bits of the counter).
However, while this will always give an accurate count of the cycles consumed, results can be inconsistent across repeated executions of the test, and additional steps must be taken to yield representative data. Firstly, RDTSC is a "non serializing" instruction, which means that out of order instruction-execution could cause it to return a value before the test sequence has completed. It is therefore necessary to force the CPU to complete all operations before executing RDTSC, and while there are several instructions that can be used to effect this, the most suitable by far is CPUID. This should be executed immediately before the first RDTSC, and immediately before the second.
Page 1 of 1
BYTE.com > Features > 2006
|