From patchwork Sun Oct 2 15:53:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9359701 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 2A6826075E for ; Sun, 2 Oct 2016 16:07:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B02828A8B for ; Sun, 2 Oct 2016 16:07:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FD1D28A9C; Sun, 2 Oct 2016 16:07:36 +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 AD80228A8B for ; Sun, 2 Oct 2016 16:07:35 +0000 (UTC) Received: from localhost ([::1]:59986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjIc-0007kv-NL for patchwork-qemu-devel@patchwork.kernel.org; Sun, 02 Oct 2016 12:07:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjC2-0002f9-8f for qemu-devel@nongnu.org; Sun, 02 Oct 2016 12:00:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bqjBz-0003Hm-L1 for qemu-devel@nongnu.org; Sun, 02 Oct 2016 12:00:46 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:33263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bqjBz-0003H6-66; Sun, 02 Oct 2016 12:00:43 -0400 Received: by mail-lf0-x241.google.com with SMTP id l131so7946132lfl.0; Sun, 02 Oct 2016 09:00:42 -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=CnG2NcT32VWre/5LKfN4/dgVbWhB4WIQiXbecTlwedY=; b=ltEyDyRKF8iwz4oFHhvTJ3EwDWDCNRxbkEvofAIqdBtNQGxZkVMMlmxciRITAep+x7 tvTxgSDaTX70I+gbIGy8CvGR0nZJ9eCz8KTVAILivuRG4XBIrer1dJ0bFSItkLdNhF6w CMDbnl1t5Dtu8qiJkRfycVaUu8Alvbjw00IlTJfUWajVUzEdX46HP5h6cmrRpOCtEmdl fbprQaKqtzjViJcdPbOkZxXig1FtnMeNR1vFUfzKdCzdg/TtoobOvj01DIXHpKWhDGy/ uXoy9S0QKW8mPJ7X0eNQPw+E37jEfYiEnHUZSFCEjFKGZjDvQE3aIvDFJrirV//miBHh acNQ== 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=CnG2NcT32VWre/5LKfN4/dgVbWhB4WIQiXbecTlwedY=; b=UgBvnqei4inumiFXZa9ktkBU4XSASDdf8mvXPSeVN1vtVPP5Ygj/zdSZzGPSbFZtcI oQWSagx3GwH8/F4jOhyw5q3NeUOcnGjDisbpLOIdPPdvkuHhCPDKfwaLoHyrs9azOH3R X/UWr/PC8QcY1dgoqdjdsxgNbLprPi8zFkcm7N0169lcx7GJw2qKfTlqEwiZzjQ8C0Yb xnMgAcWzZ28UVsVvoMzPtcmtADH12ik013QGsA3M/0ejstcl0N5mxNc8vmcsu9EHVxJK NEMWBH5A0aJTj06/OQXBrYg7xZjtDjd5Jx8m+01UIxeullCJuGg2oS9E55/5Ng4kxurB pWmQ== X-Gm-Message-State: AA6/9RlfBxgsL8YA5EWQvdlA9SVVohcYI0u7sEXMgOSxgu6G2wEDW0QwiT+RgQ/u6rGsSw== X-Received: by 10.25.139.66 with SMTP id n63mr6897075lfd.111.1475424011197; Sun, 02 Oct 2016 09:00:11 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Oct 2016 09:00:10 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Sun, 2 Oct 2016 18:53:35 +0300 Message-Id: <632b23dd11055d9bd5e338d66b38fac0bd51462e.1475421224.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::241 Subject: [Qemu-devel] [PATCH v17 03/14] hw/ptimer: Add "continuous trigger" 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 Currently, periodic timer that has load = delta = 0 performs trigger on timer reload and stops, printing a "period zero" error message. Introduce new policy that makes periodic timer to continuously trigger with a period interval in case of load = 0. Signed-off-by: Dmitry Osipenko --- hw/core/ptimer.c | 30 +++++++++++++++++++++++++++--- include/hw/ptimer.h | 4 ++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 1f4122d..1aa0194 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -47,7 +47,8 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) ptimer_trigger(s); delta = s->delta = s->limit; } - if (delta == 0 || s->period == 0) { + + if (s->period == 0) { if (!qtest_enabled()) { fprintf(stderr, "Timer with period zero, disabling\n"); } @@ -60,6 +61,21 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) delta += delta_adjust; } + if (delta == 0 && (s->policy_mask & PTIMER_POLICY_CONTINUOUS_TRIGGER)) { + if (s->enabled == 1 && s->limit == 0) { + delta = 1; + } + } + + if (delta == 0) { + if (!qtest_enabled()) { + fprintf(stderr, "Timer with delta zero, disabling\n"); + } + timer_del(s->timer); + s->enabled = 0; + return; + } + /* * Artificially limit timeout rate to something * achievable under QEMU. Otherwise, QEMU spends all @@ -90,7 +106,15 @@ static void ptimer_tick(void *opaque) if (s->enabled == 2) { s->enabled = 0; } else { - ptimer_reload(s, DELTA_ADJUST); + int delta_adjust = DELTA_ADJUST; + + if (s->limit == 0) { + /* If a "continuous trigger" policy is not used and limit == 0, + we should error out. */ + delta_adjust = 0; + } + + ptimer_reload(s, delta_adjust); } } @@ -98,7 +122,7 @@ uint64_t ptimer_get_count(ptimer_state *s) { uint64_t counter; - if (s->enabled) { + 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; diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h index 03441cb..b2fb4f9 100644 --- a/include/hw/ptimer.h +++ b/include/hw/ptimer.h @@ -39,6 +39,10 @@ * around. */ #define PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD (1 << 0) +/* Running periodic timer that has counter = limit = 0 would continuously + * re-trigger every period. */ +#define PTIMER_POLICY_CONTINUOUS_TRIGGER (1 << 1) + /* ptimer.c */ typedef struct ptimer_state ptimer_state; typedef void (*ptimer_cb)(void *opaque);