From: Jens Axboe Date: Tue, 26 Feb 2013 20:55:43 +0000 (+0100) Subject: Merge branch 'master' of ssh://brick.kernel.dk/data/git/fio X-Git-Tag: fio-2.0.15~50 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=3ba1ba7f3d0fde62817e3e0c2aa284759de96ec8;hp=b65588b3c0b1007378d64088ef8a0928b7150c15 Merge branch 'master' of ssh://brick.kernel.dk/data/git/fio --- diff --git a/arch/arch-ppc.h b/arch/arch-ppc.h index e73093df..0cc0cbda 100644 --- a/arch/arch-ppc.h +++ b/arch/arch-ppc.h @@ -1,6 +1,11 @@ #ifndef ARCH_PPC_H #define ARCH_PPH_H +#include +#include +#include +#include + #define FIO_ARCH (arch_ppc) #ifndef __NR_ioprio_set @@ -43,26 +48,72 @@ static inline int arch_ffz(unsigned long bitmask) return __ilog2(bitmask & -bitmask); } +static inline unsigned int mfspr(unsigned int reg) +{ + unsigned int val; + + asm volatile("mfspr %0,%1": "=r" (val) : "K" (reg)); + return val; +} + +#define SPRN_TBRL 0x10C /* Time Base Register Lower */ +#define SPRN_TBRU 0x10D /* Time Base Register Upper */ +#define SPRN_ATBL 0x20E /* Alternate Time Base Lower */ +#define SPRN_ATBU 0x20F /* Alternate Time Base Upper */ + static inline unsigned long long get_cpu_clock(void) { unsigned int tbl, tbu0, tbu1; unsigned long long ret; do { - __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0)); - __asm__ __volatile__ ("mftb %0" : "=r"(tbl) ); - __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1)); + if (arch_flags & ARCH_FLAG_1) { + tbu0 = mfspr(SPRN_ATBU); + tbl = mfspr(SPRN_ATBL); + tbu1 = mfspr(SPRN_ATBU); + } else { + __asm__ __volatile__("mftbu %0" : "=r"(tbu0)); + __asm__ __volatile__("mftb %0" : "=r"(tbl) ); + __asm__ __volatile__("mftbu %0" : "=r"(tbu1)); + } } while (tbu0 != tbu1); ret = (((unsigned long long)tbu0) << 32) | tbl; return ret; } +static void atb_child(void) +{ + arch_flags |= ARCH_FLAG_1; + get_cpu_clock(); + _exit(0); +} + +static void atb_clocktest(void) +{ + pid_t pid; + + pid = fork(); + if (!pid) + atb_child(); + else if (pid != -1) { + int status; + + pid = wait(&status); + if (pid == -1 || !WIFEXITED(status)) + arch_flags &= ~ARCH_FLAG_1; + else + arch_flags |= ARCH_FLAG_1; + } +} + #define ARCH_HAVE_INIT extern int tsc_reliable; + static inline int arch_init(char *envp[]) { tsc_reliable = 1; + atb_clocktest(); return 0; } diff --git a/arch/arch.h b/arch/arch.h index 4165c9f9..31d96d40 100644 --- a/arch/arch.h +++ b/arch/arch.h @@ -27,6 +27,8 @@ enum { ARCH_FLAG_4 = 1 << 3, }; +extern unsigned long arch_flags; + #if defined(__i386__) #include "arch-x86.h" #elif defined(__x86_64__) diff --git a/gettime.c b/gettime.c index 660ba4c8..4c998e5f 100644 --- a/gettime.c +++ b/gettime.c @@ -497,7 +497,8 @@ static void *clock_thread_fn(void *data) c->tsc = tsc; } - log_info("cs: cpu%3d: %lu clocks seen\n", t->cpu, t->entries[i - 1].tsc - t->entries[0].tsc); + log_info("cs: cpu%3d: %llu clocks seen\n", t->cpu, + (unsigned long long) t->entries[i - 1].tsc - t->entries[0].tsc); /* * The most common platform clock breakage is returning zero