From patchwork Sun Oct 2 15:53:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9359721 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 62665600C8 for ; Sun, 2 Oct 2016 16:26:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48EB9289D3 for ; Sun, 2 Oct 2016 16:26:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D217289DF; Sun, 2 Oct 2016 16:26:23 +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 C123E289D3 for ; Sun, 2 Oct 2016 16:26:21 +0000 (UTC) Received: from localhost ([::1]:60115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjam-0005nS-DN for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Oct 2016 12:26:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjC3-0002gX-Kp for qemu-devel@nongnu.org; Sun, 02 Oct 2016 12:00:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqjC2-0003Je-G2 for qemu-devel@nongnu.org; Sun, 02 Oct 2016 12:00:47 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:35784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjC2-0003J6-7T; Sun, 02 Oct 2016 12:00:46 -0400 Received: by mail-lf0-x244.google.com with SMTP id s64so7954939lfs.2; Sun, 02 Oct 2016 09:00:45 -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=3pehwTlOe0n70CfQAjC/Vzsvzay8PCWbwC58SgDqBT4=; b=a5WbeWXdo13zpRy11WnJ651cuci2JXdhuXczsXG4fMqsPDO+U2p4EXSEiFYLNjqpAu f0GJ8Jf94g/Zy079yzy5Er7h1aIZtQ4CHt/05rLuuteqzORfZ4oYNsLB32GKPk6U23mG G+CrqXW2RFof9nVkDApSsCia7KE3GNyVMk993iKasP5w9+IBI+Gdi3R0wHKMYuEqbDDI KCxXOpIzp0sl5yav6msOB6y7o6WcpMXR28bS5OsTrDSCJ9OofxscM6amlQPJZ77VbOZw SP0BxSl4CMyomugOao3w27nFKZwdEJZ39Bd2TuK2m0iyoocgaEM7Dv3Gq0EbbwX99pR9 oYCg== 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=3pehwTlOe0n70CfQAjC/Vzsvzay8PCWbwC58SgDqBT4=; b=mAHkTlwOmkrecVxSX0ixOYGi9qcqi7qQbBdcapB4fKkJGG/O9PSdVFjqs0IWU7wHcO x8byxUx0sBmDTdc2NDpfXQgisxwWe2x706F5xK6cDi7mFzGMljU+h+fQ3KLYQedg6PMT tmeTbIxyS2YV0fQk4IkUK4nsFVfRRyN4ulC08Nb8+RGtrrm5BrrCSFQvH8/E99Kvfcgo wof4n4EGslgKp20SF4tvl7erszsb8Dvv9AF9x6dCH8YkRS8G/RiZvme4JHdmuCKJq9W5 Zb+EfSYPHWIIzqRq2XtrTAEbYrpHwBOV/6pVyBROZarzHbO6HfCRXiN2O8GAgCp0Eiry X62Q== X-Gm-Message-State: AA6/9RkNBATbEoGDmBWFxE8EOsuic80JwvSFBBRunzRwQgGW+m8MY5p4RFKgoRw6y2AQEQ== X-Received: by 10.46.9.131 with SMTP id 125mr6289092ljj.6.1475424014315; Sun, 02 Oct 2016 09:00:14 -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.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Oct 2016 09:00:13 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Sun, 2 Oct 2016 18:53:39 +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::244 Subject: [Qemu-devel] [PATCH v17 07/14] hw/ptimer: Add "no immediate reload" 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 Immediate counter re-load on setting (or on starting to run with) counter = 0 is a wrong behaviour for some of the timers. Add "no immediate reload" policy that provides correct behaviour for such timers. Signed-off-by: Dmitry Osipenko --- hw/core/ptimer.c | 31 ++++++++++++++++++++++++++----- include/hw/ptimer.h | 4 ++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index ed3fb6c..2a69daf 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -48,7 +48,7 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) ptimer_trigger(s); } - if (delta == 0) { + if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_RELOAD)) { delta = s->delta = s->limit; } @@ -79,6 +79,12 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) } } + if (delta == 0 && (s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_RELOAD)) { + if (s->enabled == 1 && s->limit != 0) { + delta = 1; + } + } + if (delta == 0) { if (!qtest_enabled()) { fprintf(stderr, "Timer with delta zero, disabling\n"); @@ -113,21 +119,36 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) static void ptimer_tick(void *opaque) { ptimer_state *s = (ptimer_state *)opaque; - ptimer_trigger(s); - s->delta = 0; + bool trigger = true; + if (s->enabled == 2) { + s->delta = 0; s->enabled = 0; } else { int delta_adjust = DELTA_ADJUST; - if (s->limit == 0) { + if (s->delta == 0 || s->limit == 0) { /* If a "continuous trigger" policy is not used and limit == 0, - we should error out. */ + we should error out. delta == 0 means that this tick is + caused by a "no immediate reload" policy, so it shouldn't + be adjusted. */ delta_adjust = DELTA_NO_ADJUST; } + if (!(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) { + /* Avoid re-trigger on deferred reload if "no immediate trigger" + policy isn't used. */ + trigger = (delta_adjust == DELTA_ADJUST); + } + + s->delta = s->limit; + ptimer_reload(s, delta_adjust); } + + if (trigger) { + ptimer_trigger(s); + } } uint64_t ptimer_get_count(ptimer_state *s) diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h index 911cc11..5455340 100644 --- a/include/hw/ptimer.h +++ b/include/hw/ptimer.h @@ -47,6 +47,10 @@ * but after a one period for both oneshot and periodic modes. */ #define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER (1 << 2) +/* Starting to run with/setting counter to "0" won't re-load counter + * immediately, but after a one period. */ +#define PTIMER_POLICY_NO_IMMEDIATE_RELOAD (1 << 3) + /* ptimer.c */ typedef struct ptimer_state ptimer_state; typedef void (*ptimer_cb)(void *opaque);