From patchwork Thu Jul 21 14:31:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9241789 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 0F30660574 for ; Thu, 21 Jul 2016 14:37:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00AD327D85 for ; Thu, 21 Jul 2016 14:37:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E929F27EE2; Thu, 21 Jul 2016 14:37:28 +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 8CD2E27D85 for ; Thu, 21 Jul 2016 14:37:28 +0000 (UTC) Received: from localhost ([::1]:41200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQF6N-0006ra-5J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 10:37:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQF1Y-000312-Hv for qemu-devel@nongnu.org; Thu, 21 Jul 2016 10:32:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQF1T-0003iX-I7 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 10:32:28 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:33554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQF1T-0003iD-Av; Thu, 21 Jul 2016 10:32:23 -0400 Received: by mail-lf0-x243.google.com with SMTP id f93so5656669lfi.0; Thu, 21 Jul 2016 07:32:23 -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=8Ap+fNmaDyuVVLUDgKl+76U72QR+p7T4vAb9TXqwCxA=; b=UcHOPyP6Y+LuxlbmQcl7RRjSHHKAO/zjN3gZPbWVf7kAzlQfSe+KZl6QSkByQjn2jA Cq3Z9lh3YKXE99+S1KvfTauodUHGXHa7Tk/Ep9LO6xZ8COd3yQd6xtQWksa290W34zWX LTGWrKzFugpPZq1ehjqUQ1zZO99O/rh1GxvtWky5g6l8/kc7W5Ju28oW4+rkslXap/x2 JYBmRHOPvt0A9kPU4EaKOwMRNHkpvXk2quseaT3LuTIM6t9ifPjL20wVZhWonl/YC18N p06qbVlnKrtdbcU4gdMIzdLTQLY3h0ud3t5gwxPxcBEF2WapY+Qqnm92X6YBi/PUqlzT cEoA== 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=8Ap+fNmaDyuVVLUDgKl+76U72QR+p7T4vAb9TXqwCxA=; b=TWBD9bptPjW6stmBfjdWmBg8ey+d4WEeApJi1dYITPbcuMaceDJb43GTfz9JzU0kd8 eBDgBvagohXZDCqcW80bYgnmIaCdMYHg5bjGj1Pyxf9vn0yqxZ3K5Qmu+HqkI5QT8j2R LnuheyYz1pHJpJfI2jnAjTt6PNQlJc7828o5nhMFeFiEuGd4vf0f0G5mKHjqeJCWDeJ7 lfP7LBBRWONEm6V9aKoLHaZ8yFLNn4oRJB+7tMVMltZhDeOxnA8RNoEB73+tNhqomIbm Cq4WZs3S7zm1EDqy2xo8qFBYLNYcZjWNqktzX5imtVjXtVJicNHz1WsHytHbkiBpd1Kx bq0g== X-Gm-Message-State: ALyK8tJRlAgP746USKccGUlIQagO7kwFNmF73O/srpJjTJog4+qtE+XVstHFfiqS2aaajQ== X-Received: by 10.46.0.92 with SMTP id 89mr24183195lja.37.1469111542585; Thu, 21 Jul 2016 07:32:22 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-52-30.pppoe.spdop.ru. [109.252.52.30]) by smtp.gmail.com with ESMTPSA id c12sm1887932lfc.40.2016.07.21.07.32.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Jul 2016 07:32:21 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Thu, 21 Jul 2016 17:31:13 +0300 Message-Id: <2592778c5f9be74a63c50647075843f13e6e24f6.1469110137.git.digetx@gmail.com> X-Mailer: git-send-email 2.9.2 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::243 Subject: [Qemu-devel] [PATCH v15 02/15] 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 enabled 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. Fix this by adding 1 to the counter value. Signed-off-by: Dmitry Osipenko --- hw/core/ptimer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 9dc2bb0..461b91c 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -89,6 +89,7 @@ uint64_t ptimer_get_count(ptimer_state *s) if (s->enabled) { int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); int64_t next = s->next_event; + int64_t last = s->last_event; bool expired = (now - next >= 0); bool oneshot = (s->enabled == 2); @@ -97,6 +98,8 @@ uint64_t ptimer_get_count(ptimer_state *s) /* Prevent timer underflowing if it should already have triggered. */ counter = 1; + } else if (now == last) { + counter = s->delta; } else { uint64_t rem; uint64_t div; @@ -139,7 +142,7 @@ uint64_t ptimer_get_count(ptimer_state *s) if ((uint32_t)(period_frac << shift)) div += 1; } - counter = rem / div; + counter = rem / div + 1; } } else { counter = s->delta;