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: 9719439 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 6B40460236 for ; Wed, 10 May 2017 08:33:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DEAA284E4 for ; Wed, 10 May 2017 08:33:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 515B628557; Wed, 10 May 2017 08:33:30 +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 03BDC284E4 for ; Wed, 10 May 2017 08:33:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752062AbdEJIdY (ORCPT ); Wed, 10 May 2017 04:33:24 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35103 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751081AbdEJIdW (ORCPT ); Wed, 10 May 2017 04:33:22 -0400 Received: by mail-pg0-f67.google.com with SMTP id i63so3236106pgd.2 for ; Wed, 10 May 2017 01:33:21 -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=jBL+U3yiotMhbudo0+zpJRUW+q7YN0vQBhMfbgFXh9iOSD86Qi5oQ3bdkYPFup3Dic D8vLmPLLt6PsrENmLHYSlkBzGvH2THx4kZHr1Zx6e4SBNpZl5W4VsOMZxd+SzsigJ0NN Ucy2uQqsLpfFI8d3S8aJbTJBdWs9D3AybvpcSvQKTxQ5D5WmAgP9QNfZgcguoIaAlsc3 dG+ZdZnyxa+1a/B5r9/0gG9uRZCwrZ8EJJnfl1THk/9Ir+OWC8qYMYL7u8UFuXfRDqzD M1tZGNdv2Gu+3PBbr0pxkrTMbe46qh18PNiHNuMBatkE2dBBaDvJRsmFvmtD6qnKhx/8 qo+A== X-Gm-Message-State: AODbwcCWg66c4WsJSGbsSCp6+LjpO5W33i2LvOPbUJ013TysQgFcLyzP lweChYahOXhZBfY0 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 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, yunfangtai@tencent.com, Xiao Guangrong Subject: [PATCH v3 1/5] mc146818rtc: update periodic timer only if it is needed 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> 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: