From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: nshettyj@marvell.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Harman Kalra <hkalra@marvell.com>,
Sunil Goutham <sgoutham@marvell.com>,
Ratheesh Kannoth <rkannoth@marvell.com>,
Geetha sowjanya <gakula@marvell.com>,
Subbaraya Sundeep <sbhatta@marvell.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Richard Cochran <richardcochran@gmail.com>
Subject: Re: [PATCH net-next] octeontx2-af: return tsc value along with PTP clock
Date: Fri, 7 Aug 2026 00:00:17 +0100 [thread overview]
Message-ID: <513b009f-9327-4524-98b0-82b83121665a@linux.dev> (raw)
In-Reply-To: <20260806161649.2592484-1-nshettyj@marvell.com>
On 06/08/2026 17:16, nshettyj@marvell.com wrote:
> From: Harman Kalra <hkalra@marvell.com>
>
> This patch updates the existing PTP_OP_GET_CLOCK mbox message to
> return the timestamp counter value, tsc (cntvct_el0 or pmccntr_el0)
> along with the PTP HI clock value.
>
> In some debugging scenarios, a user might need to read the PTP HI
> clock value in the fastpath to know how many ticks have been spent
> since the reception of the packet (as the packet reception tick value
> is already appended to the packet by CGX). If the PTP_OP_GET_CLOCK
> mbox message is sent every time the user wants to record the PTP HI
> clock value, it will bring down performance to a great extent as mbox
> communication is a very expensive process.
>
> To handle this, the PTP HI clock can be derived from the timestamp
> counter (tsc, which could be running at 100MHz or system freq) using
> two parameters: freq multiplier (ratio of frequencies of PTP HI clock
> and tsc) and clock delta (by how much tsc is lagging from PTP HI
> clock).
>
> By returning both the PTP_HI value and the tsc value simultaneously
> via PTP_OP_GET_CLOCK, the consumer can calculate these parameters
> without being affected by mbox propagation delay:
> freq_mult = (freq of PTP HI clock) / (freq of tsc counter)
> clk_delta = (PTP_HI clock value / freq_mult) - (tsc val)
>
> Now, whenever the user wants to know the PTP HI clock in the fastpath,
> it can be derived from the local tsc counter:
> PTP_HI val = (tsc value + clk_delta) * freq_mult
>
> Signed-off-by: Harman Kalra <hkalra@marvell.com>
> Signed-off-by: Nitin Shetty J <nshettyj@marvell.com>
> ---
> .../net/ethernet/marvell/octeontx2/af/mbox.h | 1 +
> .../net/ethernet/marvell/octeontx2/af/ptp.c | 26 ++++++++++++++++---
> 2 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
> index 73f743e4a83d..21c3d3d5018e 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/mbox.h
> @@ -2010,6 +2010,7 @@ struct ptp_req {
> struct mbox_msghdr hdr;
> u8 op;
> s64 scaled_ppm;
> + u8 is_pmu;
> u64 thresh;
> u64 period;
> int pps_on;
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
> index 58e62e955554..0b66a86246b6 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/ptp.c
> @@ -356,10 +356,27 @@ static int ptp_adjfine(struct ptp *ptp, long scaled_ppm)
> return 0;
> }
>
> -static int ptp_get_clock(struct ptp *ptp, u64 *clk)
> +static inline u64 get_tsc(bool is_pmu)
> {
> - /* Return the current PTP clock */
> - *clk = ptp->read_ptp_tstmp(ptp);
> +#if defined(CONFIG_ARM64)
> + return is_pmu ? read_sysreg(pmccntr_el0) : read_sysreg(cntvct_el0);
> +#else
> + return 0;
> +#endif
> +}
> +
> +static int ptp_get_clock(struct ptp *ptp, bool is_pmu, u64 *clk, u64 *tsc)
> +{
> + u64 end, start;
> + u8 retries = 0;
> +
> + do {
> + start = get_tsc(0);
> + *tsc = get_tsc(is_pmu);
> + *clk = ptp->read_ptp_tstmp(ptp);
> + end = get_tsc(0);
> + retries++;
> + } while (((end - start) > 50) && retries < 5);
didn't fully get why do you need this cycle? what are you trying to
avoid?
>
> return 0;
> }
> @@ -636,7 +653,8 @@ int rvu_mbox_handler_ptp_op(struct rvu *rvu, struct ptp_req *req,
> err = ptp_adjfine(rvu->ptp, req->scaled_ppm);
> break;
> case PTP_OP_GET_CLOCK:
> - err = ptp_get_clock(rvu->ptp, &rsp->clk);
> + err = ptp_get_clock(rvu->ptp, req->is_pmu, &rsp->clk,
> + &rsp->tsc);
> break;
> case PTP_OP_GET_TSTMP:
> err = ptp_get_tstmp(rvu->ptp, &rsp->clk);
prev parent reply other threads:[~2026-08-06 23:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 16:16 [PATCH net-next] octeontx2-af: return tsc value along with PTP clock nshettyj
2026-08-06 23:00 ` Vadim Fedorenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=513b009f-9327-4524-98b0-82b83121665a@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=hkalra@marvell.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nshettyj@marvell.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=rkannoth@marvell.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox