From mboxrd@z Thu Jan 1 00:00:00 1970 From: Muli Ben-Yehuda Subject: Re: Accessing host TSC from a guest kernel Date: Sun, 26 Sep 2010 13:02:34 +0200 Message-ID: <20100926110234.GA2924@il.ibm.com> References: <4C9C11C7.70202@klipix.org> <4C9F2246.209@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Julien Desfossez , kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mtagate1.uk.ibm.com ([194.196.100.161]:55076 "EHLO mtagate1.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756927Ab0IZLCn (ORCPT ); Sun, 26 Sep 2010 07:02:43 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o8QB2fWl007412 for ; Sun, 26 Sep 2010 11:02:41 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8QB2Zp34018268 for ; Sun, 26 Sep 2010 12:02:41 +0100 Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o8QB2ZNP003985 for ; Sun, 26 Sep 2010 12:02:35 +0100 Content-Disposition: inline In-Reply-To: <4C9F2246.209@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sun, Sep 26, 2010 at 12:36:54PM +0200, Avi Kivity wrote: > On 09/24/2010 04:49 AM, Julien Desfossez wrote: > >Hello, > > > >I'd like to access the host TSC from the inside of a guest kernel > >and I don't really know if it's possible. > > > >I'm working with kvm_clock and I have been playing with the > >pvclock_vcpu_time_info structure, but I'm not sure if I'm in the > >right direction. > > > >So could you tell me if there is an efficient way to access to > >access the host TSC (or at least the TSC_OFFSET) from a module > >inside a guest kernel ? > > > >I did it with an hypercall, but it's for tracing purpose and doing > >an hypercall every time I want to record an event, is way too > >costly. > > It isn't possible. If you need a coherent host/guest timestamp, I > suggest using ktime_get(). I think Avi meant that it isn't possible with stock KVM. If you hack KVM to run the guest with 'RDTSC exiting' set to 0 and either disable 'use TSC offseting' or communicate the TSC offset to the guest out of band, you should have efficient & consistent guest/host timestamps. Cheers, Muli