All of lore.kernel.org
 help / color / mirror / Atom feed
* How to measure  flow of time using Time Stamp Counter on i386 machines
@ 2004-12-08 19:30 krishna
  2004-12-08 19:57 ` linux-os
  0 siblings, 1 reply; 2+ messages in thread
From: krishna @ 2004-12-08 19:30 UTC (permalink / raw)
  To: Linux Kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to measure  flow of time using Time Stamp Counter on i386 machines
  2004-12-08 19:30 How to measure flow of time using Time Stamp Counter on i386 machines krishna
@ 2004-12-08 19:57 ` linux-os
  0 siblings, 0 replies; 2+ messages in thread
From: linux-os @ 2004-12-08 19:57 UTC (permalink / raw)
  To: krishna; +Cc: Linux Kernel

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-12-08 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-08 19:30 How to measure flow of time using Time Stamp Counter on i386 machines krishna
2004-12-08 19:57 ` linux-os

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.