From patchwork Fri May 27 17:03:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 9138781 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 CD8886075A for ; Fri, 27 May 2016 17:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C093327CEC for ; Fri, 27 May 2016 17:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B572D28159; Fri, 27 May 2016 17:11:41 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 6D99727CEC for ; Fri, 27 May 2016 17:11:41 +0000 (UTC) Received: from localhost ([::1]:47082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6LIS-0008Qw-DG for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 May 2016 13:11:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6LBx-0002Sl-8J for qemu-devel@nongnu.org; Fri, 27 May 2016 13:04:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6LBn-0003pN-6O for qemu-devel@nongnu.org; Fri, 27 May 2016 13:04:56 -0400 Received: from mail-lb0-x244.google.com ([2a00:1450:4010:c04::244]:36386) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6LBm-0003p9-Ul; Fri, 27 May 2016 13:04:47 -0400 Received: by mail-lb0-x244.google.com with SMTP id r5so6038616lbj.3; Fri, 27 May 2016 10:04:46 -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=TQnMpbtvU7lGRNgY5cGe8YJUa9WOOKjvmR/MKv6Y5CE=; b=INejF5xrPOz6EglbkTUNUBZZx617zMzXGKGBZHxpkSd92ZyXes9hdIjKYOvbvdxDTp opfRS31LOxsgqLwOZcsTA9GIghjVQZvJUFI4PSH92+4hFeorJ6Y3i0xGizEBSTs/tBln d+2bWeLasG/qeLvK0jrNaEPjAAngGId3M2VUgPR3T5eHlz7es0KZx+qp1VZ1tx2OBPzz eiBlKGUwg4pZ2UHaQoO0ZozakY4l90zQGyLWMtS0NSVVlJXo3zlTufPyGQwMsDOzn9o7 CtPyM/640kyWJGg5gVp7efaOlJhb2Rss09I25xC+hef1iKmaRDVqF62pXtQ1hx3GH8bU eoLQ== 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=TQnMpbtvU7lGRNgY5cGe8YJUa9WOOKjvmR/MKv6Y5CE=; b=L4hdlnkNFWF0d6W8ZbpT9PWHTzlXnWhJXpP4pzJ7EdWVA6LrWOh7lMAFfviE9mR7Kx e4Z+PRhVgv5GqTFJ4QgfTUeeo2nnCsCfFgc6AGm641vHaXVSvJEMSRxZrEF/9rY8en8z HaFC1h62xr3Ev1e/1MA7JnYoIZYZl1PeglCTJN5rRLGRZx0s66bZS0tRl0XTCnCwlORG sNbmg+dOiz3JyuMGY2L7WjgBXGzXKUTnvE28txLdabulu6f3NRHgu30QF+eKbivXN/gZ Y7aLiUSW+wPa2Th6QMbdVOfwvL0hRF9zO3lnOA5T43Di02a4lZOfo+eckILAoybumXBS BMjg== X-Gm-Message-State: ALyK8tLmSOcHyQOEjX23NtkDxYmbZMdcD74wRe7cfRut/AUN9rHoJwnXaVnaU5nW3JoIdA== X-Received: by 10.112.43.210 with SMTP id y18mr4907123lbl.105.1464368686232; Fri, 27 May 2016 10:04:46 -0700 (PDT) Received: from localhost.localdomain ([109.252.52.1]) by smtp.gmail.com with ESMTPSA id p4sm3123088lfe.40.2016.05.27.10.04.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 10:04:45 -0700 (PDT) From: Dmitry Osipenko To: QEMU Developers , qemu-arm@nongnu.org Date: Fri, 27 May 2016 20:03:32 +0300 Message-Id: X-Mailer: git-send-email 2.8.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:c04::244 Subject: [Qemu-devel] [PATCH v13 4/8] hw/ptimer: Support "on the fly" timer mode switch 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 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 76ebe9b..d0b2f38 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -163,16 +163,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