From patchwork Mon Apr 10 12:55: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: 97120 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1349003qgd; Mon, 10 Apr 2017 05:58:14 -0700 (PDT) X-Received: by 10.200.43.17 with SMTP id 17mr49091442qtu.199.1491829094656; Mon, 10 Apr 2017 05:58:14 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s56si8938142qta.206.2017.04.10.05.58.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 10 Apr 2017 05:58:14 -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]:34332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYtY-0004fd-72 for patch@linaro.org; Mon, 10 Apr 2017 08:58:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxYqt-0002Uw-Ep for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxYqs-0003AF-MH for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:27 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:38615) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxYqs-00039I-Gi for qemu-devel@nongnu.org; Mon, 10 Apr 2017 08:55:26 -0400 Received: by mail-wm0-x231.google.com with SMTP id t189so36722602wmt.1 for ; Mon, 10 Apr 2017 05:55: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=s788N5UQVXQevsKcqsLb9eqQIYzLp/5AC4TyUxSEJSk=; b=FribKfYicy9noqWuyUL9XyF+frO1bHpZ+OYeQs8cGYaUcpMmVsIywLzYU+6YZVYrah YztNad9dc8icJJpWGLM7aFuuLu5j48Zb/JZ0WHYhAdDhbZMN0NvEC1TXdjrQJZMsFdZN k9p4J7FCSQ+f8zQa1r8lStyelnDWOgJQV3KQA= 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=s788N5UQVXQevsKcqsLb9eqQIYzLp/5AC4TyUxSEJSk=; b=qsDfIcljYQWL2uDRj50ibZhZ+uAloRZdWcYZW4Q20y6/zUxyWK8sMTQihWy+NYMu7j Hl0JV0uQM3FTr8RLj70V6JWli5piPaZp8bHLXWayv1Hn7GGMVU9IYjXn28d9eCxaLb+I 64es2dK1NSr7DrDyB0Gel/Q8vtj7IAoAsMCzcigv7tH0XaZI8Hnp4ggZ/i5oO1KeuwsK z8cSCIvFplKmYL1nIRj3yQeB5Ld1rEjryAfGbB29xI0fCzGVemmLhrY3QkWKjhEQIPQ4 sIdc/ggTeuP7yt5eTt5Qlm0yL7Cqp+70BfgpTXIEnmpbZeB/NSwQfu0ncy5CII+JzLgu EmmQ== X-Gm-Message-State: AN3rC/5yqHqvR1y/NrYyXwoYAg4U1QqawGCm58YrnmJkorJbMIySo1jg g2/bkJ5FnAFtkZkF X-Received: by 10.28.167.18 with SMTP id q18mr7462610wme.82.1491828925333; Mon, 10 Apr 2017 05:55:25 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a66sm17494696wrc.58.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 94A8D3E1058; 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:23 +0100 Message-Id: <20170410125524.21008-11-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: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Subject: [Qemu-devel] [PULL 10/11] cpus: call cpu_update_icount on read 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" This ensures each time the vCPU thread reads the icount we update the master timer_state.qemu_icount field. This way as long as updates are in BQL protected sections (which they should be) the main-loop can never come to update the log and find time has gone backwards. Signed-off-by: Alex Bennée -- 2.11.0 diff --git a/cpus.c b/cpus.c index 9c8bd2c991..740b8dc3f8 100644 --- a/cpus.c +++ b/cpus.c @@ -253,19 +253,21 @@ void cpu_update_icount(CPUState *cpu) int64_t cpu_get_icount_raw(void) { - int64_t icount; CPUState *cpu = current_cpu; - icount = atomic_read(&timers_state.qemu_icount); if (cpu && cpu->running) { if (!cpu->can_do_io) { fprintf(stderr, "Bad icount read\n"); exit(1); } /* Take into account what has run */ - icount += cpu_get_icount_executed(cpu); + cpu_update_icount(cpu); } - return icount; +#ifdef CONFIG_ATOMIC64 + return atomic_read__nocheck(&timers_state.qemu_icount); +#else /* FIXME: we need 64bit atomics to do this safely */ + return timers_state.qemu_icount; +#endif } /* Return the virtual CPU time, based on the instruction counter. */