From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agx7B-0000RT-9K for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:19:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agx79-0002xN-VV for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:19:05 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:37504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agx79-0002wt-P5 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:19:03 -0400 Received: by mail-wm0-x22a.google.com with SMTP id p65so44379901wmp.0 for ; Fri, 18 Mar 2016 09:19:03 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 18 Mar 2016 16:18:49 +0000 Message-Id: <1458317932-1875-9-git-send-email-alex.bennee@linaro.org> In-Reply-To: <1458317932-1875-1-git-send-email-alex.bennee@linaro.org> References: <1458317932-1875-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [RFC v1 08/11] tcg: add kick timer for single-threaded vCPU emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Cc: Peter Crosthwaite , mark.burton@greensocs.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson 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 --- cpus.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cpus.c b/cpus.c index 76bd321..a87fbf9 100644 --- a/cpus.c +++ b/cpus.c @@ -1145,11 +1145,30 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) #endif } +/* 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 int tcg_cpu_exec(CPUState *cpu); +static void qemu_cpu_kick_no_halt(void); + +static void kick_tcg_thread(void *opaque) +{ + QEMUTimer *self = *(QEMUTimer **) opaque; + timer_mod(self, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + get_ticks_per_sec() / 10); + qemu_cpu_kick_no_halt(); +} static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUState *cpu = arg; + QEMUTimer *kick_timer; rcu_register_thread(); @@ -1173,6 +1192,14 @@ 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, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + get_ticks_per_sec() / 10); + } + /* process any pending work */ atomic_mb_set(&exit_request, 1); -- 2.7.3