From patchwork Mon Apr 10 12:55:20 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: 97124 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1350002qgd; Mon, 10 Apr 2017 06:00:39 -0700 (PDT) X-Received: by 10.31.140.205 with SMTP id o196mr24424025vkd.7.1491829239587; Mon, 10 Apr 2017 06:00:39 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c187si6770922vkd.194.2017.04.10.06.00.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 06:00:39 -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]:34352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYvs-0006l9-8U for patch@linaro.org; Mon, 10 Apr 2017 09:00:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqv-0002X3-UE for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqs-00039T-0t for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:30 -0400 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:35913) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqr-00038l-PP for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:25 -0400 Received: by mail-wr0-x22c.google.com with SMTP id c55so74645747wrc.3 for ; Mon, 10 Apr 2017 05:55:25 -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=OZJ/wv1+CPPX/SHSaZmm/NonoUYVNkdrmRwtU1WtUI0=; b=OQ0EPNIhEjHEam/4pwN1DJa+9H8OeyQvTt9fXBLjsKhasyaxqbkIb/RPAQR7+2ojuq TpX8iC2hMflK4AY4OjtfgJIi8mB3OkKdZBkyO0D1wzoupUPA4DNMsSigh1k9RSPJ4MMm ZNi/LTzZvd/NLpx6brC/KNjhZth7BbLfZcxWE= 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=OZJ/wv1+CPPX/SHSaZmm/NonoUYVNkdrmRwtU1WtUI0=; b=K1qhEK8el89lVsbny0LvQACaTSGDej9Pz35Getm7EowrHopp/Zmo7z0FGbEZQUUtEg rW4kgDmD46zNj1392vft0s6CuU0qLCcEKZZ2ysVlH3IHrSn1zbtBU0E3Lc+D9YwftaEy dX6IDUoPpZqzw5uQCN7VjMRNZX2eJY8dCcCmxqzBWiqnBkhj1uQ9rJTUU8eT7NKaZplW pFFZZJXWmnyeoGslUfmejynWjCwNfjNHm6aVt9fmpA6qcfUjJ/8JCc+tqO+PE4p4bTLh o7dVb5NkW+F1P6DLXfhs8DCJf/PNF8Y2NDlh6Q0QjHfB8U1h96pnerQsOwfjS2LzysrU lb0A== X-Gm-Message-State: AFeK/H2yUMbrkV9qtFeiao284bxgwpAPICms12qwlsEg5IDaLEFG5dpPYO6Xi7pgq3uRPOhf X-Received: by 10.223.128.194 with SMTP id 60mr38388550wrl.175.1491828924501; Mon, 10 Apr 2017 05:55:24 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u63sm10142732wmu.22.2017.04.10.05.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 05:55:20 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 6028F3E100D; 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:20 +0100 Message-Id: <20170410125524.21008-8-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::22c Subject: [Qemu-devel] [PULL 07/11] 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: 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" 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 -- 2.11.0 diff --git a/cpus.c b/cpus.c index 6034b104c3..0ecb0b87f0 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;