X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=arch%2Farch-ppc.h;h=d4a080c4e91f31050404cab8c61b6d23bbe7f371;hb=02957cd47484f5c84c687db3ce01b084a53ae25b;hp=87198699edaa0bf21d23d3e538cbf2f9d4008a02;hpb=5f39d8f797fcf01bd94b89ef7ed2bdb76deb2601;p=fio.git diff --git a/arch/arch-ppc.h b/arch/arch-ppc.h index 87198699..d4a080c4 100644 --- a/arch/arch-ppc.h +++ b/arch/arch-ppc.h @@ -1,7 +1,12 @@ #ifndef ARCH_PPC_H -#define ARCH_PPH_H +#define ARCH_PPC_H -#define ARCH (arch_ppc) +#include +#include +#include +#include + +#define FIO_ARCH (arch_ppc) #ifndef __NR_ioprio_set #define __NR_ioprio_set 273 @@ -43,22 +48,86 @@ 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; + 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)); - } while (tbu0 != tbu1); + do { + if (arch_flags & ARCH_FLAG_1) { + tbu0 = mfspr(SPRN_ATBU); + tbl = mfspr(SPRN_ATBL); + tbu1 = mfspr(SPRN_ATBU); + } else { + tbu0 = mfspr(SPRN_TBRU); + tbl = mfspr(SPRN_TBRL); + tbu1 = mfspr(SPRN_TBRU); + } + } while (tbu0 != tbu1); - ret = (((unsigned long long)tbu0) << 32) | tbl; - return ret; + ret = (((unsigned long long)tbu0) << 32) | tbl; + return ret; +} + +#if 0 +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; + } +} +#endif + +#define ARCH_HAVE_INIT +extern int tsc_reliable; + +static inline int arch_init(char *envp[]) +{ +#if 0 + tsc_reliable = 1; + atb_clocktest(); +#endif + return 0; } #define ARCH_HAVE_FFZ -#define ARCH_HAVE_CPU_CLOCK + +/* + * We don't have it on all platforms, lets comment this out until we + * can handle it more intelligently. + * + * #define ARCH_HAVE_CPU_CLOCK + */ #endif