From nobody Mon Feb 9 20:32:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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 1552553255546896.6537851323154; Thu, 14 Mar 2019 01:47:35 -0700 (PDT) Received: from localhost ([127.0.0.1]:59172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4M1W-0002hE-D5 for importer@patchew.org; Thu, 14 Mar 2019 04:47:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4LxV-0008SH-Ml for qemu-devel@nongnu.org; Thu, 14 Mar 2019 04:43:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4LxU-0002mP-LQ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 04:43:25 -0400 Received: from 8.mo69.mail-out.ovh.net ([46.105.56.233]:57817) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h4LxU-0002i4-80 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 04:43:24 -0400 Received: from player762.ha.ovh.net (unknown [10.109.159.20]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id C9DB744154 for ; Thu, 14 Mar 2019 09:43:19 +0100 (CET) Received: from kaod.org (lfbn-1-2226-17.w90-76.abo.wanadoo.fr [90.76.48.17]) (Authenticated sender: clg@kaod.org) by player762.ha.ovh.net (Postfix) with ESMTPSA id DFA0B3AA2E84; Thu, 14 Mar 2019 08:43:11 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Thu, 14 Mar 2019 09:42:33 +0100 Message-Id: <20190314084235.9887-4-clg@kaod.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190314084235.9887-1-clg@kaod.org> References: <20190314084235.9887-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 1452129406510271249 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedutddrhedugdduvdefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.56.233 Subject: [Qemu-devel] [PATCH 3/5] aspeed/timer: Fix match calculations 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: Andrew Jeffery , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-arm@nongnu.org, Joel Stanley , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Andrew Jeffery If the match value exceeds reload then we don't want to include it in calculations for the next event. Signed-off-by: Andrew Jeffery Signed-off-by: C=C3=A9dric Le Goater --- hw/timer/aspeed_timer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c index 2f8522a597d3..6c184572ea04 100644 --- a/hw/timer/aspeed_timer.c +++ b/hw/timer/aspeed_timer.c @@ -107,6 +107,11 @@ static inline uint64_t calculate_time(struct AspeedTim= er *t, uint32_t ticks) return t->start + delta_ns; } =20 +static inline uint32_t calculate_match(struct AspeedTimer *t, int i) +{ + return t->match[i] < t->reload ? t->match[i] : 0; +} + static uint64_t calculate_next(struct AspeedTimer *t) { uint64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); @@ -118,12 +123,12 @@ static uint64_t calculate_next(struct AspeedTimer *t) * the timer counts down to zero. */ =20 - next =3D calculate_time(t, MAX(t->match[0], t->match[1])); + next =3D calculate_time(t, MAX(calculate_match(t, 0), calculate_match(= t, 1))); if (now < next) { return next; } =20 - next =3D calculate_time(t, MIN(t->match[0], t->match[1])); + next =3D calculate_time(t, MIN(calculate_match(t, 0), calculate_match(= t, 1))); if (now < next) { return next; } @@ -141,8 +146,10 @@ static uint64_t calculate_next(struct AspeedTimer *t) qemu_set_irq(t->irq, t->level); } =20 + next =3D MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0); t->start =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0)); + + return calculate_time(t, next); } =20 static void aspeed_timer_mod(AspeedTimer *t) --=20 2.20.1