From patchwork Wed Apr 12 09:51:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9676925 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 4E8C060382 for ; Wed, 12 Apr 2017 09:52:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F1702855A for ; Wed, 12 Apr 2017 09:52:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33CF7285D3; Wed, 12 Apr 2017 09:52:08 +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 9DB652855A for ; Wed, 12 Apr 2017 09:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752877AbdDLJwF (ORCPT ); Wed, 12 Apr 2017 05:52:05 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35957 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752772AbdDLJwB (ORCPT ); Wed, 12 Apr 2017 05:52:01 -0400 Received: by mail-pg0-f65.google.com with SMTP id 34so1371854pgx.3 for ; Wed, 12 Apr 2017 02:52:01 -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=95oGEhcSCSxA8dayWct3bpTBoVjwvh7b68XnyuUVb4Q=; b=vYq2noedglXEM3uYQsvJG8WCm1+yYBKoHae1m7p9wc+F04anFBgXJm2lg2YFGF5ZLu sQ+uc6PI+wgftl6b+mt2CGz+yQhFnDGDUjYzTmlCiXlWFTlWZ36+l5ZrHrpQd1n0qPiI f0+8eTZA8/yhKuoI3avQF6Vtiv6j9TL/+fsn1ROCYbbZ240RGkGGd4fbSYdD8avCr6Sf B+Qc+IiuDf1ppaAViQkAIa32/cRyCu4vdf8VPKHKwzQo5CSdpMFVKBbxkN8khfxUP82E YIKEdvMvY2/loRX4ohKtbzBTD2z82fXdnqp7IU5Td7S466ToZSYlFckwgfbCMtUAcJQM vYyg== 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=95oGEhcSCSxA8dayWct3bpTBoVjwvh7b68XnyuUVb4Q=; b=SnavpU6gLO8ctHBrdpEeUqBjbS97H9o9WjHaZOg/op/EuimrKrIefjVa+Vm9XYP5+Y RPLp5aGTwpp0bYIJIuV1uBXK3Xsc51tuYLXX8b+S8CgoneLen7PukXFiDzmrtSevhgrt 5KtqjMHb+zjhoPr3UUSLj3aLV1S3KJJtxtOS+MOLFkVkncNZY3gYNV1D59EsHDayozUq OnAzgU4E1p4QYegSYFYlos8NCAp+A/lG8KsrAxqh42EChjriy7TmKfld6R07YNFfpuPq QPThsR99Yw3I+3vTTaRt71YZx3KoraAgYxPp+irZLyMbTQCNNYkt6W0DOwguCo6GrVpb nJdA== X-Gm-Message-State: AN3rC/4VaU2TDSr+KA45dxq2XNwGHgpQcKmNowFYj/bpH9wdQWLyiLA17w6dQmpyDObCXQ== X-Received: by 10.84.238.198 with SMTP id l6mr28302403pln.95.1491990721090; Wed, 12 Apr 2017 02:52:01 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 02:52:00 -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 4/5] mc146818rtc: move x86 specific code out of periodic_timer_update Date: Wed, 12 Apr 2017 17:51:10 +0800 Message-Id: <20170412095111.11728-5-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> 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 Move the x86 specific code in periodic_timer_update() to a common place, the actual logic is not changed Signed-off-by: Xiao Guangrong --- hw/timer/mc146818rtc.c | 112 +++++++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 46 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 3bf559d..d7b7c56 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -144,6 +144,63 @@ static void rtc_coalesced_timer(void *opaque) rtc_coalesced_timer_update(s); } + +static int64_t +arch_periodic_timer_update(RTCState *s, int period, int64_t lost_clock) +{ + if (period != s->period) { + int64_t scale_lost_clock; + int current_irq_coalesced = s->irq_coalesced; + + s->irq_coalesced = (current_irq_coalesced * s->period) / period; + + /* + * calculate the lost clock after it is scaled which should be + * compensated in the next interrupt. + */ + scale_lost_clock = current_irq_coalesced * s->period - + s->irq_coalesced * period; + DPRINTF_C("cmos: coalesced irqs scaled from %d to %d, %ld clocks " + "are compensated.\n", current_irq_coalesced, + s->irq_coalesced, scale_lost_clock); + lost_clock += scale_lost_clock; + s->period = period; + } + + /* + * if more than period clocks were passed, i.e, the timer interrupt + * has been lost, we should catch up the time. + */ + if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW && + (lost_clock / period)) { + int lost_interrupt = lost_clock / period; + + s->irq_coalesced += lost_interrupt; + lost_clock -= lost_interrupt * period; + if (lost_interrupt) { + DPRINTF_C("cmos: compensate %d interrupts, coalesced irqs " + "increased to %d\n", lost_interrupt, s->irq_coalesced); + rtc_coalesced_timer_update(s); + } + } + + return lost_clock; +} + +static void arch_periodic_timer_disable(RTCState *s) +{ + s->irq_coalesced = 0; +} +#else +static int64_t +arch_periodic_timer_update(RTCState *s, int period, int64_t lost_clock) +{ + return lost_clock; +} + +static void arch_periodic_timer_disable(RTCState *s) +{ +} #endif static int period_code_to_clock(int period_code) @@ -175,24 +232,7 @@ periodic_timer_update(RTCState *s, int64_t current_time, int old_period) if (period_code != 0 && (s->cmos_data[RTC_REG_B] & REG_B_PIE)) { period = period_code_to_clock(period_code); -#ifdef TARGET_I386 - if (period != s->period) { - int current_irq_coalesced = s->irq_coalesced; - - s->irq_coalesced = (current_irq_coalesced * s->period) / period; - /* - * calculate the lost clock after it is scaled which should be - * compensated in the next interrupt. - */ - lost_clock += current_irq_coalesced * s->period - - s->irq_coalesced * period; - DPRINTF_C("cmos: coalesced irqs scaled from %d to %d, %ld clocks " - "are compensated.\n", - current_irq_coalesced, s->irq_coalesced, lost_clock); - } - s->period = period; -#endif /* compute 32 khz clock */ cur_clock = muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND); @@ -219,42 +259,22 @@ periodic_timer_update(RTCState *s, int64_t current_time, int old_period) /* calculate the clock since last interrupt. */ lost_clock += cur_clock - last_periodic_clock; - -#ifdef TARGET_I386 - /* - * if more than period clocks were passed, i.e, the timer interrupt - * has been lost, we should catch up the time. - */ - if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW && - (lost_clock / period)) { - int lost_interrupt = lost_clock / period; - - s->irq_coalesced += lost_interrupt; - lost_clock -= lost_interrupt * period; - if (lost_interrupt) { - DPRINTF_C("cmos: compensate %d interrupts, coalesced irqs " - "increased to %d\n", lost_interrupt, - s->irq_coalesced); - rtc_coalesced_timer_update(s); - } - } else -#endif - /* - * no way to compensate the interrupt if LOST_TICK_POLICY_SLEW - * is not used, we should make the time progress anyway. - */ - lost_clock = MIN(lost_clock, period); - assert(lost_clock >= 0); } + lost_clock = arch_periodic_timer_update(s, period, lost_clock); + + /* + * we should make the time progress anyway. + */ + lost_clock = MIN(lost_clock, period); + assert(lost_clock >= 0); + next_irq_clock = cur_clock + period - lost_clock; s->next_periodic_time = muldiv64(next_irq_clock, NANOSECONDS_PER_SECOND, RTC_CLOCK_RATE) + 1; timer_mod(s->periodic_timer, s->next_periodic_time); } else { -#ifdef TARGET_I386 - s->irq_coalesced = 0; -#endif + arch_periodic_timer_disable(s); timer_del(s->periodic_timer); } }