home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!darkstar.UCSC.EDU!cats.ucsc.edu!mmcohen
- From: mmcohen@cats.ucsc.edu (Michael M Cohen)
- Newsgroups: comp.sys.sgi
- Subject: Re: How Accurate Is The System Clock
- Date: 24 Dec 1992 00:47:04 GMT
- Organization: University of California; Santa Cruz
- Lines: 72
- Message-ID: <1hb1a8INNr7m@darkstar.UCSC.EDU>
- References: <AJ3U.92Dec22153748@larch.cs.virginia.edu> <1992Dec23.194149.27172@odin.corp.sgi.com> <tvl10pk@rhyolite.wpd.sgi.com>
- NNTP-Posting-Host: si.ucsc.edu
-
-
- In article <tvl10pk@rhyolite.wpd.sgi.com> vjs@rhyolite.wpd.sgi.com (Vernon Schryver) writes:
- >In article <1992Dec23.194149.27172@odin.corp.sgi.com>, archer@elysium.esd.sgi.com (Archer Sully) writes:
- >> In <AJ3U.92Dec22153748@larch.cs.virginia.edu> aj3u@larch.cs.virginia.edu (Asim Jalis) writes:
- >>
- >> *I am writing some programs on the SGI that requires millisecond
- >> *timing accuracy. How accurate is the clock on these machines?
-
- If you have an IO3 board there is another timer with
- submillisecond cycles. Here is some code I use....
- call cy_setup before use.
- cy_start sets beginning point
- cy_timer will wait for specified usec
- cy_read returns usec sinc beginning
-
- ============================
- #include <sys/types.h>
- #include <sys/syssgi.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- #include <limits.h>
-
- volatile unsigned int* counter; /* Pointer to IO3 counter */
- #define MICROSECS_PER_PICOSEC 1.0e-6
- unsigned long counterTickPicoSecs;
- unsigned int* counterAddr;
- int mmemfd;
- unsigned int previousCounter;
- unsigned int currentCounter;
-
- cy_setup()
- {
- int i;
-
- counterAddr = (unsigned*)syssgi(SGI_QUERY_CYCLECNTR, &counterTickPicoSecs);
- mmemfd = open("/dev/mmem", O_RDONLY, 0);
- counter = mmap(0, sizeof(*counter), PROT_READ, MAP_PRIVATE, mmemfd,
- (unsigned)counterAddr);
- }
-
- cy_start()
- {
- previousCounter = *counter; /* reads current value from mmapped */
- }
-
- int cy_read()
- {
- double cy_ticks; int cy_usec;
-
- currentCounter = *counter; /* reads current value from mmapped */
- cy_ticks = (currentCounter >= previousCounter) ?
- currentCounter - previousCounter :
- currentCounter + UINT_MAX - previousCounter;
- cy_usec = cy_ticks * counterTickPicoSecs * MICROSECS_PER_PICOSEC;
- return(cy_usec);
- }
-
- cy_timer(cyt)
- int cyt;
- {
- cy_start();
- while(cy_read() < cyt){};
- }
- --
-
- ======================================================================
- = Dr. Michael M. Cohen mmcohen@dewi.ucsc.edu =
- = Program in Experimental Psychology mmcohen@fuzzy.ucsc.edu =
- = 433 Clark Kerr Hall 408-459-2655 LAB =
- = University of California - Santa Cruz 408-459-2700 MSGS =
- = Santa Cruz, CA 95064 408-459-3519 FAX =
- ======================================================================
-