From patchwork Thu May 4 11:59:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9711769 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 C7C6560362 for ; Thu, 4 May 2017 12:02:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4E1C286D1 for ; Thu, 4 May 2017 12:02:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44034286BC; Thu, 4 May 2017 12:02:16 +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=unavailable 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 6AEEE28676 for ; Thu, 4 May 2017 12:02:14 +0000 (UTC) Received: from localhost ([::1]:41331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FSX-0003Hl-Ny for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 May 2017 08:02:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6FQb-0002VI-7z for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6FQZ-0006d5-OG for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:13 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36056) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d6FQZ-0006cU-I2 for qemu-devel@nongnu.org; Thu, 04 May 2017 08:00:11 -0400 Received: by mail-pg0-x244.google.com with SMTP id v1so2011964pgv.3 for ; Thu, 04 May 2017 05:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s63d/d9Ct+4iwdhqUjdWr5K2eUVPHwTFpMV9Gkue+r4=; b=rH89LCyOUofHeJkCp0p9cMrRWrixSYfQLkRneYNkVi4CkJrm+r6bJyBxHrU4EFf4LJ LfghM7tXz3J4Jx+6dh+W9qY6c5SWQsdry5tJXswu7YH0i5IQ5KB3J6QfPXE+LqdBBCfJ 44mechQlhgswESOorIjb/4d57PVl2m0oX/9e5ZvyB+C6IUQI0QcEfK+uKJDZvt3f9uhG MeSHzJVP/b9xwNr/0q/Ph67Obd2ZZI1GEO1B/ImxOrzL4aZoL/oKF9XVu15jqEBMmZ3H f01KBZ7QSokNEEP5df6X1hx2kuvjN34vQPlMhc6xfEXb05qlW5nyvLCPnnHAQV7mjrPC N8pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s63d/d9Ct+4iwdhqUjdWr5K2eUVPHwTFpMV9Gkue+r4=; b=FHP0tpOuZB3dA/W9XlV6lZV3TDkx1fXDeRwUmVAD4oBvvNf/rB8lKVjGsp2of+ykDp uSl2bxGa2XDMH0E1U9uMKQXZYGiX/BgfyTbhgIzNlP27H0V9UGQZv14fYJPJfriSOykY QgymnL3LEUSQ5QjB//RC4CWUsmVvvUcSKxbLOn7X61WZU0fD1L/gR1ZSlsh1z3qt64uO RDr8RyKjG0TVILQr+GO3ljMTpyh97JI4kM5QXfUvToJcKAoSYq9VFfPqVG3GpA/T2B0J gUZzTpHdLPZOGXPvZ4FMdcSlKGNdTwZAr+Uw2huwosgHDs1mYQSdY/16wzAbMcA5olc9 6w7g== X-Gm-Message-State: AN3rC/4ZQtThfjXeU5mvfTZoB+Fqa8LW/djH21Oy6mKL7I5c+mTrbV7J j71eJ4IIjuJVQw== X-Received: by 10.99.232.69 with SMTP id a5mr44674067pgk.167.1493899210554; Thu, 04 May 2017 05:00:10 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id p7sm3698261pfb.125.2017.05.04.05.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 05:00:10 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Date: Thu, 4 May 2017 19:59:44 +0800 Message-Id: <20170504115948.3048-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504115948.3048-1-xiaoguangrong@tencent.com> References: <20170504115948.3048-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH v2 1/5] mc146818rtc: update periodic timer only if it is needed 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: Xiao Guangrong , yunfangtai@tencent.com, qemu-devel@nongnu.org, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong Currently, the timer is updated whenever RegA or RegB is written even if the periodic timer related configuration is not changed This patch optimizes it slightly to make the update happen only if its period or enable-status is changed, also later patches are depend on this optimization Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 4165450..5cccb2a 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -391,6 +391,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { RTCState *s = opaque; + bool update_periodic_timer; if ((addr & 1) == 0) { s->cmos_index = data & 0x7f; @@ -423,6 +424,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, } break; case RTC_REG_A: + update_periodic_timer = (s->cmos_data[RTC_REG_A] ^ data) & 0x0f; + if ((data & 0x60) == 0x60) { if (rtc_running(s)) { rtc_update_time(s); @@ -445,10 +448,17 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, /* UIP bit is read only */ s->cmos_data[RTC_REG_A] = (data & ~REG_A_UIP) | (s->cmos_data[RTC_REG_A] & REG_A_UIP); - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + + if (update_periodic_timer) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + check_update_timer(s); break; case RTC_REG_B: + update_periodic_timer = (s->cmos_data[RTC_REG_B] ^ data) + & REG_B_PIE; + if (data & REG_B_SET) { /* update cmos to when the rtc was stopping */ if (rtc_running(s)) { @@ -475,7 +485,11 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, qemu_irq_lower(s->irq); } s->cmos_data[RTC_REG_B] = data; - periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + + if (update_periodic_timer) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + check_update_timer(s); break; case RTC_REG_C: