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: 9711741 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 BA31060362 for ; Thu, 4 May 2017 12:00:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DECF2623C for ; Thu, 4 May 2017 12:00:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90D5228689; Thu, 4 May 2017 12:00:15 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72E342623C for ; Thu, 4 May 2017 12:00:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752839AbdEDMAN (ORCPT ); Thu, 4 May 2017 08:00:13 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34115 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752352AbdEDMAL (ORCPT ); Thu, 4 May 2017 08:00:11 -0400 Received: by mail-pg0-f65.google.com with SMTP id t7so2026782pgt.1 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=NmG/6NE0iBbd6mWlRmYol/u6cZdnsb2nfSj/q4uJQ+2RrY5qMs8zwYyThCjlRl6b2W kKdT++2e0+anGNykA7blwDyRT9ZgoGEZ8ea+Xljv4qN3VkYgPB2JMiBYJmn0bwMRWq8F W27ARedKC9i9HbG1IJY8FdB6hvbH1D2APYEzhMOgXoasWkzEBn7WBzgJRe5T8tnZha8d 2wfgnP2AslGItFrcPKrlwhIp5eph2BNu1hSqtMWbtJP4hV20fJHfr2pYT2mmLerWTbJn 3Z+4f63gi/8Pca4do1RTR3gli/aJpwVul2Vxqq3UtjHNf7hA67Ce6XAordySTT5TdtRf RV6Q== X-Gm-Message-State: AN3rC/4u+LD4YMhuH4DPkzkUClO3eP0T6pYKT2WPMvvppqhRmnRSNpnV fVgsWgOHZfLIVA== 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, yunfangtai@tencent.com, Xiao Guangrong Subject: [PATCH v2 1/5] mc146818rtc: update periodic timer only if it is needed 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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: