diff mbox series

[net-next] mlxsw: update adjfine to use adjust_by_scaled_ppm

Message ID 20221114213701.815132-1-jacob.e.keller@intel.com (mailing list archive)
State Accepted
Commit d82303df06481235fe7cbaf605075e0c2c87e99b
Delegated to: Netdev Maintainers
Headers show
Series [net-next] mlxsw: update adjfine to use adjust_by_scaled_ppm | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: pabeni@redhat.com davem@davemloft.net edumazet@google.com kuba@kernel.org richardcochran@gmail.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jacob Keller Nov. 14, 2022, 9:37 p.m. UTC
The mlxsw adjfine implementation in the spectrum_ptp.c file converts
scaled_ppm into ppb before updating a cyclecounter multiplier using the
standard "base * ppb / 1billion" calculation.

This can be re-written to use adjust_by_scaled_ppm, directly using the
scaled parts per million and reducing the amount of code required to
express this calculation.

We still calculate the parts per billion for passing into
mlxsw_sp_ptp_phc_adjfreq because this function requires the input to be in
parts per billion.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Amit Cohen <amcohen@nvidia.com>
Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Petr Machata <petrm@nvidia.com>
---

Noticed this while investigating conversion of max_adj to scaled PPM format.
This was missed in the previous round of updates that modified drivers to
use the adjust_by_scaled_ppm interface.

 .../net/ethernet/mellanox/mlxsw/spectrum_ptp.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)


base-commit: f12ed9c04804eec4f1819097a0fd0b4800adac2f

Comments

Ido Schimmel Nov. 15, 2022, 9:23 a.m. UTC | #1
On Mon, Nov 14, 2022 at 01:37:01PM -0800, Jacob Keller wrote:
> The mlxsw adjfine implementation in the spectrum_ptp.c file converts
> scaled_ppm into ppb before updating a cyclecounter multiplier using the
> standard "base * ppb / 1billion" calculation.
> 
> This can be re-written to use adjust_by_scaled_ppm, directly using the
> scaled parts per million and reducing the amount of code required to
> express this calculation.
> 
> We still calculate the parts per billion for passing into
> mlxsw_sp_ptp_phc_adjfreq because this function requires the input to be in
> parts per billion.
> 
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Amit Cohen <amcohen@nvidia.com>
> Cc: Ido Schimmel <idosch@nvidia.com>
> Cc: Petr Machata <petrm@nvidia.com>

Thanks for the patch, code looks good to me.

Petr, please apply this patch to our tree for testing.
Petr Machata Nov. 15, 2022, 1:56 p.m. UTC | #2
Ido Schimmel <idosch@nvidia.com> writes:

> On Mon, Nov 14, 2022 at 01:37:01PM -0800, Jacob Keller wrote:
>> The mlxsw adjfine implementation in the spectrum_ptp.c file converts
>> scaled_ppm into ppb before updating a cyclecounter multiplier using the
>> standard "base * ppb / 1billion" calculation.
>> 
>> This can be re-written to use adjust_by_scaled_ppm, directly using the
>> scaled parts per million and reducing the amount of code required to
>> express this calculation.
>> 
>> We still calculate the parts per billion for passing into
>> mlxsw_sp_ptp_phc_adjfreq because this function requires the input to be in
>> parts per billion.
>> 
>> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
>> Cc: Amit Cohen <amcohen@nvidia.com>
>> Cc: Ido Schimmel <idosch@nvidia.com>
>> Cc: Petr Machata <petrm@nvidia.com>
>
> Thanks for the patch, code looks good to me.
>
> Petr, please apply this patch to our tree for testing.

Applied. Jacob, we'll let you know tomorrow whether it exploded.
Ido Schimmel Nov. 16, 2022, 8:01 a.m. UTC | #3
On Mon, Nov 14, 2022 at 01:37:01PM -0800, Jacob Keller wrote:
> The mlxsw adjfine implementation in the spectrum_ptp.c file converts
> scaled_ppm into ppb before updating a cyclecounter multiplier using the
> standard "base * ppb / 1billion" calculation.
> 
> This can be re-written to use adjust_by_scaled_ppm, directly using the
> scaled parts per million and reducing the amount of code required to
> express this calculation.
> 
> We still calculate the parts per billion for passing into
> mlxsw_sp_ptp_phc_adjfreq because this function requires the input to be in
> parts per billion.
> 
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Jakub Kicinski Nov. 16, 2022, 8:20 p.m. UTC | #4
On Wed, 16 Nov 2022 10:01:18 +0200 Ido Schimmel wrote:
> On Mon, Nov 14, 2022 at 01:37:01PM -0800, Jacob Keller wrote:
> > The mlxsw adjfine implementation in the spectrum_ptp.c file converts
> > scaled_ppm into ppb before updating a cyclecounter multiplier using the
> > standard "base * ppb / 1billion" calculation.
> > 
> > This can be re-written to use adjust_by_scaled_ppm, directly using the
> > scaled parts per million and reducing the amount of code required to
> > express this calculation.
> > 
> > We still calculate the parts per billion for passing into
> > mlxsw_sp_ptp_phc_adjfreq because this function requires the input to be in
> > parts per billion.
> > 
> > Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>  
> 
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Tested-by: Ido Schimmel <idosch@nvidia.com>

FTR this patch got marked as 'not applicable' in pw but I'm not sure
why, so applying...
patchwork-bot+netdevbpf@kernel.org Nov. 16, 2022, 8:30 p.m. UTC | #5
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 14 Nov 2022 13:37:01 -0800 you wrote:
> The mlxsw adjfine implementation in the spectrum_ptp.c file converts
> scaled_ppm into ppb before updating a cyclecounter multiplier using the
> standard "base * ppb / 1billion" calculation.
> 
> This can be re-written to use adjust_by_scaled_ppm, directly using the
> scaled parts per million and reducing the amount of code required to
> express this calculation.
> 
> [...]

Here is the summary with links:
  - [net-next] mlxsw: update adjfine to use adjust_by_scaled_ppm
    https://git.kernel.org/netdev/net-next/c/d82303df0648

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
index 7b01b9c20722..cbb6c75a6620 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
@@ -189,29 +189,17 @@  mlxsw_sp1_ptp_phc_settime(struct mlxsw_sp1_ptp_clock *clock, u64 nsec)
 static int mlxsw_sp1_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct mlxsw_sp1_ptp_clock *clock = mlxsw_sp1_ptp_clock(ptp);
-	int neg_adj = 0;
-	u32 diff;
-	u64 adj;
 	s32 ppb;
 
 	ppb = scaled_ppm_to_ppb(scaled_ppm);
 
-	if (ppb < 0) {
-		neg_adj = 1;
-		ppb = -ppb;
-	}
-
-	adj = clock->nominal_c_mult;
-	adj *= ppb;
-	diff = div_u64(adj, NSEC_PER_SEC);
-
 	spin_lock_bh(&clock->lock);
 	timecounter_read(&clock->tc);
-	clock->cycles.mult = neg_adj ? clock->nominal_c_mult - diff :
-				       clock->nominal_c_mult + diff;
+	clock->cycles.mult = adjust_by_scaled_ppm(clock->nominal_c_mult,
+						  scaled_ppm);
 	spin_unlock_bh(&clock->lock);
 
-	return mlxsw_sp_ptp_phc_adjfreq(&clock->common, neg_adj ? -ppb : ppb);
+	return mlxsw_sp_ptp_phc_adjfreq(&clock->common, ppb);
 }
 
 static int mlxsw_sp1_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)