Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754577AbcKNQSU (ORCPT ); Mon, 14 Nov 2016 11:18:20 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34668 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbcKNQSQ (ORCPT ); Mon, 14 Nov 2016 11:18:16 -0500 Subject: Re: [PATCH] KVM: x86: do not go through vcpu in __get_kvmclock_ns To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1478859141-25146-1-git-send-email-pbonzini@redhat.com> <20161114145239.GA2185@potion> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, mtosatti@redhat.com From: Paolo Bonzini Message-ID: <18a835aa-407e-6102-8b41-05b90cae1784@redhat.com> Date: Mon, 14 Nov 2016 17:17:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161114145239.GA2185@potion> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1119 Lines: 34 On 14/11/2016 15:52, Radim Krčmář wrote: > The hunk below should return the same value in pvclock_ns and kernel_ns > if they can be used interchangeably. boot_ns is expected to be a bit > delayed, because it is read late. boot_ns shows a bounded offset from > kernel_ns, unlike the drifting pvclock_ns. > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 83990ad3710e..30d4d3d02ac7 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -6653,6 +6653,17 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > goto cancel_injection; > } > > + if (vcpu->kvm->arch.use_master_clock) { > + s64 kernel_ns; > + cycle_t tsc_now, pvclock_ns, boot_ns; > + > + kvm_get_time_and_clockread(&kernel_ns, &tsc_now); > + pvclock_ns = __pvclock_read_cycles(&vcpu->arch.hv_clock, kvm_read_l1_tsc(vcpu, tsc_now)) - vcpu->kvm->arch.kvmclock_offset; > + boot_ns = ktime_get_boot_ns(); > + > + printk("ns diff: %lld %lld\n", pvclock_ns - kernel_ns, boot_ns - kernel_ns); > + } > + > preempt_disable(); > > kvm_x86_ops->prepare_guest_switch(vcpu); Ok, I'll post a v2 of this patch. Paolo