From nobody Wed Feb 11 05:17:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491580181533136.6092236803314; Fri, 7 Apr 2017 08:49:41 -0700 (PDT) Received: from localhost ([::1]:51520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW8p-0007qh-V6 for importer@patchew.org; Fri, 07 Apr 2017 11:49:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwW1t-0002RX-2G for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwW1s-0007Wi-4a for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:29 -0400 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:35735) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwW1r-0007WU-UC for qemu-devel@nongnu.org; Fri, 07 Apr 2017 11:42:28 -0400 Received: by mail-wm0-x232.google.com with SMTP id w64so1698364wma.0 for ; Fri, 07 Apr 2017 08:42:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g23sm6733124wme.8.2017.04.07.08.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Apr 2017 08:42:24 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AEFC73E121E; Fri, 7 Apr 2017 16:42:22 +0100 (BST) 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=FymwcrX/nal7C5r6MWL6iyizFy4DQcKc7z+EDAFp5Oo=; b=c+0ABzIeRjPWanWunWoCKaZg3YmHxCGuampRPIsMoYpUOfF+4yT+jaM2HMSS855rNV p7r5RSbEdtwRY4uQqzzNxBm9jXjPiZd47//cBN+Y1rKbW35KXWx+Wwz4gZ9Eht8hgADM yJ+sK7/h9yAkeSvIfFTLDziDcOsifAp8QheMU= 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=FymwcrX/nal7C5r6MWL6iyizFy4DQcKc7z+EDAFp5Oo=; b=a6ykgT0ICGmKkhFT3WY+8fhq4ZLCcxUqMml7S7BjYpZIXQAUSVAoFK0ES93YtT0+ok dJsUxSRLZQ9uVeMyKmYKJUxkFWndMp6oI3lldX1c0fa5GVYicGZ6xCLecTT0/LwTrtiM 7MqNssGguGrktOHrQUTr7VrOEOXQdBf4priTggGExO5udYL2S8VsBXigv1V8Cs3VurSo /DZhBMXb7Ao/SptW1ckbla3L1WynV0PBFht1P4GGHT+M1mZU4/V0VCiukDKOfCcidNjz JF2NA0VuR1+uCXB5nyvs2Dipk1Zm0p2JS68Dts1L5fXA14H9HK7Md7gxT+S5+uR86zF1 r3bg== X-Gm-Message-State: AN3rC/7nnx3FPKVALJQuv/Ptffy3drXHp9fe8HJOKatYbGqvq7XO0ZzecruhzYJPVKpNoUbB X-Received: by 10.28.63.71 with SMTP id m68mr34442wma.46.1491579746860; Fri, 07 Apr 2017 08:42:26 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: dovgaluk@ispras.ru, rth@twiddle.net, pbonzini@redhat.com Date: Fri, 7 Apr 2017 16:42:18 +0100 Message-Id: <20170407154221.26918-10-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 Subject: [Qemu-devel] [PATCH v3 09/12] cpus: introduce cpu_update_icount helper 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=20Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 By holding off updates to timer_state.qemu_icount we can run into trouble when the non-vCPU thread needs to know the time. This helper ensures we atomically update timers_state.qemu_icount based on what has been currently executed. Signed-off-by: Alex Benn=C3=A9e --- cpus.c | 23 +++++++++++++++++++++-- include/qemu/timer.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index 88eabdc19f..3854f17c35 100644 --- a/cpus.c +++ b/cpus.c @@ -232,12 +232,31 @@ static int64_t cpu_get_icount_executed(CPUState *cpu) return cpu->icount_budget - (cpu->icount_decr.u16.low + cpu->icount_ex= tra); } =20 +/* + * Update the global shared timer_state.qemu_icount to take into + * account executed instructions. This is done by the TCG vCPU + * thread so the main-loop can see time has moved forward. + */ +void cpu_update_icount(CPUState *cpu) +{ + int64_t executed =3D cpu_get_icount_executed(cpu); + cpu->icount_budget -=3D executed; + +#ifdef CONFIG_ATOMIC64 + atomic_set__nocheck(&timers_state.qemu_icount, + atomic_read__nocheck(&timers_state.qemu_icount) + + executed); +#else /* FIXME: we need 64bit atomics to do this safely */ + timers_state.qemu_icount +=3D executed; +#endif +} + int64_t cpu_get_icount_raw(void) { int64_t icount; CPUState *cpu =3D current_cpu; =20 - icount =3D timers_state.qemu_icount; + icount =3D atomic_read(&timers_state.qemu_icount); if (cpu && cpu->running) { if (!cpu->can_do_io) { fprintf(stderr, "Bad icount read\n"); @@ -1220,7 +1239,7 @@ static void process_icount_data(CPUState *cpu) { if (use_icount) { /* Account for executed instructions */ - timers_state.qemu_icount +=3D cpu_get_icount_executed(cpu); + cpu_update_icount(cpu); =20 /* Reset the counters */ cpu->icount_decr.u16.low =3D 0; diff --git a/include/qemu/timer.h b/include/qemu/timer.h index e1742f2f3d..8a1eb74839 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -869,6 +869,7 @@ int64_t cpu_get_icount_raw(void); int64_t cpu_get_icount(void); int64_t cpu_get_clock(void); int64_t cpu_icount_to_ns(int64_t icount); +void cpu_update_icount(CPUState *cpu); =20 /*******************************************/ /* host CPU ticks (if available) */ --=20 2.11.0