Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3028242ybh; Mon, 5 Aug 2019 10:41:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOR8dRRXC2nB/Km/0PpH4qcqf1P5g3GeO74iEm6nSYp0rpRFfKLrwIWPY4vvcy+W8yWkyV X-Received: by 2002:a63:595d:: with SMTP id j29mr15640555pgm.134.1565026906117; Mon, 05 Aug 2019 10:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565026906; cv=none; d=google.com; s=arc-20160816; b=gjCAC39YuofuH1vFmHnjkCYqr8K6SS9cQm4rHrpnFzcvoQL1gadLeHksbxR7KMVvnr o1IDIwnOGPW6Tn6CxR4mA/Eh5itUaZlnivyHJDBMozy8Lc22JRDUxptNjM7wQT81xeOV 072wuiQM6xs6eqQ9G304TaryQyLye2Ou5pYE2Z/0V7xvVu4dZFlxMqvWzkDiNZhxu6zU XBOVXnBCxEq0G/kkKwR6pysnbLoVxuvtEXtI18+jtZGbp4Qlw6sdYBo/Gs133pbeeD4Z 41BZI722JyOf4DQxPS3i8wkKf46644ayvC8Xz5NnJWD4oYUSN3Igtf6GJdaFiJ+XEYw/ cMrA== 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:dkim-signature; bh=ebRdmkjcxT+QZN99eIo6Wyjsn+ls17In3FnqQq3wMpY=; b=dnISjiw4mANMEpgxuCgL525iVAHZoSItXugGvKwBUFNTnzBC5zyC3iHUA0HUXArx/t gFnYv23jt/YQa9/kXq+AHcnVS2L5yOTzmjsig+CdoxZLcFm4tTKsfUsyYJh6Cx8WGzAP GPPwdO7QXeP/TVWFZDivaDLjIBDHcqzoLpGT2ELiNxVHqSguAopKdffRXlxpXQdxONhc AWmBCi/nF4AnpnBb62JdhdABOjU8uXeVaqyawL5zhLXy0uD2Ra4Code+0GVYAlR09vvr 3vdBVSXZDr03bBkDbdKvGzeUEila6Lmm0s4UMfPf8/cJ/0IDhAwUn7FgQMHAFTU9c6ee I8wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lunn.ch header.s=20171124 header.b=rbn2dLOE; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t31si13162975pjb.25.2019.08.05.10.41.29; Mon, 05 Aug 2019 10:41:46 -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; dkim=fail header.i=@lunn.ch header.s=20171124 header.b=rbn2dLOE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728898AbfHERkz (ORCPT + 99 others); Mon, 5 Aug 2019 13:40:55 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:35036 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbfHERky (ORCPT ); Mon, 5 Aug 2019 13:40:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ebRdmkjcxT+QZN99eIo6Wyjsn+ls17In3FnqQq3wMpY=; b=rbn2dLOEPu5Rlz2tmKntmy6/+n ZO0gYBXAWtviaY9T44hoiJQfbq9p73NshciENUou+p0F06s1qBQnBJ/XraRllkuve0GzkcucnbOrf ofdlG6MdIKmKHax7ocilJx2/rjCJKVU0nv7s6TP2FU9aIcMD0MTdsXHQjwyiQo6sooW0=; Received: from andrew by vps0.lunn.ch with local (Exim 4.89) (envelope-from ) id 1hugyZ-0000IM-7I; Mon, 05 Aug 2019 19:40:51 +0200 Date: Mon, 5 Aug 2019 19:40:51 +0200 From: Andrew Lunn To: Hubert Feurstein Cc: netdev , lkml , Richard Cochran , Vivien Didelot , Florian Fainelli , "David S. Miller" Subject: Re: [PATCH net-next v2] net: dsa: mv88e6xxx: extend PTP gettime function to read system clock Message-ID: <20190805174051.GW24275@lunn.ch> References: <20190805082642.12873-1-hubert.feurstein@vahle.at> <20190805135838.GF24275@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +static int mv88e6xxx_mdiobus_write_nested(struct mv88e6xxx_chip > *chip, int addr, u32 regnum, u16 val) > +{ > + int err; > + > + BUG_ON(in_interrupt()); > + > + mutex_lock_nested(&chip->bus->mdio_lock, MDIO_MUTEX_NESTED); > + ptp_read_system_prets(chip->ptp_sts); > + err = __mdiobus_write(chip->bus, addr, regnum, val); > + ptp_read_system_postts(chip->ptp_sts); > + mutex_unlock(&chip->bus->mdio_lock); > + > + return err; > +} > + > static int mv88e6xxx_smi_direct_write(struct mv88e6xxx_chip *chip, > int dev, int reg, u16 data) > { > int ret; > > - ret = mdiobus_write_nested_ptp(chip->bus, dev, reg, data, > chip->ptp_sts); > + ret = mv88e6xxx_mdiobus_write_nested(chip, dev, reg, data); > if (ret < 0) > return ret; > > The result was: > Min: -8052 > Max: 9988 > StdDev: 2490.17 > Count: 3592 > > It got improved, but you still have the unpredictable latencies caused by the > mdio_done-completion (=> wait_for_completion_timeout) in imx_fec. O.K. So lets think about a more generic solution we can use inside the mdio bus driver. I don't know if adding an sts pointer to struct device will be accepted. But adding one to struct mii_bus should be O.K. It can be assigned to once the mdio_lock is taken, to avoid race conditions. Add mdio_ptp_read_system_prets(bus) and mdio_ptp_read_system_postts(bus) which the bus driver can use. We also need a fallback in case the bus driver does not use them, so something like: mdiobus_write_sts(...) { int retval; BUG_ON(in_interrupt()); mutex_lock(&bus->mdio_lock); bus->sts = sts; sts->post_ts = 0; ktime_get_real_ts64(&sts->pre_ts); retval = __mdiobus_write(bus, addr, regnum, val); if (!sts->post_ts) ktime_get_real_ts64(sts->post_ts) bus->sts = NULL; mutex_unlock(&bus->mdio_lock); return retval; } So at worse case, we get the time around the whole write operation, but the MDIO bus driver can overwrite the pre_ts and set post_ts, using mdio_ptp_read_system_prets(bus) and mdio_ptp_read_system_postts(bus). A similar scheme could be implemented to SPI devices, if the SPI maintainer would accepted a sts pointer in the SPI bus driver structure. Andrew