From nobody Tue Feb 10 01:34:37 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 ARC-Seal: i=1; a=rsa-sha256; t=1560878638; cv=none; d=zoho.com; s=zohoarc; b=KXRTeUmeBX1EL3j5ZdkfWQJBzzWP0aer61xhY0Jy8pn1RdI6hx1xVieMlyNI9hirtngdptz8fszGjRKNMDQeZvm5Q64OqqppZDbWTWcwAi98itD1QimMuURFZYWchwQprfUmAQd+1nGK/qNgM6XrOvmcz77NGxVZAjO++YXhWjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560878638; 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:ARC-Authentication-Results; bh=rHk2E6kKQQvqXbcQJVQ9EBQRqq5hNvCfkwpVgddGxdY=; b=FoYaZdJ1IV8g37yCJFl2r+OLnJo881TWDwoucuIxqwK29FKYV6piVkacsBe2d/IYJldZLE0VODrFFFiEj87Ih1wTldK/13FCUvqNona8kY3QYJTqxnuuaW1z2EdB3qrIj30HBoJ2Y/ttOTwDkC4jArSuKqh7x6443aS+OMSDdFs= ARC-Authentication-Results: i=1; mx.zoho.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 1560878638119944.9698649216008; Tue, 18 Jun 2019 10:23:58 -0700 (PDT) Received: from localhost ([::1]:60462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdHpt-0006Fu-6D for importer@patchew.org; Tue, 18 Jun 2019 13:23:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60655) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdHNO-0000OQ-Ln for qemu-devel@nongnu.org; Tue, 18 Jun 2019 12:54:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdHNN-0004d0-LY for qemu-devel@nongnu.org; Tue, 18 Jun 2019 12:54:30 -0400 Received: from 11.mo7.mail-out.ovh.net ([87.98.173.157]:42783) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdHNN-0004b4-8o for qemu-devel@nongnu.org; Tue, 18 Jun 2019 12:54:29 -0400 Received: from player157.ha.ovh.net (unknown [10.108.42.228]) by mo7.mail-out.ovh.net (Postfix) with ESMTP id 0432C1224B5 for ; Tue, 18 Jun 2019 18:54:26 +0200 (CEST) Received: from kaod.org (lfbn-1-10649-41.w90-89.abo.wanadoo.fr [90.89.235.41]) (Authenticated sender: clg@kaod.org) by player157.ha.ovh.net (Postfix) with ESMTPSA id 6E7426EB5314; Tue, 18 Jun 2019 16:54:20 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Peter Maydell Date: Tue, 18 Jun 2019 18:52:59 +0200 Message-Id: <20190618165311.27066-10-clg@kaod.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190618165311.27066-1-clg@kaod.org> References: <20190618165311.27066-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 1675902012338768657 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduvddrtddtgdejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 87.98.173.157 Subject: [Qemu-devel] [PATCH v2 09/21] aspeed/timer: Fix match calculations 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: Andrew Jeffery , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Joel Stanley 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 8d6266b0fd81..745eb8608b56 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.21.0