From patchwork Fri Apr 7 15:42:17 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: 97036 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp341508qgd; Fri, 7 Apr 2017 08:47:13 -0700 (PDT) X-Received: by 10.237.61.74 with SMTP id h10mr3406936qtf.225.1491580033406; Fri, 07 Apr 2017 08:47:13 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c38si5130198qte.183.2017.04.07.08.47.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:47:13 -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]:51511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW6S-0005iD-Op for patch@linaro.org; Fri, 07 Apr 2017 11:47:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1r-0002PX-Cy for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1q-0007W5-FB for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:27 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:35726) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1q-0007Vt-9i for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:26 -0400 Received: by mail-wm0-x22c.google.com with SMTP id w64so1697780wma.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=OujuJTRrHqM7wKLvvLxcSDIhuBftGtKlsyFfgtR7jxU=; b=WS9TH+KIK21em4EC8rkoNY5O2G86pI3VVIlDioD7nXjRdfkaQV53IYRtB/GOXBaEKn 6aVrnot+ng4aWvrFmvfLmYx+Xvmdqe+M97bMYMigla6wkb2JZVqQsx2PM5oNcMGsoBXq 3DkbdPS0DerV6s+0RFjUha/zA1DoC3dIGfCbA= 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=OujuJTRrHqM7wKLvvLxcSDIhuBftGtKlsyFfgtR7jxU=; b=p57+YnJxRx/Qp639BxEmwGh/9+5f6x5sHzuoXrn/u1GN2Yqd5gUvw99PbGByq2WMBW xyw2SOMBMVyYxQbsdRems5SUsY4dwiEyjaA6qAtCnFWg7PxQT5OmH2Sh5Z4E7rI0hbeF 0rip17X8naMxMryoOboxyVAIRFlMEkLQwtrPQylkjFj6FjtyBsuhKYzLUlCxc7ozmxig klaVIV6uUZzTCsIq1uqWegmTHFlJDIDPym4QvewpVFRcGIzEjJ0F5CZlmgvsaINSm0p0 nLZXLeBHMv5A2oRNdkzDR4bYrv5HFK9qmDa9qw6RtD9R0WU7hmFjF12wXRRgonmjweBN nE5g== X-Gm-Message-State: AN3rC/7OXQ2hOjcPcNyJ2k70383IzfNtBScYlzrSeUGtI/TCt7KGV3q4M8+JsLfmQ72ipvkQ X-Received: by 10.28.45.216 with SMTP id t207mr10409482wmt.85.1491579745071; 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 l141sm6729939wma.32.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 9C1673E11B6; 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:17 +0100 Message-Id: <20170407154221.26918-9-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:c09::22c Subject: [Qemu-devel] [PATCH v3 08/12] 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 | 25 +++++++++++++++++++------ include/qom/cpu.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index d9cb9407a2..88eabdc19f 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,14 +1219,14 @@ 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); /* Reset the counters */ cpu->icount_decr.u16.low = 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;