From patchwork Mon Apr 10 12:55:22 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: 97126 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1350390qgd; Mon, 10 Apr 2017 06:01:24 -0700 (PDT) X-Received: by 10.31.178.79 with SMTP id b76mr19809290vkf.104.1491829284868; Mon, 10 Apr 2017 06:01:24 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m3si6796449vkg.88.2017.04.10.06.01.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:01:24 -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]:34359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYwc-0007MD-8G for patch@linaro.org; Mon, 10 Apr 2017 09:01:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqu-0002Vo-No for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqt-0003Ai-Jq for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:28 -0400 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:35923) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqt-0003AM-DI for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: by mail-wr0-x22f.google.com with SMTP id c55so74646367wrc.3 for ; Mon, 10 Apr 2017 05:55:27 -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=LXdfzu+XHr9LvGqDDL/cIa9x/i+mda3BEPIGHvgMcEE=; b=eoJdWhtSyattsK6yEVPfIappbR+STy9ttk+I8O+4I7Ld1txNSQ0VP1x/fqk4pfrSWw dcabqk2Dczl+6iQ5vftd1S2dzduK4Eer0fRcJMDE3svO6ilaTD+EP+jCdnWZipspAXdy 0FBmHuekxLYLKunJkah6Pg2LcVZ63jbTqlA24= 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=LXdfzu+XHr9LvGqDDL/cIa9x/i+mda3BEPIGHvgMcEE=; b=ZfQCVaJqX1WKwRH3Jkl+McrhEhUzkMKtu66gG6gq21gNv4cYdbBkhlLPP9eVRVUAU9 YvZ2vK0XM23lgrmEqu0+OJlzWMvraWAhWIB+CYQtxHaOJLxdHfeXx5l8ssoHFTlZwYzt C49TAY7vmdJFaEmTobp6gwyJiKyxP1DzHRyt6+1OzCjOVBZbTeo5dd1r/X22/CxVm5mA KlATeic8yj5Kimu6aIBt3nlyTFBQkaceuchzpO6ejBBn8/kpG3LiOUNk9bCekD75wPvq PlLAeluZ1t8CVUkHSniUaDPto2hrzypDL2EdbRrXbrJlf0uuISPoG1Y7lJZiAmirqQV8 wggA== X-Gm-Message-State: AN3rC/7fHpw6V++qUC5y/5sB3JxAKkQN9PpTAd6zQjLQhBTLhKHonnNPt9wpVlkuUO8rauNd X-Received: by 10.223.163.212 with SMTP id m20mr2959852wrb.29.1491828926261; Mon, 10 Apr 2017 05:55:26 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a10sm17412204wra.17.2017.04.10.05.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:22 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 841923E102C; Mon, 10 Apr 2017 13:55:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 10 Apr 2017 13:55:22 +0100 Message-Id: <20170410125524.21008-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170410125524.21008-1-alex.bennee@linaro.org> References: <20170410125524.21008-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::22f Subject: [Qemu-devel] [PULL 09/11] 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: 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 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 -- 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 a5125d7167..9c8bd2c991 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; } }