From patchwork Fri Jun 3 20:40:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 9154011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EBD446082E for ; Fri, 3 Jun 2016 20:45:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD538281F9 for ; Fri, 3 Jun 2016 20:45:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1CA528333; Fri, 3 Jun 2016 20:45:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A0B3281F9 for ; Fri, 3 Jun 2016 20:45:35 +0000 (UTC) Received: from localhost ([::1]:57646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vyI-0004KY-4w for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 16:45:34 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rVmmgtLv6j4k6OP8yrVe/YTEvIBgCZC3k6jHU815BK8=; b=Zdl9mZX+YZoMUWVk9O8dCCAPoRP3jAKbuBfmfapOcfNQ5MWyhqLXlBrN1esqKq4b+6 sPkzSFNJWJO6USCZRcZPsOs4Y4apaZYX80SryoVzrxsACqZ7tMHSUo8RzWf41chGZptJ IeN7Nyas2+/fwly3KBXnAA5GIeFZw2L2ix2HU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rVmmgtLv6j4k6OP8yrVe/YTEvIBgCZC3k6jHU815BK8=; b=hof9lX4lAz1/XjtQ8bAEGa7o4WlDaKqbFm5AargFmoc42ehuiBLWQyj9bi3QRXauih tYj5euwdnBLLI71gEwGLS9PJW4w+HWq8ZqFA/s4Sx6MX5UmB3Wus1Ztcjc9DexQmjN80 soeiwvieSKwN0cpZdeI1gapV2rN5IbIHxpynha2Eyo+HKZqWKrQqTBAGXf1EnZJ6mstn udZE8w0wwF9VGqWvZd2o9y+72G8vSquDemjKmyRLqLc61kU7DfUHxh6Gwlyt55vR5OJh YcukRd5FdALfZF4ie/WzqWDlfTs8nEnnp5Z/vxIlENsNYWFrN6Dxgj9woPh2AeUw8NHp WR4g== X-Gm-Message-State: ALyK8tKeGpnwEc+5HTCCakmFVdYlDgUL7U5U1Y7JYUDDwzBpLj1hFwjusvqal+yRit8IrdHg X-Received: by 10.28.29.7 with SMTP id d7mr1193318wmd.27.1464986441033; Fri, 03 Jun 2016 13:40:41 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q194sm1203219wme.18.2016.06.03.13.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jun 2016 13:40:35 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 2AAEA3E302E; Fri, 3 Jun 2016 21:40:40 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= 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 Date: Fri, 3 Jun 2016 21:40:21 +0100 Message-Id: <1464986428-6739-13-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22b Subject: [Qemu-devel] [RFC v3 12/19] tcg: add kick timer for single-threaded vCPU emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Peter Crosthwaite , claudio.fontana@huawei.com, mark.burton@greensocs.com, jan.kiszka@siemens.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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);