From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vtc-0008Vc-JZ for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8vta-0000Xs-Ar for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:43 -0400 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:36995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vtZ-0000Wd-PO for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:42 -0400 Received: by mail-wm0-x22b.google.com with SMTP id z87so9737773wmh.0 for ; Fri, 03 Jun 2016 13:40:41 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 3 Jun 2016 21:40:21 +0100 Message-Id: <1464986428-6739-13-git-send-email-alex.bennee@linaro.org> In-Reply-To: <1464986428-6739-1-git-send-email-alex.bennee@linaro.org> References: <1464986428-6739-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 v3 12/19] 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, qemu-devel@nongnu.org, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org, bobby.prani@gmail.com Cc: mark.burton@greensocs.com, pbonzini@redhat.com, jan.kiszka@siemens.com, rth@twiddle.net, peter.maydell@linaro.org, claudio.fontana@huawei.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Crosthwaite 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 --- 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