From patchwork Thu Jul 14 16:29:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9230247 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9571860572 for ; Thu, 14 Jul 2016 16:38:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 872A927FB6 for ; Thu, 14 Jul 2016 16:38:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C3C528249; Thu, 14 Jul 2016 16:38:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 333A827FB6 for ; Thu, 14 Jul 2016 16:38:21 +0000 (UTC) Received: from localhost ([::1]:55569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNjeW-0007in-E2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Jul 2016 12:38:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNjWO-0006jG-Nf for qemu-devel@nongnu.org; Thu, 14 Jul 2016 12:29:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNjWM-0002Dr-L8 for qemu-devel@nongnu.org; Thu, 14 Jul 2016 12:29:55 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58290) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNjWM-0002A6-De for qemu-devel@nongnu.org; Thu, 14 Jul 2016 12:29:54 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bNjWD-0000Jm-4c for qemu-devel@nongnu.org; Thu, 14 Jul 2016 17:29:45 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 14 Jul 2016 17:29:34 +0100 Message-Id: <1468513783-25449-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468513783-25449-1-git-send-email-peter.maydell@linaro.org> References: <1468513783-25449-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 02/11] Revert "hw/ptimer: Perform counter wrap around if timer already expired" 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Osipenko Software should see timer counter wraparound only after IRQ being triggered. This fixes regression introduced by the commit 5a50307 ("hw/ptimer: Perform counter wrap around if timer already expired"), resulting in monotonic timer jumping backwards on SPARC emulated machine running NetBSD guest OS, as reported by Mark Cave-Ayland. Signed-off-by: Dmitry Osipenko Message-id: 20160708132206.2080-1-digetx@gmail.com Signed-off-by: Peter Maydell --- hw/core/ptimer.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 05b0c27..30829ee 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -93,7 +93,7 @@ uint64_t ptimer_get_count(ptimer_state *s) bool oneshot = (s->enabled == 2); /* Figure out the current counter value. */ - if (s->period == 0 || (expired && (oneshot || use_icount))) { + if (expired) { /* Prevent timer underflowing if it should already have triggered. */ counter = 0; @@ -120,7 +120,7 @@ uint64_t ptimer_get_count(ptimer_state *s) backwards. */ - rem = expired ? now - next : next - now; + rem = next - now; div = period; clz1 = clz64(rem); @@ -140,11 +140,6 @@ uint64_t ptimer_get_count(ptimer_state *s) div += 1; } counter = rem / div; - - if (expired && counter != 0) { - /* Wrap around periodic counter. */ - counter = s->limit - (counter - 1) % s->limit; - } } } else { counter = s->delta;