From patchwork Sun Oct 2 15:53:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9359703 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 BAA0B6075E for ; Sun, 2 Oct 2016 16:10:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A998F28A8B for ; Sun, 2 Oct 2016 16:10:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A0CA28A9C; Sun, 2 Oct 2016 16:10:44 +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=-3.3 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 4B4EB28A8B for ; Sun, 2 Oct 2016 16:10:44 +0000 (UTC) Received: from localhost ([::1]:60004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjLf-0001u7-18 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Oct 2016 12:10:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjC6-0002iS-N0 for qemu-devel@nongnu.org; Sun, 02 Oct 2016 12:00:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqjC4-0003LU-9v for qemu-devel@nongnu.org; Sun, 02 Oct 2016 12:00:49 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:36684) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjC3-0003KI-SZ; Sun, 02 Oct 2016 12:00:48 -0400 Received: by mail-lf0-x242.google.com with SMTP id b75so429247lfg.3; Sun, 02 Oct 2016 09:00:47 -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=qQ4EnurbmMZ5Ockl+4iG4WfWOj2tPLIFocLrU1+8g/E=; b=trfoIWbIHoN5x/oql2OtOcqs0H5jSFnFGEZ7M55Qbr7x/pJPnDYOUGWiIDQbx0mDVT rtQp2DJzc/2dCqYUWCDUKTagJbYPpoH8eZkElLVzQEfrmTW5GNeAQtqc2GLbtbjefNqD XpThWYsWU7rhQ/PbNWkSEU264AZmSO/I87FIFH1JUPMoPUbMHx89pUxsrCRRSYSs3PfS KvI+5th7nd860xgJkvwz5CnZ2o6mBYkBbZkPCqF7Fv0oMbQ3BQgBxkNbdXxG/VbOlAyw 99B25xHveQJVupp7u8B6Gn8YekPN1HHQ09uhjr5wwAqQgAFsyWBt3tIGPVpdq/inwfug dkTA== 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=qQ4EnurbmMZ5Ockl+4iG4WfWOj2tPLIFocLrU1+8g/E=; b=MNTBwIMDrWIfj2+e9tz/kjfGh0sBg6j5g6OwKA1HNi3JINBf6T2ftrfEzUNX7QynzM SmElmXS+LvO5BwcJvE1yUOCdNFFlQPIoOf9S1swK/xY0/f5FhhbDx3muRJF62kZcnT6E 0NAUS43McBAThvj1h7i0h+8sssaDv7KK7uyscL6C93A4gjmukSY9eiT4Z6+wWO7Tfn9t 4FyCq1aRa7SaILK8cA8FFcVpUnLJ+CcfPPVZSjOIzw/3SWHgO4Hp0Y6r/+3AFZh2ymLV t3Fcm2kaMVFI2HRg9ucsnTYCH1TT8j7apjhuJsbc9vUyo0tYZelJBI5yH7rTBUMKpqGj z29A== X-Gm-Message-State: AA6/9Rk+htd6Q5RzFbKAjA2SrZK9DTKAAnTJwA8/PnSxfpJSgzWMV5IEe/0UoqCax6cinA== X-Received: by 10.46.33.76 with SMTP id h73mr6265247ljh.37.1475424015743; Sun, 02 Oct 2016 09:00:15 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-52-17.pppoe.spdop.ru. [109.252.52.17]) by smtp.gmail.com with ESMTPSA id o84sm4864679lfi.34.2016.10.02.09.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Oct 2016 09:00:15 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Sun, 2 Oct 2016 18:53:41 +0300 Message-Id: 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 v17 09/14] 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, 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);