From patchwork Fri Apr 7 15:42:19 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: 97031 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp339736qgd; Fri, 7 Apr 2017 08:42:58 -0700 (PDT) X-Received: by 10.55.159.136 with SMTP id i130mr11274895qke.94.1491579778693; Fri, 07 Apr 2017 08:42:58 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j3si5129932qtj.62.2017.04.07.08.42.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:42:58 -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]:51492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW2M-0002U2-6o for patch@linaro.org; Fri, 07 Apr 2017 11:42:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1u-0002RZ-3n 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 1cwW1t-0007X2-7A for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:30 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:35594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1t-0007Wq-12 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:29 -0400 Received: by mail-wr0-x230.google.com with SMTP id o21so83625107wrb.2 for ; Fri, 07 Apr 2017 08:42:28 -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=kUaptWrpMRcEzjgmHXYy8PHozSdCXQFCFoqBG2b9QzY=; b=OpYSUVplRyWFlMnj1cMzJD0lUP7NXHVpMOObGD07raJbIGAxEbC6+WjWlqpHzuIGGA h8KWTIYzn7RcuPpFJIGSi3RJq0W9OfA8m90oPqfFK93TGGuIvalo9pG2D0NZ9pOX7zDB Q7BnJ7JwIXK6PLQ2coZYGhHw33iQgcY/tyv6c= 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=kUaptWrpMRcEzjgmHXYy8PHozSdCXQFCFoqBG2b9QzY=; b=LZVnK/accIXPX2YmQbvOZWjZYr19byVjlBNe3XVBReYjhRyd7bnWSihM4gmitlmsiT 1T4RT0wGhwjyOilq7yHBZ+NyEqn7ixt2OG0lppXvq0ohTh6Y1oSG3MJ46uNtfjWJH8v3 XJuCCU5TJwq0H1ZagU9/8+4ScstiFlxsVkVlxB8AOip9hK+f7PZAoiXv99BUTuOnW2Yu A5XggFxSYpkjXKa+wTAYckbJ877DjyCzLWlvFxYaZrsY30IjnJZ5YiVvx8HKKGEMzRuS /Pe94BWerQuhanqgMJhAcu5ZbYKj93QT4pbM0jkTTbSoX0c1tdg6kKx0ge9m/FwqVkdk 1NGQ== X-Gm-Message-State: AFeK/H2W3A08KeAaEheu1NFTwCtRcUScMsIsO51m3+iBWtUbIIAA9pt7F50Z1xqiHLuvsPmK X-Received: by 10.223.141.214 with SMTP id o80mr18213022wrb.110.1491579747826; Fri, 07 Apr 2017 08:42:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d4sm6464358wrb.24.2017.04.07.08.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:24 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C33173E123B; 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:19 +0100 Message-Id: <20170407154221.26918-11-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::230 Subject: [Qemu-devel] [PATCH v3 10/12] cpu-exec: update icount after each TB_EXIT 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" There is no particular reason we shouldn't update the global system icount time as we exit each TranslationBlock run. This ensures the main-loop doesn't have to wait until we exit to the outer loop for executed instructions to be credited to timer_state. The prepare_icount_for_run function is slightly tweaked to match the logic we run in cpu_loop_exec_tb. Based on Paolo's original suggestion. Signed-off-by: Alex Bennée --- cpu-exec.c | 14 +++++++------- cpus.c | 18 +++++------------- 2 files changed, 12 insertions(+), 20 deletions(-) -- 2.11.0 diff --git a/cpu-exec.c b/cpu-exec.c index 748cb66bca..63a56d0407 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -600,13 +600,13 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, /* Instruction counter expired. */ assert(use_icount); #ifndef CONFIG_USER_ONLY - if (cpu->icount_extra) { - /* Refill decrementer and continue execution. */ - cpu->icount_extra += insns_left; - insns_left = MIN(0xffff, cpu->icount_extra); - cpu->icount_extra -= insns_left; - cpu->icount_decr.u16.low = insns_left; - } else { + /* Ensure global icount has gone forward */ + cpu_update_icount(cpu); + /* Refill decrementer and continue execution. */ + insns_left = MIN(0xffff, cpu->icount_budget); + cpu->icount_decr.u16.low = insns_left; + cpu->icount_extra = cpu->icount_budget - insns_left; + if (!cpu->icount_extra) { /* Execute any remaining instructions, then let the main loop * handle the next event. */ diff --git a/cpus.c b/cpus.c index 3854f17c35..14c2149987 100644 --- a/cpus.c +++ b/cpus.c @@ -1211,8 +1211,7 @@ static void handle_icount_deadline(void) static void prepare_icount_for_run(CPUState *cpu) { if (use_icount) { - int64_t count; - int decr; + int insns_left; /* These should always be cleared by process_icount_data after * each vCPU execution. However u16.high can be raised @@ -1221,17 +1220,10 @@ static void prepare_icount_for_run(CPUState *cpu) g_assert(cpu->icount_decr.u16.low == 0); g_assert(cpu->icount_extra == 0); - - count = tcg_get_icount_limit(); - - /* To calculate what we have executed so far we need to know - * what we originally budgeted to run this cycle */ - cpu->icount_budget = count; - - decr = (count > 0xffff) ? 0xffff : count; - count -= decr; - cpu->icount_decr.u16.low = decr; - cpu->icount_extra = count; + cpu->icount_budget = tcg_get_icount_limit(); + insns_left = MIN(0xffff, cpu->icount_budget); + cpu->icount_decr.u16.low = insns_left; + cpu->icount_extra = cpu->icount_budget - insns_left; } }