home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sgi / 18316 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.8 KB  |  84 lines

  1. Path: sparky!uunet!spool.mu.edu!agate!darkstar.UCSC.EDU!cats.ucsc.edu!mmcohen
  2. From: mmcohen@cats.ucsc.edu (Michael M Cohen)
  3. Newsgroups: comp.sys.sgi
  4. Subject: Re: How Accurate Is The System Clock
  5. Date: 24 Dec 1992 00:47:04 GMT
  6. Organization: University of California; Santa Cruz
  7. Lines: 72
  8. Message-ID: <1hb1a8INNr7m@darkstar.UCSC.EDU>
  9. References: <AJ3U.92Dec22153748@larch.cs.virginia.edu> <1992Dec23.194149.27172@odin.corp.sgi.com> <tvl10pk@rhyolite.wpd.sgi.com>
  10. NNTP-Posting-Host: si.ucsc.edu
  11.  
  12.  
  13. In article <tvl10pk@rhyolite.wpd.sgi.com> vjs@rhyolite.wpd.sgi.com (Vernon Schryver) writes:
  14. >In article <1992Dec23.194149.27172@odin.corp.sgi.com>, archer@elysium.esd.sgi.com (Archer Sully) writes:
  15. >> In <AJ3U.92Dec22153748@larch.cs.virginia.edu> aj3u@larch.cs.virginia.edu (Asim Jalis) writes:
  16. >> 
  17. >> *I am writing some programs on the SGI that requires millisecond
  18. >> *timing accuracy.  How accurate is the clock on these machines?
  19.  
  20. If you have an IO3 board there is another timer with
  21. submillisecond cycles. Here is some code I use....
  22. call cy_setup before use.
  23. cy_start sets beginning point
  24. cy_timer will wait for specified usec
  25. cy_read returns usec sinc beginning
  26.  
  27. ============================
  28. #include <sys/types.h>
  29. #include <sys/syssgi.h>
  30. #include <sys/mman.h>
  31. #include <fcntl.h>
  32. #include <limits.h>
  33.  
  34. volatile unsigned int* counter;         /* Pointer to IO3 counter */
  35. #define MICROSECS_PER_PICOSEC 1.0e-6
  36. unsigned long counterTickPicoSecs;
  37. unsigned int* counterAddr;
  38. int mmemfd;
  39. unsigned int previousCounter;
  40. unsigned int currentCounter;
  41.  
  42. cy_setup()
  43. {
  44.     int i;
  45.  
  46.     counterAddr = (unsigned*)syssgi(SGI_QUERY_CYCLECNTR, &counterTickPicoSecs);
  47.     mmemfd = open("/dev/mmem", O_RDONLY, 0);
  48.     counter = mmap(0, sizeof(*counter), PROT_READ, MAP_PRIVATE, mmemfd,
  49.                 (unsigned)counterAddr);
  50. }
  51.  
  52. cy_start()
  53. {
  54.     previousCounter = *counter;      /* reads current value from mmapped */
  55. }
  56.  
  57. int cy_read()
  58. {
  59. double cy_ticks; int cy_usec;
  60.  
  61.     currentCounter = *counter;      /* reads current value from mmapped */
  62.     cy_ticks = (currentCounter >= previousCounter) ?
  63.                currentCounter - previousCounter :
  64.                currentCounter + UINT_MAX - previousCounter;
  65.     cy_usec = cy_ticks * counterTickPicoSecs * MICROSECS_PER_PICOSEC;
  66.     return(cy_usec);
  67. }
  68.  
  69. cy_timer(cyt)
  70. int cyt;
  71. {
  72.         cy_start();
  73.         while(cy_read() < cyt){};
  74. }
  75. -- 
  76.  
  77. ======================================================================
  78. =   Dr. Michael M. Cohen                   mmcohen@dewi.ucsc.edu     = 
  79. =   Program in Experimental Psychology     mmcohen@fuzzy.ucsc.edu    =
  80. =   433 Clark Kerr Hall                    408-459-2655 LAB          = 
  81. =   University of California - Santa Cruz  408-459-2700 MSGS         = 
  82. =   Santa Cruz, CA 95064                   408-459-3519 FAX          = 
  83. ======================================================================
  84.