From patchwork Wed Sep 7 13:22:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9319269 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 5C20060752 for ; Wed, 7 Sep 2016 13:28:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47D23292CF for ; Wed, 7 Sep 2016 13:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C7FA292E1; Wed, 7 Sep 2016 13:28:39 +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.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, 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 C86FF292CF for ; Wed, 7 Sep 2016 13:28:38 +0000 (UTC) Received: from localhost ([::1]:41005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhcu5-0005uI-V6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Sep 2016 09:28:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhcp8-0001dO-7B for qemu-devel@nongnu.org; Wed, 07 Sep 2016 09:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhcp6-0005jP-7i for qemu-devel@nongnu.org; Wed, 07 Sep 2016 09:23:29 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:36444) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhcp6-0005j5-0X; Wed, 07 Sep 2016 09:23:28 -0400 Received: by mail-lf0-x242.google.com with SMTP id j41so826386lfi.3; Wed, 07 Sep 2016 06:23:27 -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=PP9zossZ/X/FGxoQZJ7W4iBHtnL03Q4LZXNIGsm1FN8=; b=nJqPd0pBy4NFrPy2nhWGjtcV6GqV2+ZExSUIR1Wq0jAokfU/fIVrdwkbZLPzkV5Zl9 STKW4SA3cUW4MvUoQRfuPSnr3e2Xo2uqBsqPfdoihS4DBMfBm/aNI3KOPQwJnu536uV5 oHMfhQANb/WAjYcYpxgYSi7ko7JBQZ3jfVNV5G59icjaf+G2aEQnt052sDsjtfztPAm/ 7EWk0JqX/KUsYKtUcWpyoZfbjxAnHSev+u9VeGNLOoDrdEBBYWwe9eKhDYoyrrH5ORTG lV5HfJeMugxDS6cqqO75Jc6A6OmjpdkMS7Muu8Kd7f4kYk5/Wagi6y6vOjweCPVmTeji k0kw== 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=PP9zossZ/X/FGxoQZJ7W4iBHtnL03Q4LZXNIGsm1FN8=; b=FWjaBzSNyA0n23STvkD90WL3LDI08ykw2gL9cy30KBRIJtCy84Rv3JtyJPI9nCc0jr c5w6q7GfWNbBW9cwNPK85GPhFAiZBpjNsxafFzeROi5OgLsEYPJtP105Qp+EhBeQnTHg Ur3Hi4qw72PlM0NPxAXo5nbxo1pXR8izX+Fxzr00h6YHf0rZt1Shqvn93L1jhHmz5Ubd sklJRZMoWpwi0y5zvpdPGnLjvksR8sBnX57xtnwQ4PmHclWdtux+NFgDwrI2aJHDs3gv NXjnKuVb5ajzk6DzznqbjX2MiF8BZ2ihrDkDt9EIvE6FLjbg27174n+Lxw/0NcSAbht3 ATSA== X-Gm-Message-State: AE9vXwPOYcCecD8102YPT3ibGUv1gM7uy4DZgaSoTos4gb1MkRgjs2cDBELypVtQ9Y0AKg== X-Received: by 10.25.158.140 with SMTP id h134mr28528lfe.0.1473254607250; Wed, 07 Sep 2016 06:23:27 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-52-17.pppoe.spdop.ru. [109.252.52.17]) by smtp.gmail.com with ESMTPSA id h29sm11375lfi.18.2016.09.07.06.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Sep 2016 06:23:26 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Wed, 7 Sep 2016 16:22:24 +0300 Message-Id: <492e22e91b58c2d7092a95f4140222c266b5534d.1473252818.git.digetx@gmail.com> X-Mailer: git-send-email 2.9.3 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::242 Subject: [Qemu-devel] [PATCH v16 13/16] hw/ptimer: Add "no counter round down" policy 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 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 --- hw/core/ptimer.c | 9 +++++++-- include/hw/ptimer.h | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index f7f5538..88a1fe2 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -119,11 +119,14 @@ static void ptimer_tick(void *opaque) uint64_t ptimer_get_count(ptimer_state *s) { + bool no_round_down = + !!(s->policy_mask & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); uint64_t counter; if (s->enabled && s->delta != 0) { 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); @@ -131,7 +134,9 @@ uint64_t ptimer_get_count(ptimer_state *s) if (expired) { /* Prevent timer underflowing if it should already have triggered. */ - counter = 0; + counter = no_round_down ? 1 : 0; + } else if (now == last && no_round_down) { + counter = s->delta; } else { uint64_t rem; uint64_t div; @@ -174,7 +179,7 @@ uint64_t ptimer_get_count(ptimer_state *s) if ((uint32_t)(period_frac << shift)) div += 1; } - counter = rem / div; + counter = rem / div + (no_round_down ? 1 : 0); if (!oneshot && s->delta == s->limit) { /* Before wrapping around, timer should stay with counter = 0 diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h index 131fed1..5ce3270 100644 --- a/include/hw/ptimer.h +++ b/include/hw/ptimer.h @@ -49,6 +49,10 @@ /* Starting to run with/setting counter = 0 won't re-load counter. */ #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);