lkml.org 
[lkml]   [2004]   [Dec]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: How to measure flow of time using Time Stamp Counter on i386 machines
On Thu, 9 Dec 2004, krishna wrote:

> 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.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:08    [W:0.168 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site