From patchwork Sat Jan 30 16:43:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 8171561 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BA4B79F818 for ; Sat, 30 Jan 2016 16:48:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0F28320382 for ; Sat, 30 Jan 2016 16:48:10 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 6CC892024F for ; Sat, 30 Jan 2016 16:48:09 +0000 (UTC) Received: from localhost ([::1]:39111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPYgy-0002Zq-Qq for patchwork-qemu-devel@patchwork.kernel.org; Sat, 30 Jan 2016 11:48:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPYgi-0002Wq-QD for qemu-devel@nongnu.org; Sat, 30 Jan 2016 11:47:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPYgi-0002EF-2K for qemu-devel@nongnu.org; Sat, 30 Jan 2016 11:47:52 -0500 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:35981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPYgh-0002Do-RB; Sat, 30 Jan 2016 11:47:52 -0500 Received: by mail-lf0-x244.google.com with SMTP id t141so5187291lfd.3; Sat, 30 Jan 2016 08:47:51 -0800 (PST) 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=Mxp7s/OZdtUUVPrduRicDC26L2HlOOWcFQ0y8HoDZ0k=; b=QeMRh/2gQRVyitCIRzfzPbUYey2kceg6U9gjVlc4djfqWVEkSfSp71W09jQ0A9lISo ouiusHFHpcy4tBAGkzS9YfpVY8olKh0EudNZhGZwW7FQjop3FdS/7qaZErsRge4SEuUu ti+uw0jd/hlf4hP79av6tBKT2GOHoFhrj7iebfqTkb08OnLkHGM8zTVh2FQzYqkvB+ts dotGcWgBhDSI9vd6op5S2gnG/d7GTPg8umFdqjoqQ0qn2Oyrdvk9l2sWHviS7xV1JQmU h9nkg8WsrG7i9wh6VyYJt1KW4h3nmHUn98LA19Djz2R3YzEsmeJfZ87AOz5WeovsRdKy 6+sg== 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=Mxp7s/OZdtUUVPrduRicDC26L2HlOOWcFQ0y8HoDZ0k=; b=GiebRZO052UbbeWijq/LQK1rERFD3loS4cwFLTAwpDVGZdYP5e2fDo3Ke81SqJZceR WazTeVnt4o9ZXv3IHf7fS3Ecj9RSicU33iPuLuLb/791RjYteniieR8TO+1TrhTyQ+Bw c8NgN60RnfNaSaAiqACxYwEjyAaarq/JTvBt2zu3E/A5ewNdqpVEpt/MExOj3OImAsU1 wQe+LvRPeS6mpPOh28MbA5TC/x3NybhOsLLsRL604HTPlhuQkfK8FTv9xFzLglzYi1BD eVlAGKxZCY7aDygytAekyr/qT8EpeAUYXMZj4Hm73oUmc54Bs5gIegCL7IhOZkYWeU+5 h7Tw== X-Gm-Message-State: AG10YORkmzHF4W3Uo2J2m1/+z+AO5D5soL449kWXvV/qUli1lDS77ZFmm5rvM0Kb20zmfQ== X-Received: by 10.25.91.81 with SMTP id p78mr5572707lfb.19.1454172470997; Sat, 30 Jan 2016 08:47:50 -0800 (PST) Received: from localhost.localdomain (ppp46-138-151-163.pppoe.spdop.ru. [46.138.151.163]) by smtp.gmail.com with ESMTPSA id b135sm2834417lfe.28.2016.01.30.08.47.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 30 Jan 2016 08:47:50 -0800 (PST) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Sat, 30 Jan 2016 19:43:13 +0300 Message-Id: X-Mailer: git-send-email 2.7.0 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 Cc: Peter Maydell , Peter Crosthwaite Subject: [Qemu-devel] [PATCH v12 4/9] hw/ptimer: Support "on the fly" timer mode switch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow switching between periodic <-> oneshot modes while timer is running. Signed-off-by: Dmitry Osipenko Reviewed-by: Peter Crosthwaite --- hw/core/ptimer.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index f58790a..78ae443 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -162,16 +162,17 @@ void ptimer_set_count(ptimer_state *s, uint64_t count) void ptimer_run(ptimer_state *s, int oneshot) { - if (s->enabled) { - return; - } - if (s->period == 0) { + bool was_disabled = !s->enabled; + + if (was_disabled && s->period == 0) { fprintf(stderr, "Timer with period zero, disabling\n"); return; } s->enabled = oneshot ? 2 : 1; - s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - ptimer_reload(s); + if (was_disabled) { + s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + ptimer_reload(s); + } } /* Pause a timer. Note that this may cause it to "lose" time, even if it