aboutsummaryrefslogtreecommitdiff
path: root/cpus.c
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2017-04-05 10:53:47 +0100
committerAlex Bennée <alex.bennee@linaro.org>2017-04-10 10:23:38 +0100
commit1d05906b95e7f2a35be2392506f9af8f89ff39a5 (patch)
tree2de27cd5cb6f1ddccd6fd4abb3d07bfa38773ff4 /cpus.c
parenteda5f7c6a147c8eb927a6198ec48fe677cb079b3 (diff)
cpus: call cpu_update_icount on read
This ensures each time the vCPU thread reads the icount we update the master timer_state.qemu_icount field. This way as long as updates are in BQL protected sections (which they should be) the main-loop can never come to update the log and find time has gone backwards. Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Diffstat (limited to 'cpus.c')
-rw-r--r--cpus.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/cpus.c b/cpus.c
index 9c8bd2c991..740b8dc3f8 100644
--- a/cpus.c
+++ b/cpus.c
@@ -253,19 +253,21 @@ void cpu_update_icount(CPUState *cpu)
int64_t cpu_get_icount_raw(void)
{
- int64_t icount;
CPUState *cpu = current_cpu;
- icount = atomic_read(&timers_state.qemu_icount);
if (cpu && cpu->running) {
if (!cpu->can_do_io) {
fprintf(stderr, "Bad icount read\n");
exit(1);
}
/* Take into account what has run */
- icount += cpu_get_icount_executed(cpu);
+ cpu_update_icount(cpu);
}
- return icount;
+#ifdef CONFIG_ATOMIC64
+ return atomic_read__nocheck(&timers_state.qemu_icount);
+#else /* FIXME: we need 64bit atomics to do this safely */
+ return timers_state.qemu_icount;
+#endif
}
/* Return the virtual CPU time, based on the instruction counter. */