From nobody Sat Apr 20 13:32:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575346528; cv=none; d=zohomail.com; s=zohoarc; b=lt73ZkpZ68suSHXj5cTSnie9kjIqG22Ui31+M5PiODXq+kvEl01NpvyeUROGsYWQjmAncSim4MfypCUyTZPgUK4We3xeppvHuWjaS7pZz/FT7N4S6j+j4EH7aHBlD95CM5CJUich+RRUVB0rzPRraD5zZ/rugmo0pwCOJCk9VeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575346528; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xQZFQojovBLO7NXxKyIwYjcITEQBg1WTDSYEUPbUvsQ=; b=cSkkBb88PKnagaWfthXfussb8puLexPtWaRArtQ4wk3BNdCRLs2ESQEUeNIoagY5MnDWVfOq26ma3tSDQHAQ72NWXcWGZBsb4FTziL4KC+ZJhCtVEcyK0NrbeHVfS7ca9pepBEUjucJv7eqEb9rwxwdnMI55iwF3VzswVzQQIBo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157534652846798.96868801988091; Mon, 2 Dec 2019 20:15:28 -0800 (PST) Received: from localhost ([::1]:48210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzax-0007OT-Bd for importer@patchew.org; Mon, 02 Dec 2019 23:15:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33527) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzYz-0005dP-9s for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibzYy-0001Ai-7P for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:25 -0500 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:34713) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibzYv-00015I-2A; Mon, 02 Dec 2019 23:13:21 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id CE5C2EC1; Mon, 2 Dec 2019 23:13:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 02 Dec 2019 23:13:20 -0500 Received: from mistburn.au.ibm.com (bh02i525f01.au.ibm.com [202.81.18.30]) by mail.messagingengine.com (Postfix) with ESMTPA id D29B48005C; Mon, 2 Dec 2019 23:13:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=fm1; bh= xQZFQojovBLO7NXxKyIwYjcITEQBg1WTDSYEUPbUvsQ=; b=psiTW247RLk6Bn+b OHJ5bOJIY8TB3QfJNrWZKWoaqlJH8mcSWBn/vWjFZ/ZgPw8cjt3K8dLeJaJB7NRf zyNfEkpZP20Q2oU8zIUkJdy2Fc0mBxaeQAd5U9D5rDPKglmsKR+9PKA2zBPtArZY y1o6S0+Yt2Ff2YjEmnmKrYi2pvu7XzlFAgxHad9lHJilgDkNm1MnfuGXqhzo+JwN E/z290Nvo9At28xjYL3qS25dv1+booOAgTR+vR49KdyDpr3QNb4+DpsOAc0yivaa mpUkN+4yselQnRNTIztQeGzE57EN9P8N3e0wKQZ8dMXV6of2Eh0MhEVZ1H2IuDj1 jb9aHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=xQZFQojovBLO7NXxKyIwYjcITEQBg1WTDSYEUPbUv sQ=; b=DltCjfY/2s8M8DMpmvBsds5dpYyaozh1+KoFQaO1Momh73PY3egzFmyeo YWU1Stu/9b8ZR+9KTZmMtzlNmQrm2ZiYQIhzEMO5sXgtup1XeOx1nD5CCngIlnnB QQAX7udwxoL+2v2Iu7Gru2sdwma07/PmNhxOTVbrQw1IpISaEPGSn85Z9yDXImBV kYo0fcrLvKsQuG0l+DLR7Rd5rLqR37w7ulUxPorU5q/vCAAEwx9a1fOSJjR+sfzo 3tjTSjnsoUzXNfNtEbyNUU2j5x3X2YQvoVW2GAQcpRwoVjHUCiRW5gVEQg2tWnjT iMt/i5nHYr8zeL8zSKPO3idwjo5OQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejiedgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheptehnughr vgifucflvghffhgvrhihuceorghnughrvgifsegrjhdrihgurdgruheqnecukfhppedvtd dvrdekuddrudekrdeftdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvgifsegr jhdrihgurdgruhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: From: Andrew Jeffery To: qemu-arm@nongnu.org Subject: [PATCH v2 1/4] target/arm: Remove redundant scaling of nexttick Date: Tue, 3 Dec 2019 14:44:37 +1030 Message-Id: <20191203041440.6275-2-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203041440.6275-1-andrew@aj.id.au> References: <20191203041440.6275-1-andrew@aj.id.au> 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] [fuzzy] X-Received-From: 64.147.123.24 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, Richard Henderson , clg@kaod.org, joel@jms.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" The corner-case codepath was adjusting nexttick such that overflow wouldn't occur when timer_mod() scaled the value back up. Remove a use of GTIMER_SCALE and avoid unnecessary operations by calling timer_mod_ns() directly. Signed-off-by: Andrew Jeffery Reviewed-by: Richard Henderson Reviewed-by: C=C3=A9dric Le Goater --- target/arm/helper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index a089fb5a6909..65c4441a3896 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2446,9 +2446,10 @@ static void gt_recalc_timer(ARMCPU *cpu, int timerid= x) * timer expires we will reset the timer for any remaining period. */ if (nexttick > INT64_MAX / GTIMER_SCALE) { - nexttick =3D INT64_MAX / GTIMER_SCALE; + timer_mod_ns(cpu->gt_timer[timeridx], INT64_MAX); + } else { + timer_mod(cpu->gt_timer[timeridx], nexttick); } - timer_mod(cpu->gt_timer[timeridx], nexttick); trace_arm_gt_recalc(timeridx, irqstate, nexttick); } else { /* Timer disabled: ISTATUS and timer output always clear */ --=20 2.20.1 From nobody Sat Apr 20 13:32:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575346712; cv=none; d=zohomail.com; s=zohoarc; b=F/0JCX9QYP4JtwtHoP2EISxxFmrdVP4w22nSA4y0xKZXz6FzOHUF0JxqjJA6Qh+oGnpCBd+HdZVw/cK4v4aWBfpeNhi5QVcaViFcPL9QF8lU2VtuQliz+f5mAR3gnQAMfQnp714IBaVnYobEdXaiH/Qg2th2JHe7YZrnjrLx3WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575346712; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rb9NcXkJ9zfKj9uToigm9zdKRmguNiX84tLrvX+4KtM=; b=LzOvLalVydv9QWi9ZkIrLReX+4kichKjFgEtS1S62TpfSICNoABqGbcwvZ1V/SU1Fa0cPLdGixgrR5n00IypfyQmcbrJkeay6k782XAj0H+unOc8Oe95zv7VGFztIVAt6HLNZYvKZk28GdTkl3kfskRZuq9II5HQrgEKsJlok3E= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575346712144886.9117344174887; Mon, 2 Dec 2019 20:18:32 -0800 (PST) Received: from localhost ([::1]:48272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzdu-0002c0-WA for importer@patchew.org; Mon, 02 Dec 2019 23:18:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34018) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzZ3-0005hW-GU for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibzZ1-0001FJ-0o for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:29 -0500 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:56831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibzYy-00019R-9q; Mon, 02 Dec 2019 23:13:24 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id F2E39C28; Mon, 2 Dec 2019 23:13:22 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 02 Dec 2019 23:13:23 -0500 Received: from mistburn.au.ibm.com (bh02i525f01.au.ibm.com [202.81.18.30]) by mail.messagingengine.com (Postfix) with ESMTPA id E375C80060; Mon, 2 Dec 2019 23:13:19 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=rb9NcXkJ9zfKj 9uToigm9zdKRmguNiX84tLrvX+4KtM=; b=rxWOCAb4QrTYOHw+AOy9CHaP5yQDu ds+pxsIFfO9BFgBI7FoLLK0qXoKMCesOvXF1pj3ogu+akepRTdud9P5IyiDf6E9I HYoKDLKa7qRu9+aNbSBmCBnxV82dR7xbjwjrMz4zUlOtqT6jdqM2BiKRvrGhBKs0 2AlmCWFeiZIbsHqfjDDrq4HDm7AaIyl8KX2m9mu195yT6/CdI/MO0M3j2u1FYkVY blZ9DmDe7az8dkBE5TNDLMGY+Yr2au8jFekLESI4N+3uBlOPl8wJF2IkT28TA7J3 bQn+/y3rcladJtUYeXMGy+BstGRWwxLFVFa4Q9lCkwcya3sGsTm5eYB+A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=rb9NcXkJ9zfKj9uToigm9zdKRmguNiX84tLrvX+4KtM=; b=WkWYouxI 5CUu77WyTFyO2M6zDePAr/jScj+GR/8I3O1OKS/wMkCJcoao/7xt+pkb5ceAQRw0 Cs74PJMWZ8/x4LXr5vZh5UGHxKxSTKsOJC/LrjYC+f+OAIJgvDTN4kbJSyBQysnD u81Cv8VAA+18JaHK085JNmtcLYPRk9755gp2tjWOc3FweK5GROnQXSfNVD3K0pP6 BYw8nLFQnIuDGG+tvH/6tVVh9ZmQ+n06c4UcvATaD9gCfGZ2irydJv9OELuxfsO/ KrDa+9GKXmi+FoalFwcjtIwHahZ6a/vbgJR90NOdcKFXPxrs2tdFm2aCCagTNpED L3Akb93Vzv5wKA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejiedgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetnhgurhgv ficulfgvfhhfvghrhicuoegrnhgurhgvfiesrghjrdhiugdrrghuqeenucfkphepvddtvd drkedurddukedrfedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvfiesrghj rdhiugdrrghunecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: From: Andrew Jeffery To: qemu-arm@nongnu.org Subject: [PATCH v2 2/4] target/arm: Abstract the generic timer frequency Date: Tue, 3 Dec 2019 14:44:38 +1030 Message-Id: <20191203041440.6275-3-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203041440.6275-1-andrew@aj.id.au> References: <20191203041440.6275-1-andrew@aj.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: 64.147.123.24 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, Richard Henderson , clg@kaod.org, joel@jms.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Prepare for SoCs such as the ASPEED AST2600 whose firmware configures CNTFRQ to values significantly larger than the static 62.5MHz value currently derived from GTIMER_SCALE. As the OS potentially derives its timer periods from the CNTFRQ value the lack of support for running QEMUTimers at the appropriate rate leads to sticky behaviour in the guest. Substitute the GTIMER_SCALE constant with use of a helper to derive the period from gt_cntfrq stored in struct ARMCPU. Initially set gt_cntfrq to the frequency associated with GTIMER_SCALE so current behaviour is maintained. Signed-off-by: Andrew Jeffery Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/cpu.c | 2 ++ target/arm/cpu.h | 10 ++++++++++ target/arm/helper.c | 10 +++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 7a4ac9339bf9..5698a74061bb 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -974,6 +974,8 @@ static void arm_cpu_initfn(Object *obj) if (tcg_enabled()) { cpu->psci_version =3D 2; /* TCG implements PSCI 0.2 */ } + + cpu->gt_cntfrq =3D NANOSECONDS_PER_SECOND / GTIMER_SCALE; } =20 static Property arm_cpu_reset_cbar_property =3D diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 83a809d4bac4..666c03871fdf 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -932,8 +932,18 @@ struct ARMCPU { */ DECLARE_BITMAP(sve_vq_map, ARM_MAX_VQ); DECLARE_BITMAP(sve_vq_init, ARM_MAX_VQ); + + /* Generic timer counter frequency, in Hz */ + uint64_t gt_cntfrq; }; =20 +static inline unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) +{ + /* XXX: Could include qemu/timer.h to get NANOSECONDS_PER_SECOND? */ + const unsigned int ns_per_s =3D 1000 * 1000 * 1000; + return ns_per_s > cpu->gt_cntfrq ? ns_per_s / cpu->gt_cntfrq : 1; +} + void arm_cpu_post_init(Object *obj); =20 uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz); diff --git a/target/arm/helper.c b/target/arm/helper.c index 65c4441a3896..2622a9a8d02f 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2409,7 +2409,9 @@ static CPAccessResult gt_stimer_access(CPUARMState *e= nv, =20 static uint64_t gt_get_countervalue(CPUARMState *env) { - return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / GTIMER_SCALE; + ARMCPU *cpu =3D env_archcpu(env); + + return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / gt_cntfrq_period_ns(cpu= ); } =20 static void gt_recalc_timer(ARMCPU *cpu, int timeridx) @@ -2445,7 +2447,7 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) * set the timer for as far in the future as possible. When the * timer expires we will reset the timer for any remaining period. */ - if (nexttick > INT64_MAX / GTIMER_SCALE) { + if (nexttick > INT64_MAX / gt_cntfrq_period_ns(cpu)) { timer_mod_ns(cpu->gt_timer[timeridx], INT64_MAX); } else { timer_mod(cpu->gt_timer[timeridx], nexttick); @@ -2874,11 +2876,13 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[= ] =3D { =20 static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) { + ARMCPU *cpu =3D env_archcpu(env); + /* Currently we have no support for QEMUTimer in linux-user so we * can't call gt_get_countervalue(env), instead we directly * call the lower level functions. */ - return cpu_get_clock() / GTIMER_SCALE; + return cpu_get_clock() / gt_cntfrq_period_ns(cpu); } =20 static const ARMCPRegInfo generic_timer_cp_reginfo[] =3D { --=20 2.20.1 From nobody Sat Apr 20 13:32:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575346698; cv=none; d=zohomail.com; s=zohoarc; b=b0XM75I9Qzgl2d5WhNy/KgSKbB0E6iW1Lte7KetFOZ31rs98r3NR55TUll/jV4tcy1Y9vrkPIB4zH/4/FPBsY684pc5cOIfUH85CReAdxo8KNErfGrSCsTMxgBmk5V1OvUk60hBV0sJzCt6JDHd/C+oeWOo6TrJ1HSWw6Kfdx9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575346698; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UnMHwPPfQ4KRN61OUf/u4EXG5kQhV6gU2lUxKArzxDo=; b=GcUzhfZwF6wRLYMW9r7MySWLMUqCOYisJW3BgaLjewpPEm72bW3fpk3jVQ6eD58zdx1umIAn6h2Zfj5crbCbeeCl5st2fhDZJ8i4cUkKRAyOgiwgdoPJTsSuVqDZGBLqmf8RjSjboV/VFT/++/RoKJvmb2CherW1+KCAOUw7i2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575346698142544.9008492966069; Mon, 2 Dec 2019 20:18:18 -0800 (PST) Received: from localhost ([::1]:48268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzdg-0002HD-Kf for importer@patchew.org; Mon, 02 Dec 2019 23:18:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34571) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzZ9-0005ma-IJ for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibzZ6-0001KK-2c for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:35 -0500 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:56489) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibzZ1-0001El-7c; Mon, 02 Dec 2019 23:13:27 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 08B10ED2; Mon, 2 Dec 2019 23:13:25 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 02 Dec 2019 23:13:26 -0500 Received: from mistburn.au.ibm.com (bh02i525f01.au.ibm.com [202.81.18.30]) by mail.messagingengine.com (Postfix) with ESMTPA id EE4028005A; Mon, 2 Dec 2019 23:13:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=UnMHwPPfQ4KRN 61OUf/u4EXG5kQhV6gU2lUxKArzxDo=; b=jv6kpy63xqnWAhau27nV+ZCposTPf kiQ61fjwkzCXyx/Nk8bWtxMAnkHfKVViOVY6PuS4AA0EoEMDAdlaNL4FsmyLGDtJ rt/WrlC9YEZy+fSFRIOMgQOImGseiVyLrxYGTc3JUtFUzf1vNQTYHVHK9sltf/i8 6nxyFr72oG1+huUPdAydtc5eV/JL5uvxTze4u3sRc13hrUlTAYXewTBO+SiZmRLY txueFKm1YRVYmq44VXzQnLBq3qeSAAQ/c8ELJNsLyLLmKOqgWtbzNfuVvZ0Pxzsk a/EA/R3XwU+weeGsAnc9R7JDTQyZ9GiuV7VNtwQUybiR8qVBQeTE6mJTg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=UnMHwPPfQ4KRN61OUf/u4EXG5kQhV6gU2lUxKArzxDo=; b=uT9tE2oL Y9GYFM8myJifEkSq33gIoLUwOb63A9AWdaSmY1Qmn8x/WnFmmIv8d2cOsTRTb3DR vxqo3/C/xn4ssizCYw1XEJDyprvPyirB7GT2NcgRk7wOIvSwNI83cwTRH/Nxe7or BYo3kIMWkXQPrk+fmrUIBm4nsy4zWRCwnBJ+L1X+WaWQXCtDWpLFywlYDwXPQzBv X1NYDo/mjfaQcKzapjqDZLWYfiY1LPY4MWO275HE2o09CKkHC55M9oGxdPBbxMGH oHxRkK4sbptx0G5IrmZVJJVK1IFmoIfU3R5uZDSdq1iOelYt/coWxTVov1vzyMd3 ta+nnviQ9FhXFg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejiedgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetnhgurhgv ficulfgvfhhfvghrhicuoegrnhgurhgvfiesrghjrdhiugdrrghuqeenucfkphepvddtvd drkedurddukedrfedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvfiesrghj rdhiugdrrghunecuvehluhhsthgvrhfuihiivgepud X-ME-Proxy: From: Andrew Jeffery To: qemu-arm@nongnu.org Subject: [PATCH v2 3/4] target/arm: Prepare generic timer for per-platform CNTFRQ Date: Tue, 3 Dec 2019 14:44:39 +1030 Message-Id: <20191203041440.6275-4-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203041440.6275-1-andrew@aj.id.au> References: <20191203041440.6275-1-andrew@aj.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: 64.147.123.24 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, Richard Henderson , clg@kaod.org, joel@jms.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The ASPEED AST2600 clocks the generic timer at the rate of HPLL. On recent firmwares this is at 1125MHz, which is considerably quicker than the assumed 62.5MHz of the current generic timer implementation. The delta between the value as read from CNTFRQ and the true rate of the underlying QEMUTimer leads to sticky behaviour in AST2600 guests. Add a feature-gated property exposing CNTFRQ for ARM CPUs providing the generic timer. This allows platforms to configure CNTFRQ (and the associated QEMUTimer) to the appropriate frequency prior to starting the guest. As the platform can now determine the rate of CNTFRQ we're exposed to limitations of QEMUTimer that didn't previously materialise: In the course of emulation we need to arbitrarily and accurately convert between guest ticks and time, but we're constrained by QEMUTimer's use of an integer scaling factor. The effect is QEMUTimer cannot exactly capture the period of frequencies that do not cleanly divide NANOSECONDS_PER_SECOND for scaling ticks to time. As such, provide an equally inaccurate scaling factor for scaling time to ticks so at least a self-consistent inverse relationship holds. Signed-off-by: Andrew Jeffery Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/cpu.c | 43 +++++++++++++++++++++++++++++++++---------- target/arm/cpu.h | 18 ++++++++++++++++++ target/arm/helper.c | 9 ++++++++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 5698a74061bb..f186019a77fd 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -974,10 +974,12 @@ static void arm_cpu_initfn(Object *obj) if (tcg_enabled()) { cpu->psci_version =3D 2; /* TCG implements PSCI 0.2 */ } - - cpu->gt_cntfrq =3D NANOSECONDS_PER_SECOND / GTIMER_SCALE; } =20 +static Property arm_cpu_gt_cntfrq_property =3D + DEFINE_PROP_UINT64("cntfrq", ARMCPU, gt_cntfrq, + NANOSECONDS_PER_SECOND / GTIMER_SCALE); + static Property arm_cpu_reset_cbar_property =3D DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0); =20 @@ -1174,6 +1176,11 @@ void arm_cpu_post_init(Object *obj) =20 qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property, &error_abort); + + if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) { + qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property, + &error_abort); + } } =20 static void arm_cpu_finalizefn(Object *obj) @@ -1253,14 +1260,30 @@ static void arm_cpu_realizefn(DeviceState *dev, Err= or **errp) } } =20 - cpu->gt_timer[GTIMER_PHYS] =3D timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SC= ALE, - arm_gt_ptimer_cb, cpu); - cpu->gt_timer[GTIMER_VIRT] =3D timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SC= ALE, - arm_gt_vtimer_cb, cpu); - cpu->gt_timer[GTIMER_HYP] =3D timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCA= LE, - arm_gt_htimer_cb, cpu); - cpu->gt_timer[GTIMER_SEC] =3D timer_new(QEMU_CLOCK_VIRTUAL, GTIMER_SCA= LE, - arm_gt_stimer_cb, cpu); + + { + uint64_t scale; + + if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) { + if (!cpu->gt_cntfrq) { + error_setg(errp, "Invalid CNTFRQ: %"PRId64"Hz", + cpu->gt_cntfrq); + return; + } + scale =3D gt_cntfrq_period_ns(cpu); + } else { + scale =3D GTIMER_SCALE; + } + + cpu->gt_timer[GTIMER_PHYS] =3D timer_new(QEMU_CLOCK_VIRTUAL, scale, + arm_gt_ptimer_cb, cpu); + cpu->gt_timer[GTIMER_VIRT] =3D timer_new(QEMU_CLOCK_VIRTUAL, scale, + arm_gt_vtimer_cb, cpu); + cpu->gt_timer[GTIMER_HYP] =3D timer_new(QEMU_CLOCK_VIRTUAL, scale, + arm_gt_htimer_cb, cpu); + cpu->gt_timer[GTIMER_SEC] =3D timer_new(QEMU_CLOCK_VIRTUAL, scale, + arm_gt_stimer_cb, cpu); + } #endif =20 cpu_exec_realizefn(cs, &local_err); diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 666c03871fdf..0bcd13dcac81 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -939,6 +939,24 @@ struct ARMCPU { =20 static inline unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) { + /* + * The exact approach to calculating guest ticks is: + * + * muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), cpu->gt_cntfrq, + * NANOSECONDS_PER_SECOND); + * + * We don't do that. Rather we intentionally use integer division + * truncation below and in the caller for the conversion of host monot= onic + * time to guest ticks to provide the exact inverse for the semantics = of + * the QEMUTimer scale factor. QEMUTimer's scale facter is an integer,= so + * it loses precision when representing frequencies where + * `(NANOSECONDS_PER_SECOND % cpu->gt_cntfrq) > 0` holds. Failing to + * provide an exact inverse leads to scheduling timers with negative + * periods, which in turn leads to sticky behaviour in the guest. + * + * Finally, CNTFRQ is effectively capped at 1GHz to ensure our scale f= actor + * cannot become zero. + */ /* XXX: Could include qemu/timer.h to get NANOSECONDS_PER_SECOND? */ const unsigned int ns_per_s =3D 1000 * 1000 * 1000; return ns_per_s > cpu->gt_cntfrq ? ns_per_s / cpu->gt_cntfrq : 1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 2622a9a8d02f..da960d17040b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2683,6 +2683,13 @@ void arm_gt_stimer_cb(void *opaque) gt_recalc_timer(cpu, GTIMER_SEC); } =20 +static void arm_gt_cntfrq_reset(CPUARMState *env, const ARMCPRegInfo *opaq= ue) +{ + ARMCPU *cpu =3D env_archcpu(env); + + cpu->env.cp15.c14_cntfrq =3D cpu->gt_cntfrq; +} + static const ARMCPRegInfo generic_timer_cp_reginfo[] =3D { /* Note that CNTFRQ is purely reads-as-written for the benefit * of software; writing it doesn't actually change the timer frequency. @@ -2697,7 +2704,7 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = =3D { .opc0 =3D 3, .opc1 =3D 3, .crn =3D 14, .crm =3D 0, .opc2 =3D 0, .access =3D PL1_RW | PL0_R, .accessfn =3D gt_cntfrq_access, .fieldoffset =3D offsetof(CPUARMState, cp15.c14_cntfrq), - .resetvalue =3D (1000 * 1000 * 1000) / GTIMER_SCALE, + .resetfn =3D arm_gt_cntfrq_reset, }, /* overall control: mostly access permissions */ { .name =3D "CNTKCTL", .state =3D ARM_CP_STATE_BOTH, --=20 2.20.1 From nobody Sat Apr 20 13:32:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1575346538; cv=none; d=zohomail.com; s=zohoarc; b=YGHrfTmoYyRojJT28a/M2V+t7a1NiLSx9lEM6QTW8CjqmYjhvZqGkIn6S1a/kmHyLknndOq0Tm01AvZo2SH1FLzCa0BPe65WGAaZ8unW0TOya3orAVBm1+W+OrQY/sw5pyccciqjS1z/TH724IsiHuCJm7EJFU/RYa7op3igw4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575346538; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8MgJM3J3IhBnKwFW2SJqSeqOlRczVQkkEIqpATcIvsU=; b=L/kGxVKklglwXBXziI3C0L+Cq/L+Fu5dlYE1LVDektzL8f7sw6EObO7hNjiTSy7sOppfBPD4wlPzHMmLktcKM/vqwzyHG33lahsZH6gq+jyu8aLS2xHwVjt7rzQe4D5mpAvSyYO/MnHvN+bawOGFodxieP9Mb52mwbd1nBHPF+c= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575346538380375.7698820202187; Mon, 2 Dec 2019 20:15:38 -0800 (PST) Received: from localhost ([::1]:48220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzb7-0007ge-4g for importer@patchew.org; Mon, 02 Dec 2019 23:15:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34937) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibzZE-0005qT-UU for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibzZC-0001QM-5M for qemu-devel@nongnu.org; Mon, 02 Dec 2019 23:13:40 -0500 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:43443) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ibzZ5-0001Hr-T9; Mon, 02 Dec 2019 23:13:32 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 1032FC28; Mon, 2 Dec 2019 23:13:29 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 02 Dec 2019 23:13:29 -0500 Received: from mistburn.au.ibm.com (bh02i525f01.au.ibm.com [202.81.18.30]) by mail.messagingengine.com (Postfix) with ESMTPA id 03FB880060; Mon, 2 Dec 2019 23:13:25 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=fm1; bh= 8MgJM3J3IhBnKwFW2SJqSeqOlRczVQkkEIqpATcIvsU=; b=R3M6lwnrDWJz4HEf xRcLyRZFSLtXks4a8rzJLzRGVlwlDWKziNcdMlodCGJarTDja8PE2Jo+zLSdT340 CybYogFCKMxhS0rU2Qz4oRb3AT7DBH2hfI9ITKJDwHAI46wNsq5J9yCpCoNh4d2y jzhoB7u3iIyHTXfNpzQVuWdjm8snGGvl1670zpxgots1GwzJVaI0XqiVFc5fzb8B kveXTIREuuAo39e4SKQmVF7BzWUKAOH5isxvMxVzmlMVe5IUF26QjZySKlCVKNi0 DqqZMSfXAYz/2ievqBSlBfdfnmZyKjjobZsz3qqYWKjps8Ak4JJeoON5XA3yOmLl e3okGQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=8MgJM3J3IhBnKwFW2SJqSeqOlRczVQkkEIqpATcIv sU=; b=cyNocwe7zRRg7qZyoqiApGhSHGuY20krC3YrzXePhcacMw4HwHcWon66Y dzF6kUXex/fg0qJNEmkzJaJaCaYTRe2dlgyykFH0uODVkwUV5q3N7w/9orfwNQYj tkwJarq4US3RmO99lsgB8coClH4jn2Y+mI/rB2+5svPllMz1pD0a42nkv0lGAAwr CeFZZS9HEw+ruTLUQpywWXETsqe+v3OtP9YMBjJz+8FdGgBm2hExYQfkj6VIJHnX hFBgObAZABLxXFKDXlUq5Klbg6pLHz6VsIGKaTy3wcJyW3nA6A3ot2BaNuWXtC0a sGyPMrTXWkXbge+dbgcLo47U/P9yw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejiedgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheptehnughr vgifucflvghffhgvrhihuceorghnughrvgifsegrjhdrihgurdgruheqnecukfhppedvtd dvrdekuddrudekrdeftdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvgifsegr jhdrihgurdgruhenucevlhhushhtvghrufhiiigvpedu X-ME-Proxy: From: Andrew Jeffery To: qemu-arm@nongnu.org Subject: [PATCH v2 4/4] ast2600: Configure CNTFRQ at 1125MHz Date: Tue, 3 Dec 2019 14:44:40 +1030 Message-Id: <20191203041440.6275-5-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203041440.6275-1-andrew@aj.id.au> References: <20191203041440.6275-1-andrew@aj.id.au> 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] [fuzzy] X-Received-From: 64.147.123.24 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, Richard Henderson , clg@kaod.org, joel@jms.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This matches the configuration set by u-boot on the AST2600. Signed-off-by: Andrew Jeffery Reviewed-by: Richard Henderson Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/aspeed_ast2600.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c index 931887ac681f..5aecc3b3caec 100644 --- a/hw/arm/aspeed_ast2600.c +++ b/hw/arm/aspeed_ast2600.c @@ -259,6 +259,9 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev= , Error **errp) object_property_set_int(OBJECT(&s->cpu[i]), aspeed_calc_affinity(i= ), "mp-affinity", &error_abort); =20 + object_property_set_int(OBJECT(&s->cpu[i]), 1125000000, "cntfrq", + &error_abort); + /* * TODO: the secondary CPUs are started and a boot helper * is needed when using -kernel --=20 2.20.1