From patchwork Fri Jun 24 20:29:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9198123 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 551EE6075F for ; Fri, 24 Jun 2016 20:31:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E651262F2 for ; Fri, 24 Jun 2016 20:31:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3099B284D4; Fri, 24 Jun 2016 20:31:20 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 CEE9C262F2 for ; Fri, 24 Jun 2016 20:31:19 +0000 (UTC) Received: from localhost ([::1]:47231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGXl0-0002ux-Ih for patchwork-qemu-devel@patchwork.kernel.org; Fri, 24 Jun 2016 16:31:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGXkj-0002oR-4u for qemu-devel@nongnu.org; Fri, 24 Jun 2016 16:31:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGXkf-0001az-58 for qemu-devel@nongnu.org; Fri, 24 Jun 2016 16:31:01 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:34633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGXke-0001ar-T1; Fri, 24 Jun 2016 16:30:57 -0400 Received: by mail-lf0-x244.google.com with SMTP id l184so22878987lfl.1; Fri, 24 Jun 2016 13:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4NYSbLHeGnMunz+YmizcGvO8lNR2QG5vP+z3WGr7dAg=; b=tF4mhYj33PZp8jMwViE02VJyzjXVdCcJQlyoCsDu5/tzK0v3C1dsN4djczJ35P4P0z E1AHfK+3JH+fgMN9xo3TmEa8bxNfZFr8YJjeWgmyC6LXxKWxmf29xzFZ9kBeAbKaacEj tEpaNCM7o07rekfMBVSSiFuJBZIY072FwQP1QYYithV8LZE2KEZHHVZG8xGvc2xPQJov xG429aIJaaapN6veYZytxvCpL3oFUWEHIiH5wnJpEuI7o3ljkpS0qVkKe1995YFNmiU8 PTuoJUFmED36Ep8Y5QgTC0HFV42MSSsULZhCIb8emUrmXwzptK+7BXsrGjzy1o2fMWY7 ZPJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4NYSbLHeGnMunz+YmizcGvO8lNR2QG5vP+z3WGr7dAg=; b=OIMCNhOTxO+JKzo+Th5JbaSBWEseriHfUiH9pFZLWWi9fAnM536zaPhbaSBFNN21Mm 8cHmAuZKbKVIIuLBKh/PkO5Tl4CqGbRP+fGR4FwcfHtbe0qxxsnQD2kUfMqkBeUlgaxP vCWjNbPcselD0zAi6OxcjzYnoCyLFfSSnsAl5Ju7I5DxQwdwmZuobR2cqhbz4psw0qu1 w8igB7ucTdJbH6CA8uktr57enWAYipS+tHJsCv3UrmeiALSzBvPPwNZ3H8IBLZGA5v4V ubi+67PESfwvRVHFGZx9EQRYzXR9spZzzbT9uTyqteWQiMhYpRe3vmtTNeWZ19rjqKbG vDzw== X-Gm-Message-State: ALyK8tKPCPsCjv2OLYFbbeY6f/G/+WnYmbTtx3t7hZ19rv+tWTmUdYdDt0bY0FtkYvGeLg== X-Received: by 10.25.169.7 with SMTP id s7mr2092482lfe.57.1466800255981; Fri, 24 Jun 2016 13:30:55 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-52-30.pppoe.spdop.ru. [109.252.52.30]) by smtp.gmail.com with ESMTPSA id u13sm1119542lja.15.2016.06.24.13.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jun 2016 13:30:55 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Fri, 24 Jun 2016 23:29:34 +0300 Message-Id: <20160624202934.702-1-digetx@gmail.com> X-Mailer: git-send-email 2.9.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::244 Subject: [Qemu-devel] [PATCH] hw/ptimer: Don't wrap around counter for expired timer that uses tick handler 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: Peter Maydell , Peter Crosthwaite , Mark Cave-Ayland Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Software should see timer counter wrap around only after IRQ being triggered. Change returned counter value to "1" for the expired timer and avoid returning wrapped around counter value in periodic mode for the timer that has bottom-half handler setup, assuming it is IRQ handler. This fixes regression introduced by the commit 5a50307 ("hw/ptimer: Perform counter wrap around if timer already expired") on SPARC emulated machine as reported by Mark Cave-Ayland. Signed-off-by: Dmitry Osipenko --- hw/core/ptimer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 7f89001..620ac2e 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -98,10 +98,10 @@ uint64_t ptimer_get_count(ptimer_state *s) bool oneshot = (s->enabled == 2); /* Figure out the current counter value. */ - if (expired && (oneshot || use_icount)) { + if (expired && (oneshot || use_icount || s->bh != NULL)) { /* Prevent timer underflowing if it should already have triggered. */ - counter = 0; + counter = 1; } else { uint64_t rem; uint64_t div; @@ -148,7 +148,9 @@ uint64_t ptimer_get_count(ptimer_state *s) if (expired && counter != 0) { /* Wrap around periodic counter. */ - counter = s->limit - (counter - 1) % s->limit; + counter = s->delta = s->limit - (counter - 1) % s->limit; + /* Re-arm timer according to the wrapped around value. */ + ptimer_reload(s); } } } else {