From patchwork Wed Apr 5 13:24:59 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: 96856 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp260951obc; Wed, 5 Apr 2017 06:31:16 -0700 (PDT) X-Received: by 10.55.174.198 with SMTP id x189mr29068029qke.318.1491399076183; Wed, 05 Apr 2017 06:31:16 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g9si17800458qte.112.2017.04.05.06.31.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 05 Apr 2017 06:31:16 -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]:40575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvl1n-00018F-KB for patch@linaro.org; Wed, 05 Apr 2017 09:31:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkvv-0004dO-ID for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkvu-0000Ja-Es for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:11 -0400 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:36429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvkvu-0000Iz-8I for qemu-devel@nongnu.org; Wed, 05 Apr 2017 09:25:10 -0400 Received: by mail-wr0-x22c.google.com with SMTP id w11so13735154wrc.3 for ; Wed, 05 Apr 2017 06:25:10 -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=IBec1eMIHmqz4tpVXRaCjleUhxYcHd5hzA3LALv1mbJOuPoISMN5RcJPeRMQpBs4nQ Pf4m3uTcOfVYsjXm5Kocyqyhrf0AagpeDvNPJ14SuHid+rej0GRatnqszDIrIrc5ERe+ 5bMXO1KVj8aELJfIg2+rO+ksCCR20t8jMgfow= 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=d4owI+kiN54+G0JR4iMPk+m+Y3fYWiyVFTjaIpyLazgme0glKI9uIiX/82LWOQE/OS +3WVV1kpYpb75VobQcDdihPivnKLMvCvG5gSBIr9yWwtVWD2TRWS9bPBGcEIur1AS0mj 9Crd262DcLCs6zqEdqNtjwjzx9d+YSdbBdewaPjkN5/kD9NoBJgTHDinPevhG/vqgbDX aVy8VkNvKfAA4/UIRN/sFT8JKx5ItjokBx3uvnBpET7CTKUWmTlCyRY8wiePvjDI1+Ts H+Uc2eyY4RJX+zg7RpBjkpBMkw6ifF5x8N2I1k6H7I39lPXFhPWAFAm/lZFx1l9o5WOu 2hzQ== X-Gm-Message-State: AFeK/H3lsYdR9w/ylvH1oPQ8iaO4mSjpBVwgjteKPPAZRR8lZ+IkAllBp8cc4PEJTG7axXDT X-Received: by 10.28.46.213 with SMTP id u204mr19002421wmu.136.1491398708682; Wed, 05 Apr 2017 06:25:08 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m21sm22270844wma.19.2017.04.05.06.25.03 (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 A85D33E0FF9; 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:24:59 +0100 Message-Id: <20170405132503.32125-9-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::22c Subject: [Qemu-devel] [PATCH v2 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;