From nobody Tue Feb 10 06:08:28 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518407438086414.8020357465174; Sun, 11 Feb 2018 19:50:38 -0800 (PST) Received: from localhost ([::1]:34235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1el58N-0006SQ-JN for importer@patchew.org; Sun, 11 Feb 2018 22:50:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1el4zP-0007kZ-9H for qemu-devel@nongnu.org; Sun, 11 Feb 2018 22:41:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1el4zL-0006CT-Nz for qemu-devel@nongnu.org; Sun, 11 Feb 2018 22:41:11 -0500 Received: from ozlabs.org ([103.22.144.67]:58399) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1el4zL-00068P-6R; Sun, 11 Feb 2018 22:41:07 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3zfrzv0HlRz9t4t; Mon, 12 Feb 2018 14:40:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1518406859; bh=JoPc6tyRR+MwUkjvf+vit5Avh/VIzmYD7QmvciLJDWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KbaE/F+IPQK9BDKx4JLTgW5WtsONSrzn/NlGaR20c7uxdYYfo50i8sKFA4PZpE3cj wuzeLpKQbxPWtBkYFjhypRM7WJ3IpGnDGolTysX3oWPD1ktVjlQaG8L8j47oquor4M 9yx4ThrbeR6fyF/c8u6ETQ59pm3M9X3kitYW73yg= From: David Gibson To: peter.maydell@linaro.org Date: Mon, 12 Feb 2018 14:40:53 +1100 Message-Id: <20180212034054.23441-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212034054.23441-1-david@gibson.dropbear.id.au> References: <20180212034054.23441-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 11/12] cuda: factor out timebase-derived counter value and load time 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: lvivier@redhat.com, mark.cave-ayland@ilande.co.uk, groug@kaod.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, David Gibson 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 Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland Commit b981289c49 "PPC: Cuda: Use cuda timer to expose tbfreq to guest" alt= ered the timer calculations from those based upon the hardware CUDA clock freque= ncy to those based upon the CPU timebase frequency. In fact we can isolate the differences to 2 simple changes: one to the coun= ter read value and another to the counter load time. Move these changes into separate functions so the implementation can be swapped later. Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Gibson --- hw/misc/macio/cuda.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c index e00df4a21a..a185252144 100644 --- a/hw/misc/macio/cuda.c +++ b/hw/misc/macio/cuda.c @@ -145,21 +145,29 @@ static void cuda_update_irq(CUDAState *s) } } =20 -static uint64_t get_tb(uint64_t time, uint64_t freq) +static uint64_t get_counter_value(CUDAState *s, CUDATimer *ti) { - return muldiv64(time, freq, NANOSECONDS_PER_SECOND); + /* Reverse of the tb calculation algorithm that Mac OS X uses on bootu= p */ + uint64_t tb_diff =3D muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + s->tb_frequency, NANOSECONDS_PER_SECOND) - + ti->load_time; + + return (tb_diff * 0xBF401675E5DULL) / (s->tb_frequency << 24); +} + +static uint64_t get_counter_load_time(CUDAState *s, CUDATimer *ti) +{ + uint64_t load_time =3D muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + s->tb_frequency, NANOSECONDS_PER_SECOND); + return load_time; } =20 static unsigned int get_counter(CUDAState *s, CUDATimer *ti) { int64_t d; unsigned int counter; - uint64_t tb_diff; - uint64_t current_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); =20 - /* Reverse of the tb calculation algorithm that Mac OS X uses on bootu= p. */ - tb_diff =3D get_tb(current_time, s->tb_frequency) - ti->load_time; - d =3D (tb_diff * 0xBF401675E5DULL) / (s->tb_frequency << 24); + d =3D get_counter_value(s, ti); =20 if (ti->index =3D=3D 0) { /* the timer goes down from latch to -1 (period of latch + 2) */ @@ -178,8 +186,7 @@ static unsigned int get_counter(CUDAState *s, CUDATimer= *ti) static void set_counter(CUDAState *s, CUDATimer *ti, unsigned int val) { CUDA_DPRINTF("T%d.counter=3D%d\n", 1 + ti->index, val); - ti->load_time =3D get_tb(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), - s->tb_frequency); + ti->load_time =3D get_counter_load_time(s, ti); ti->counter_value =3D val; cuda_timer_update(s, ti, ti->load_time); } --=20 2.14.3