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
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 #if TIME_WITH_SYS_TIME
00082 # include <sys/time.h>
00083 # include <time.h>
00084 #else
00085 # if HAVE_SYS_TIME_H
00086 # include <sys/time.h>
00087 # else
00088 # include <time.h>
00089 # endif
00090 #endif
00091
00092 #define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
00093 { \
00094 return (double)t1 - (double)t0; \
00095 }
00096
00097 #if 1 == 0
00098 #else
00099
00100
00101
00102 #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
00103 typedef hrtime_t ticks;
00104
00105 #define getticks gethrtime
00106
00107 INLINE_ELAPSED(inline)
00108
00109 #define HAVE_TICK_COUNTER
00110 #endif
00111
00112
00113
00114 #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
00115 typedef timebasestruct_t ticks;
00116
00117 static __inline ticks getticks(void)
00118 {
00119 ticks t;
00120 read_real_time(&t, TIMEBASE_SZ);
00121 return t;
00122 }
00123
00124 static __inline double elapsed(ticks t1, ticks t0)
00125 {
00126 time_base_to_time(&t1, TIMEBASE_SZ);
00127 time_base_to_time(&t0, TIMEBASE_SZ);
00128 return (((double)t1.tb_high - (double)t0.tb_high) * 1.0e9 +
00129 ((double)t1.tb_low - (double)t0.tb_low));
00130 }
00131
00132 #define HAVE_TICK_COUNTER
00133 #endif
00134
00135
00136
00137
00138
00139 #if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
00140 typedef unsigned long long ticks;
00141
00142 static __inline__ ticks getticks(void)
00143 {
00144 unsigned int tbl, tbu0, tbu1;
00145
00146 do {
00147 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
00148 __asm__ __volatile__ ("mftb %0" : "=r"(tbl));
00149 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
00150 } while (tbu0 != tbu1);
00151
00152 return (((unsigned long long)tbu0) << 32) | tbl;
00153 }
00154
00155 INLINE_ELAPSED(__inline__)
00156
00157 #define HAVE_TICK_COUNTER
00158 #endif
00159
00160
00161
00162 #if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
00163 #include <mach/mach_time.h>
00164 typedef uint64_t ticks;
00165 #define getticks mach_absolute_time
00166 INLINE_ELAPSED(__inline__)
00167 #define HAVE_TICK_COUNTER
00168 #endif
00169
00170
00171
00172
00173
00174 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
00175 typedef unsigned long long ticks;
00176
00177 static __inline__ ticks getticks(void)
00178 {
00179 ticks ret;
00180
00181 __asm__ __volatile__("rdtsc": "=A" (ret));
00182
00183 return ret;
00184 }
00185
00186 INLINE_ELAPSED(__inline__)
00187
00188 #define HAVE_TICK_COUNTER
00189 #define TIME_MIN 5000.0
00190 #endif
00191
00192
00193 #if defined(_MSC_VER) && _MSC_VER >= 1200 && _M_IX86 >= 500 && !defined(HAVE_TICK_COUNTER)
00194 #include <windows.h>
00195 typedef LARGE_INTEGER ticks;
00196 #define RDTSC __asm __emit 0fh __asm __emit 031h
00197
00198 static __inline ticks getticks(void)
00199 {
00200 ticks retval;
00201
00202 __asm {
00203 RDTSC
00204 mov retval.HighPart, edx
00205 mov retval.LowPart, eax
00206 }
00207 return retval;
00208 }
00209
00210 static __inline double elapsed(ticks t1, ticks t0)
00211 {
00212 return (double)t1.QuadPart - (double)t0.QuadPart;
00213 }
00214
00215 #define HAVE_TICK_COUNTER
00216 #define TIME_MIN 5000.0
00217 #endif
00218
00219
00220
00221
00222
00223 #if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
00224 typedef unsigned long long ticks;
00225
00226 static __inline__ ticks getticks(void)
00227 {
00228 unsigned a, d;
00229 asm volatile("rdtsc" : "=a" (a), "=d" (d));
00230 return ((ticks)a) | (((ticks)d) << 32);
00231 }
00232
00233 INLINE_ELAPSED(__inline__)
00234
00235 #define HAVE_TICK_COUNTER
00236 #endif
00237
00238
00239
00240
00241 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
00242 typedef unsigned long long ticks;
00243 static ticks getticks(void)
00244 {
00245 asm(" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
00246 }
00247 INLINE_ELAPSED(__inline__)
00248 #define HAVE_TICK_COUNTER
00249 #endif
00250
00251
00252 #if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
00253
00254 #include <intrin.h>
00255 #pragma intrinsic(__rdtsc)
00256 typedef unsigned __int64 ticks;
00257 #define getticks __rdtsc
00258 INLINE_ELAPSED(__inline)
00259
00260 #define HAVE_TICK_COUNTER
00261 #endif
00262
00263
00264
00265
00266
00267
00268
00269 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
00270 typedef unsigned long ticks;
00271 #include <ia64intrin.h>
00272
00273 static __inline__ ticks getticks(void)
00274 {
00275 return __getReg(_IA64_REG_AR_ITC);
00276 }
00277
00278 INLINE_ELAPSED(__inline__)
00279
00280 #define HAVE_TICK_COUNTER
00281 #endif
00282
00283
00284 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
00285 typedef unsigned long ticks;
00286
00287 static __inline__ ticks getticks(void)
00288 {
00289 ticks ret;
00290
00291 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
00292 return ret;
00293 }
00294
00295 INLINE_ELAPSED(__inline__)
00296
00297 #define HAVE_TICK_COUNTER
00298 #endif
00299
00300
00301 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
00302 #include <machine/sys/inline.h>
00303 typedef unsigned long ticks;
00304
00305 static inline ticks getticks(void)
00306 {
00307 ticks ret;
00308
00309 ret = _Asm_mov_from_ar (_AREG_ITC);
00310 return ret;
00311 }
00312
00313 INLINE_ELAPSED(inline)
00314
00315 #define HAVE_TICK_COUNTER
00316 #endif
00317
00318
00319 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
00320 typedef unsigned __int64 ticks;
00321
00322 # ifdef __cplusplus
00323 extern "C"
00324 # endif
00325 ticks __getReg(int whichReg);
00326 #pragma intrinsic(__getReg)
00327
00328 static __inline ticks getticks(void)
00329 {
00330 volatile ticks temp;
00331 temp = __getReg(3116);
00332 return temp;
00333 }
00334
00335 INLINE_ELAPSED(inline)
00336
00337 #define HAVE_TICK_COUNTER
00338 #endif
00339
00340
00341
00342
00343
00344 #if defined(__hppa__) || defined(__hppa) && !defined(HAVE_TICK_COUNTER)
00345 typedef unsigned long ticks;
00346
00347 # ifdef __GNUC__
00348 static __inline__ ticks getticks(void)
00349 {
00350 ticks ret;
00351
00352 __asm__ __volatile__("mfctl 16, %0": "=r" (ret));
00353
00354 return ret;
00355 }
00356 # else
00357 # include <machine/inline.h>
00358 static inline unsigned long getticks(void)
00359 {
00360 register ticks ret;
00361 _MFCTL(16, ret);
00362 return ret;
00363 }
00364 # endif
00365
00366 INLINE_ELAPSED(inline)
00367
00368 #define HAVE_TICK_COUNTER
00369 #endif
00370
00371
00372
00373 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
00374 typedef unsigned long long ticks;
00375
00376 static __inline__ ticks getticks(void)
00377 {
00378 ticks cycles;
00379 __asm__("stck 0(%0)" : : "a" (&(cycles)) : "memory", "cc");
00380 return cycles;
00381 }
00382
00383 INLINE_ELAPSED(__inline__)
00384
00385 #define HAVE_TICK_COUNTER
00386 #endif
00387
00388 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
00389
00390
00391
00392
00393 typedef unsigned int ticks;
00394
00395 static __inline__ ticks getticks(void)
00396 {
00397 unsigned long cc;
00398 __asm__ __volatile__ ("rpcc %0" : "=r"(cc));
00399 return (cc & 0xFFFFFFFF);
00400 }
00401
00402 INLINE_ELAPSED(__inline__)
00403
00404 #define HAVE_TICK_COUNTER
00405 #endif
00406
00407
00408 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
00409 typedef unsigned long ticks;
00410
00411 static __inline__ ticks getticks(void)
00412 {
00413 ticks ret;
00414 __asm__ __volatile__("rd %%tick, %0" : "=r" (ret));
00415 return ret;
00416 }
00417
00418 INLINE_ELAPSED(__inline__)
00419
00420 #define HAVE_TICK_COUNTER
00421 #endif
00422
00423
00424 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
00425 # include <c_asm.h>
00426 typedef unsigned int ticks;
00427
00428 static __inline ticks getticks(void)
00429 {
00430 unsigned long cc;
00431 cc = asm("rpcc %v0");
00432 return (cc & 0xFFFFFFFF);
00433 }
00434
00435 INLINE_ELAPSED(__inline)
00436
00437 #define HAVE_TICK_COUNTER
00438 #endif
00439
00440
00441 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
00442 typedef struct timespec ticks;
00443
00444 static inline ticks getticks(void)
00445 {
00446 struct timespec t;
00447 clock_gettime(CLOCK_SGI_CYCLE, &t);
00448 return t;
00449 }
00450
00451 static inline double elapsed(ticks t1, ticks t0)
00452 {
00453 return ((double)t1.tv_sec - (double)t0.tv_sec) * 1.0E9 +
00454 ((double)t1.tv_nsec - (double)t0.tv_nsec);
00455 }
00456 #define HAVE_TICK_COUNTER
00457 #endif
00458
00459
00460
00461 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
00462 #ifdef HAVE_INTRINSICS_H
00463 # include <intrinsics.h>
00464 #endif
00465
00466 typedef long long ticks;
00467
00468 #define getticks _rtc
00469
00470 INLINE_ELAPSED(inline)
00471
00472 #define HAVE_TICK_COUNTER
00473 #endif
00474
00475
00476
00477 #if defined(HAVE_MIPS_ZBUS_TIMER) && HAVE_MIPS_ZBUS_TIMER
00478 #if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
00479 #include <sys/mman.h>
00480 #include <unistd.h>
00481 #include <fcntl.h>
00482
00483 typedef uint64_t ticks;
00484
00485 static inline ticks getticks(void)
00486 {
00487 static uint64_t* addr = 0;
00488
00489 if (addr == 0)
00490 {
00491 uint32_t rq_addr = 0x10030000;
00492 int fd;
00493 int pgsize;
00494
00495 pgsize = getpagesize();
00496 fd = open ("/dev/mem", O_RDONLY | O_SYNC, 0);
00497 if (fd < 0) {
00498 perror("open");
00499 return NULL;
00500 }
00501 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
00502 close(fd);
00503 if (addr == (uint64_t *)-1) {
00504 perror("mmap");
00505 return NULL;
00506 }
00507 }
00508
00509 return *addr;
00510 }
00511
00512 INLINE_ELAPSED(inline)
00513
00514 #define HAVE_TICK_COUNTER
00515 #endif
00516 #endif
00517
00518 #endif