From patchwork Wed May 10 08:32:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9719449 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 6CD1760236 for ; Wed, 10 May 2017 08:34:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61143284E4 for ; Wed, 10 May 2017 08:34:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5429E28557; Wed, 10 May 2017 08:34: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=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 32A87284E4 for ; Wed, 10 May 2017 08:34:39 +0000 (UTC) Received: from localhost ([::1]:41102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8N4w-0000g3-IP for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 May 2017 04:34:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8N3l-0000dq-2M for qemu-devel@nongnu.org; Wed, 10 May 2017 04:33:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8N3i-0003hX-Lz for qemu-devel@nongnu.org; Wed, 10 May 2017 04:33:25 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:34517) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d8N3i-0003hF-Fy for qemu-devel@nongnu.org; Wed, 10 May 2017 04:33:22 -0400 Received: by mail-pg0-x241.google.com with SMTP id u187so3229240pgb.1 for ; Wed, 10 May 2017 01:33:22 -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=X6ToGPrQnFRTIX2YJZdtEzDQeY9GN7ZauapljXqb5mjJDd5WsEvh6eUHln+rIqEcmv Em1GjXUVQ6vE+F+OMGRcsCaZE7R19Hb9q9eV7Ek/DdKPAlMqN4WCVcTiLSYS9XUsi6wX jzWuJ3Z5zDK0uGnOpNwcndienc8KljYEFzdwM3MMXFR3cUpYqcoB3g4jMdyRPcGHkQvM 5yQqncZEhkwY9O9Z8cDqmdXf/EF62RS2R1n/ng0QRVK9jV1G2zvdj53Evy7yDk6AGO/j AZwhGcGojBgs1aSmkatkmyiVbJn4iEY1+fhSxcXt289EXqd3aMaOBfyOKW8Hw7HAFcYt Oa5A== 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=btJP9ZR2JnOWEL+Tsri8UY8sufhncBBdcNqhxiwQjwqo55VTFpsDy4Wm18IiFf5CFW hohkpz9pjXD7RuntCs89rILBEBzik+Wz8AGrA1QtTRFcY5If5borBsQDmkDx8WASjgLI skFFtGWYLHX3JUO66WJ50X+OJ/KA9F7mLJlGiSa4xNLYih1Kn3G2fNhS4b6ktRU1LuFS H0eYRjfxArM+zVYzCgH1zBRDwjfCHUiBI3rSidxHdMp65UvMiTA3umSoOhFYKN81jYa4 FOUd6y1iKD34oCKZGQqA/AFJk1R8vyCjIsJtvNDB6Y04hnEHn138ZShvLU8488sYeg5V 6biA== X-Gm-Message-State: AODbwcCq5XHFnEtiASIMiEJ4eBa+3GcVuG07FjCyDgWu3DhyYuy04Q99 Ckrn38aWLSEFbg== X-Received: by 10.98.160.130 with SMTP id p2mr4939385pfl.184.1494405201495; Wed, 10 May 2017 01:33:21 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.37]) by smtp.gmail.com with ESMTPSA id z125sm3829043pfb.64.2017.05.10.01.33.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 May 2017 01:33:19 -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, 10 May 2017 16:32:55 +0800 Message-Id: <20170510083259.3900-2-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170510083259.3900-1-xiaoguangrong@tencent.com> References: <20170510083259.3900-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH v3 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: