From patchwork Tue Aug 13 12:56:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciek Machnikowski X-Patchwork-Id: 13761994 X-Patchwork-Delegate: kuba@kernel.org Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78C8F19CCEB for ; Tue, 13 Aug 2024 12:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723553781; cv=pass; b=QjpgkDXmBCAH+ooGs7JfQXuoxQN707kZx6f7aOflvTGCOo1z7XwKIBr78NDeMTctILQ8CtVjWW+84sZMeiiMOD8s5GEJ0lmwG5NwMjqR9mjinm8vOSMEE2lbuiVYXxKRMXdEIokRcEEKTys2AnyL7FbrYF+5i7JaAtxe/y4UvHM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723553781; c=relaxed/simple; bh=x3eqkVjDGJOI1g3dhzXuFryvDbHTzYbhfzIJzBqlJuU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LoI6p65Xh8FjbT4SGk5siYnl/W9OAholxhPv43UliKcMzMw0t3Yr0Up8BxZQUd9H7FVvhMSCl6omVEiHlJkrGWK14sbqbMkZ899dfoKaaLyw4KMNzZWxl8CEvu/bBgKdsUs3pvumqNKBwCLQJkqoBmI88RN5+6To96J9Vv1USRQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=machnikowski.net; spf=pass smtp.mailfrom=machnikowski.net; dkim=pass (2048-bit key) header.d=machnikowski.net header.i=maciek@machnikowski.net header.b=hOhWombx; arc=pass smtp.client-ip=136.143.188.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=machnikowski.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=machnikowski.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=machnikowski.net header.i=maciek@machnikowski.net header.b="hOhWombx" ARC-Seal: i=1; a=rsa-sha256; t=1723553773; cv=none; d=zohomail.com; s=zohoarc; b=iqvqBBYIrNivtdV90vdcpacqxwHGYrWrsfuOYxLjpB/nzQuZbC+N4uemELAt1ooVwrGkj9DsN6AjnMamkmDlFMV51CNxAVU3wEJaJTUGayoU4gCBKjeSTxBGkfaes6RyvGcagGpTxMSUp1G8chUmr4B1Gjpqv0rYTBFuMEOfZNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723553773; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=C3WRiby8Wq8K7hvlbeM8eLrIDuE2Hz1HiitaBp9tZok=; b=PZAuJW4u9cRMlRaBf8Oaapfo8dXMqF9EPhoX/wLyRrvBM28Ps1+Wh7W0BPeOjIst/6GgJWzfMgGWMCwRni2w5nW5nPT3mnyQj7QB+Wdi4F6sj+UZ3j38o+ra6SDebgae5rOK1g1VxebdVwo5VD6tjl6bYI2eROTY6ObMYIeG0Rw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=machnikowski.net; spf=pass smtp.mailfrom=maciek@machnikowski.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1723553773; s=zoho; d=machnikowski.net; i=maciek@machnikowski.net; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=C3WRiby8Wq8K7hvlbeM8eLrIDuE2Hz1HiitaBp9tZok=; b=hOhWombxE36+Fps57cRvIBa+AQ943ilRxtTAuGONb/gy4T0TXooS7V6AtM2UCKQj qyI9pQaxzqfbHIZMLz8IHZKo+eau/kFc5cnC01DzMMmgNBcmWjEzY2NPbj7pf8/vJTI dv/13AkZzH0zVJ+OhND5yAqvUgENEGetlaOsZy3RY2X4P7dnjNxB7ZYvcaKhFyrLZia V92PklRhgU1/9bfPyjGUrXfdVHewe4sJV94pk+gKF2CBcwY3UWA3mJjcQiIgZ9fnQEF 71tXwSc+EvU/PhgsmizJerWu2WGsOXSAHuGmRzdpWXQF5GtWDRlF/EC+lNUxN5WOT3Q XPBE3HHsLQ== Received: by mx.zohomail.com with SMTPS id 172355377056920.89656851491634; Tue, 13 Aug 2024 05:56:10 -0700 (PDT) From: Maciek Machnikowski To: maciek@machnikowski.net Cc: netdev@vger.kernel.org, richardcochran@gmail.com, jacob.e.keller@intel.com, vadfed@meta.com, darinzon@amazon.com, kuba@kernel.org Subject: [RFC 1/3] ptp: Implement timex esterror support Date: Tue, 13 Aug 2024 12:56:00 +0000 Message-Id: <20240813125602.155827-2-maciek@machnikowski.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240813125602.155827-1-maciek@machnikowski.net> References: <20240813125602.155827-1-maciek@machnikowski.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ZohoMailClient: External X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The Timex structure returned by the clock_adjtime() POSIX API allows the clock to return the estimated error. Implement getesterror and setesterror functions in the ptp_clock_info to enable drivers to interact with the hardware to get the error information. getesterror additionally implements returning hw_ts and sys_ts to enable upper layers to estimate the maximum error of the clock based on the last time of correction. This functionality is not directly implemented in the clock_adjtime and will require a separate interface in the future. Signed-off-by: Maciek Machnikowski --- drivers/ptp/ptp_clock.c | 18 +++++++++++++++++- include/linux/ptp_clock_kernel.h | 11 +++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index c56cd0f63909..2cb1f6af60ea 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -164,9 +164,25 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx) err = ops->adjphase(ops, offset); } + } else if (tx->modes & ADJ_ESTERROR) { + if (ops->setesterror) + if (tx->modes & ADJ_NANO) + err = ops->setesterror(ops, tx->esterror * 1000); + else + err = ops->setesterror(ops, tx->esterror); } else if (tx->modes == 0) { + long esterror; + tx->freq = ptp->dialed_frequency; - err = 0; + if (ops->getesterror) { + err = ops->getesterror(ops, &esterror, NULL, NULL); + if (err) + return err; + tx->modes &= ADJ_NANO; + tx->esterror = esterror; + } else { + err = 0; + } } return err; diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 6e4b8206c7d0..e78ea81fc4cf 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -136,6 +136,14 @@ struct ptp_system_timestamp { * parameter cts: Contains timestamp (device,system) pair, * where system time is realtime and monotonic. * + * @getesterror: Reads the current error estimate of the hardware clock. + * parameter phase: Holds the error estimate in nanoseconds. + * parameter hw_ts: If not NULL, holds the timestamp of the hardware clock. + * parameter sw_ts: If not NULL, holds the timestamp of the CPU clock. + * + * @setesterror: Set the error estimate of the hardware clock. + * parameter phase: Desired error estimate in nanoseconds. + * * @enable: Request driver to enable or disable an ancillary feature. * parameter request: Desired resource to enable or disable. * parameter on: Caller passes one to enable or zero to disable. @@ -188,6 +196,9 @@ struct ptp_clock_info { struct ptp_system_timestamp *sts); int (*getcrosscycles)(struct ptp_clock_info *ptp, struct system_device_crosststamp *cts); + int (*getesterror)(struct ptp_clock_info *ptp, long *phase, + struct timespec64 *hw_ts, struct timespec64 *sys_ts); + int (*setesterror)(struct ptp_clock_info *ptp, long phase); int (*enable)(struct ptp_clock_info *ptp, struct ptp_clock_request *request, int on); int (*verify)(struct ptp_clock_info *ptp, unsigned int pin, From patchwork Tue Aug 13 12:56:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciek Machnikowski X-Patchwork-Id: 13761995 X-Patchwork-Delegate: kuba@kernel.org Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0A5319B580 for ; Tue, 13 Aug 2024 12:56:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723553782; cv=pass; b=HEVRAxc4l2sMKS004C8T3BqA1Bm/l66A7JBgvGhaRZULJT2ORy7gPShDwBUDywMofHUJiiYCAKaSX/FejE8gc88SkbDdKqlnhRhKy1CTsFEhosOr1u4QCiudkIamyJ3kNDCE2S9DIk0W0QldkQmYPYwyLIUH6jWAoFJJx3FmX0w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723553782; c=relaxed/simple; bh=csLIXwhzVMKXxdpYpS2z2tH4FIquiExDW33a5MAsjlk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eLPYP/LoWJqd6uK3wMmxD8ONGw0yVW8E/TDCCZHyCH0g+946WveXDgFqFllL4A2YNlua30cjUMYuvMfV85FxA+OjLo8wjD6B5+YN2wBsKUADlsUaRe6qhVa/xBgxOJMPMlaee2rQK+gK3ilmctQ59Bj4xEJMO8yIWJp6qug5tHY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=machnikowski.net; spf=pass smtp.mailfrom=machnikowski.net; dkim=pass (2048-bit key) header.d=machnikowski.net header.i=maciek@machnikowski.net header.b=WnjhTiWo; arc=pass smtp.client-ip=136.143.188.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=machnikowski.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=machnikowski.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=machnikowski.net header.i=maciek@machnikowski.net header.b="WnjhTiWo" ARC-Seal: i=1; a=rsa-sha256; t=1723553774; cv=none; d=zohomail.com; s=zohoarc; b=GM6Ga5kUKy2MIaQMV++lyPuVVJQCHH3citrF6WXZWGTyJoRxkSZ+OLuJE4MfAcpk/hdamp7ehG60nv4SaWtc0yg9TkdU48PJpTs0yqDM0aQnrJWfzwpjmdWSPu8HyRObEliG0l1MiINF9gyfRneazKfRF5OdqHOj53T03PBomgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723553774; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=vMibIEdDAvusM9BkQQAIy/PeiFmeVAawxS4pM2gWLDA=; b=Hm1e3tC4BRXWIHXElhRxm5Y7hen7B1rckec0qlutuCkIf5wcRgndotag5YNe5KauSjdA0m834PMKJ4q7Q+joI6ynGBbALL2NJd1HpZk1IR+F17dB4k6KF2qS/q4UQ5X1g7RAceXP5LGIoUeMhKjRdRXtvRu8c1L1y+z6d3Uz4+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=machnikowski.net; spf=pass smtp.mailfrom=maciek@machnikowski.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1723553774; s=zoho; d=machnikowski.net; i=maciek@machnikowski.net; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=vMibIEdDAvusM9BkQQAIy/PeiFmeVAawxS4pM2gWLDA=; b=WnjhTiWo6UXXrokND5khgeY0cpSrDr+xmSp/dQTGVj+3FAqltYGlt/RiCIP40qHJ 6x4DNmX0nvwcG3z2t2pEGifILKHOhxkE/C+gp/obJLZsoMWuLzRJtaPUkAym6CIvF/r hDhITF4Bc5FWnzPxGSsQIMq1yx3k2U9HYItandcXGzufCWObce+C4ykU7Aa6aCO7dX8 PPdeCI33Q2654wBbpVoDy0WVc1UgIxF4dtL/78SJ+umBuunVo8hHUQgcEISKH+I0rc8 rb618h5gJZSIIkzwQR8XvQKFfMLxQ0OViTtBLEb/pPcpeaUEmQffwdWMwdchS+oJwQb HXSisM6eWQ== Received: by mx.zohomail.com with SMTPS id 1723553773143674.3065954727515; Tue, 13 Aug 2024 05:56:13 -0700 (PDT) From: Maciek Machnikowski To: maciek@machnikowski.net Cc: netdev@vger.kernel.org, richardcochran@gmail.com, jacob.e.keller@intel.com, vadfed@meta.com, darinzon@amazon.com, kuba@kernel.org Subject: [RFC 2/3] ptp: Implement support for esterror in ptp_mock Date: Tue, 13 Aug 2024 12:56:01 +0000 Message-Id: <20240813125602.155827-3-maciek@machnikowski.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240813125602.155827-1-maciek@machnikowski.net> References: <20240813125602.155827-1-maciek@machnikowski.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ZohoMailClient: External X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement basic example of handling the esterror using getesterror/setesterror functions of the ptp_clock_info Signed-off-by: Maciek Machnikowski --- drivers/ptp/ptp_mock.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/ptp/ptp_mock.c b/drivers/ptp/ptp_mock.c index e7b459c846a2..1786da790f82 100644 --- a/drivers/ptp/ptp_mock.c +++ b/drivers/ptp/ptp_mock.c @@ -35,10 +35,13 @@ struct mock_phc { struct ptp_clock_info info; + struct timespec64 sys_ts; + struct timespec64 hw_ts; struct ptp_clock *clock; struct timecounter tc; struct cyclecounter cc; spinlock_t lock; + long esterror; }; static u64 mock_phc_cc_read(const struct cyclecounter *cc) @@ -100,6 +103,31 @@ static int mock_phc_gettime64(struct ptp_clock_info *info, struct timespec64 *ts return 0; } +static int mock_phc_getesterror(struct ptp_clock_info *info, long *esterror, + struct timespec64 *hw_ts, struct timespec64 *sys_ts) +{ + struct mock_phc *phc = info_to_phc(info); + + *esterror = phc->esterror; + if (hw_ts) + *hw_ts = phc->hw_ts; + if (sys_ts) + *sys_ts = phc->sys_ts; + + return 0; +} + +static int mock_phc_setesterror(struct ptp_clock_info *info, long esterror) +{ + struct mock_phc *phc = info_to_phc(info); + + phc->esterror = esterror; + phc->hw_ts = ns_to_timespec64(timecounter_read(&phc->tc)); + phc->sys_ts = ns_to_timespec64(ktime_get_raw_ns()); + + return 0; +} + static long mock_phc_refresh(struct ptp_clock_info *info) { struct timespec64 ts; @@ -134,6 +162,8 @@ struct mock_phc *mock_phc_create(struct device *dev) .adjtime = mock_phc_adjtime, .gettime64 = mock_phc_gettime64, .settime64 = mock_phc_settime64, + .getesterror = mock_phc_getesterror, + .setesterror = mock_phc_setesterror, .do_aux_work = mock_phc_refresh, }; From patchwork Tue Aug 13 12:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciek Machnikowski X-Patchwork-Id: 13761996 Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4B8819AD8D for ; Tue, 13 Aug 2024 12:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723553787; cv=pass; b=QdjUmK6HB0rS3ymtYbSlLP7nkrhhSMjDwXUqZIG/H1uY7M/bkaT6YrFyHpXhpuXUa19va5U1sEQoFOGfOuamWO4qCZ+cXeu0GduzjSCkiJy18vfkFZSmUorF9azefc8sAyn2d/KiJesBs6nf12PZJCyT41DFFus5WVAzCsi/XaY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723553787; c=relaxed/simple; bh=dRKKVpf7HNPCUgSlJykr6sV1dSg68HuKwGhQyF/66tg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RngAadTwCnV2eAOXTLSlCEYY/om4NJb2HIscBHDF0V7foWBWGLSc1h7jJ/kn6eptSWCLCDfUQKchxz5D27Ht/lFiZXkICkdqkxloIzw+7bOhz0fRTh0P3WnaIlFmH5yyJI3gRr5oVi/i5Kn/2PzDOhQ702UaMVoWYF1OCyK8tLE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=machnikowski.net; spf=pass smtp.mailfrom=machnikowski.net; dkim=pass (2048-bit key) header.d=machnikowski.net header.i=maciek@machnikowski.net header.b=pmj3izJ7; arc=pass smtp.client-ip=136.143.188.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=machnikowski.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=machnikowski.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=machnikowski.net header.i=maciek@machnikowski.net header.b="pmj3izJ7" ARC-Seal: i=1; a=rsa-sha256; t=1723553777; cv=none; d=zohomail.com; s=zohoarc; b=NhSn3oVXwo3IUXMhGk7Tw+xDSKnItdyeRn1ZRnNdKOxdplZ1P0kMvov8CxGm50zt5rI6A8nJTC2RoRJLlSnkTb6j7TCnFHNyQuIq7x3zzXYF9nkbxRYt7Oqf3C6+oZZsKtiPnmewcPlMzDKGN3VNzRQyLUCbOE1cy/HorwiJchs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723553777; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=5KzrrdkmMb5M8nz9an5gcqE+De9mYbddjo+yWqmV+7w=; b=dTfRRCJdtMiE1NenJxtmiEHoGUugWjro/rUImZCllJCzjY7x4Q4x+nYnn3KS5K5DtdUdG1VsJ/1m6jXQRWpsXmxs2lCkm7ppVk9yMe+9lWfYc2S25tAY8hkC08BZAJDk34wfLPlwQQEzjaRmwsteoqCzcdB37rWI759vL7cuJAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=machnikowski.net; spf=pass smtp.mailfrom=maciek@machnikowski.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1723553777; s=zoho; d=machnikowski.net; i=maciek@machnikowski.net; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=5KzrrdkmMb5M8nz9an5gcqE+De9mYbddjo+yWqmV+7w=; b=pmj3izJ77kBfH68tbG94UL16akNz6BV2h07xdpJr/wbowncGFFv2uGC8bTif1IjR 0dQSOMJTVPSOqmtaBlRnO52EeWDv9QHnwb+fITagDtFCFcPwP7vK+VOrQknaRa8+Uq+ 8r71h4aNXZqYwZD/uXX2vXJrY8wba3ay/3dwLG2XgNevo6GHYABFn2DpY8kyeHaynja suypLKagEuAqFBW2PtXgSe5jjAaFJeoATpYuAWhm0Fuuow3DvtF3NbNx3Lva3+fJ6u3 E1h/3gPSpW3tGOox/JMciFpISXOvTwegUDcCFRa+c7pL2+ikxMytaBVoMOZVjqmrV8K olMYFGMQUQ== Received: by mx.zohomail.com with SMTPS id 17235537763111005.0319638378652; Tue, 13 Aug 2024 05:56:16 -0700 (PDT) From: Maciek Machnikowski To: maciek@machnikowski.net Cc: netdev@vger.kernel.org, richardcochran@gmail.com, jacob.e.keller@intel.com, vadfed@meta.com, darinzon@amazon.com, kuba@kernel.org Subject: [RFC 3/3] ptp: Add setting esterror and reading timex structure Date: Tue, 13 Aug 2024 12:56:02 +0000 Message-Id: <20240813125602.155827-4-maciek@machnikowski.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240813125602.155827-1-maciek@machnikowski.net> References: <20240813125602.155827-1-maciek@machnikowski.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ZohoMailClient: External X-Patchwork-State: RFC Implement setting the esterror using clock_adjtime for ptp clocks and reading the clock setting using timex structure and clock_adjtime Signed-off-by: Maciek Machnikowski --- tools/testing/selftests/ptp/testptp.c | 39 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c index 011252fe238c..38405803b881 100644 --- a/tools/testing/selftests/ptp/testptp.c +++ b/tools/testing/selftests/ptp/testptp.c @@ -117,6 +117,7 @@ static void usage(char *progname) { fprintf(stderr, "usage: %s [options]\n" + " -a val adjust the estimated error by 'val' ns\n" " -c query the ptp clock's capabilities\n" " -d name device to open\n" " -e val read 'val' external time stamp events\n" @@ -140,6 +141,7 @@ static void usage(char *progname) " -H val set output phase to 'val' nanoseconds (requires -p)\n" " -w val set output pulse width to 'val' nanoseconds (requires -p)\n" " -P val enable or disable (val=1|0) the system clock PPS\n" + " -r read clock info in the timex structure using clock_adjtime\n" " -s set the ptp clock time from the system time\n" " -S set the system time from the ptp clock time\n" " -t val shift the ptp clock time by 'val' seconds\n" @@ -175,12 +177,14 @@ int main(int argc, char *argv[]) int adjns = 0; int adjphase = 0; int capabilities = 0; + long esterror = 0; int extts = 0; int flagtest = 0; int gettime = 0; int index = 0; int list_pins = 0; int pct_offset = 0; + int readclk = 0; int getextended = 0; int getcross = 0; int n_samples = 0; @@ -198,8 +202,11 @@ int main(int argc, char *argv[]) progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt(argc, argv, "cd:e:f:F:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) { + while (EOF != (c = getopt(argc, argv, "a:cd:e:f:F:ghH:i:k:lL:n:o:p:P:rsSt:T:w:x:Xz"))) { switch (c) { + case 'a': + esterror = atoi(optarg); + break; case 'c': capabilities = 1; break; @@ -250,6 +257,9 @@ int main(int argc, char *argv[]) case 'P': pps = atoi(optarg); break; + case 'r': + readclk = 1; + break; case 's': settime = 1; break; @@ -290,7 +300,6 @@ int main(int argc, char *argv[]) return -1; } } - fd = open(device, O_RDWR); if (fd < 0) { fprintf(stderr, "opening %s: %s\n", device, strerror(errno)); @@ -621,6 +630,32 @@ int main(int argc, char *argv[]) } } + if (esterror) { + memset(&tx, 0, sizeof(tx)); + tx.modes = ADJ_ESTERROR; + tx.esterror = esterror; + if (clock_adjtime(clkid, &tx)) + perror("clock_adjtime"); + else + puts("esterror adjustment okay"); + } + + if (readclk) { + struct timex clk_info = {0}; + + memset(&tx, 0, sizeof(tx)); + if (clock_adjtime(clkid, &tx)) { + perror("clock_adjtime"); + } else { + printf("clock_adjtime:\n" + "\tstatus %d,\n" + "\toffset %ld,\n" + "\tfreq %ld,\n" + "\testerror %ld\n", + tx.status, tx.offset, tx.freq, tx.esterror); + } + } + close(fd); return 0; }