1 /****************************************************************************** 2 * 3 * Copyright © International Business Machines Corp., 2006-2008 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 * NAME 20 * libtsc.h 21 * 22 * DESCRIPTION 23 * 24 * USAGE: 25 * To be included in some testcases. 26 * 27 * AUTHOR 28 * Darren Hart <dvhltc@us.ibm.com> 29 * Giuseppe Cavallaro <peppe.cavallarost.com> 30 * 31 * HISTORY 32 * It directly comes from the librttest.h (see its HISTORY). 33 * 34 *****************************************************************************/ 35 36 #undef TSC_UNSUPPORTED 37 38 /* TSC macros */ 39 #if defined(__i386__) 40 #define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val)) 41 #elif defined(__x86_64__) 42 #define rdtscll(val) \ 43 do { \ 44 uint32_t low, high; \ 45 __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \ 46 val = (uint64_t)high << 32 | low; \ 47 } while (0) 48 #elif defined(__powerpc__) 49 #if defined(__powerpc64__) /* 64bit version */ 50 #define rdtscll(val) \ 51 do { \ 52 __asm__ __volatile__ ("mfspr %0, 268" : "=r" (val)); \ 53 } while (0) 54 #else /*__powerpc__ 32bit version */ 55 #define rdtscll(val) \ 56 do { \ 57 uint32_t tbhi, tblo ; \ 58 __asm__ __volatile__ ("mftbu %0" : "=r" (tbhi)); \ 59 __asm__ __volatile__ ("mftbl %0" : "=r" (tblo)); \ 60 val = 1000 * ((uint64_t) tbhi << 32) | tblo; \ 61 } while (0) 62 #endif 63 #else 64 #warning TSC UNSUPPORTED 65 /* All tests will be compiled also for the 66 * architecture without TSC support (e.g. SH). 67 * At run-time these will fail with ENOTSUP. 68 */ 69 #define rdtscll(val) do { } while (0) 70 #define TSC_UNSUPPORTED 71 #endif 72 73