From patchwork Thu Aug 11 15:24:16 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: 73787 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp183707qga; Thu, 11 Aug 2016 09:05:32 -0700 (PDT) X-Received: by 10.129.81.85 with SMTP id f82mr7256413ywb.300.1470931532442; Thu, 11 Aug 2016 09:05:32 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d125si747453ybb.81.2016.08.11.09.05.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 11 Aug 2016 09:05:32 -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]:49450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXsU7-0003P8-SL for patch@linaro.org; Thu, 11 Aug 2016 12:05:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXrwe-00025z-7C for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:30:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXrwb-0007tq-2M for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:30:56 -0400 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:38222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXrwa-0007td-RG for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:30:52 -0400 Received: by mail-wm0-x22b.google.com with SMTP id o80so3520119wme.1 for ; Thu, 11 Aug 2016 08:30:52 -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=lo8f8aJTrJDepoM/C/TostOw2re2wgH+KNkB04SZ9Tc=; b=T6weACjkbJJgesCBKe1MyGvs9Gjk8ZqHUwfwCFKvT3/1xGDI0vADaFI1nmTO9jxSet qviW4YTvnYrWJXGRJDyJJcjKTeF8U93ge8S6dLolHqmnvpoSSopHEdVjeDT8lvz9Olw8 iOMm8V48CHg8nFT5I9osWfmvURjkm5cVCjM4c= 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=lo8f8aJTrJDepoM/C/TostOw2re2wgH+KNkB04SZ9Tc=; b=Wag8G9rACKph2Q+tJEboy1uIJLGgCIgG5JPMYKM7x0dyOQE1s0wnhTYGIN8FukY0iH h6AQ51/WNxn9SR3PhgCyRil/GttQ5gnSCSpNkdvIZ3rm5FvCG9if3Hbuv4WIc64gzWdA Vz5cW0vTpN1iGXmJkM/vV6WkXhAnVhfGgTzb08YkQJizzLsWWLYdwsPBSwHN+NZqCa23 fz7ZP7XQDZgy8hsKEnaS1CuBPe4uhwQL1ihYqu676XmA8Z7GMTLLuKNaUqrcwLCqaXFt 9qTDlwdeWRNjR1mJbpxuu1mj5wspkGFuZIhCnfCCBZlC0bDFu115tAN9y1ZkYZO4pZHU UscQ== X-Gm-Message-State: AEkoouug5QuQGMYlfw0wbUyDs0BkquPzTKtkMxIB31iGMqLfL199qVv5bkrv9CDBhye1S4f5 X-Received: by 10.194.175.38 with SMTP id bx6mr11812060wjc.47.1470929452084; Thu, 11 Aug 2016 08:30:52 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m81sm642117wmf.1.2016.08.11.08.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 08:30:49 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5FE6B3E033A; Thu, 11 Aug 2016 16:24:31 +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, cota@braap.org, bobby.prani@gmail.com, nikunj@linux.vnet.ibm.com Date: Thu, 11 Aug 2016 16:24:16 +0100 Message-Id: <1470929064-4092-21-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470929064-4092-1-git-send-email-alex.bennee@linaro.org> References: <1470929064-4092-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 v4 20/28] cpus: tweak sleeping and safe_work rules for MTTCG 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, claudio.fontana@huawei.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, serge.fdrv@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Once TCG gains the ability to sleep individual threads we need to make sure they don't sleep when safe work is pending as all threads need to go through the process_queued_work function. Also if we have multiple threads wait_for_safe_work can now sleep without deadlocking. Signed-off-by: Alex Bennée --- v4 - new for v4, ontop of async-safe-work-v5 --- cpu-exec-common.c | 15 ++++++++++++++- cpus.c | 2 +- include/qom/cpu.h | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/cpu-exec-common.c b/cpu-exec-common.c index e29cf6d..84cb789 100644 --- a/cpu-exec-common.c +++ b/cpu-exec-common.c @@ -83,6 +83,18 @@ QemuCond qemu_exclusive_cond; static int safe_work_pending; +/* No vCPUs can sleep while there is safe work pending as we need + * everything to finish up in process_cpu_work. + */ +bool cpu_has_queued_work(CPUState *cpu) +{ + if (cpu->queued_work || atomic_mb_read(&safe_work_pending) > 0) { + return true; + } else { + return false; + } +} + #ifdef CONFIG_USER_ONLY #define can_wait_for_safe() (1) #else @@ -91,7 +103,8 @@ static int safe_work_pending; * all vCPUs are in the same thread. This will change for MTTCG * however. */ -#define can_wait_for_safe() (0) +extern int smp_cpus; +#define can_wait_for_safe() (mttcg_enabled && smp_cpus > 1) #endif void wait_safe_cpu_work(void) diff --git a/cpus.c b/cpus.c index 8a40a08..4fc5e4c 100644 --- a/cpus.c +++ b/cpus.c @@ -88,7 +88,7 @@ bool cpu_is_stopped(CPUState *cpu) static bool cpu_thread_is_idle(CPUState *cpu) { - if (cpu->stop || cpu->queued_work) { + if (cpu->stop || cpu_has_queued_work(cpu)) { return false; } if (cpu_is_stopped(cpu)) { diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 5ecbd29..d0db846 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -661,6 +661,14 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data); void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data); /** + * cpu_has_queued_work: + * @cpu: The vCPU to check + * + * Returns true if there is *_run_on_cpu work to be done. + */ +bool cpu_has_queued_work(CPUState *cpu); + +/** * qemu_get_cpu: * @index: The CPUState@cpu_index value of the CPU to obtain. *