How to measure flow of time using Time Stamp Counter on i386 machines
Hi all,
Can anyone tell me how to measure flow of time using Time Stamp
Counter on pentium machines.
Which documentation could help me in understanding it.
Regards,
Krishna Chaitanya
Quoted 9 lines · krishna
Hi all,
Can anyone tell me how to measure flow of time using Time Stamp Counter on
pentium machines.
Which documentation could help me in understanding it.Regards,
Krishna Chaitanya
-
The rdtsc instruction returns the CPU clocks that have occurred since the time the machine was started. If you assemble the provided code as:
as -o tim.o tim.S
... then link this with your code, it will return the CPU clocks that have occurred between two successive calls..
extern long long tim(void);
code()
{
long long total;
(void)tim(); // Initialize
do_something(); // Some code to measure
total = tim(); // Get measurement printf("Total CPU clocks are %lld\n", total);}
-------------
#
# This is free software written by Richard B. Johnson. No
# copyright is claimed. It is also not guaranteed to do anything
# useful.
#
#
.data
lastl: .long 0
lasth: .long 0
.text
.align 8 .globl tim
.type tim@function
#
# Return the CPU clock difference between successive calls. #
tim: pushl %ebx
rdtsc
movl (lastl), %ebx # Get last low longword
movl (lasth), %ecx # Get last high longword
movl %eax, (lastl) # Save current low longword
movl %edx, (lasth) # Save current high longword
subl %ebx, %eax # Current - last
sbbl %ecx, %edx # Same with borrow
popl %ebx
ret
.end
--------------------
Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by John Ashcroft.
98.36% of all statistics are fiction.