qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/5] cpu-all.h: fix cpu_get_real_ticks on mips host


From: Aurelien Jarno
Subject: [Qemu-devel] [PATCH 2/5] cpu-all.h: fix cpu_get_real_ticks on mips host
Date: Thu, 22 Oct 2009 22:17:47 +0200

From: Arnaud Patard <address@hidden>

Fix cpu_get_real_ticks:
- check should be done on __mips and not __mips_isa_rev
- linux kernels >= 2.6.25 are emulating the 2 needed rdhwr functions
  so it's safe to use rdhwr.

This is better than what's currently in but it doesn't mean it works nicely
Some tests needs to be done imho

Signed-off-by: Arnaud Patard <address@hidden>
Signed-off-by: Aurelien Jarno <address@hidden>
---
 cpu-all.h |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index ebe8bfb..e214374 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -1017,24 +1017,33 @@ static inline int64_t cpu_get_real_ticks (void)
 #endif
 }
 
-#elif defined(__mips__)
+#elif (defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__)
+/*
+ * binutils wants to use rdhwr only on mips32r2
+ * but as linux kernel emulate it, it's fine
+ * to use it.
+ *
+ */
+#define MIPS_RDHWR(rd, value) {                 \
+    __asm__ __volatile__ (                      \
+                          ".set   push\n\t"     \
+                          ".set mips32r2\n\t"   \
+                          "rdhwr  %0, "rd"\n\t" \
+                          ".set   pop"          \
+                          : "=r" (value));      \
+}
 
 static inline int64_t cpu_get_real_ticks(void)
 {
-#if defined(__mips_isa_rev) && __mips_isa_rev >= 2
+/* On kernels >= 2.6.25 rdhwr <reg>, $2 and $3 are emulated */
     uint32_t count;
     static uint32_t cyc_per_count = 0;
 
     if (!cyc_per_count)
-        __asm__ __volatile__("rdhwr %0, $3" : "=r" (cyc_per_count));
+        MIPS_RDHWR("$3", cyc_per_count);
 
-    __asm__ __volatile__("rdhwr %1, $2" : "=r" (count));
+    MIPS_RDHWR("$2", count);
     return (int64_t)(count * cyc_per_count);
-#else
-    /* FIXME */
-    static int64_t ticks = 0;
-    return ticks++;
-#endif
 }
 
 #else
-- 
1.6.1.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]