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: 749905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w2zmC0SR1z9rxm for ; Wed, 12 Apr 2017 19:54:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vYq2noed"; dkim-atps=neutral Received: from localhost ([::1]:43239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyEyu-00075Y-HT for incoming@patchwork.ozlabs.org; Wed, 12 Apr 2017 05:54:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyEwY-0005aQ-DX for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:52:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyEwU-0004nT-6g for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:52:06 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:34922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyEwT-0004nN-VP for qemu-devel@nongnu.org; Wed, 12 Apr 2017 05:52:02 -0400 Received: by mail-pg0-x241.google.com with SMTP id g2so4225886pge.2 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=Y4FzzPmF2XFiKosAGgTiW+SjSLWoKI+wNPvTcHawmj3S7qZ1hf8rmIuswHzSczeqEU okx3RU+IQeDhHsmioYuztqmFvSwqf/3s757fLS+NTYNT65gBFeVSxQ/jRSjIbJl5BVBu GpZw3wvcPiAIejs+/5BMIfU/9cIirDPRbLv/DPC5Po0XNsLhvYFyPNE2hOWNfUnS/81E dVGHt1cRMXJ6SVKs993kFsk33sLye4UoKWL+jhqVgGELPPOgU3peat/Djd+8T7iWTZWy F7k1PoQyQuU9AhFc4GNgHjlYYbpAwHPLhvNBxXPT3gwMav09aGoKP6ySuUoNnSWc6K9o zV2w== X-Gm-Message-State: AN3rC/6V/0A7IO7jP1sdYs6QRk//eI+SzUBcZ0gqm/4L4UN9MYLsgCoBSGs1ntPXcbI7Ew== 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 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH 4/5] mc146818rtc: move x86 specific code out of periodic_timer_update 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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); } }