DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Soumyadeep Hore <soumyadeep.hore@intel.com>
Cc: <manoj.kumar.subbarao@intel.com>, <aman.deep.singh@intel.com>,
	<dev@dpdk.org>, <rajesh3.kumar@intel.com>
Subject: Re: [PATCH v2] net/idpf: harden PTP frequency adjustment
Date: Tue, 21 Apr 2026 11:49:23 +0100	[thread overview]
Message-ID: <aedWMyQzJ7As4YL5@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20260407200405.1568940-1-soumyadeep.hore@intel.com>

On Tue, Apr 07, 2026 at 04:04:05PM -0400, Soumyadeep Hore wrote:
> Normalize ppm to an unsigned magnitude before using it in the
> increment value scaling path.
> 
> This avoids negating INT64_MIN and also prevents subtracting 62
> from the reduced log sum unless the sum is still above the
> overflow threshold reported by Coverity.
> 
> Coverity issue: 501832
> 
> Signed-off-by: Soumyadeep Hore <soumyadeep.hore@intel.com>
> ---
> v2:
> -Addressed Bruce's comments
> ---

The code is a lot cleaner, but unfortunately the 32-bit builds are failing
due to a lack of 128-bit type. I'd suggest keeping thge 128-bit calculation
for simplicity on 64-bit platforms, and maybe adding back your original
calculation for 32-bit systems.

/Bruce

>  drivers/net/intel/idpf/idpf_ethdev.c | 38 ++++------------------------
>  1 file changed, 5 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/net/intel/idpf/idpf_ethdev.c b/drivers/net/intel/idpf/idpf_ethdev.c
> index 5e57a45775..23a2af6332 100644
> --- a/drivers/net/intel/idpf/idpf_ethdev.c
> +++ b/drivers/net/intel/idpf/idpf_ethdev.c
> @@ -1005,42 +1005,14 @@ idpf_timesync_adjust_freq(struct rte_eth_dev *dev, int64_t ppm)
>  	struct idpf_vport *vport = dev->data->dev_private;
>  	struct idpf_adapter *adapter = vport->adapter;
>  	struct idpf_ptp *ptp = adapter->ptp;
> -	int64_t incval, diff = 0;
> -	bool negative = false;
> -	uint64_t div, rem;
> -	uint64_t divisor = 1000000ULL << 16;
> -	int shift;
> +	uint64_t incval;
> +	__int128 diff;
>  	int ret;
>  
> +	/* ppm is scaled by 2^16 to match Linux adjfine. */
>  	incval = ptp->base_incval;
> -
> -	if (ppm < 0) {
> -		negative = true;
> -		ppm = -ppm;
> -	}
> -
> -	/* can incval * ppm overflow ? */
> -	if (rte_log2_u64(incval) + rte_log2_u64(ppm) > 62) {
> -		rem = ppm % divisor;
> -		div = ppm / divisor;
> -		diff = div * incval;
> -		ppm = rem;
> -
> -		shift = rte_log2_u64(incval) + rte_log2_u64(ppm) - 62;
> -		if (shift > 0) {
> -			/* drop precision */
> -			ppm >>= shift;
> -			divisor >>= shift;
> -		}
> -	}
> -
> -	if (divisor)
> -		diff = diff + incval * ppm / divisor;
> -
> -	if (negative)
> -		incval -= diff;
> -	else
> -		incval += diff;
> +	diff = ((__int128)incval * ppm) / (1000000LL << 16);
> +	incval += (int64_t)diff;
>  
>  	ret = idpf_ptp_adj_dev_clk_fine(adapter, incval);
>  	if (ret) {
> -- 
> 2.47.1
> 

  reply	other threads:[~2026-04-21 10:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 18:43 [PATCH v1] net/idpf: harden PTP frequency adjustment Soumyadeep Hore
2026-03-12 11:57 ` Bruce Richardson
2026-04-07 15:14   ` Stephen Hemminger
2026-04-07 15:56     ` Bruce Richardson
2026-04-07 20:04 ` [PATCH v2] " Soumyadeep Hore
2026-04-21 10:49   ` Bruce Richardson [this message]
2026-05-06 20:41   ` [PATCH v3] " Soumyadeep Hore

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=aedWMyQzJ7As4YL5@bricha3-mobl1.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=manoj.kumar.subbarao@intel.com \
    --cc=rajesh3.kumar@intel.com \
    --cc=soumyadeep.hore@intel.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