Received: from eggs.gnu.org ([2001:4830:134:3::10]:35289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byj0L-0006T9-2o for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:25:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byj0K-0007UO-7S for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:25:45 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:47424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byj0K-0007Sl-1D for qemu-devel@nongnu.org; Mon, 24 Oct 2016 13:25:44 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1byj0C-0002N7-B6 for qemu-devel@nongnu.org; Mon, 24 Oct 2016 18:25:36 +0100 From: Peter Maydell Date: Mon, 24 Oct 2016 18:25:12 +0100 Message-Id: <1477329928-26414-17-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1477329928-26414-1-git-send-email-peter.maydell@linaro.org> References: <1477329928-26414-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 16/32] hw/ptimer: Add "no counter round down" policy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Dmitry Osipenko For most of the timers counter starts to decrement after first period expires. Due to rounding down performed by the ptimer_get_count, it returns counter - 1 for the running timer, so that for the ptimer user it looks like counter gets decremented immediately after running the timer. Add "no counter round down" policy that provides correct behaviour for those timers. Signed-off-by: Dmitry Osipenko Message-id: ef39622d0ebfdc32a0877e59ffdf6910dc3db688.1475421224.git.digetx@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/core/ptimer.c | 9 +++++++++ include/hw/ptimer.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 2a69daf..3af82af 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -231,6 +231,15 @@ uint64_t ptimer_get_count(ptimer_state *s) } } } + + if (s->policy_mask & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) { + /* If now == last then delta == limit, i.e. the counter already + represents the correct value. It would be rounded down a 1ns + later. */ + if (now != last) { + counter += 1; + } + } } else { counter = s->delta; } diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h index 5455340..48cccbd 100644 --- a/include/hw/ptimer.h +++ b/include/hw/ptimer.h @@ -51,6 +51,10 @@ * immediately, but after a one period. */ #define PTIMER_POLICY_NO_IMMEDIATE_RELOAD (1 << 3) +/* Make counter value of the running timer represent the actual value and + * not the one less. */ +#define PTIMER_POLICY_NO_COUNTER_ROUND_DOWN (1 << 4) + /* ptimer.c */ typedef struct ptimer_state ptimer_state; typedef void (*ptimer_cb)(void *opaque); -- 2.7.4