[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 3/3] icount: create a new icount based timer.
From: |
fred . konrad |
Subject: |
[Qemu-devel] [RFC 3/3] icount: create a new icount based timer. |
Date: |
Thu, 18 Jul 2013 17:02:37 +0200 |
From: KONRAD Frederic <address@hidden>
This creates a new icount based timer, with no bias.
It moves only with the instruction counter.
Signed-off-by: KONRAD Frederic <address@hidden>
---
cpus.c | 10 ++++++++--
include/qemu/timer.h | 4 ++++
qemu-timer.c | 6 ++++++
3 files changed, 18 insertions(+), 2 deletions(-)
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) {
--
1.8.1.4
- [Qemu-devel] [RFC 0/3] Determinitic behaviour with icount., fred . konrad, 2013/07/18
- [Qemu-devel] [RFC 2/3] icount: sync vm_clock on the next event., fred . konrad, 2013/07/18
- [Qemu-devel] [RFC 3/3] icount: create a new icount based timer.,
fred . konrad <=
- Re: [Qemu-devel] [RFC 0/3] Determinitic behaviour with icount., Peter Maydell, 2013/07/18
- Re: [Qemu-devel] [RFC 0/3] Determinitic behaviour with icount., Frederic Konrad, 2013/07/29
- Re: [Qemu-devel] [RFC 0/3] Determinitic behaviour with icount., Paolo Bonzini, 2013/07/29