1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright © International Business Machines Corp., 2006-2008 4 * 5 * AUTHOR 6 * Darren Hart <dvhltc@us.ibm.com> 7 * Giuseppe Cavallaro <peppe.cavallarost.com> 8 * 9 * HISTORY 10 * It directly comes from the librttest.h (see its HISTORY). 11 */ 12 13 #ifndef TST_TSC_H 14 #define TST_TSC_H 15 16 #undef TSC_UNSUPPORTED 17 18 /* TSC macros */ 19 #if defined(__i386__) 20 #define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val)) 21 #elif defined(__x86_64__) 22 #define rdtscll(val) \ 23 do { \ 24 uint32_t low, high; \ 25 __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \ 26 val = (uint64_t)high << 32 | low; \ 27 } while (0) 28 #elif defined(__powerpc__) 29 #if defined(__powerpc64__) /* 64bit version */ 30 #define rdtscll(val) \ 31 do { \ 32 __asm__ __volatile__ ("mfspr %0, 268" : "=r" (val)); \ 33 } while (0) 34 #else /*__powerpc__ 32bit version */ 35 #define rdtscll(val) \ 36 do { \ 37 uint32_t tbhi, tblo ; \ 38 __asm__ __volatile__ ("mftbu %0" : "=r" (tbhi)); \ 39 __asm__ __volatile__ ("mftbl %0" : "=r" (tblo)); \ 40 val = 1000 * ((uint64_t) tbhi << 32) | tblo; \ 41 } while (0) 42 #endif 43 #else 44 #warning TSC UNSUPPORTED 45 /* All tests will be compiled also for the 46 * architecture without TSC support (e.g. SH). 47 * At run-time these will fail with ENOTSUP. 48 */ 49 #define rdtscll(val) do { } while (0) 50 #define TSC_UNSUPPORTED 51 #endif 52 53 #endif 54