From patchwork Fri Apr 7 15:42: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: 97042 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp344389qgd; Fri, 7 Apr 2017 08:54:41 -0700 (PDT) X-Received: by 10.200.39.56 with SMTP id g53mr43379405qtg.134.1491580481913; Fri, 07 Apr 2017 08:54:41 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r6si5162110qkb.41.2017.04.07.08.54.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Apr 2017 08:54:41 -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]:51551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwWDh-0003fK-I4 for patch@linaro.org; Fri, 07 Apr 2017 11:54:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1z-0002WG-Sy for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1v-0007YB-5X for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:35 -0400 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:33719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1u-0007Xq-V8 for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:31 -0400 Received: by mail-wr0-x234.google.com with SMTP id g19so68079292wrb.0 for ; Fri, 07 Apr 2017 08:42:30 -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=xfiexOHs1UqlXeei4yUFNO4/ImgtjV9V7GCgD8vy7UE=; b=J0y639Nzzei/uLOxLQ+gaqwtEQGNqZUaKLBb5s/rTi2VrCcGffB5aIr40NvJ1ufgZ7 G7fsmBOZDgXhdcJa8K4+8BaDdEJQTYKWk3iEP1nA9jlIUCgEatMZtfVbOZfH93+pGIvd xwb6nKTKF81KUPVCy4uHRjNNFvc1K7Do1yeyE= 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=xfiexOHs1UqlXeei4yUFNO4/ImgtjV9V7GCgD8vy7UE=; b=XVCm7/+mLgtrqSqA1v0wHH6YLFZjsp1XXgGxevuKaT5os9smze0ZRvWJYplSwN13wM bLHU/D88T7t6VrKXaMtqEoBKrqEP9z4uRGPBL88LeJUDpVfOdvqaw7211y+aYg8c9EQS dw4YRZrNAHEIK7RS+X7lPUf6oc7iw7grIQZrnd6So5t8XhM79rjIlvl1/ih8JpHm3Bwp fc8wHpP7AjXtWL20epgSLUcqxmtyJ2Yc4fhM1LNAJOA+R6afNV1FHdQPhTXC67rPv0ZT hcsu+GuwcxbKU1IAcbaqKfinld+wBxkh4vECns5oRZLXvC+VnoNfDAbRugLKmzxr/zOk G88A== X-Gm-Message-State: AN3rC/4SbzJcSmJtRduKPgi69s9eoSIXY40HHuwifGNOTSxiCDo+bt0SeCfX/eO8VYMdScaD X-Received: by 10.223.161.222 with SMTP id v30mr3457267wrv.132.1491579749798; Fri, 07 Apr 2017 08:42:29 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u145sm30656919wmu.1.2017.04.07.08.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:25 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id D4CA73E1775; 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:20 +0100 Message-Id: <20170407154221.26918-12-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:c0c::234 Subject: [Qemu-devel] [PATCH v3 11/12] 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: 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" 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 --- cpus.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 14c2149987..a6a85bfdba 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. */