1 : |
dalvarez |
15 |
/******************************************************************************/
|
2 : |
|
|
/* */
|
3 : |
|
|
/* Copyright (c) 2008, 2009, 2010 */
|
4 : |
|
|
/* Computer Architecture Group (CAG) */
|
5 : |
|
|
/* University of A Coruña, Spain */
|
6 : |
|
|
/* (http://gac.des.udc.es) */
|
7 : |
|
|
/* Galicia Supercomputing Center (CESGA) */
|
8 : |
|
|
/* (http://www.cesga.es) */
|
9 : |
|
|
/* Hewlett-Packard Spain (HP) */
|
10 : |
|
|
/* (http://www.hp.es) */
|
11 : |
|
|
/* */
|
12 : |
|
|
/* This file is part of UPC Operations Microbenchmarking Suite (UOMS). */
|
13 : |
|
|
/* */
|
14 : |
|
|
/* UOMS is free software: you can redistribute it and/or modify */
|
15 : |
|
|
/* it under the terms of the GNU Lesser General Public License as published */
|
16 : |
|
|
/* by the Free Software Foundation, either version 3 of the License, or */
|
17 : |
|
|
/* (at your option) any later version. */
|
18 : |
|
|
/* */
|
19 : |
|
|
/* UOMS is distributed in the hope that it will be useful, */
|
20 : |
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
21 : |
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
22 : |
|
|
/* GNU Lesser General Public License for more details. */
|
23 : |
|
|
/* */
|
24 : |
|
|
/* You should have received a copy of the GNU Lesser General Public License */
|
25 : |
|
|
/* along with UOMS. If not, see <http://www.gnu.org/licenses/>. */
|
26 : |
|
|
/* */
|
27 : |
|
|
/******************************************************************************/
|
28 : |
|
|
|
29 : |
|
|
/******************************************************************************/
|
30 : |
|
|
/* */
|
31 : |
|
|
/* FUNDING: This development has been funded by Hewlett-Packard Spain */
|
32 : |
|
|
/* */
|
33 : |
|
|
/* Project Name: */
|
34 : |
|
|
/* UPCHACO (2008-2011) */
|
35 : |
|
|
/* Subproject: */
|
36 : |
|
|
/* Improving UPC Usability and Performance in Constellation Systems: */
|
37 : |
|
|
/* Implementation/Extensions of UPC Libraries. */
|
38 : |
|
|
/* (UPCPUProject -> UPC Performance and Usability Project) */
|
39 : |
|
|
/* */
|
40 : |
|
|
/******************************************************************************/
|
41 : |
|
|
|
42 : |
|
|
/******************************************************************************
|
43 : |
|
|
|
44 : |
|
|
For further documentation, see
|
45 : |
|
|
|
46 : |
|
|
[1] Files under doc/
|
47 : |
|
|
|
48 : |
|
|
*******************************************************************************/
|
49 : |
|
|
|
50 : |
|
|
|
51 : |
|
|
#include <stdio.h>
|
52 : |
|
|
#include <stdint.h>
|
53 : |
|
|
#include <stdlib.h>
|
54 : |
|
|
#include <string.h>
|
55 : |
|
|
|
56 : |
|
|
/* Get clock ticks */
|
57 : |
|
|
uint64_t getTicks() {
|
58 : |
|
|
#ifdef __ia64
|
59 : |
|
|
#ifdef __INTEL_COMPILER
|
60 : |
|
|
#include <ia64intrin.h>
|
61 : |
|
|
return (uint64_t)__getReg(_IA64_REG_AR_ITC);
|
62 : |
|
|
#else
|
63 : |
|
|
uint64_t ret = 0;
|
64 : |
|
|
__asm__ __volatile__("mov %0=ar.itc" : "=r"(ret) );
|
65 : |
|
|
return ret;
|
66 : |
|
|
#endif
|
67 : |
|
|
#else
|
68 : |
|
|
#ifdef __HP_UPC_VER
|
69 : |
|
|
return hpupc_ticks_now();
|
70 : |
|
|
#elif __BERKELEY_UPC__
|
71 : |
|
|
return bupc_ticks_now();
|
72 : |
|
|
#else
|
73 : |
|
|
uint64_t tstamp;
|
74 : |
|
|
struct timeval tv;
|
75 : |
|
|
if (gettimeofday(&tv, NULL)) {
|
76 : |
|
|
perror("gettimeofday");
|
77 : |
|
|
abort();
|
78 : |
|
|
}
|
79 : |
|
|
tstamp = (((uint64_t)tv.tv_sec) * 1000000 + tv.tv_usec)*1000;
|
80 : |
|
|
return tstamp;
|
81 : |
|
|
#endif
|
82 : |
|
|
#endif
|
83 : |
|
|
}
|
84 : |
|
|
|
85 : |
|
|
/* Ticks to nanoseconds */
|
86 : |
|
|
uint64_t ticksToNS(uint64_t ticks) {
|
87 : |
|
|
#ifdef __ia64
|
88 : |
|
|
#include <errno.h>
|
89 : |
|
|
double tick_rate_ns = 0;
|
90 : |
|
|
errno = 0;
|
91 : |
|
|
FILE *fp = fopen("/proc/cpuinfo","r");
|
92 : |
|
|
if (errno != 0){
|
93 : |
|
|
perror("*** Error opening /proc/cpuinfo: ");
|
94 : |
|
|
exit(-1);
|
95 : |
|
|
}
|
96 : |
|
|
char input[255];
|
97 : |
|
|
while (!feof(fp) && fgets(input, 255, fp)) {
|
98 : |
|
|
if (strstr(input,"itc MHz")) {
|
99 : |
|
|
char *p = strchr(input,':');
|
100 : |
|
|
double MHz = 0.0;
|
101 : |
|
|
if (p) MHz = atof(p+1);
|
102 : |
|
|
if(!(MHz > 1 && MHz < 100000)) /* ensure it looks reasonable */
|
103 : |
|
|
fprintf(stderr, "*** Warning: ITC frequency unreasonable: %f MHz\n*** Expect unexpected results\n",MHz);
|
104 : |
|
|
tick_rate_ns = 1000. / MHz;
|
105 : |
|
|
break;
|
106 : |
|
|
}
|
107 : |
|
|
}
|
108 : |
|
|
fclose(fp);
|
109 : |
|
|
return (ticks * tick_rate_ns);
|
110 : |
|
|
#else
|
111 : |
|
|
#ifdef __HP_UPC_VER
|
112 : |
|
|
return hpupc_ticks_to_ns(ticks);
|
113 : |
|
|
#elif __BERKELEY_UPC__
|
114 : |
|
|
return bupc_ticks_to_ns(ticks);
|
115 : |
|
|
#else // if gettimeofday is used
|
116 : |
|
|
return ticks;
|
117 : |
|
|
#endif
|
118 : |
|
|
#endif
|
119 : |
|
|
}
|