From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPYgl-0002aX-7e for qemu-devel@nongnu.org; Sat, 30 Jan 2016 11:47:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPYgk-0002FX-IS for qemu-devel@nongnu.org; Sat, 30 Jan 2016 11:47:55 -0500 From: Dmitry Osipenko Date: Sat, 30 Jan 2016 19:43:16 +0300 Message-Id: <77d17ad13f7b20deb433ca7a7b3d7cf40429665e.1454169735.git.digetx@gmail.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v12 7/9] hw/ptimer: Fix counter - 1 returned by ptimer_get_count for the active timer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , qemu-arm@nongnu.org Cc: Peter Maydell , Peter Crosthwaite 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 62f8cb1..b2044fb 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -136,7 +136,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. */ -- 2.7.0