00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #define PCXX_EVENT_SRC
00052 #include "Profile/TulipTimers.h"
00053
00054 #include <sys/types.h>
00055
00056
00057
00058
00059 static int pcxxT_notinit = 1;
00060
00061 #ifdef __PARAGON__
00062 # include <math.h>
00063 # include <i860paragon/rpm.h>
00064
00065 # define _2_to_52d (4503599627370496.0)
00066 # define OR_EXPONENT (0x4330)
00067 # define MASK_EXPONENT (0x000F)
00068
00069 double pcxxT_start;
00070
00071 static struct rpm *rpm = (struct rpm *) RPM_BASE_VADDR;
00072
00073 double pcxxT_dclock() {
00074 union {
00075 unsigned short wordwise[4];
00076 double value;
00077 } t;
00078 t.value = rpm->rpm_time;
00079 t.wordwise[3] = (t.wordwise[3] & MASK_EXPONENT) | OR_EXPONENT;
00080 return (t.value - _2_to_52d);
00081 }
00082
00083 void tulip_InitClocks() {
00084 if ( pcxxT_notinit ) {
00085 pcxxT_notinit = 0;
00086 pcxxT_start = floor (pcxxT_dclock()*1.0e-9)*1.0e9;
00087 }
00088 }
00089 #else
00090 #ifdef __ksr__
00091 void tulip_InitClocks() {}
00092 #else
00093 #if ( defined(_SEQUENT_) || defined(sequent) )
00094 void tulip_InitClocks() {
00095 if ( pcxxT_notinit ) {
00096 pcxxT_notinit = 0;
00097 usclk_init();
00098 }
00099 }
00100 #else
00101 #ifdef butterfly
00102 void tulip_InitClocks() {}
00103 #else
00104
00105 #ifdef __SP1_T__
00106 # include <math.h>
00107 double pcxxT_time;
00108 double pcxxT_start;
00109
00110 void tulip_InitClocks() {
00111 if ( pcxxT_notinit ) {
00112 pcxxT_notinit = 0;
00113 tb0time(&pcxxT_time);
00114 pcxxT_start = floor(pcxxT_time*1.0e-5)*1.0e5;
00115 }
00116 }
00117 #else
00118 #ifdef __SOLARIS2__
00119 # include <fcntl.h>
00120 static int pcxxT_fd;
00121
00122 static void pcxx_InitUserClock() {
00123 char proc[64];
00124 pcxxT_notinit = 0;
00125 sprintf(proc,"/proc/%d", getpid());
00126 pcxxT_fd = open(proc,O_RDONLY);
00127 }
00128 #endif
00129 #if ( !defined( __T3D__) && !defined(_CRAYT3E) )
00130
00131 # include <sys/time.h>
00132
00133 static long pcxxT_secs = 0L;
00134
00135 unsigned long int pcxxT_GetClock() {
00136 struct timeval tp;
00137 gettimeofday (&tp, 0);
00138 return ( (tp.tv_sec - pcxxT_secs) * 1000000 + tp.tv_usec );
00139 }
00140
00141 void tulip_InitClocks() {
00142 struct timeval tp;
00143 if ( pcxxT_notinit ) {
00144 pcxxT_notinit = 0;
00145 gettimeofday (&tp, 0);
00146 pcxxT_secs = tp.tv_sec;
00147 #ifdef __SOLARIS2__
00148 pcxx_InitUserClock();
00149 #endif
00150 }
00151 }
00152 #endif
00153 #endif
00154 #endif
00155 #endif
00156 #endif
00157 #endif
00158
00159
00160
00161
00162 #include <sys/time.h>
00163 #ifdef __SOLARIS2__
00164
00165
00166
00167
00168
00169
00170
00171 # ifdef USE_RUSAGE_H
00172 # include <sys/rusage.h>
00173 # else
00174 # include <sys/resource.h>
00175 # endif
00176 # include <sys/procfs.h>
00177 #else
00178 # include <sys/resource.h>
00179 #endif
00180
00181 #ifdef __hpux
00182 #include <sys/syscall.h>
00183 #define getrusage(a,b) syscall(SYS_getrusage,a,b)
00184 #endif
00185
00186 #if ( defined(_SEQUENT_) || defined(cray) && !defined(__T3D__) && \
00187 !defined(_CRAYT3E) )
00188 # include <sys/types.h>
00189
00190 # include <sys/param.h>
00191
00192 # if defined(cray)
00193 # define HZ CLK_TCK
00194 # endif
00195
00196
00197
00198
00199
00200
00201
00202
00203 #else
00204 #ifdef __SOLARIS2__
00205 double tulip_UserClock() {
00206 prusage_t myrusage;
00207 ioctl(pcxxT_fd, PIOCUSAGE, &myrusage);
00208 return (double)(myrusage.pr_utime.tv_sec+myrusage.pr_stime.tv_sec) +
00209 ((double)(myrusage.pr_utime.tv_nsec+myrusage.pr_stime.tv_nsec) * 1.0e-9);
00210 }
00211 #else
00212 #if ( !defined(__ksr__) && !defined(__T3D__) && !defined(_CRAYT3E) )
00213 double tulip_UserClock() {
00214 struct rusage myrusage;
00215 getrusage(RUSAGE_SELF,&myrusage);
00216 return (double)(myrusage.ru_utime.tv_sec+myrusage.ru_stime.tv_sec) +
00217 ((double)(myrusage.ru_utime.tv_usec+myrusage.ru_stime.tv_usec) * 1.0e-6);
00218 }
00219 #endif
00220 #endif
00221 #endif
00222
00223
00224
00225
00226
00227 #define MAXTIMERS 64
00228
00229 #if ( !defined(__ksr__) || defined(UNIPROC) )
00230 # define __private
00231 #endif
00232
00233
00234 __private static double WTimerStart[MAXTIMERS];
00235 __private static double WTimerStop[MAXTIMERS];
00236 __private static double WTimerElapsed[MAXTIMERS];
00237
00238
00239 #ifndef CM5
00240 __private static double UTimerStart[MAXTIMERS];
00241 __private static double UTimerStop[MAXTIMERS];
00242 __private static double UTimerElapsed[MAXTIMERS];
00243 #endif
00244
00245 #ifdef CM5
00246 #include <cm/cmmd.h>
00247 #endif
00248
00249 int tulip_UserTimerClear(int i) {
00250 PCXX_EVENT (PCXX_EC_TIMER, PCXX_UTIMER_CLEAR, i);
00251
00252 #ifdef CM5
00253 CMMD_node_timer_clear(i);
00254 #else
00255 UTimerStart[i] = 0.0;
00256 UTimerStop[i] = 0.0;
00257 UTimerElapsed[i] = 0.0;
00258 #endif
00259 return 1;
00260 }
00261
00262
00263 int tulip_UserTimerStart(int i) {
00264 PCXX_EVENT (PCXX_EC_TIMER, PCXX_UTIMER_START + i, 0);
00265 #ifdef CM5
00266 return CMMD_node_timer_start(i);
00267 #else
00268 UTimerStart[i] = tulip_UserClock();
00269 #endif
00270 return 1;
00271 }
00272
00273 int tulip_UserTimerStop(int i) {
00274 PCXX_EVENT (PCXX_EC_TIMER, PCXX_UTIMER_STOP + i, 0);
00275 #ifdef CM5
00276 CMMD_node_timer_stop(i);
00277 #else
00278 UTimerStop[i] = tulip_UserClock() - UTimerStart[i];
00279 UTimerElapsed[i] = UTimerElapsed[i] + UTimerStop[i];
00280 #endif
00281 return 1;
00282 }
00283
00284 double tulip_UserTimerElapsed(int i) {
00285 #ifdef CM5
00286 return CMMD_node_timer_elapsed(i);
00287 #else
00288 return UTimerElapsed[i];
00289 #endif
00290 }
00291
00292
00293
00294 int tulip_WallTimerClear(int i) {
00295 PCXX_EVENT (PCXX_EC_TIMER, PCXX_WTIMER_CLEAR, i);
00296
00297 WTimerStart[i] = 0.0;
00298 WTimerStop[i] = 0.0;
00299 WTimerElapsed[i] = 0.0;
00300 return 1;
00301 }
00302
00303 int tulip_WallTimerStart(int i) {
00304 PCXX_EVENT (PCXX_EC_TIMER, PCXX_WTIMER_START + i, 0);
00305
00306 WTimerStart[i] = tulip_WallClock();
00307 return 1;
00308 }
00309
00310 int tulip_WallTimerStop(int i) {
00311 PCXX_EVENT (PCXX_EC_TIMER, PCXX_WTIMER_STOP + i, 0);
00312
00313 WTimerStop[i] = tulip_WallClock() - WTimerStart[i];
00314 WTimerElapsed[i] = WTimerElapsed[i] + WTimerStop[i];
00315 return 1;
00316 }
00317
00318 double tulip_WallTimerElapsed(int i) {
00319 return WTimerElapsed[i];
00320 }
00321
00322
00323
00324
00325
00326
00327