Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3823089ybl; Tue, 20 Aug 2019 02:50:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHjHZrW79RQ1ksO1ljzfXxNbHxOcUq+kOcXzvCH8pMwAsIUqqDq3C3P1gSvqEXcPfNsa1y X-Received: by 2002:a63:204b:: with SMTP id r11mr23934070pgm.121.1566294637885; Tue, 20 Aug 2019 02:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566294637; cv=none; d=google.com; s=arc-20160816; b=k65V82tw1WXD24Ytab4HaCJ96FxmObupEb1VV2U8Ums5t52zSHZQaFqSRR/3/DYanH /n3rF38XAsnK/Hr4rZywUI6Laa3qh14qApW0Yx/bQIrd2KTuYvbdM10ScVnNCOS0nGbu TKWjP0W2r0Cl/oFEzG8+zwkS6UNKzkVIsXjIwRM1nih1pva9bIe9jy/wi8ZO6dfoKth0 4ugaB+2fD5RnalYzU5AA0dLLfDmSLMfnL8x1aSpLW2tqNj5rhZUeomELMzaJn1194XUf ftMafKZj4ffSfth21pp5otGP6joCQ1KqrnpytN1Ttk7+Cc9GfmI6lqw9FL8h63I1PBxS NAnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=73/YAGaQkCzi0LBM/sIC3YJVdhyyOmyWEjtRTjSe+Qg=; b=0TcCubraKyq/MlTiYRG6A/eMtlqQfuXPbo2Sieso+ZkslgwTZf76fYQj+iicsDmAhG hzGUJK5RIMYdgt5V0gDirH1cTCz7O2AnbwOEaHsktYJpROcDSxu/Ma50Ho/XF2YEhyjO tY66tbAgFy2/85feJcyuQ0eTjOrMjdXw1zX2EOrdpOHtxqGOhIIdhkA6KkaqOXnweb6H bCUm+u0r5r1xAE6bqU4hcsNhVLbb5fZ6DnhO82Sej03+8ifVvypMnskgoQJJCj5o/ftA ZQHAXDi32lBXAzpI8jgC2Q8tNuxFUfjiluZbT2bJVXrzcSuXRXkddJs3gLaxTGpl9FWd I72Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h194si12724407pfe.144.2019.08.20.02.50.22; Tue, 20 Aug 2019 02:50:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729567AbfHTJtJ (ORCPT + 99 others); Tue, 20 Aug 2019 05:49:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59180 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728426AbfHTJtI (ORCPT ); Tue, 20 Aug 2019 05:49:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 642362F3670; Tue, 20 Aug 2019 09:49:08 +0000 (UTC) Received: from localhost (holly.tpb.lab.eng.brq.redhat.com [10.43.134.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 787376092F; Tue, 20 Aug 2019 09:49:06 +0000 (UTC) Date: Tue, 20 Aug 2019 11:49:03 +0200 From: Miroslav Lichvar To: Hubert Feurstein Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn , Richard Cochran , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , "David S. Miller" Subject: Re: [PATCH net-next v3 2/4] net: mdio: add PTP offset compensation to mdiobus_write_sts Message-ID: <20190820094903.GI891@localhost> References: <20190820084833.6019-1-hubert.feurstein@vahle.at> <20190820084833.6019-3-hubert.feurstein@vahle.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190820084833.6019-3-hubert.feurstein@vahle.at> User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 20 Aug 2019 09:49:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 20, 2019 at 10:48:31AM +0200, Hubert Feurstein wrote: > + /* PTP offset compensation: > + * After the MDIO access is completed (from the chip perspective), the > + * switch chip will snapshot the PHC timestamp. To make sure our system > + * timestamp corresponds to the PHC timestamp, we have to add the > + * duration of this MDIO access to sts->post_ts. Linuxptp's phc2sys > + * takes the average of pre_ts and post_ts to calculate the final > + * system timestamp. With this in mind, we have to add ptp_sts_offset > + * twice to post_ts, in order to not introduce an constant time offset. > + */ > + if (sts) > + timespec64_add_ns(&sts->post_ts, 2 * bus->ptp_sts_offset); This correction looks good to me. Is the MDIO write delay constant in reality, or does it at least have an upper bound? That is, is it always true that the post_ts timestamp does not point to a time before the PHC timestamp was actually taken? This is important to not break the estimation of maximum error in the measured offset. Applications using the ioctl may assume that the maximum error is (post_ts-pre_ts)/2 (i.e. half of the delay printed by phc2sys). That would not work if the delay could be occasionally 50 microseconds for instance, i.e. the post_ts timestamp would be earlier than the PHC timestamp. -- Miroslav Lichvar