home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / MP / timer / iot4 / second.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.8 KB  |  69 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <sys/mman.h>
  20. #include <fcntl.h>
  21. #include <sys/IP5.h>
  22. #include <sys/syssgi.h>
  23.  
  24. extern int errno;
  25. unsigned *clockaddr, resolution;
  26. /*****************************************************************************/
  27. /*
  28.  
  29. */
  30. double io4clock()
  31. {
  32.  
  33.     static int first = 1;
  34.     int filed;
  35.     unsigned int phys_addr;
  36.  
  37.     
  38.     if (first) {
  39.  
  40.         first = 0;
  41.  
  42.         /* Open memory special device */
  43.         if ( (filed = open("/dev/mmem",O_RDONLY)) == -1) {
  44.             perror ("ERROR in open"); exit(errno);
  45.         }
  46.  
  47.         /* Query for physical address of HW counter */
  48.         phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &resolution);
  49.         /* Map high resolution clock to user space */
  50.         if ( ((int)(clockaddr = mmap(0, 8, PROT_READ, MAP_PRIVATE, filed, phys_addr))) == -1) {
  51.             perror ("ERROR in mmap"); exit(errno);
  52.         }
  53.         clockaddr+=1;
  54.     }
  55.  
  56.     return ((double)(*clockaddr) * resolution * 1.e-12);
  57. }
  58.  
  59. double io4clock_()
  60. {
  61.     return (io4clock());
  62. }
  63.  
  64. float second_()
  65. {
  66.     return ((float)io4clock());
  67. }
  68.  
  69.