Message ID | 20160726025625.7343-10-brian.brooks@linaro.org |
---|---|
State | New |
Headers | show |
On 07/26/16 05:56, Brian Brooks wrote: > Signed-off-by: Brian Brooks <brian.brooks@linaro.org> > --- > platform/linux-generic/arch/powerpc/odp_cpu_arch.c | 26 ++++++++-------------- > 1 file changed, 9 insertions(+), 17 deletions(-) > > diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c > index 109dd93..346c170 100644 > --- a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c > +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c > @@ -14,25 +14,17 @@ > #include <odp/api/system_info.h> > #include <odp_debug_internal.h> > > -#define GIGA 1000000000 > - > uint64_t odp_cpu_cycles(void) > { > - struct timespec time; > - uint64_t sec, ns, hz, cycles; > - int ret; > - > - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); > - > - if (ret != 0) > - ODP_ABORT("clock_gettime failed\n"); > - > - hz = odp_cpu_hz_max(); > - sec = (uint64_t)time.tv_sec; > - ns = (uint64_t)time.tv_nsec; > +#if defined(__powerpc__) || defined(__ppc__) > + uint64_t tbl, tbu0, tbu1; > > - cycles = sec * hz; > - cycles += (ns * hz) / GIGA; > + do { > + __asm__ volatile("mftbu %0" : "=r"(tbu0)); > + __asm__ volatile("mftb %0" : "=r"(tbl)); > + __asm__ volatile("mftbu %0" : "=r"(tbu1)); > + } while (tbu0 != tbu1); > > - return cycles; > + return (tbu0 << 32) | tbl; > +#endif return for non ifdef case is missing. Or there has to be #else ODP_STATIC_ASSERT("add ifdef for new case") Maxim. > }
On 07/26 10:47:44, Maxim Uvarov wrote: > On 07/26/16 05:56, Brian Brooks wrote: > > Signed-off-by: Brian Brooks <brian.brooks@linaro.org> > > --- > > platform/linux-generic/arch/powerpc/odp_cpu_arch.c | 26 ++++++++-------------- > > 1 file changed, 9 insertions(+), 17 deletions(-) > > > > diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c > > index 109dd93..346c170 100644 > > --- a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c > > +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c > > @@ -14,25 +14,17 @@ > > #include <odp/api/system_info.h> > > #include <odp_debug_internal.h> > > -#define GIGA 1000000000 > > - > > uint64_t odp_cpu_cycles(void) > > { > > - struct timespec time; > > - uint64_t sec, ns, hz, cycles; > > - int ret; > > - > > - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); > > - > > - if (ret != 0) > > - ODP_ABORT("clock_gettime failed\n"); > > - > > - hz = odp_cpu_hz_max(); > > - sec = (uint64_t)time.tv_sec; > > - ns = (uint64_t)time.tv_nsec; > > +#if defined(__powerpc__) || defined(__ppc__) > > + uint64_t tbl, tbu0, tbu1; > > - cycles = sec * hz; > > - cycles += (ns * hz) / GIGA; > > + do { > > + __asm__ volatile("mftbu %0" : "=r"(tbu0)); > > + __asm__ volatile("mftb %0" : "=r"(tbl)); > > + __asm__ volatile("mftbu %0" : "=r"(tbu1)); > > + } while (tbu0 != tbu1); > > - return cycles; > > + return (tbu0 << 32) | tbl; > > +#endif > return for non ifdef case is missing. Or there has to be #else > ODP_STATIC_ASSERT("add ifdef for new case") > > Maxim. Can we agree: int foo() { #if defined(__target__) return 42; #else #error Add support for your target in this file. #endif } is preferred over static assertion or returning a zero value?
On 07/26/16 20:06, Brian Brooks wrote: > On 07/26 10:47:44, Maxim Uvarov wrote: >> On 07/26/16 05:56, Brian Brooks wrote: >>> Signed-off-by: Brian Brooks <brian.brooks@linaro.org> >>> --- >>> platform/linux-generic/arch/powerpc/odp_cpu_arch.c | 26 ++++++++-------------- >>> 1 file changed, 9 insertions(+), 17 deletions(-) >>> >>> diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c >>> index 109dd93..346c170 100644 >>> --- a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c >>> +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c >>> @@ -14,25 +14,17 @@ >>> #include <odp/api/system_info.h> >>> #include <odp_debug_internal.h> >>> -#define GIGA 1000000000 >>> - >>> uint64_t odp_cpu_cycles(void) >>> { >>> - struct timespec time; >>> - uint64_t sec, ns, hz, cycles; >>> - int ret; >>> - >>> - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); >>> - >>> - if (ret != 0) >>> - ODP_ABORT("clock_gettime failed\n"); >>> - >>> - hz = odp_cpu_hz_max(); >>> - sec = (uint64_t)time.tv_sec; >>> - ns = (uint64_t)time.tv_nsec; >>> +#if defined(__powerpc__) || defined(__ppc__) >>> + uint64_t tbl, tbu0, tbu1; >>> - cycles = sec * hz; >>> - cycles += (ns * hz) / GIGA; >>> + do { >>> + __asm__ volatile("mftbu %0" : "=r"(tbu0)); >>> + __asm__ volatile("mftb %0" : "=r"(tbl)); >>> + __asm__ volatile("mftbu %0" : "=r"(tbu1)); >>> + } while (tbu0 != tbu1); >>> - return cycles; >>> + return (tbu0 << 32) | tbl; >>> +#endif >> return for non ifdef case is missing. Or there has to be #else >> ODP_STATIC_ASSERT("add ifdef for new case") >> >> Maxim. > Can we agree: > > int foo() > { > #if defined(__target__) > return 42; > #else > #error Add support for your target in this file. > #endif > } > > is preferred over static assertion or returning a zero value? yes, I think that is ok. Maxim.
diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c index 109dd93..346c170 100644 --- a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c @@ -14,25 +14,17 @@ #include <odp/api/system_info.h> #include <odp_debug_internal.h> -#define GIGA 1000000000 - uint64_t odp_cpu_cycles(void) { - struct timespec time; - uint64_t sec, ns, hz, cycles; - int ret; - - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); - - if (ret != 0) - ODP_ABORT("clock_gettime failed\n"); - - hz = odp_cpu_hz_max(); - sec = (uint64_t)time.tv_sec; - ns = (uint64_t)time.tv_nsec; +#if defined(__powerpc__) || defined(__ppc__) + uint64_t tbl, tbu0, tbu1; - cycles = sec * hz; - cycles += (ns * hz) / GIGA; + do { + __asm__ volatile("mftbu %0" : "=r"(tbu0)); + __asm__ volatile("mftb %0" : "=r"(tbl)); + __asm__ volatile("mftbu %0" : "=r"(tbu1)); + } while (tbu0 != tbu1); - return cycles; + return (tbu0 << 32) | tbl; +#endif }
Signed-off-by: Brian Brooks <brian.brooks@linaro.org> --- platform/linux-generic/arch/powerpc/odp_cpu_arch.c | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) -- 2.9.0