From patchwork Fri Apr 7 15:42:16 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: 97041 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp342897qgd; Fri, 7 Apr 2017 08:50:48 -0700 (PDT) X-Received: by 10.237.35.164 with SMTP id j33mr43599224qtc.194.1491580248763; Fri, 07 Apr 2017 08:50:48 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n41si5134833qtf.240.2017.04.07.08.50.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:50:48 -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 sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW9w-0000Sp-AY for patch@linaro.org; Fri, 07 Apr 2017 11:50:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1s-0002QW-2f for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1r-0007WI-53 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:28 -0400 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:33697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1q-0007Vz-VG for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:27 -0400 Received: by mail-wr0-x22a.google.com with SMTP id g19so68078056wrb.0 for ; Fri, 07 Apr 2017 08:42:26 -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=do5s9bqyDkirtBCVtHMCEH1EhNrpNVT5N+MVuFJKP1s=; b=XJewxhm+dsGdFm0MssxGQNHSju99kLTNF0WuCLV0NAkA+H4JMIY4ygl0MhbcFJqjSr maHuiTaCCJdUIyM7OgaoCy6IKnC+gHyXqsolzSnDUJlJwHBAMTdA3k+I7FQQAjVL5ffY FI90qqpZdSsrN7VIrXkeDWozEtFJe+4jul9+k= 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=do5s9bqyDkirtBCVtHMCEH1EhNrpNVT5N+MVuFJKP1s=; b=Z6V490ua1xfl9ONVJlm4uQbdifabUvuYDlmFMY9xnDvNg+VVx74PX4TmsGaG9ENPL8 tQxNNo2iUWx+1yqgqsfpAVDFvNcSfBP52YhzYdMOjEHec+eCYJosmveRkASShul/jK/o CcdPWTvJ1wCr+FG5kXeZGzoGPPUD8MT8uU56STaWUiee/lRVmCQeiSMU+hiEDuNnv3Zy rL3WFq852ojHEDyRNvp7dlrKKiPVPLKdpJWJiQP+eMAWLt8YxfHG9xMxxMPvYcHeLJkN 4QqpLzCsAJrOx9tL5nTsEc1yPJL4wck7itWdM2gh3M4JzFICL4coh9YKLXq2z4ImZKG7 cP1w== X-Gm-Message-State: AN3rC/5IsPa4K3p3wRNltqvxxi3UFfINT9psqkLus3fEtRAf/AZ5C8dpi84wWKzkbFMnZMUc X-Received: by 10.223.130.81 with SMTP id 75mr7018860wrb.150.1491579745752; Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 134sm30553597wmj.6.2017.04.07.08.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:21 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 89AC73E118A; Fri, 7 Apr 2017 16:42:22 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:16 +0100 Message-Id: <20170407154221.26918-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170407154221.26918-1-alex.bennee@linaro.org> References: <20170407154221.26918-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22a Subject: [Qemu-devel] [PATCH v3 07/12] cpus: move icount preparation out of tcg_exec_cpu 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, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" As icount is only supported for single-threaded execution due to the requirement for determinism let's remove it from the common tcg_exec_cpu path. Also remove the additional fiddling which shouldn't be required as the icount counters should all be rectified as you enter the loop. Signed-off-by: Alex Bennée --- v2 - only clear u16.low - drop BQL assert --- cpus.c | 67 ++++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 22 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 18b1746770..d9cb9407a2 100644 --- a/cpus.c +++ b/cpus.c @@ -1179,47 +1179,64 @@ static void handle_icount_deadline(void) } } -static int tcg_cpu_exec(CPUState *cpu) +static void prepare_icount_for_run(CPUState *cpu) { - int ret; -#ifdef CONFIG_PROFILER - int64_t ti; -#endif - -#ifdef CONFIG_PROFILER - ti = profile_getclock(); -#endif if (use_icount) { int64_t count; int decr; - timers_state.qemu_icount -= (cpu->icount_decr.u16.low - + cpu->icount_extra); - cpu->icount_decr.u16.low = 0; - cpu->icount_extra = 0; + + /* These should always be cleared by process_icount_data after + * each vCPU execution. However u16.high can be raised + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt + */ + g_assert(cpu->icount_decr.u16.low == 0); + g_assert(cpu->icount_extra == 0); + + count = tcg_get_icount_limit(); + timers_state.qemu_icount += count; decr = (count > 0xffff) ? 0xffff : count; count -= decr; cpu->icount_decr.u16.low = decr; cpu->icount_extra = count; } - qemu_mutex_unlock_iothread(); - cpu_exec_start(cpu); - ret = cpu_exec(cpu); - cpu_exec_end(cpu); - qemu_mutex_lock_iothread(); -#ifdef CONFIG_PROFILER - tcg_time += profile_getclock() - ti; -#endif +} + +static void process_icount_data(CPUState *cpu) +{ if (use_icount) { /* Fold pending instructions back into the instruction counter, and clear the interrupt flag. */ timers_state.qemu_icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); - cpu->icount_decr.u32 = 0; + + /* Reset the counters */ + cpu->icount_decr.u16.low = 0; cpu->icount_extra = 0; replay_account_executed_instructions(); } +} + + +static int tcg_cpu_exec(CPUState *cpu) +{ + int ret; +#ifdef CONFIG_PROFILER + int64_t ti; +#endif + +#ifdef CONFIG_PROFILER + ti = profile_getclock(); +#endif + qemu_mutex_unlock_iothread(); + cpu_exec_start(cpu); + ret = cpu_exec(cpu); + cpu_exec_end(cpu); + qemu_mutex_lock_iothread(); +#ifdef CONFIG_PROFILER + tcg_time += profile_getclock() - ti; +#endif return ret; } @@ -1306,7 +1323,13 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) if (cpu_can_run(cpu)) { int r; + + prepare_icount_for_run(cpu); + r = tcg_cpu_exec(cpu); + + process_icount_data(cpu); + if (r == EXCP_DEBUG) { cpu_handle_guest_debug(cpu); break;