From patchwork Tue Apr 5 15:32:22 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: 65102 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp536676lbc; Tue, 5 Apr 2016 08:35:41 -0700 (PDT) X-Received: by 10.140.37.113 with SMTP id q104mr21827561qgq.104.1459870541289; Tue, 05 Apr 2016 08:35:41 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r79si22386472qkl.62.2016.04.05.08.35.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 05 Apr 2016 08:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anT12-0002vZ-Dk for patch@linaro.org; Tue, 05 Apr 2016 11:35:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSy8-0006kV-6u for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anSy7-0007EK-6i for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:32:40 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:33785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSy7-0007E9-0A for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:32:39 -0400 Received: by mail-wm0-x233.google.com with SMTP id f198so37283972wme.0 for ; Tue, 05 Apr 2016 08:32:38 -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=cXgu2RPDN17hLHRTkqsiPQcYimoYQ2G6u4P8jLvLnrM=; b=ApulMobXtjoFSlLAw0yTY0NTfX6Mwb2EtuL5+Q6sM4ZJdQbazccY3m6Fzm22OmLmcN RBnpVxxmUyM13yH33+AQfC6kTO6FYM/zpJw/cMDkW+LzrawrYUefkrErsgKejsv8SaU9 BdxEGjjKYjSehSI9St5vMkide0sgHX7RoMueY= 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=cXgu2RPDN17hLHRTkqsiPQcYimoYQ2G6u4P8jLvLnrM=; b=AWXp0HLqNHoT4t0E0JSBBuqkSrbaKHGGXaOx2ucMjYQaTMODahMj3PFZsir4mY5yGR /k43YNljkUBpamzvAUCLP2vs0uEQ2/COlgnT8G3T0uAy4JB7BtUCbbGTqSwdRoz4m9ck PYCz3l5TXJlIM+ja3jZcNR8k8HUGuBMVJE0hdhF8J0mue+4Y3MimivgyGqSh6HCtEo8h 1+cQgGsx+VhukbE8KoHbptID5nmDrH3WP5FFI2DgEYA2iuRNdLvwWOwvRuSRO5Cu/5Zq gXRPpH8os19w68CdXR3dmfVhomUk8fOVBlXYpi94uQmtMBeAeT1eVgs7ipSdC7O5cgz6 /OTQ== X-Gm-Message-State: AD7BkJLWuPQUVU6pI0j2A+mCGMkf++TDlgWA0Mk/czG4Q8AGOPrc5VUBWbWQUZcP4pfidTND X-Received: by 10.28.111.77 with SMTP id k74mr10487407wmc.37.1459870358355; Tue, 05 Apr 2016 08:32:38 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d1sm19029658wmh.18.2016.04.05.08.32.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Apr 2016 08:32:36 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 8B3103E0808; Tue, 5 Apr 2016 16:32:33 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Date: Tue, 5 Apr 2016 16:32:22 +0100 Message-Id: <1459870344-16773-10-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1459870344-16773-1-git-send-email-alex.bennee@linaro.org> References: <1459870344-16773-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::233 Cc: peter.maydell@linaro.org, claudio.fontana@huawei.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Subject: [Qemu-devel] [RFC v2 09/11] tcg: add kick timer for single-threaded vCPU emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- cpus.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.7.4 diff --git a/cpus.c b/cpus.c index 8d27fb0..e22bb77 100644 --- a/cpus.c +++ b/cpus.c @@ -1151,11 +1151,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) + + NANOSECONDS_PER_SECOND / 10); + qemu_cpu_kick_no_halt(); +} static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUState *cpu = arg; + QEMUTimer *kick_timer; rcu_register_thread(); @@ -1179,6 +1198,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) + + NANOSECONDS_PER_SECOND / 10); + } + /* process any pending work */ atomic_mb_set(&exit_request, 1);