Announcing the release of nanotime v0.1

Posted by dave on Mar 16, 2004 1:07 PM EDT
Bob Whitinger
Mail this story
Print this story

nanotime is a shell callable utility which reads and returns a 64 bit high resolution time stamp on cpus which support the TSC register. The TSC register increments at the basic system clock rate, making this a very high speed counter. [Editor's note: Not your every day story, but interesting, thus I posted it. :) ]

/* 
 * nanotime 
 *
 * version 0.1
 * 
 * Copyright 2004 under the terms of the GNU General Public License (GPL)
 *
 * nanotime is a shell callable utility which reads and 
 * returns a 64 bit high resolution time stamp on cpus 
 * which support the TSC register.  Results are returned
 * as a decimal number. The TSC register begins counting
 * at CPU reset time and increments at the basic system 
 * clock rate, making this a very high speed counter.
 * 
 * example: a 2.8GHz clock on an Intel P4  results in a 
 * nanotime resolution of 0.357 nanoseconds. 
 *
 * 
 */

#include <stdio.h>

#define get_nanotime(nanotime) __asm__ __volatile__ ( "rdtscntmovl %%eax, %0ntmovl %%edx, %%eaxntmovl %%eax, 4%0n" : "=m" (nanotime) :: "eax", "edx" );

int main(int argc, char *argv[]) { unsigned long long tm;

if (argc > 1) { printf("Usage:t %snnanotime v0.1 nCopyright 2004 GPLn",argv[0]); return 0; }

get_nanotime(tm);

printf("%Lun",tm); return 0; }

  Nav
» Read more about: Story Type: Announcements

« Return to the newswire homepage

This topic does not have any threads posted yet!

You cannot post until you login.