[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v3 12/19] tcg: add kick timer for single-threaded vCPU
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [RFC v3 12/19] tcg: add kick timer for single-threaded vCPU emulation |
Date: |
Fri, 3 Jun 2016 21:40:21 +0100 |
Currently we rely on the side effect of the main loop grabbing the
iothread_mutex to give any long running basic block chains a kick to
ensure the next vCPU is scheduled. As this code is being re-factored and
rationalised we now do it explicitly here.
Signed-off-by: Alex Bennée <address@hidden>
---
v2
- re-base fixes
- get_ticks_per_sec() -> NANOSECONDS_PER_SEC
v3
- add define for TCG_KICK_FREQ
- fix checkpatch warning
---
cpus.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/cpus.c b/cpus.c
index 1694ce9..12e04c9 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1208,9 +1208,29 @@ static int tcg_cpu_exec(CPUState *cpu)
return ret;
}
+/* Single-threaded TCG
+ *
+ * In the single-threaded case each vCPU is simulated in turn. If
+ * there is more than a single vCPU we create a simple timer to kick
+ * the vCPU and ensure we don't get stuck in a tight loop in one vCPU.
+ * This is done explicitly rather than relying on side-effects
+ * elsewhere.
+ */
+static void qemu_cpu_kick_no_halt(void);
+#define TCG_KICK_FREQ (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + \
+ NANOSECONDS_PER_SECOND / 10)
+
+static void kick_tcg_thread(void *opaque)
+{
+ QEMUTimer *self = *(QEMUTimer **) opaque;
+ timer_mod(self, TCG_KICK_FREQ);
+ qemu_cpu_kick_no_halt();
+}
+
static void *qemu_tcg_cpu_thread_fn(void *arg)
{
CPUState *cpu = arg;
+ QEMUTimer *kick_timer;
rcu_register_thread();
@@ -1234,6 +1254,13 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
}
}
+ /* Set to kick if we have to do more than one vCPU */
+ if (CPU_NEXT(first_cpu)) {
+ kick_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, kick_tcg_thread,
+ &kick_timer);
+ timer_mod(kick_timer, TCG_KICK_FREQ);
+ }
+
/* process any pending work */
atomic_mb_set(&exit_request, 1);
--
2.7.4
- Re: [Qemu-devel] [RFC v3 03/19] translate-all: add DEBUG_LOCKING asserts, (continued)
[Qemu-devel] [RFC v3 05/19] exec: add assert_debug_safe and notes on debug structures, Alex Bennée, 2016/06/03
[Qemu-devel] [RFC v3 06/19] tcg: comment on which functions have to be called with tb_lock held, Alex Bennée, 2016/06/03
[Qemu-devel] [RFC v3 04/19] docs: new design document multi-thread-tcg.txt (DRAFTING), Alex Bennée, 2016/06/03
[Qemu-devel] [RFC v3 07/19] translate-all: Add assert_memory_lock annotations, Alex Bennée, 2016/06/03
[Qemu-devel] [RFC v3 12/19] tcg: add kick timer for single-threaded vCPU emulation,
Alex Bennée <=
[Qemu-devel] [RFC v3 08/19] tcg: protect TBContext with tb_lock., Alex Bennée, 2016/06/03
[Qemu-devel] [RFC v3 11/19] tcg: add options for enabling MTTCG, Alex Bennée, 2016/06/03
[Qemu-devel] [RFC v3 13/19] tcg: rename tcg_current_cpu to tcg_current_rr_cpu, Alex Bennée, 2016/06/03