source: CIVL/examples/omp/nas-dc/common/wtime_sgi64.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <sys/types.h>
2#include <fcntl.h>
3#include <sys/mman.h>
4#include <sys/syssgi.h>
5#include <sys/immu.h>
6#include <errno.h>
7#include <stdio.h>
8
9/* The following works on SGI Power Challenge systems */
10
11typedef unsigned long iotimer_t;
12
13unsigned int cycleval;
14volatile iotimer_t *iotimer_addr, base_counter;
15double resolution;
16
17/* address_t is an integer type big enough to hold an address */
18typedef unsigned long address_t;
19
20
21
22void timer_init()
23{
24
25 int fd;
26 char *virt_addr;
27 address_t phys_addr, page_offset, pagemask, pagebase_addr;
28
29 pagemask = getpagesize() - 1;
30 errno = 0;
31 phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
32 if (errno != 0) {
33 perror("SGI_QUERY_CYCLECNTR");
34 exit(1);
35 }
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);
40
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;
47}
48
49void wtime_(double *time)
50{
51 static int initialized = 0;
52 volatile iotimer_t counter_value;
53 if (!initialized) {
54 timer_init();
55 initialized = 1;
56 }
57 counter_value = *iotimer_addr - base_counter;
58 *time = (double)counter_value * resolution;
59}
60
61
62void wtime(double *time)
63{
64 static int initialized = 0;
65 volatile iotimer_t counter_value;
66 if (!initialized) {
67 timer_init();
68 initialized = 1;
69 }
70 counter_value = *iotimer_addr - base_counter;
71 *time = (double)counter_value * resolution;
72}
73
74
Note: See TracBrowser for help on using the repository browser.