Skip to contentSkip to conversation

timer.h: Provide monotonic time for ARM guests

PATCH In review Pranith Kumar 3 participants 6 messages Apr 15, 2017 – Apr 20, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timer.h: Provide monotonic time for ARM guests

Tested and confirmed that the stretch i386 debian qcow2 image on a raspberry pi 2 works.

---
 include/qemu/timer.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/qemu/timer.h +10 -0
index e1742f2f3d..14c9558da4 100644
@@ -1015,6 +1015,16 @@ static inline int64_t cpu_get_host_ticks(void)
     return cur - ofs;
 }
 
+#elif defined(__arm__) || defined(__aarch64__)
+
+/* ARM does not have a user-space readble cycle counter available.
+ * This is a compromise to get monotonically increasing time.
+ */
+static inline int64_t cpu_get_host_ticks(void)
+{
+    return get_clock();
+}
+
 #else
 /* The host CPU doesn't have an easily accessible cycle counter.
    Just return a monotonically increasing value.  This will be
Signature · 1 line
2.11.0
#1 lore raw
Quoted 16 lines · Pranith Kumar

Tested and confirmed that the stretch i386 debian qcow2 image on a raspberry pi 2 works.

---
 include/qemu/timer.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/qemu/timer.h +0 -0
index e1742f2f3d..14c9558da4 100644
@@ -1015,6 +1015,16 @@ static inline int64_t cpu_get_host_ticks(void)
     return cur - ofs;
 }

include/qemu/timer.h static inline int64_t cpu_get_host_ticks(void) · line 1026

Quoted 10 lines
include/qemu/timer.h +9 -0
 
+#elif defined(__arm__) || defined(__aarch64__)
+
+/* ARM does not have a user-space readble cycle counter available.
+ * This is a compromise to get monotonically increasing time.
+ */
+static inline int64_t cpu_get_host_ticks(void)
+{
+    return get_clock();
+}

This doesn't look like it should be ARM-specific. Is it better than the current default implementation? If so, why not make this the default implementation?

Quoted 6 lines
include/qemu/timer.h +1 -1
+
 #else
 /* The host CPU doesn't have an easily accessible cycle counter.
    Just return a monotonically increasing value.  This will be
--

2.11.0

The comment here says that our default is already a monotonically increasing implementation -- is it wrong, or is there some other advantage of your version?

thanks
-- PMM

#2 lore raw
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Pranith Kumar

Tested and confirmed that the stretch i386 debian qcow2 image on a raspberry pi 2 works.

---
 include/qemu/timer.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/qemu/timer.h +0 -0
index e1742f2f3d..14c9558da4 100644
@@ -1015,6 +1015,16 @@ static inline int64_t cpu_get_host_ticks(void)
     return cur - ofs;
 }
 
Quoted 14 lines

include/qemu/timer.h static inline int64_t cpu_get_host_ticks(void) · line 1026

Quoted 9 lines
include/qemu/timer.h +9 -0
+#elif defined(__arm__) || defined(__aarch64__)
+
+/* ARM does not have a user-space readble cycle counter available.
+ * This is a compromise to get monotonically increasing time.
+ */
+static inline int64_t cpu_get_host_ticks(void)
+{
+    return get_clock();
+}

This doesn't look like it should be ARM-specific. Is it better than the current default implementation? If so, why not make this the default implementation?

I think we can do that...

Quoted 8 lines

include/qemu/timer.h static inline int64_t cpu_get_host_ticks(void) · line 1030

Quoted 4 lines
include/qemu/timer.h +1 -0
+
 #else
 /* The host CPU doesn't have an easily accessible cycle counter.
    Just return a monotonically increasing value.  This will be

The comment here says that our default is already a monotonically increasing implementation -- is it wrong, or is there some other advantage of your version?

Comment #6 in the bug report by Laszlo Ersek explains why. Incrementing by 1 for approximately 55 ms is what is causing the divide by zero in grub.

Signature · 1 line
Pranith
#3 lore raw
Quoted 11 lines · Pranith Kumar
Quoted 10 lines

include/qemu/timer.h static inline int64_t cpu_get_host_ticks(void) · line 1026

Quoted 7 lines
include/qemu/timer.h +7 -0
+/* ARM does not have a user-space readble cycle counter available.
+ * This is a compromise to get monotonically increasing time.
+ */
+static inline int64_t cpu_get_host_ticks(void)
+{
+    return get_clock();
+}

This doesn't look like it should be ARM-specific. Is it better than the current default implementation? If so, why not make this the default implementation?

Quoted 1 line

I think we can do that...

Yes, it is always better for emulation accuracy. It may be much slower, depending on your OS (especially if get_clock requires a user->kernel->user transition), but the current code is quite broken.

Paolo

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

+
#else
/* The host CPU doesn't have an easily accessible cycle counter.
Just return a monotonically increasing value. This will be

The comment here says that our default is already a monotonically increasing implementation -- is it wrong, or is there some other advantage of your version?

Comment #6 in the bug report by Laszlo Ersek explains why. Incrementing by 1 for approximately 55 ms is what is causing the divide by zero in grub.

#4 lore raw
Quoted 14 lines · Paolo Bonzini
Quoted 11 lines · Pranith Kumar
Quoted 10 lines

include/qemu/timer.h static inline int64_t cpu_get_host_ticks(void) · line 1026

Quoted 7 lines
include/qemu/timer.h +7 -0
+/* ARM does not have a user-space readble cycle counter available.
+ * This is a compromise to get monotonically increasing time.
+ */
+static inline int64_t cpu_get_host_ticks(void)
+{
+    return get_clock();
+}

This doesn't look like it should be ARM-specific. Is it better than the current default implementation? If so, why not make this the default implementation?

Quoted 6 lines
Quoted 1 line

I think we can do that...

Yes, it is always better for emulation accuracy. It may be much slower, depending on your OS (especially if get_clock requires a user->kernel->user transition), but the current code is quite broken.

OK, I sent an updated patch using get_clock() for all other cases.

--
Pranith

#5 lore raw
Quoted 15 lines · Pranith Kumar
Quoted 14 lines · Paolo Bonzini
Quoted 11 lines · Pranith Kumar
Quoted 10 lines

include/qemu/timer.h static inline int64_t cpu_get_host_ticks(void) · line 1026

Quoted 7 lines
include/qemu/timer.h +7 -0
+/* ARM does not have a user-space readble cycle counter available.
+ * This is a compromise to get monotonically increasing time.
+ */
+static inline int64_t cpu_get_host_ticks(void)
+{
+    return get_clock();
+}

This doesn't look like it should be ARM-specific. Is it better than the current default implementation? If so, why not make this the default implementation?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I think we can do that...

Yes, it is always better for emulation accuracy. It may be much slower, depending on your OS (especially if get_clock requires a user->kernel->user transition), but the current code is quite broken.

OK, I sent an updated patch using get_clock() for all other cases.

Thanks. As it happens I just checked against what configure supports for host CPU architectures, and ARM is the only one without a special-purpose cpu_get_host_ticks() (except perhaps elderly MIPS chips).

thanks
-- PMM