From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,508255217f73d30e X-Google-Attributes: gidfee84,public From: Vincent Nicolas Subject: Re: mmapping the system clock Date: 1999/07/12 Message-ID: <3789DBEF.71BF67F7@cosmosbay.com>#1/1 X-Deja-AN: 500122062 Cache-Post-Path: news1!unknown@10.65.0.252 Content-Transfer-Encoding: 7bit References: <3784F179.6D410388@netscape.com> <7m2v7c$85k@ds2.acs.ucalgary.ca> <37853B51.13C2A901@netscape.com> To: wtc@netscape.com X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@infonie.fr X-Trace: starship.infonie.fr 931788868 3475 10.1.5.10 (12 Jul 1999 14:14:28 GMT) Organization: Infonie Mime-Version: 1.0 NNTP-Posting-Date: 12 Jul 1999 14:14:28 GMT Newsgroups: comp.unix.osf.osf1 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