From patchwork Fri Jun 17 13:17:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9184045 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 5C1C16075F for ; Fri, 17 Jun 2016 14:00:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58DD328388 for ; Fri, 17 Jun 2016 14:00:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DBAE283A4; Fri, 17 Jun 2016 14:00:36 +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 AA57828388 for ; Fri, 17 Jun 2016 14:00:34 +0000 (UTC) Received: from localhost ([::1]:57740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDuK0-0005Dg-Fw for patchwork-qemu-devel@patchwork.kernel.org; Fri, 17 Jun 2016 10:00:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDtev-0003AV-MS for qemu-devel@nongnu.org; Fri, 17 Jun 2016 09:18:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDtel-0002qP-IS for qemu-devel@nongnu.org; Fri, 17 Jun 2016 09:18:04 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:36773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDtel-0002pz-BH; Fri, 17 Jun 2016 09:17:55 -0400 Received: by mail-lf0-x244.google.com with SMTP id a2so8322194lfe.3; Fri, 17 Jun 2016 06:17:55 -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:in-reply-to:references :in-reply-to:references; bh=q6+fh2TRcfaG7Ai2kTlT0N4WEeLJzic8KL3fN4FpFuI=; b=maINaua7IquOu4fDPWXrNMVneabE+JpLZbMgPaQCLWi27knT9QwRkgu3rbagafGyl+ WRlIIAX+x7MnZPzkmRPBeP/Ny5ydum6QshiYdUuAj0RQ9EF1/WAZmzmGMpgNL1EvREtL LnH7gMVtwAzxWKzmGkZLdvkRTB7tMPeAsKmcaRZlK/BjLPTVVrEWpE08vpo68m7rtD4l uYgXF6pGbVXr/1kXa7zu9XaqdE/owmgK2F19isLXYydPvOBxOcWINUNNykAVXle/koey RPdxUj0dRizC5xYGVP/ie5ipf7FkZAM6BzENv4LKSUYrwLCsPRioumDwjXePvo3YX1xy vK/Q== 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:in-reply-to :references:in-reply-to:references; bh=q6+fh2TRcfaG7Ai2kTlT0N4WEeLJzic8KL3fN4FpFuI=; b=Ff7ILAR1UDD1td6JITpfRCX1mU04x5mQjT7D9mPJMyCDbaQ7JBxANo7g/MjERC8pYG ORSJVkz2lLO6nBpd271wS2f57u/kROvypOJGuOJmh5DwqE979ukl3SVGTtHZhOfA0AVd RnGxqPbNQNlDyprL6pKeZ1ZczvW3H1FKr0rjTJ75V4zwRxR48SRkuJmitEdEhudXZ6Rj EufCa+p5u6CTxtndpP6dCSSyXk7cp9TTLtun34lENGc0yUIPKP8mHSQACvN/WsbqZUjD WZMm/xF2Vz8PBMIlmLQ2sppFFDpngLPRZRh/gkhAHC8shfiFutA5KsHHnDlVvgNuO5E1 NRaA== X-Gm-Message-State: ALyK8tIezgP+Y7Wl5PEsvlCHvpiaLdo76K6QiInJZmyEtasCfmfbfKLVX8NloHcNxXN0FA== X-Received: by 10.25.196.216 with SMTP id u207mr592420lff.164.1466169474474; Fri, 17 Jun 2016 06:17:54 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-52-30.pppoe.spdop.ru. [109.252.52.30]) by smtp.gmail.com with ESMTPSA id d8sm2538183lbc.29.2016.06.17.06.17.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Jun 2016 06:17:53 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Fri, 17 Jun 2016 16:17:27 +0300 Message-Id: X-Mailer: git-send-email 2.9.0 In-Reply-To: References: In-Reply-To: References: 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 v14 2/3] hw/ptimer: Fix counter - 1 returned by ptimer_get_count for the active timer 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 Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Due to rounding down performed by ptimer_get_count, it returns counter - 1 for the active timer. That's incorrect because counter should decrement only after period been expired, not before. I.e. if running timer has been loaded with value X, then timer counter should stay with X until period expired and decrement after. Fix this by adding 1 to the counter value for the active and unexpired timer. Signed-off-by: Dmitry Osipenko --- hw/core/ptimer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 289e23e..7f89001 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -89,10 +89,10 @@ static void ptimer_tick(void *opaque) uint64_t ptimer_get_count(ptimer_state *s) { + int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); uint64_t counter; - if (s->enabled && s->delta != 0) { - int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + if (s->enabled && s->delta != 0 && now != s->last_event) { int64_t next = s->next_event; bool expired = (now - next >= 0); bool oneshot = (s->enabled == 2); @@ -144,7 +144,7 @@ uint64_t ptimer_get_count(ptimer_state *s) if ((uint32_t)(period_frac << shift)) div += 1; } - counter = rem / div; + counter = rem / div + (expired ? 0 : 1); if (expired && counter != 0) { /* Wrap around periodic counter. */