[ntp:questions] Re: Linux PPS triggering with NMEA

Bjorn Gabrielsson bg at lysator.liu.se
Tue May 10 17:29:35 UTC 2005


per at hedeland.org (Per Hedeland) writes:

> In article <m3acn4ozpe.fsf at lysator.liu.se> Bjorn Gabrielsson
> <bg at lysator.liu.se> writes:
> >
> >I know what TIOCMIWAIT gives. Is there a user-space function that can
> >return time with better than than the 1us resolution that
> >gettimeofday() gives?
> 
> To answer your question in the literal sense, "there is" the function
> clock_gettime(), that *can* return time with 1 ns resolution (through a
> struct timespec rather than struct timeval). 

Thanks! I will try that too. Late last night I found rdtscl() and
rdtsc(,). Which seem to capture a counter running at CPU speed - ca
2.002656 GHz. A 32-bit counter loops around in about 2 seconds! This
gives all resolution I was asking about... and more.


#include <asm/msr.h>
#include <unistd.h>

volatile unsigned long ini, end;

rdtscl(ini);
rdtscl(end);

printf("time lapse: %li\n", end - ini);

rdtscl(ini);
sleep(1);
rdtscl(end);

printf("time lapse: %li\n", end - ini);

--
        Björn



More information about the questions mailing list