From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752822AbdARPwf (ORCPT ); Wed, 18 Jan 2017 10:52:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39868 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751834AbdARPwd (ORCPT ); Wed, 18 Jan 2017 10:52:33 -0500 Subject: Re: [patch 3/3] PTP: add kvm PTP driver To: Marcelo Tosatti References: <20170116194715.GA8017@amt.cnet> <20170116200112.GB8739@amt.cnet> <20170117080327.GG14227@localhost> <20170117113052.GA27759@amt.cnet> <20170117153621.GE31452@potion> <20170118121738.GA14832@amt.cnet> <20170118122456.GC13762@amt.cnet> <94a761cb-8bcd-e1a6-d07e-02fedc423e33@redhat.com> <20170118133614.GK14227@localhost> <255c35c1-4400-7e52-8cb0-bf5a344e9f74@redhat.com> <20170118144955.GC9713@amt.cnet> Cc: Miroslav Lichvar , Radim Krcmar , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Cochran From: Paolo Bonzini Message-ID: Date: Wed, 18 Jan 2017 16:45:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170118144955.GC9713@amt.cnet> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 18 Jan 2017 15:45:12 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/01/2017 15:50, Marcelo Tosatti wrote: >> Interesting idea! For this to work, KVM needs to implement >> getcrosstimestamp and ptp_chardev.c can then add an alternative >> implementation of PTP_SYS_OFFSET, based on precise cross timestamps. >> >> Something like >> >> for (i = 0; i <= sysoff->n_samples; i++) { >> // ... call getcrosststamp ... >> sysns = ktime_to_ns(xtstamp.sys_realtime); >> if (i > 0) { >> devns = ktime_to_ns(xtstamp.device); >> devns -= (sysns - prev_sysns) / 2; >> devts = ns_to_timespec(devns); >> pct->sec = devts.tv_sec; >> pct->nsec = devts.tv_nsec; >> pct++; >> } >> systs = ns_to_timespec(sysns); >> pct->sec = ts.tv_sec; >> pct->nsec = ts.tv_nsec; >> pct++; >> prev_sysns = sysns; >> } >> >> Marcelo, can you give it a try? > > Can convert fine, but problem is the simultaneous read > of host and guest clocks. Could the TSC from the hypercall be applied to kvmclock to do this? My understanding is that get_device_system_crosststamp (which is used in the sole in-tree implementation of getcrosststamp) already contains all the logic to do that. Paolo