From patchwork Wed Apr 12 09:51:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9676931 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 E942660383 for ; Wed, 12 Apr 2017 09:54:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAAB8285D4 for ; Wed, 12 Apr 2017 09:54:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE994285E3; Wed, 12 Apr 2017 09:54:06 +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 4D818285D4 for ; Wed, 12 Apr 2017 09:54:06 +0000 (UTC) Received: from localhost ([::1]:43237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyEyT-0006NE-E3 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Apr 2017 05:54:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyEwO-0005Tl-MN for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:51:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyEwN-0004kx-JY for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:51:56 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:33938) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyEwN-0004kp-EM for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:51:55 -0400 Received: by mail-pf0-x242.google.com with SMTP id o126so4065486pfb.1 for ; Wed, 12 Apr 2017 02:51:55 -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=IHG0eq7pYInf5jBkUXcHbbwYX0qxmNcW19UBVxRj8fk=; b=GzWzfgurlxCHX6H5A0EMxAbSTv4gcNyFknepyfaGmYvehFmlTxpWydqCenucv84NsS 4PNqfBeHpntACadMQ1mP5FBGjIDUwNtp/BxcU5LPjZxlG1hjeDtdFh7cVNJW7dDFLp9j ou0rNaV7cL4JXS01NF8qQrtXjbqlR/BL9Dq+9Homue/htIyYTn3BPxv8DEZ/E4s4MPHL GGtr6LBg37Jldby9PSLbTaIg3FjbJQPmemVNK3Xpkz6WVqKqlGlBGZfT9suzPtRaPcrE z4OhJsK6WRHhKH9Ev6O4qhHIigLZ+i6jAseTPkE/8L0v7XxREcFqPS0MGU5BP91oU8x8 8/cg== 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=IHG0eq7pYInf5jBkUXcHbbwYX0qxmNcW19UBVxRj8fk=; b=hwM0vlerLmOhaFMoCufxjR0GZJsp1Dr6hiFdVPuNfZjt8tLTvqq/VOugkSZa7ar4Fv j8YiiANVaBEOem4o6+54iuZvGeHGlfUCoszCCTbwQiw+STXONNbyU2eKhYctk1Yy2jlz 7bHMhqiPPTFB+d8A6atSkaiAOf/zV+ZpYkLwIGC8I90lRK7X5DjgrNXlWAl+4bb1KUuX dyq4xh48BFch/sJBKLQvkZ3MA2TDXCRGv8byvYUepLhneEsk07c/GIr23cGld1vbJJVo 6vyVn8i4pY5hoFUt8CuxCcfdU0SM9sdFxchS2J/4UFXVS7GzjHiDpfQJji+1kntl9BiQ 75Lg== X-Gm-Message-State: AN3rC/7qvOGXp5ugLjGUq5choX6ggFomSPiM8SCjowZoBfV5MVMbu9z7ore5mDvtCdiCMg== X-Received: by 10.84.232.205 with SMTP id x13mr24058071plm.153.1491990714482; Wed, 12 Apr 2017 02:51:54 -0700 (PDT) Received: from eric.tencent.com ([103.7.29.8]) by smtp.gmail.com with ESMTPSA id 4sm35445749pff.17.2017.04.12.02.51.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 02:51:54 -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: Wed, 12 Apr 2017 17:51:07 +0800 Message-Id: <20170412095111.11728-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170412095111.11728-1-xiaoguangrong@tencent.com> References: <20170412095111.11728-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:c00::242 Subject: [Qemu-devel] [PATCH 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 | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 4165450..749e206 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -387,10 +387,25 @@ static void rtc_update_timer(void *opaque) check_update_timer(s); } +static bool rtc_periodic_timer_updated_by_regA(RTCState *s, uint64_t data) +{ + uint8_t orig = s->cmos_data[RTC_REG_A]; + + return (orig & 0x0f) != (data & 0x0f); +} + +static bool rtc_periodic_timer_updated_by_regB(RTCState *s, uint64_t data) +{ + uint8_t orig = s->cmos_data[RTC_REG_B]; + + return (orig & REG_B_PIE) != (data & REG_B_PIE); +} + 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 +438,8 @@ static void cmos_ioport_write(void *opaque, hwaddr addr, } break; case RTC_REG_A: + update_periodic_timer = rtc_periodic_timer_updated_by_regA(s, data); + if ((data & 0x60) == 0x60) { if (rtc_running(s)) { rtc_update_time(s); @@ -445,10 +462,16 @@ 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 = rtc_periodic_timer_updated_by_regB(s, data); + if (data & REG_B_SET) { /* update cmos to when the rtc was stopping */ if (rtc_running(s)) { @@ -475,7 +498,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: