From patchwork Mon Apr 3 12:45:23 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: 96634 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp83957qgd; Mon, 3 Apr 2017 05:51:27 -0700 (PDT) X-Received: by 10.55.116.70 with SMTP id p67mr14781043qkc.216.1491223887250; Mon, 03 Apr 2017 05:51:27 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e15si11802420qte.166.2017.04.03.05.51.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Apr 2017 05:51:27 -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]:59151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1SA-0005VR-Q8 for patch@linaro.org; Mon, 03 Apr 2017 08:51:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv1MV-0001Mc-7d for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv1MT-00013q-Pp for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:35 -0400 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:36780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv1MT-00013Q-JL for qemu-devel@nongnu.org; Mon, 03 Apr 2017 08:45:33 -0400 Received: by mail-wr0-x232.google.com with SMTP id w11so166922226wrc.3 for ; Mon, 03 Apr 2017 05:45:33 -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=4BGdwVkXgVTmpLmAjpfuBGmOkAO7R7uNtNrCdKvX/Ew=; b=d+00OirUib9x1mb4ajUEUkImcGTU79hpJvN3DZUp1DYtDjmi8Yz19SZiRlZyo+/bxE ZP+MWcb6BusvIZuRjLmX2dr9L/Q50Ip0Eev77tRyiW8v2xE0meWY8IjLii1gAYuwbjD7 bBSBVX1Ic4N5B9gNc6/iiL1WTgGXabyz5bMi0= 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=4BGdwVkXgVTmpLmAjpfuBGmOkAO7R7uNtNrCdKvX/Ew=; b=FJuNKaeKW+BnkfPWS9tWvZFHP52M+8iJU6q7ckMC9iDGqMp543VukHaL33s06s6W68 Dpfmhxy06dY82LNZXA/AnpqRgJjwMaA3yr9+vNqSqux2Wc0S50X2BZUI6P4MJ0Op5sSb hI43rfy/FsgCPFbSaOOmR9Pq6N3AQtsCHcJ9qXwUbgW3HEkAyOhUuMso1lAPfNvWRoGz SvsGSY8eSWFprIGVyyK9wfHP43WiPvaKLNcfFicS74z8Qo50Fta22MJAJJiu8WKIOM+p eGfR2DDhBDn6N8eXqohdGN+9yz0MKUla+jBzP/61wtirEP1ayguNkuMZbpq80RQa6Pfq tCvg== X-Gm-Message-State: AFeK/H1p9DpKU39kyNcMXEwuicabqWD7Vshqi+iHDsiI5vZGQky01ZVa+Z/c1PUCditwAKj7 X-Received: by 10.28.111.136 with SMTP id c8mr9668975wmi.128.1491223532421; Mon, 03 Apr 2017 05:45:32 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j77sm14199634wmj.3.2017.04.03.05.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:45:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5585E3E1104; Mon, 3 Apr 2017 13:45:25 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Mon, 3 Apr 2017 13:45:23 +0100 Message-Id: <20170403124524.10824-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170403124524.10824-1-alex.bennee@linaro.org> References: <20170403124524.10824-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::232 Subject: [Qemu-devel] [RFC PATCH v1 8/9] cpus: don't credit executed instructions before they have run 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" Outside of the vCPU thread icount time will only be tracked against timers_state.qemu_icount. We no longer credit cycles until they have completed the run. Inside the vCPU thread we adjust for passage of time by looking at how many have run so far. This is only valid inside the vCPU thread while it is running. Signed-off-by: Alex Bennée --- cpus.c | 27 +++++++++++++++++++++------ include/qom/cpu.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 87638a75d2..3d18374b0e 100644 --- a/cpus.c +++ b/cpus.c @@ -223,6 +223,15 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp) } } +/* The current number of executed instructions is based on what we + * originally budgeted minus the current state of the decrementing + * icount counters in extra/u16.low. + */ +static int64_t cpu_get_icount_executed(CPUState *cpu) +{ + return cpu->icount_budget - (cpu->icount_decr.u16.low + cpu->icount_extra); +} + int64_t cpu_get_icount_raw(void) { int64_t icount; @@ -234,7 +243,8 @@ int64_t cpu_get_icount_raw(void) fprintf(stderr, "Bad icount read\n"); exit(1); } - icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); + /* Take into account what has run */ + icount += cpu_get_icount_executed(cpu); } return icount; } @@ -1195,7 +1205,10 @@ static void prepare_icount_for_run(CPUState *cpu) count = tcg_get_icount_limit(); - timers_state.qemu_icount += count; + /* 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; @@ -1206,16 +1219,18 @@ static void prepare_icount_for_run(CPUState *cpu) 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); + /* Account for executed instructions */ + timers_state.qemu_icount += cpu_get_icount_executed(cpu); /* We must be under BQL here as cpu_exit can tweak icount_decr.u32 */ g_assert(qemu_mutex_iothread_locked()); + + /* Reset the counters */ cpu->icount_decr.u32 = 0; cpu->icount_extra = 0; + cpu->icount_budget = 0; + replay_account_executed_instructions(); } } diff --git a/include/qom/cpu.h b/include/qom/cpu.h index c3292efe1c..5d10359c8f 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -332,6 +332,7 @@ struct CPUState { /* updates protected by BQL */ uint32_t interrupt_request; int singlestep_enabled; + int64_t icount_budget; int64_t icount_extra; sigjmp_buf jmp_env;