[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 2/5] timer: arm: Introduce functions to get the host cntfrq
From: |
Andrew Jones |
Subject: |
[RFC PATCH 2/5] timer: arm: Introduce functions to get the host cntfrq |
Date: |
Mon, 7 Oct 2019 19:06:19 +0200 |
When acceleration like KVM is in use it's necessary to use the host's
counter frequency when converting ticks to or from time units.
Signed-off-by: Andrew Jones <address@hidden>
---
include/qemu/timer.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 85bc6eb00b21..8941ddea8242 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -1006,6 +1006,22 @@ static inline int64_t cpu_get_host_ticks(void)
}
#endif
+#if defined(__aarch64__)
+static inline uint32_t cpu_get_host_tick_frequency(void)
+{
+ uint64_t frq;
+ asm volatile("mrs %0, cntfrq_el0" : "=r" (frq));
+ return frq;
+}
+#elif defined(__arm__)
+static inline uint32_t cpu_get_host_tick_frequency(void)
+{
+ uint32_t frq;
+ asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq));
+ return frq;
+}
+#endif
+
#ifdef CONFIG_PROFILER
static inline int64_t profile_getclock(void)
{
--
2.20.1