From patchwork Wed Apr 5 13:25:01 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: 96857 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp261331obc; Wed, 5 Apr 2017 06:32:01 -0700 (PDT) X-Received: by 10.55.161.6 with SMTP id k6mr12852944qke.148.1491399121646; Wed, 05 Apr 2017 06:32:01 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a128si17778022qkb.211.2017.04.05.06.32.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:32:01 -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]:40579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl2X-0001pY-7f for patch@linaro.org; Wed, 05 Apr 2017 09:32:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvz-0004ha-7c for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvw-0000Kx-QW for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:15 -0400 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:34259) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvw-0000KU-Ks for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: by mail-wr0-x22a.google.com with SMTP id t20so14817886wra.1 for ; Wed, 05 Apr 2017 06:25:12 -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=LeN7a6z8rTYNSZpSeuvUih+9Syn1e5KGL2c4SK4PsMs=; b=D0t5FRFeQHo5EXUxllbS84yL4ZJM6FqcbBtIJnuwkyU5HieOupSr7s5fEq6MBFzrG4 QNmhOV6tFOQisXit4z14KXClLTLxd4Wgd+XlSwc2tobxr4k2Ub9vBF4dFYtwLM6wCY2m caP/vIzFpYyRdifboipnAn9Z5ZJei+uWHm2+0= 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=LeN7a6z8rTYNSZpSeuvUih+9Syn1e5KGL2c4SK4PsMs=; b=bUFa8M/wWBkTSz01yHvEMPoMfz7C4LKQZc11jFvPMMGUXvTG7G8nXzPqhIcNuV141x doWjIb1MWdlPvNe5njU3WQ/xhXVsd03jwOWFmgkLAcT/HHjcni19zcvMFwIDuMe6lqKk oBZNG3EAzqacZv2aNJS5atU5sljpIBchvGIv0tSmblZ5KbkgAzr/o/Qzss3jQPIxRh80 kiR5eoSocZEimehkxNAGmbm9m2cGv719DrMUR1zGOMciZO3DcMrE8rocUhibAE/RL/S1 psIQfWxDbf8lQaTi06NkYFwVS/uV6K+FqjXcMTrOyfcBFiWmzZtoKYgqxRw5WS7nmf67 nXjw== X-Gm-Message-State: AFeK/H0ALc/PpwkXT/T0TDa6QED2rxt9PX8IN7E6ZBWhxQ3tvH4wxawx/kdBn1xGWC3X7K0R X-Received: by 10.223.132.35 with SMTP id 32mr2270764wrf.58.1491398711458; Wed, 05 Apr 2017 06:25:11 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 18sm26302054wrt.52.2017.04.05.06.25.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 06:25:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id CDC423E1055; Wed, 5 Apr 2017 14:25:03 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Wed, 5 Apr 2017 14:25:01 +0100 Message-Id: <20170405132503.32125-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170405132503.32125-1-alex.bennee@linaro.org> References: <20170405132503.32125-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 v2 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 71c3baba87..ff75af449a 100644 --- a/cpus.c +++ b/cpus.c @@ -1204,8 +1204,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 @@ -1214,17 +1213,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; } }