annotate src/fftw-3.3.3/kernel/cycle.h @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * Permission is hereby granted, free of charge, to any person obtaining
Chris@10 6 * a copy of this software and associated documentation files (the
Chris@10 7 * "Software"), to deal in the Software without restriction, including
Chris@10 8 * without limitation the rights to use, copy, modify, merge, publish,
Chris@10 9 * distribute, sublicense, and/or sell copies of the Software, and to
Chris@10 10 * permit persons to whom the Software is furnished to do so, subject to
Chris@10 11 * the following conditions:
Chris@10 12 *
Chris@10 13 * The above copyright notice and this permission notice shall be
Chris@10 14 * included in all copies or substantial portions of the Software.
Chris@10 15 *
Chris@10 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@10 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@10 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@10 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
Chris@10 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
Chris@10 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@10 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@10 23 *
Chris@10 24 */
Chris@10 25
Chris@10 26
Chris@10 27 /* machine-dependent cycle counters code. Needs to be inlined. */
Chris@10 28
Chris@10 29 /***************************************************************************/
Chris@10 30 /* To use the cycle counters in your code, simply #include "cycle.h" (this
Chris@10 31 file), and then use the functions/macros:
Chris@10 32
Chris@10 33 ticks getticks(void);
Chris@10 34
Chris@10 35 ticks is an opaque typedef defined below, representing the current time.
Chris@10 36 You extract the elapsed time between two calls to gettick() via:
Chris@10 37
Chris@10 38 double elapsed(ticks t1, ticks t0);
Chris@10 39
Chris@10 40 which returns a double-precision variable in arbitrary units. You
Chris@10 41 are not expected to convert this into human units like seconds; it
Chris@10 42 is intended only for *comparisons* of time intervals.
Chris@10 43
Chris@10 44 (In order to use some of the OS-dependent timer routines like
Chris@10 45 Solaris' gethrtime, you need to paste the autoconf snippet below
Chris@10 46 into your configure.ac file and #include "config.h" before cycle.h,
Chris@10 47 or define the relevant macros manually if you are not using autoconf.)
Chris@10 48 */
Chris@10 49
Chris@10 50 /***************************************************************************/
Chris@10 51 /* This file uses macros like HAVE_GETHRTIME that are assumed to be
Chris@10 52 defined according to whether the corresponding function/type/header
Chris@10 53 is available on your system. The necessary macros are most
Chris@10 54 conveniently defined if you are using GNU autoconf, via the tests:
Chris@10 55
Chris@10 56 dnl ---------------------------------------------------------------------
Chris@10 57
Chris@10 58 AC_C_INLINE
Chris@10 59 AC_HEADER_TIME
Chris@10 60 AC_CHECK_HEADERS([sys/time.h c_asm.h intrinsics.h mach/mach_time.h])
Chris@10 61
Chris@10 62 AC_CHECK_TYPE([hrtime_t],[AC_DEFINE(HAVE_HRTIME_T, 1, [Define to 1 if hrtime_t is defined in <sys/time.h>])],,[#if HAVE_SYS_TIME_H
Chris@10 63 #include <sys/time.h>
Chris@10 64 #endif])
Chris@10 65
Chris@10 66 AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time])
Chris@10 67
Chris@10 68 dnl Cray UNICOS _rtc() (real-time clock) intrinsic
Chris@10 69 AC_MSG_CHECKING([for _rtc intrinsic])
Chris@10 70 rtc_ok=yes
Chris@10 71 AC_TRY_LINK([#ifdef HAVE_INTRINSICS_H
Chris@10 72 #include <intrinsics.h>
Chris@10 73 #endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc() intrinsic.])], [rtc_ok=no])
Chris@10 74 AC_MSG_RESULT($rtc_ok)
Chris@10 75
Chris@10 76 dnl ---------------------------------------------------------------------
Chris@10 77 */
Chris@10 78
Chris@10 79 /***************************************************************************/
Chris@10 80
Chris@10 81 #if TIME_WITH_SYS_TIME
Chris@10 82 # include <sys/time.h>
Chris@10 83 # include <time.h>
Chris@10 84 #else
Chris@10 85 # if HAVE_SYS_TIME_H
Chris@10 86 # include <sys/time.h>
Chris@10 87 # else
Chris@10 88 # include <time.h>
Chris@10 89 # endif
Chris@10 90 #endif
Chris@10 91
Chris@10 92 #define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
Chris@10 93 { \
Chris@10 94 return (double)t1 - (double)t0; \
Chris@10 95 }
Chris@10 96
Chris@10 97 /*----------------------------------------------------------------*/
Chris@10 98 /* Solaris */
Chris@10 99 #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
Chris@10 100 typedef hrtime_t ticks;
Chris@10 101
Chris@10 102 #define getticks gethrtime
Chris@10 103
Chris@10 104 INLINE_ELAPSED(inline)
Chris@10 105
Chris@10 106 #define HAVE_TICK_COUNTER
Chris@10 107 #endif
Chris@10 108
Chris@10 109 /*----------------------------------------------------------------*/
Chris@10 110 /* AIX v. 4+ routines to read the real-time clock or time-base register */
Chris@10 111 #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
Chris@10 112 typedef timebasestruct_t ticks;
Chris@10 113
Chris@10 114 static __inline ticks getticks(void)
Chris@10 115 {
Chris@10 116 ticks t;
Chris@10 117 read_real_time(&t, TIMEBASE_SZ);
Chris@10 118 return t;
Chris@10 119 }
Chris@10 120
Chris@10 121 static __inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
Chris@10 122 {
Chris@10 123 time_base_to_time(&t1, TIMEBASE_SZ);
Chris@10 124 time_base_to_time(&t0, TIMEBASE_SZ);
Chris@10 125 return (((double)t1.tb_high - (double)t0.tb_high) * 1.0e9 +
Chris@10 126 ((double)t1.tb_low - (double)t0.tb_low));
Chris@10 127 }
Chris@10 128
Chris@10 129 #define HAVE_TICK_COUNTER
Chris@10 130 #endif
Chris@10 131
Chris@10 132 /*----------------------------------------------------------------*/
Chris@10 133 /*
Chris@10 134 * PowerPC ``cycle'' counter using the time base register.
Chris@10 135 */
Chris@10 136 #if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
Chris@10 137 typedef unsigned long long ticks;
Chris@10 138
Chris@10 139 static __inline__ ticks getticks(void)
Chris@10 140 {
Chris@10 141 unsigned int tbl, tbu0, tbu1;
Chris@10 142
Chris@10 143 do {
Chris@10 144 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
Chris@10 145 __asm__ __volatile__ ("mftb %0" : "=r"(tbl));
Chris@10 146 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
Chris@10 147 } while (tbu0 != tbu1);
Chris@10 148
Chris@10 149 return (((unsigned long long)tbu0) << 32) | tbl;
Chris@10 150 }
Chris@10 151
Chris@10 152 INLINE_ELAPSED(__inline__)
Chris@10 153
Chris@10 154 #define HAVE_TICK_COUNTER
Chris@10 155 #endif
Chris@10 156
Chris@10 157 /* MacOS/Mach (Darwin) time-base register interface (unlike UpTime,
Chris@10 158 from Carbon, requires no additional libraries to be linked). */
Chris@10 159 #if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
Chris@10 160 #include <mach/mach_time.h>
Chris@10 161 typedef uint64_t ticks;
Chris@10 162 #define getticks mach_absolute_time
Chris@10 163 INLINE_ELAPSED(__inline__)
Chris@10 164 #define HAVE_TICK_COUNTER
Chris@10 165 #endif
Chris@10 166
Chris@10 167 /*----------------------------------------------------------------*/
Chris@10 168 /*
Chris@10 169 * Pentium cycle counter
Chris@10 170 */
Chris@10 171 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
Chris@10 172 typedef unsigned long long ticks;
Chris@10 173
Chris@10 174 static __inline__ ticks getticks(void)
Chris@10 175 {
Chris@10 176 ticks ret;
Chris@10 177
Chris@10 178 __asm__ __volatile__("rdtsc": "=A" (ret));
Chris@10 179 /* no input, nothing else clobbered */
Chris@10 180 return ret;
Chris@10 181 }
Chris@10 182
Chris@10 183 INLINE_ELAPSED(__inline__)
Chris@10 184
Chris@10 185 #define HAVE_TICK_COUNTER
Chris@10 186 #define TIME_MIN 5000.0 /* unreliable pentium IV cycle counter */
Chris@10 187 #endif
Chris@10 188
Chris@10 189 /* Visual C++ -- thanks to Morten Nissov for his help with this */
Chris@10 190 #if _MSC_VER >= 1200 && _M_IX86 >= 500 && !defined(HAVE_TICK_COUNTER)
Chris@10 191 #include <windows.h>
Chris@10 192 typedef LARGE_INTEGER ticks;
Chris@10 193 #define RDTSC __asm __emit 0fh __asm __emit 031h /* hack for VC++ 5.0 */
Chris@10 194
Chris@10 195 static __inline ticks getticks(void)
Chris@10 196 {
Chris@10 197 ticks retval;
Chris@10 198
Chris@10 199 __asm {
Chris@10 200 RDTSC
Chris@10 201 mov retval.HighPart, edx
Chris@10 202 mov retval.LowPart, eax
Chris@10 203 }
Chris@10 204 return retval;
Chris@10 205 }
Chris@10 206
Chris@10 207 static __inline double elapsed(ticks t1, ticks t0)
Chris@10 208 {
Chris@10 209 return (double)t1.QuadPart - (double)t0.QuadPart;
Chris@10 210 }
Chris@10 211
Chris@10 212 #define HAVE_TICK_COUNTER
Chris@10 213 #define TIME_MIN 5000.0 /* unreliable pentium IV cycle counter */
Chris@10 214 #endif
Chris@10 215
Chris@10 216 /*----------------------------------------------------------------*/
Chris@10 217 /*
Chris@10 218 * X86-64 cycle counter
Chris@10 219 */
Chris@10 220 #if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
Chris@10 221 typedef unsigned long long ticks;
Chris@10 222
Chris@10 223 static __inline__ ticks getticks(void)
Chris@10 224 {
Chris@10 225 unsigned a, d;
Chris@10 226 asm volatile("rdtsc" : "=a" (a), "=d" (d));
Chris@10 227 return ((ticks)a) | (((ticks)d) << 32);
Chris@10 228 }
Chris@10 229
Chris@10 230 INLINE_ELAPSED(__inline__)
Chris@10 231
Chris@10 232 #define HAVE_TICK_COUNTER
Chris@10 233 #endif
Chris@10 234
Chris@10 235 /* PGI compiler, courtesy Cristiano Calonaci, Andrea Tarsi, & Roberto Gori.
Chris@10 236 NOTE: this code will fail to link unless you use the -Masmkeyword compiler
Chris@10 237 option (grrr). */
Chris@10 238 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
Chris@10 239 typedef unsigned long long ticks;
Chris@10 240 static ticks getticks(void)
Chris@10 241 {
Chris@10 242 asm(" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
Chris@10 243 }
Chris@10 244 INLINE_ELAPSED(__inline__)
Chris@10 245 #define HAVE_TICK_COUNTER
Chris@10 246 #endif
Chris@10 247
Chris@10 248 /* Visual C++, courtesy of Dirk Michaelis */
Chris@10 249 #if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
Chris@10 250
Chris@10 251 #include <intrin.h>
Chris@10 252 #pragma intrinsic(__rdtsc)
Chris@10 253 typedef unsigned __int64 ticks;
Chris@10 254 #define getticks __rdtsc
Chris@10 255 INLINE_ELAPSED(__inline)
Chris@10 256
Chris@10 257 #define HAVE_TICK_COUNTER
Chris@10 258 #endif
Chris@10 259
Chris@10 260 /*----------------------------------------------------------------*/
Chris@10 261 /*
Chris@10 262 * IA64 cycle counter
Chris@10 263 */
Chris@10 264
Chris@10 265 /* intel's icc/ecc compiler */
Chris@10 266 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
Chris@10 267 typedef unsigned long ticks;
Chris@10 268 #include <ia64intrin.h>
Chris@10 269
Chris@10 270 static __inline__ ticks getticks(void)
Chris@10 271 {
Chris@10 272 return __getReg(_IA64_REG_AR_ITC);
Chris@10 273 }
Chris@10 274
Chris@10 275 INLINE_ELAPSED(__inline__)
Chris@10 276
Chris@10 277 #define HAVE_TICK_COUNTER
Chris@10 278 #endif
Chris@10 279
Chris@10 280 /* gcc */
Chris@10 281 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
Chris@10 282 typedef unsigned long ticks;
Chris@10 283
Chris@10 284 static __inline__ ticks getticks(void)
Chris@10 285 {
Chris@10 286 ticks ret;
Chris@10 287
Chris@10 288 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
Chris@10 289 return ret;
Chris@10 290 }
Chris@10 291
Chris@10 292 INLINE_ELAPSED(__inline__)
Chris@10 293
Chris@10 294 #define HAVE_TICK_COUNTER
Chris@10 295 #endif
Chris@10 296
Chris@10 297 /* HP/UX IA64 compiler, courtesy Teresa L. Johnson: */
Chris@10 298 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
Chris@10 299 #include <machine/sys/inline.h>
Chris@10 300 typedef unsigned long ticks;
Chris@10 301
Chris@10 302 static inline ticks getticks(void)
Chris@10 303 {
Chris@10 304 ticks ret;
Chris@10 305
Chris@10 306 ret = _Asm_mov_from_ar (_AREG_ITC);
Chris@10 307 return ret;
Chris@10 308 }
Chris@10 309
Chris@10 310 INLINE_ELAPSED(inline)
Chris@10 311
Chris@10 312 #define HAVE_TICK_COUNTER
Chris@10 313 #endif
Chris@10 314
Chris@10 315 /* Microsoft Visual C++ */
Chris@10 316 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
Chris@10 317 typedef unsigned __int64 ticks;
Chris@10 318
Chris@10 319 # ifdef __cplusplus
Chris@10 320 extern "C"
Chris@10 321 # endif
Chris@10 322 ticks __getReg(int whichReg);
Chris@10 323 #pragma intrinsic(__getReg)
Chris@10 324
Chris@10 325 static __inline ticks getticks(void)
Chris@10 326 {
Chris@10 327 volatile ticks temp;
Chris@10 328 temp = __getReg(3116);
Chris@10 329 return temp;
Chris@10 330 }
Chris@10 331
Chris@10 332 INLINE_ELAPSED(inline)
Chris@10 333
Chris@10 334 #define HAVE_TICK_COUNTER
Chris@10 335 #endif
Chris@10 336
Chris@10 337 /*----------------------------------------------------------------*/
Chris@10 338 /*
Chris@10 339 * PA-RISC cycle counter
Chris@10 340 */
Chris@10 341 #if defined(__hppa__) || defined(__hppa) && !defined(HAVE_TICK_COUNTER)
Chris@10 342 typedef unsigned long ticks;
Chris@10 343
Chris@10 344 # ifdef __GNUC__
Chris@10 345 static __inline__ ticks getticks(void)
Chris@10 346 {
Chris@10 347 ticks ret;
Chris@10 348
Chris@10 349 __asm__ __volatile__("mfctl 16, %0": "=r" (ret));
Chris@10 350 /* no input, nothing else clobbered */
Chris@10 351 return ret;
Chris@10 352 }
Chris@10 353 # else
Chris@10 354 # include <machine/inline.h>
Chris@10 355 static inline unsigned long getticks(void)
Chris@10 356 {
Chris@10 357 register ticks ret;
Chris@10 358 _MFCTL(16, ret);
Chris@10 359 return ret;
Chris@10 360 }
Chris@10 361 # endif
Chris@10 362
Chris@10 363 INLINE_ELAPSED(inline)
Chris@10 364
Chris@10 365 #define HAVE_TICK_COUNTER
Chris@10 366 #endif
Chris@10 367
Chris@10 368 /*----------------------------------------------------------------*/
Chris@10 369 /* S390, courtesy of James Treacy */
Chris@10 370 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
Chris@10 371 typedef unsigned long long ticks;
Chris@10 372
Chris@10 373 static __inline__ ticks getticks(void)
Chris@10 374 {
Chris@10 375 ticks cycles;
Chris@10 376 __asm__("stck 0(%0)" : : "a" (&(cycles)) : "memory", "cc");
Chris@10 377 return cycles;
Chris@10 378 }
Chris@10 379
Chris@10 380 INLINE_ELAPSED(__inline__)
Chris@10 381
Chris@10 382 #define HAVE_TICK_COUNTER
Chris@10 383 #endif
Chris@10 384 /*----------------------------------------------------------------*/
Chris@10 385 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
Chris@10 386 /*
Chris@10 387 * The 32-bit cycle counter on alpha overflows pretty quickly,
Chris@10 388 * unfortunately. A 1GHz machine overflows in 4 seconds.
Chris@10 389 */
Chris@10 390 typedef unsigned int ticks;
Chris@10 391
Chris@10 392 static __inline__ ticks getticks(void)
Chris@10 393 {
Chris@10 394 unsigned long cc;
Chris@10 395 __asm__ __volatile__ ("rpcc %0" : "=r"(cc));
Chris@10 396 return (cc & 0xFFFFFFFF);
Chris@10 397 }
Chris@10 398
Chris@10 399 INLINE_ELAPSED(__inline__)
Chris@10 400
Chris@10 401 #define HAVE_TICK_COUNTER
Chris@10 402 #endif
Chris@10 403
Chris@10 404 /*----------------------------------------------------------------*/
Chris@10 405 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
Chris@10 406 typedef unsigned long ticks;
Chris@10 407
Chris@10 408 static __inline__ ticks getticks(void)
Chris@10 409 {
Chris@10 410 ticks ret;
Chris@10 411 __asm__ __volatile__("rd %%tick, %0" : "=r" (ret));
Chris@10 412 return ret;
Chris@10 413 }
Chris@10 414
Chris@10 415 INLINE_ELAPSED(__inline__)
Chris@10 416
Chris@10 417 #define HAVE_TICK_COUNTER
Chris@10 418 #endif
Chris@10 419
Chris@10 420 /*----------------------------------------------------------------*/
Chris@10 421 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
Chris@10 422 # include <c_asm.h>
Chris@10 423 typedef unsigned int ticks;
Chris@10 424
Chris@10 425 static __inline ticks getticks(void)
Chris@10 426 {
Chris@10 427 unsigned long cc;
Chris@10 428 cc = asm("rpcc %v0");
Chris@10 429 return (cc & 0xFFFFFFFF);
Chris@10 430 }
Chris@10 431
Chris@10 432 INLINE_ELAPSED(__inline)
Chris@10 433
Chris@10 434 #define HAVE_TICK_COUNTER
Chris@10 435 #endif
Chris@10 436 /*----------------------------------------------------------------*/
Chris@10 437 /* SGI/Irix */
Chris@10 438 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
Chris@10 439 typedef struct timespec ticks;
Chris@10 440
Chris@10 441 static inline ticks getticks(void)
Chris@10 442 {
Chris@10 443 struct timespec t;
Chris@10 444 clock_gettime(CLOCK_SGI_CYCLE, &t);
Chris@10 445 return t;
Chris@10 446 }
Chris@10 447
Chris@10 448 static inline double elapsed(ticks t1, ticks t0)
Chris@10 449 {
Chris@10 450 return ((double)t1.tv_sec - (double)t0.tv_sec) * 1.0E9 +
Chris@10 451 ((double)t1.tv_nsec - (double)t0.tv_nsec);
Chris@10 452 }
Chris@10 453 #define HAVE_TICK_COUNTER
Chris@10 454 #endif
Chris@10 455
Chris@10 456 /*----------------------------------------------------------------*/
Chris@10 457 /* Cray UNICOS _rtc() intrinsic function */
Chris@10 458 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
Chris@10 459 #ifdef HAVE_INTRINSICS_H
Chris@10 460 # include <intrinsics.h>
Chris@10 461 #endif
Chris@10 462
Chris@10 463 typedef long long ticks;
Chris@10 464
Chris@10 465 #define getticks _rtc
Chris@10 466
Chris@10 467 INLINE_ELAPSED(inline)
Chris@10 468
Chris@10 469 #define HAVE_TICK_COUNTER
Chris@10 470 #endif
Chris@10 471
Chris@10 472 /*----------------------------------------------------------------*/
Chris@10 473 /* MIPS ZBus */
Chris@10 474 #if HAVE_MIPS_ZBUS_TIMER
Chris@10 475 #if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
Chris@10 476 #include <sys/mman.h>
Chris@10 477 #include <unistd.h>
Chris@10 478 #include <fcntl.h>
Chris@10 479
Chris@10 480 typedef uint64_t ticks;
Chris@10 481
Chris@10 482 static inline ticks getticks(void)
Chris@10 483 {
Chris@10 484 static uint64_t* addr = 0;
Chris@10 485
Chris@10 486 if (addr == 0)
Chris@10 487 {
Chris@10 488 uint32_t rq_addr = 0x10030000;
Chris@10 489 int fd;
Chris@10 490 int pgsize;
Chris@10 491
Chris@10 492 pgsize = getpagesize();
Chris@10 493 fd = open ("/dev/mem", O_RDONLY | O_SYNC, 0);
Chris@10 494 if (fd < 0) {
Chris@10 495 perror("open");
Chris@10 496 return NULL;
Chris@10 497 }
Chris@10 498 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
Chris@10 499 close(fd);
Chris@10 500 if (addr == (uint64_t *)-1) {
Chris@10 501 perror("mmap");
Chris@10 502 return NULL;
Chris@10 503 }
Chris@10 504 }
Chris@10 505
Chris@10 506 return *addr;
Chris@10 507 }
Chris@10 508
Chris@10 509 INLINE_ELAPSED(inline)
Chris@10 510
Chris@10 511 #define HAVE_TICK_COUNTER
Chris@10 512 #endif
Chris@10 513 #endif /* HAVE_MIPS_ZBUS_TIMER */
Chris@10 514