4 #include <sys/syssgi.h>
9 /* The following works on SGI Power Challenge systems */
11 typedef unsigned long iotimer_t;
13 unsigned int cycleval;
14 volatile iotimer_t *iotimer_addr, base_counter;
17 /* address_t is an integer type big enough to hold an address */
18 typedef unsigned long address_t;
27 address_t phys_addr, page_offset, pagemask, pagebase_addr;
29 pagemask = getpagesize() - 1;
31 phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
33 perror("SGI_QUERY_CYCLECNTR");
36 /* rel_addr = page offset of physical address */
37 page_offset = phys_addr & pagemask;
38 pagebase_addr = phys_addr - page_offset;
39 fd = open("/dev/mmem", O_RDONLY);
41 virt_addr = mmap(0, pagemask, PROT_READ, MAP_PRIVATE, fd, pagebase_addr);
42 virt_addr = virt_addr + page_offset;
43 iotimer_addr = (iotimer_t *)virt_addr;
44 /* cycleval in picoseconds to this gives resolution in seconds */
45 resolution = 1.0e-12*cycleval;
46 base_counter = *iotimer_addr;
49 void wtime_(double *time)
51 static int initialized = 0;
52 volatile iotimer_t counter_value;
57 counter_value = *iotimer_addr - base_counter;
58 *time = (double)counter_value * resolution;
62 void wtime(double *time)
64 static int initialized = 0;
65 volatile iotimer_t counter_value;
70 counter_value = *iotimer_addr - base_counter;
71 *time = (double)counter_value * resolution;