Patchwork [RFC,3/3] icount: create a new icount based timer.

login
register
mail settings
Submitter fred.konrad@greensocs.com
Date July 18, 2013, 3:02 p.m.
Message ID <1374159757-16383-4-git-send-email-fred.konrad@greensocs.com>
Download mbox | patch
Permalink /patch/260075/
State New
Headers show

Comments

fred.konrad@greensocs.com - July 18, 2013, 3:02 p.m.
From: KONRAD Frederic <fred.konrad@greensocs.com>

This creates a new icount based timer, with no bias.

It moves only with the instruction counter.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 cpus.c               | 10 ++++++++--
 include/qemu/timer.h |  4 ++++
 qemu-timer.c         |  6 ++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
Peter Maydell - July 18, 2013, 3:08 p.m.
On 18 July 2013 16:02,  <fred.konrad@greensocs.com> wrote:
> @@ -156,6 +156,12 @@ void restore_icount(CPUArchState *env, int save)
>  /* Return the virtual CPU time, based on the instruction counter.  */
>  int64_t cpu_get_icount(void)
>  {
> +    return qemu_icount_bias + cpu_get_icount_wo_bias();
> +}
> +
> +/* Return the virtual CPU time, really based on the instruction counter.  */
> +int64_t cpu_get_icount_wo_bias(void)
> +{

The comments for these two functions don't make any sense.
You need to explain what they're actually doing (and
when you'd want one and when the other).

-- PMM

Patch

diff --git a/cpus.c b/cpus.c
index fb83153..86fe82b 100644
--- a/cpus.c
+++ b/cpus.c
@@ -156,6 +156,12 @@  void restore_icount(CPUArchState *env, int save)
 /* Return the virtual CPU time, based on the instruction counter.  */
 int64_t cpu_get_icount(void)
 {
+    return qemu_icount_bias + cpu_get_icount_wo_bias();
+}
+
+/* Return the virtual CPU time, really based on the instruction counter.  */
+int64_t cpu_get_icount_wo_bias(void)
+{
     int64_t icount;
     CPUArchState *env = cpu_single_env;
 
@@ -166,7 +172,7 @@  int64_t cpu_get_icount(void)
         }
         icount -= (env->icount_decr.u16.low + env->icount_extra);
     }
-    return qemu_icount_bias + (icount << icount_time_shift);
+    return icount << icount_time_shift;
 }
 
 /* return the host CPU cycle counter and handle stop/restart */
@@ -1165,7 +1171,7 @@  static int tcg_cpu_exec(CPUArchState *env)
         qemu_icount -= (env->icount_decr.u16.low + env->icount_extra);
         env->icount_decr.u16.low = 0;
         env->icount_extra = 0;
-        count = qemu_icount_round(qemu_clock_deadline(vm_clock));
+        count = qemu_icount_round(qemu_clock_deadline(ic_clock));
         qemu_icount += count;
         decr = (count > 0xffff) ? 0xffff : count;
         count -= decr;
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index b4d8229..6e53f22 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -32,6 +32,9 @@  extern QEMUClock *vm_clock;
    the virtual clock. */
 extern QEMUClock *host_clock;
 
+/* A new clock based on icount only. */
+extern QEMUClock *ic_clock;
+
 int64_t qemu_get_clock_ns(QEMUClock *clock);
 int64_t qemu_clock_has_timers(QEMUClock *clock);
 int64_t qemu_clock_expired(QEMUClock *clock);
@@ -136,6 +139,7 @@  void qemu_put_timer(QEMUFile *f, QEMUTimer *ts);
 
 /* icount */
 int64_t cpu_get_icount(void);
+int64_t cpu_get_icount_wo_bias(void);
 int64_t cpu_get_clock(void);
 
 /*******************************************/
diff --git a/qemu-timer.c b/qemu-timer.c
index 6c607e5..79d5dcb 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -43,6 +43,7 @@ 
 #define QEMU_CLOCK_REALTIME 0
 #define QEMU_CLOCK_VIRTUAL  1
 #define QEMU_CLOCK_HOST     2
+#define QEMU_CLOCK_ICOUNT   3
 
 struct QEMUClock {
     QEMUTimer *active_timers;
@@ -230,6 +231,7 @@  next:
 QEMUClock *rt_clock;
 QEMUClock *vm_clock;
 QEMUClock *host_clock;
+QEMUClock *ic_clock;
 
 static QEMUClock *qemu_new_clock(int type)
 {
@@ -413,6 +415,8 @@  int64_t qemu_get_clock_ns(QEMUClock *clock)
         } else {
             return cpu_get_clock();
         }
+    case QEMU_CLOCK_ICOUNT:
+        return cpu_get_icount_wo_bias();
     case QEMU_CLOCK_HOST:
         now = get_clock_realtime();
         last = clock->last;
@@ -440,6 +444,7 @@  void init_clocks(void)
         rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
         vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
         host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
+        ic_clock = qemu_new_clock(QEMU_CLOCK_ICOUNT);
     }
 }
 
@@ -456,6 +461,7 @@  void qemu_run_all_timers(void)
     qemu_run_timers(vm_clock);
     qemu_run_timers(rt_clock);
     qemu_run_timers(host_clock);
+    qemu_run_timers(ic_clock);
 
     /* rearm timer, if not periodic */
     if (alarm_timer->expired) {