On Tue, Jun 6, 2017 at 2:02 PM, Brian Brooks <[email protected]> wrote:
> Expose ARMv8 Generic Timer through internal CPU global time functions.
>
> Signed-off-by: Brian Brooks <[email protected]>

Reviewed-by: Bill Fischofer <[email protected]>

> ---
>  platform/linux-generic/arch/arm/odp_cpu_arch.c | 30 
> +++++++++++++++++++++++++-
>  1 file changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/platform/linux-generic/arch/arm/odp_cpu_arch.c 
> b/platform/linux-generic/arch/arm/odp_cpu_arch.c
> index c31f9084..ceba9d1f 100644
> --- a/platform/linux-generic/arch/arm/odp_cpu_arch.c
> +++ b/platform/linux-generic/arch/arm/odp_cpu_arch.c
> @@ -50,15 +50,43 @@ uint64_t odp_cpu_cycles_resolution(void)
>
>  int cpu_has_global_time(void)
>  {
> -       return 0;
> +       uint64_t hz = cpu_global_time_freq();
> +
> +       return hz >= 1000000 && hz <= 6000000000;
>  }
>
>  uint64_t cpu_global_time(void)
>  {
> +#if __ARM_ARCH == 8
> +       uint64_t cntvct;
> +
> +       /*
> +        * The system counter must provide a uniform view of system time
> +        * to all processing elements in the system. This should hold true
> +        * for heterogeneous SoCs.
> +        *
> +        * Be consistent with other architectures and don't issue a 
> serializing
> +        * instruction, e.g. ISB.
> +        */
> +
> +       /* Memory clobber to minimize optimization around load from sys reg. 
> */
> +       __asm__ volatile("mrs %0, cntvct_el0" : "=r"(cntvct) : : "memory");
> +
> +       return cntvct;
> +#else
>         return 0;
> +#endif
>  }
>
>  uint64_t cpu_global_time_freq(void)
>  {
> +#if __ARM_ARCH == 8
> +       uint64_t cntfrq;
> +
> +       __asm__ volatile("mrs %0, cntfrq_el0" : "=r"(cntfrq) : : );
> +
> +       return cntfrq;
> +#else
>         return 0;
> +#endif
>  }
> --
> 2.13.0
>

Reply via email to