* Re: mmapping the system clock
[not found] <3784F179.6D410388@netscape.com>
@ 1999-07-08 4:00 ` Serguei Patchkovskii
[not found] ` <37853B51.13C2A901@netscape.com>
0 siblings, 1 reply; 2+ messages in thread
From: Serguei Patchkovskii @ 1999-07-08 4:00 UTC (permalink / raw)
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'
b) do p = mmap(0,sizeof(struct sysdef_info),PROT_READ,0,
open("/dev/sysdev0",O_RDONLY),0)
c) get your time at ((struct sysdef_info*)p)->tv)
Do not forget to add appropriate error checking.
Caveat: I had not tested this.
/Serge.P
--
home page: http://www.cobalt.chem.ucalgary.ca/ps/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: mmapping the system clock
[not found] ` <37853B51.13C2A901@netscape.com>
@ 1999-07-12 4:00 ` Vincent Nicolas
0 siblings, 0 replies; 2+ messages in thread
From: Vincent Nicolas @ 1999-07-12 4:00 UTC (permalink / raw)
To: wtc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-07-12 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox