From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751190AbdAWNoP (ORCPT ); Mon, 23 Jan 2017 08:44:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52470 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750726AbdAWNoO (ORCPT ); Mon, 23 Jan 2017 08:44:14 -0500 Date: Mon, 23 Jan 2017 11:19:17 -0200 From: Marcelo Tosatti To: Richard Cochran Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Radim Krcmar , Miroslav Lichvar Subject: Re: [patch 4/5] PTP: add PTP_SYS_OFFSET emulation via cross timestamps infrastructure Message-ID: <20170123131913.GA28104@amt.cnet> References: <20170120122025.665985919@redhat.com> <20170120122503.746158230@redhat.com> <20170120202502.GA10368@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170120202502.GA10368@localhost.localdomain> User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 23 Jan 2017 13:38:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 20, 2017 at 09:25:02PM +0100, Richard Cochran wrote: > On Fri, Jan 20, 2017 at 10:20:29AM -0200, Marcelo Tosatti wrote: > > Emulate PTP_SYS_OFFSET by using an arithmetic mean of the > > realtime samples from ->getcrosststamp callback. > > This change log is not very informative. > > Yes, I can see that the new code calculates a mean. > > But WHY is this needed? This is needed to generate the PTP_SYS_OFFSET data: a table with read from realtime clock, read from device clock, read from realtime clock, ... : time -> device clock | |sample2| |sample4| |sample6| ... ------------------------------------------------------------- realtime clock |sample1| |sample3| |sample5| Where sampleN is the read of the respective clock. >>From the following PTP_SYS_OFFSET_PRECISE data: device clock |sample1P,deviceclock| |sample2P,deviceclock| ------------------------------------------------------------- realtime clock |sample1P,realtimeclock| |sample2P,realtimeclock| The mean of {sample2P,realtimeclock} and {sample1P,realtimeclock} is used to generate sample1 for the realtime clock. > And why is this kvm case so special, that it requires its own new flag > within the generic PHC subsystem? We get PTP_SYS_OFFSET_PRECISE support for users and use that to implement PTP_SYS_OFFSET as well. Other drivers could do the same, as long as their ->getcrosststamp callbacks return PTP synchronized time. Since the clock is moving forward, approximating the clock read at "sample3" with the mean of "sample1" and "sample5" (in the first table above) is a very good approximation.