Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3055578rwb; Mon, 16 Jan 2023 03:09:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRhW57hWN5HnIhYLxCD0R0zn+LYM8X1PMnd1TWuEhT36LDelunMMcHUcyVAewFcgjq+FWy X-Received: by 2002:a05:6a21:6d82:b0:ac:f68:d0f8 with SMTP id wl2-20020a056a216d8200b000ac0f68d0f8mr137115792pzb.23.1673867395731; Mon, 16 Jan 2023 03:09:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673867395; cv=none; d=google.com; s=arc-20160816; b=fFY5EXUmd4jqXo7r7St+eoV1kLHGMFqxVs9fydkjdXu/Kc6WCgCQRYvOuLUV6gUnAN LHzOU5tV/fqGWWTalGQrvs1pn6cA/8597SZqKRSH+Fhp5ph9HNv/An8GwikZrPPKCcP2 ReZRZRBkpVSA0Mjz0KqhGvonQG5lf2+FfQ5evYQg46cSZdfCDz7CjKnw4EVyc5OmMzee KwCeIzjTlfMootYKlL2zFZO/WHNedUHNmiVwNPhrln9VjkPPIzwFWqfDT+NRetEpWRyv /ARdNyEQDWfpym5mpcPTQNKf8B/MNxFYwgzji7tVHYPM3jHqaKO43G3HGGB3gkd2Puow tYiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=Y7NHr52aB0vwCApD8lR9SIsxpKBinYgPI2UsdI5nqlU=; b=rSyr7aslDPAuc//QknX2TRhGIEFZx6qMIZ4AtdxM03uAjPeg/RYIHd5dFp/KpfTGxW gSp1W/nlvn075seNVPGnlilirSw4jKc8FHL7stpgj7CijSRavKwYzI84iWyjO5+mTD8g P0fQJ2/3ZYL/7lt/AgKE8hndQDPP3nwYZKQtRVHylS7g5JiQlipF2+Th/Ys2XWXQv3b8 oCmR/jG/4O+QpWOb42B7BEW7aaXUazGu5dPRKranschYHIlV0qNLjrBzvjSAenvORCke inVPeW7die6x+6UCwprJ/ET9GFWf8sbgMov8AuQaY3aETjhuuyewQ/1xLp6LGMG6BYFS rzUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020a63bf08000000b0044cce26fa32si29862533pgf.632.2023.01.16.03.09.49; Mon, 16 Jan 2023 03:09:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbjAPKYw (ORCPT + 51 others); Mon, 16 Jan 2023 05:24:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjAPKYr (ORCPT ); Mon, 16 Jan 2023 05:24:47 -0500 Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8937317CF3; Mon, 16 Jan 2023 02:24:46 -0800 (PST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 142DB2008E1; Mon, 16 Jan 2023 11:24:45 +0100 (CET) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id D16392008DF; Mon, 16 Jan 2023 11:24:44 +0100 (CET) Received: from lsv03267.swis.in-blr01.nxp.com (lsv03267.swis.in-blr01.nxp.com [92.120.147.107]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id CB780183ABEF; Mon, 16 Jan 2023 18:24:43 +0800 (+08) From: nikhil.gupta@nxp.com To: linux-arm-kernel@lists.infradead.org, Yangbo Lu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: vakul.garg@nxp.com, rajan.gupta@nxp.com, richardcochran@gmail.com, Nikhil Gupta Subject: [PATCH v1] ptp_qoriq: fix latency in ptp_qoriq_adjtime() operation. Date: Mon, 16 Jan 2023 15:54:40 +0530 Message-Id: <20230116102440.27189-1-nikhil.gupta@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikhil Gupta 1588 driver loses about 1us in adjtime operation at PTP slave. This is because adjtime operation uses a slow non-atomic tmr_cnt_read() followed by tmr_cnt_write() operation. In the above sequence, since the timer counter operation keeps incrementing, it leads to latency. The tmr_offset register (which is added to TMR_CNT_H/L register gives the current time) must be programmed with the delta nanoseconds. Signed-off-by: Nikhil Gupta Reviewed-by: Yangbo Lu --- drivers/ptp/ptp_qoriq.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/ptp/ptp_qoriq.c b/drivers/ptp/ptp_qoriq.c index 08f4cf0ad9e3..69fa77b99b45 100644 --- a/drivers/ptp/ptp_qoriq.c +++ b/drivers/ptp/ptp_qoriq.c @@ -48,6 +48,29 @@ static void tmr_cnt_write(struct ptp_qoriq *ptp_qoriq, u64 ns) ptp_qoriq->write(®s->ctrl_regs->tmr_cnt_h, hi); } +static void tmr_offset_write(struct ptp_qoriq *ptp_qoriq, u64 delta_ns) +{ + struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; + u32 hi = delta_ns >> 32; + u32 lo = delta_ns & 0xffffffff; + + ptp_qoriq->write(®s->ctrl_regs->tmroff_l, lo); + ptp_qoriq->write(®s->ctrl_regs->tmroff_h, hi); +} + +static u64 tmr_offset_read(struct ptp_qoriq *ptp_qoriq) +{ + struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; + u64 ns; + u32 lo, hi; + + lo = ptp_qoriq->read(®s->ctrl_regs->tmroff_l); + hi = ptp_qoriq->read(®s->ctrl_regs->tmroff_h); + ns = ((u64) hi) << 32; + ns |= lo; + return ns; +} + /* Caller must hold ptp_qoriq->lock. */ static void set_alarm(struct ptp_qoriq *ptp_qoriq) { @@ -55,7 +78,9 @@ static void set_alarm(struct ptp_qoriq *ptp_qoriq) u64 ns; u32 lo, hi; - ns = tmr_cnt_read(ptp_qoriq) + 1500000000ULL; + ns = tmr_cnt_read(ptp_qoriq) + tmr_offset_read(ptp_qoriq) + + 1500000000ULL; + ns = div_u64(ns, 1000000000UL) * 1000000000ULL; ns -= ptp_qoriq->tclk_period; hi = ns >> 32; @@ -212,10 +237,9 @@ int ptp_qoriq_adjtime(struct ptp_clock_info *ptp, s64 delta) struct ptp_qoriq *ptp_qoriq = container_of(ptp, struct ptp_qoriq, caps); spin_lock_irqsave(&ptp_qoriq->lock, flags); - - now = tmr_cnt_read(ptp_qoriq); + now = tmr_offset_read(ptp_qoriq); now += delta; - tmr_cnt_write(ptp_qoriq, now); + tmr_offset_write(ptp_qoriq, now); set_fipers(ptp_qoriq); spin_unlock_irqrestore(&ptp_qoriq->lock, flags); @@ -232,7 +256,7 @@ int ptp_qoriq_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) spin_lock_irqsave(&ptp_qoriq->lock, flags); - ns = tmr_cnt_read(ptp_qoriq); + ns = tmr_cnt_read(ptp_qoriq) + tmr_offset_read(ptp_qoriq); spin_unlock_irqrestore(&ptp_qoriq->lock, flags); @@ -253,6 +277,7 @@ int ptp_qoriq_settime(struct ptp_clock_info *ptp, spin_lock_irqsave(&ptp_qoriq->lock, flags); + tmr_offset_write(ptp_qoriq, 0); tmr_cnt_write(ptp_qoriq, ns); set_fipers(ptp_qoriq); -- 2.17.1