From patchwork Wed Nov 9 14:57:35 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: 81516 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp242407qge; Wed, 9 Nov 2016 07:05:20 -0800 (PST) X-Received: by 10.157.4.116 with SMTP id 107mr59188otc.30.1478703920530; Wed, 09 Nov 2016 07:05:20 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id q203si36297oia.21.2016.11.09.07.05.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 09 Nov 2016 07:05:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; 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 208.118.235.17 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]:40456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4URD-0005tA-O4 for patch@linaro.org; Wed, 09 Nov 2016 10:05:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4UKC-0000Y3-JC for qemu-devel@nongnu.org; Wed, 09 Nov 2016 09:58:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4UKB-0002HO-FE for qemu-devel@nongnu.org; Wed, 09 Nov 2016 09:58:04 -0500 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:36739) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c4UKB-0002Gy-5b for qemu-devel@nongnu.org; Wed, 09 Nov 2016 09:58:03 -0500 Received: by mail-wm0-x22c.google.com with SMTP id p190so313278721wmp.1 for ; Wed, 09 Nov 2016 06:58:02 -0800 (PST) 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=wowQ7pJO9sSyVI53vNZaDdC7r/x18GiSRbPZSTLaHEE=; b=cYhgUDaYUJzx7Sw1mej+VXb8vdcQoUeR7WzLLusEjWW+opiCKiAoPtiAwX79hvJxJe OOALKXsrP0RvLO1hIotz2ZuK9pfabiHV9FCutPtZvbuUqsmEZ887Tr78OB5lvUmL/wl0 W3WxTLDF6xNqOfJtugx5eOUL9kUgu317DPFyQ= 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=wowQ7pJO9sSyVI53vNZaDdC7r/x18GiSRbPZSTLaHEE=; b=cZ66RJNBR9JpycBoaU+CeIFdhib4aDvWXQNfM1YfYotwnPt+RDa7B2ORJHjw95nRGH 257gOcyBycpl9RMx+mCya+Pm9D6DcM7rShzCexGjWIcfYLs6rswcnGPCPaMSqMAm8xbn WtHMoWiAMhiIqBIBRMOK+kRB0oBxbqGnkVO3QmOosS8HxIOtMl4jAnMHIVkRPoc7U8+M E9CZ573CwHlzJoroQnkYY6PRwCFUZrQ/N+essePuBZQ4XJwFZ5qGNkLbmPY1B3D7YkpU LFb87CAyRlLCZ2b3Z01hBi7CWDWnMmcTMF+uyTC9X4bK+wEcHyJpjjU/aKyMKhxkFs+f +H3w== X-Gm-Message-State: ABUngvdsfDNxQF26ppDpcnle6P4qWTJ7DyFqA+1pWI5X3LMHGmT2iz/64c2clgwBz93Insts X-Received: by 10.194.113.129 with SMTP id iy1mr16181210wjb.127.1478703481826; Wed, 09 Nov 2016 06:58:01 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id wh3sm43393479wjb.49.2016.11.09.06.57.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 06:57:59 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4639E3E0404; Wed, 9 Nov 2016 14:57:57 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 9 Nov 2016 14:57:35 +0000 Message-Id: <20161109145748.27282-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161109145748.27282-1-alex.bennee@linaro.org> References: <20161109145748.27282-1-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::22c Subject: [Qemu-devel] [PATCH v6 06/19] tcg: remove global exit_request 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: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, serge.fdrv@gmail.com, bobby.prani@gmail.com, rth@twiddle.net, =?UTF-8?q?Alex=20Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There are now only two uses of the global exit_request left. The first ensures we exit the run_loop when we first start to process pending work and in the kick handler. This is just as easily done by setting the first_cpu->exit_request flag. The second use is in the round robin kick routine. The global exit_request ensured every vCPU would set its local exit_request and cause a full exit of the loop. Now the iothread isn't being held while running we can just rely on the kick handler to push us out as intended. We lightly re-factor the main vCPU thread to ensure cpu->exit_requests cause us to exit the main loop and process any IO requests that might come along. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v5 - minor merge conflict with kick patch v4 - moved to after iothread unlocking patch - needed to remove kick exit_request as well. - remove extraneous cpu->exit_request check - remove stray exit_request setting - remove needless atomic operation --- cpu-exec-common.c | 2 -- cpu-exec.c | 9 ++------- cpus.c | 18 ++++++++++-------- include/exec/exec-all.h | 3 --- 4 files changed, 12 insertions(+), 20 deletions(-) -- 2.10.1 diff --git a/cpu-exec-common.c b/cpu-exec-common.c index e2bc053..0504a94 100644 --- a/cpu-exec-common.c +++ b/cpu-exec-common.c @@ -23,8 +23,6 @@ #include "exec/exec-all.h" #include "exec/memory-internal.h" -bool exit_request; - /* exit the current TB, but without causing any exception to be raised */ void cpu_loop_exit_noexc(CPUState *cpu) { diff --git a/cpu-exec.c b/cpu-exec.c index 59a9fc4..c4c7a06 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -561,9 +561,8 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, /* Something asked us to stop executing * chained TBs; just continue round the main * loop. Whatever requested the exit will also - * have set something else (eg exit_request or - * interrupt_request) which we will handle - * next time around the loop. But we need to + * have set something else (eg interrupt_request) which we + * will handle next time around the loop. But we need to * ensure the tcg_exit_req read in generated code * comes before the next read of cpu->exit_request * or cpu->interrupt_request. @@ -619,10 +618,6 @@ int cpu_exec(CPUState *cpu) rcu_read_lock(); - if (unlikely(atomic_mb_read(&exit_request))) { - cpu->exit_request = 1; - } - cc->cpu_exec_enter(cpu); /* Calculate difference between guest clock and host clock. diff --git a/cpus.c b/cpus.c index 7116ac6..6d43f32 100644 --- a/cpus.c +++ b/cpus.c @@ -761,7 +761,6 @@ static inline int64_t qemu_tcg_next_kick(void) static void qemu_cpu_kick_rr_cpu(void) { CPUState *cpu; - atomic_mb_set(&exit_request, 1); do { cpu = atomic_mb_read(&tcg_current_rr_cpu); if (cpu) { @@ -1283,11 +1282,11 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) start_tcg_kick_timer(); - /* process any pending work */ - atomic_mb_set(&exit_request, 1); - cpu = first_cpu; + /* process any pending work */ + cpu->exit_request = 1; + while (1) { /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ qemu_account_warp_timer(); @@ -1296,7 +1295,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu = first_cpu; } - for (; cpu != NULL && !exit_request; cpu = CPU_NEXT(cpu)) { + while (cpu && !cpu->exit_request) { atomic_mb_set(&tcg_current_rr_cpu, cpu); qemu_clock_enable(QEMU_CLOCK_VIRTUAL, @@ -1316,12 +1315,15 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) break; } - } /* for cpu.. */ + cpu = CPU_NEXT(cpu); + } /* while (cpu && !cpu->exit_request).. */ + /* Does not need atomic_mb_set because a spurious wakeup is okay. */ atomic_set(&tcg_current_rr_cpu, NULL); - /* Pairs with smp_wmb in qemu_cpu_kick. */ - atomic_mb_set(&exit_request, 0); + if (cpu && cpu->exit_request) { + atomic_mb_set(&cpu->exit_request, 0); + } handle_icount_deadline(); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 5a1b3a3..37781e0 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -405,7 +405,4 @@ bool memory_region_is_unassigned(MemoryRegion *mr); /* vl.c */ extern int singlestep; -/* cpu-exec.c, accessed with atomic_mb_read/atomic_mb_set */ -extern bool exit_request; - #endif