From patchwork Fri Feb 24 11:20:54 2017 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: 94432 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp645049qgi; Fri, 24 Feb 2017 03:28:04 -0800 (PST) X-Received: by 10.200.42.151 with SMTP id b23mr1855660qta.163.1487935684840; Fri, 24 Feb 2017 03:28:04 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h82si5420718qkh.193.2017.02.24.03.28.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 24 Feb 2017 03:28:04 -0800 (PST) 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 sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chE2c-0005GW-7S for patch@linaro.org; Fri, 24 Feb 2017 06:28:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chDwF-0007Gi-1k for qemu-devel@nongnu.org; Fri, 24 Feb 2017 06:21:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chDwB-0000IA-0r for qemu-devel@nongnu.org; Fri, 24 Feb 2017 06:21:26 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:36541) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1chDwA-0000Gw-Nq for qemu-devel@nongnu.org; Fri, 24 Feb 2017 06:21:22 -0500 Received: by mail-wm0-x235.google.com with SMTP id v77so11955754wmv.1 for ; Fri, 24 Feb 2017 03:21:22 -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=rYnVDfUVoipEoRQQvVNor4uw5f4bhCBzGVwX3DxiiP8=; b=OrbcQlXhiAzALken1qd7eD5r11uaqEjDkulDBI7hWVBuorMPKy+EFGvPaNkdgFQRfN pLQeU3Dr2Sjpahe/pVvqnLKPaR2Fe4Q1Cwh8qehoBQ5w9We7DYCLti6VWsv/+51jyt3Y WsdDHBkS/lOau5DwPoMFjRNXywkj4AcYKq0yE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rYnVDfUVoipEoRQQvVNor4uw5f4bhCBzGVwX3DxiiP8=; b=J9MWtAz/BE2yHtGrc+pxnNKs0CEdNwCvXuGxwzsj2alRJUjQhOL+lwGaAp5HEaE4tE MrpeWkCm1PJraj6E6cR7qTQO6QefPy61kqfTAGyCjF6FPuPpwsQadr4/zycWBLN9fBHH j5Doj9HPJZJmkzl34fUxwSuGdM2ImrmtYV132syMYjvEPNyVNFGvpYCXFhTjiFiGOplL w+REeDUx5K2nAa0MZCdQv+Nhq4hLvSWKkN/enpLylTbqI2h724wX12rHA5fcikkZv4YY g90KtodABs0RD0pvAPKEtckeUU84BwZbMxqfFzh/tFLlL2um3UgEZgBhwaVGM7OW5P8t aOmw== X-Gm-Message-State: AMke39nEOacMDvsCCDnYi6q1/1SBYcr2oUqU7612PwG1cqmOL51eFLBk5ytHllaZSXCbmxaA X-Received: by 10.28.142.73 with SMTP id q70mr2344969wmd.3.1487935281593; Fri, 24 Feb 2017 03:21:21 -0800 (PST) Received: from zen.linaro.local (host5-81-235-77.range5-81.btcentralplus.com. [5.81.235.77]) by smtp.gmail.com with ESMTPSA id q1sm1968214wmd.6.2017.02.24.03.21.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 03:21:16 -0800 (PST) Received: from zen.home (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DC3813E06A0; Fri, 24 Feb 2017 11:21:09 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 24 Feb 2017 11:20:54 +0000 Message-Id: <20170224112109.3147-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170224112109.3147-1-alex.bennee@linaro.org> References: <20170224112109.3147-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::235 Subject: [Qemu-devel] [PULL 09/24] 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: Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Peter Crosthwaite 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. As an cpu->exit_request may legitimately get squashed while processing the EXCP_INTERRUPT exception we also check cpu->queued_work_first to ensure queued work is expedited as soon as possible. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- cpu-exec-common.c | 2 -- cpu-exec.c | 20 +++++++------------- cpus.c | 19 +++++++++++-------- include/exec/exec-all.h | 3 --- 4 files changed, 18 insertions(+), 26 deletions(-) -- 2.11.0 diff --git a/cpu-exec-common.c b/cpu-exec-common.c index e2bc053372..0504a9457b 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 1bd3d72002..85f14d4194 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -568,15 +568,13 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, *tb_exit = ret & TB_EXIT_MASK; switch (*tb_exit) { case TB_EXIT_REQUESTED: - /* 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 - * ensure the zeroing of tcg_exit_req (see cpu_tb_exec) - * comes before the next read of cpu->exit_request - * or cpu->interrupt_request. + /* 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 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. */ smp_mb(); *last_tb = NULL; @@ -630,10 +628,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 0ae8f69be5..e165d18785 100644 --- a/cpus.c +++ b/cpus.c @@ -793,7 +793,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) { @@ -1316,11 +1315,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(); @@ -1329,7 +1328,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu = first_cpu; } - for (; cpu != NULL && !exit_request; cpu = CPU_NEXT(cpu)) { + while (cpu && !cpu->queued_work_first && !cpu->exit_request) { + atomic_mb_set(&tcg_current_rr_cpu, cpu); qemu_clock_enable(QEMU_CLOCK_VIRTUAL, @@ -1349,12 +1349,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 4e34fc4cc1..82f0e12327 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -404,7 +404,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