[API-NEXT] arch: arm: add CPU global time

Message ID 20170606190252.98840-1-brian.brooks@arm.com
State New
Headers show

Commit Message

Brian Brooks June 6, 2017, 7:02 p.m.
Expose ARMv8 Generic Timer through internal CPU global time functions.

Signed-off-by: Brian Brooks <brian.brooks@arm.com>

---
 platform/linux-generic/arch/arm/odp_cpu_arch.c | 30 +++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

-- 
2.13.0

Comments

Bill Fischofer June 7, 2017, 9:48 p.m. | #1
On Tue, Jun 6, 2017 at 2:02 PM, Brian Brooks <brian.brooks@arm.com> wrote:
> Expose ARMv8 Generic Timer through internal CPU global time functions.

>

> Signed-off-by: Brian Brooks <brian.brooks@arm.com>


Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>


> ---

>  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

>

Patch hide | download patch | download mbox

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
 }