Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Vincent Nicolas <vnicolas@cosmosbay.com>
To: wtc@netscape.com
Subject: Re: mmapping the system clock
Date: 1999/07/12	[thread overview]
Message-ID: <3789DBEF.71BF67F7@cosmosbay.com> (raw)
In-Reply-To: 37853B51.13C2A901@netscape.com


I suppose gettimeofday() dont use this hack because there is a problem
when the timeval structure is modified (probably by clock interrupt,
1024 per second)
If your application reads tv.tv_sec and tv.tv_usec, it couls be
interrupted by the clock and you could have something like :

printf("first : %d.%06d\n", ptr->tv.tv_sec, ptr->tv.tv_usec) ;
printf("next : %d.%06d\n", ptr->tv.tv_sec, ptr->tv.tv_usec) ;

first : 931810701.999024
next : 931810701.000000  (interrupt between read of tv_sec and tv_usec)


In order to have correct results, the gettimeofday-like function should
:
read tv_sec in a local, then read tv_usec in an other local,
then reread tv_sec to see if a wrap occured. If not, OK, else return to
begin

So be carefull !
Eric Dumazet


Wan-Teh Chang wrote:
> 
> Serguei Patchkovskii wrote:
> 
> > Wan-Teh Chang (wtc@netscape.com) wrote:
> > : I read in comp.programming.threads that
> > : on Tru64 UNIX one can mmap /dev/sysdev0
> > : to read the system clock without a system call.
> > : I can't find any info about this technique in the
> > : man pages.
> >
> > Upon examining /dev/MAKEDEV and /sys/include/kern/sysdev_info.h,
> > it appears that you should:
> >
> > a) as root, do: 'cd /dev/;./MAKEDEV sysdev0; chmod go+r sysdev0'
> 
> Yes, I found that /dev/sysdev0 didn't exist on
> my Tru64 UNIX machine.  This command created
> the device.
> 
> > b) do p = mmap(0,sizeof(struct sysdef_info),PROT_READ,0,
> >                open("/dev/sysdev0",O_RDONLY),0)
> 
> The third argument to mmap cannot be 0.  I use MAP_SHARED,
> which worked.
> 
> > c) get your time at ((struct sysdef_info*)p)->tv)
> 
> I tried this and it worked.  I had a single-threaded program
> use this technique to get the current timeval structure, and
> it is 100 times faster than using gettimeofday.
> 
> Now I wonder why /dev/sysdev0 isn't created by the
> system by default, and why gettimeofday's implementation
> doesn't use this mmap technique.
> 
> Thanks for your help.
> 
> Wan-Teh



      parent reply	other threads:[~1999-07-12  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3784F179.6D410388@netscape.com>
1999-07-08  4:00 ` mmapping the system clock Serguei Patchkovskii
     [not found]   ` <37853B51.13C2A901@netscape.com>
1999-07-12  4:00     ` Vincent Nicolas [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox