From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH 2/5] mc146818rtc: fix clock lost after scaling coalesced irq Date: Thu, 4 May 2017 10:51:18 +0800 Message-ID: <5872c8da-35ee-fa38-802b-b865dc170c3f@gmail.com> References: <20170412095111.11728-1-xiaoguangrong@tencent.com> <20170412095111.11728-3-xiaoguangrong@tencent.com> <46377b3a-d06e-2119-eb97-5384013b0ac8@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, yunfangtai@tencent.com, Xiao Guangrong To: Paolo Bonzini , mst@redhat.com, mtosatti@redhat.com Return-path: Received: from mail-pg0-f50.google.com ([74.125.83.50]:33127 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753952AbdEDCvQ (ORCPT ); Wed, 3 May 2017 22:51:16 -0400 Received: by mail-pg0-f50.google.com with SMTP id y4so891924pge.0 for ; Wed, 03 May 2017 19:51:16 -0700 (PDT) In-Reply-To: <46377b3a-d06e-2119-eb97-5384013b0ac8@redhat.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 05/03/2017 11:15 PM, Paolo Bonzini wrote: > > > On 12/04/2017 11:51, guangrong.xiao@gmail.com wrote: >> + 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; > > This is: > > lost_clock = current_irq_coalesced * s->period - > (current_irq_coalesced * s->period) / period * period; > > i.e. > > /* When switching from a shorter to a longer period, scale down the > * missing ticks since we expect the OS handler to treat the delayed > * ticks as longer. Any leftovers are put back into next_irq_clock. > * > * When switching to a shorter period, scale up the missing ticks > * since we expect the OS handler to treat the delayed ticks as > * shorter. > */ > lost_clock = (s->irq_coalesced * s->period) % period; > s->irq_coalesced = (s->irq_coalesced * s->period) / period; > > Is this correct? > Yes, it is correct, it looks smarter, will apply it in the next version. Thanks!