From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751921AbdJFOV1 (ORCPT ); Fri, 6 Oct 2017 10:21:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43556 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751495AbdJFOV0 (ORCPT ); Fri, 6 Oct 2017 10:21:26 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 48E62C059B6F Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH v7] KVM: LAPIC: Apply change to TDCR right away to the timer To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li References: <1507298492-8300-1-git-send-email-wanpeng.li@hotmail.com> From: Paolo Bonzini Message-ID: <1ab302d3-a7d6-fc70-1857-aec556d3f55c@redhat.com> Date: Fri, 6 Oct 2017 16:21:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1507298492-8300-1-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 06 Oct 2017 14:21:26 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/10/2017 16:01, Wanpeng Li wrote: > + if (!apic->lapic_timer.period) > + return; > + > + now = ktime_get(); > + remaining = ktime_sub(apic->lapic_timer.target_expiration, now); > + if (ktime_to_ns(remaining) < 0) > + remaining = 0; > + delta = mod_64(ktime_to_ns(remaining), apic->lapic_timer.period); I think this shouldn't be happening. If it does, I'm not sure the mod is the right thing to do, so I'd just use ktime_to_ns(remaining). So perhaps let's simplify all this to: ns_remaining_old = ktime_to_ns(remaining); ns_remaining_new = mul_u64_u32_div(ns_remaining_old, apic->divide_count, old_divisor); because below you're calling nsec_to_cycles but remaining is not expressed in nanoseconds. > + if (!delta) > + return; > + > + delta = delta * apic->divide_count / old_divisor; > + > + limit_periodic_timer_frequency(apic); This should be done before all the "if"s (which should not be there in v8, but you should still call it before "now = ktime_get();"). Paolo > + apic->lapic_timer.tscdeadline += nsec_to_cycles(apic->vcpu, delta) - > + nsec_to_cycles(apic->vcpu, remaining); > + apic->lapic_timer.target_expiration = ktime_add_ns(now, delta); > +}