Skip to contentSkip to conversation

mlx5_en: use read sequence for gettimex64

PATCH Applied Vadim Fedorenko 5 participants 5 messages Oct 14, 2024 – Nov 5, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlx5_en: use read sequence for gettimex64

The gettimex64() doesn't modify values in timecounter, that's why there is no need to update sequence counter. Reduce the contention on sequence lock for multi-thread PHC reading use-case.

---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -5
index b306ae79bf97..4822d01123b4 100644
@@ -402,9 +402,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
 			     struct ptp_system_timestamp *sts)
 {
 	struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
-	struct mlx5_timer *timer = &clock->timer;
 	struct mlx5_core_dev *mdev;
-	unsigned long flags;
 	u64 cycles, ns;
 
 	mdev = container_of(clock, struct mlx5_core_dev, clock);
@@ -413,10 +411,8 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
 		goto out;
 	}
 
-	write_seqlock_irqsave(&clock->lock, flags);
 	cycles = mlx5_read_time(mdev, sts, false);
-	ns = timecounter_cyc2time(&timer->tc, cycles);
-	write_sequnlock_irqrestore(&clock->lock, flags);
+	ns = mlx5_timecounter_cyc2time(clock, cycles);
 	*ts = ns_to_timespec64(ns);
 out:
 	return 0;
Signature · 1 line
2.43.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · On Mon, 14 Oct, 2024 10:01:03 -0700 Vadim Fedorenko <[email protected]> wrote:

The gettimex64() doesn't modify values in timecounter, that's why there is no need to update sequence counter. Reduce the contention on sequence lock for multi-thread PHC reading use-case.

---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0 -2
index b306ae79bf97..4822d01123b4 100644
@@ -402,9 +402,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
 			     struct ptp_system_timestamp *sts)
 {
 	struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
-	struct mlx5_timer *timer = &clock->timer;
 	struct mlx5_core_dev *mdev;
-	unsigned long flags;
 	u64 cycles, ns;
 
 	mdev = container_of(clock, struct mlx5_core_dev, clock);
@@ -413,10 +411,8 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
 		goto out;

drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, · line 418

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -3
 	}
 
-	write_seqlock_irqsave(&clock->lock, flags);
 	cycles = mlx5_read_time(mdev, sts, false);
-	ns = timecounter_cyc2time(&timer->tc, cycles);
-	write_sequnlock_irqrestore(&clock->lock, flags);
+	ns = mlx5_timecounter_cyc2time(clock, cycles);
 	*ts = ns_to_timespec64(ns);
 out:
 	return 0;

The patch seems like a good cleanup to me. Like Vadim mentioned, we should not need to update the timecounter since this simply a read operation.

#2 lore raw
Quoted 41 lines · Rahul Rameshbabu
Quoted 25 lines · On Mon, 14 Oct, 2024 10:01:03 -0700 Vadim Fedorenko <[email protected]> wrote:

The gettimex64() doesn't modify values in timecounter, that's why there is no need to update sequence counter. Reduce the contention on sequence lock for multi-thread PHC reading use-case.

---
  drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0 -2
index b306ae79bf97..4822d01123b4 100644
@@ -402,9 +402,7 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
  			     struct ptp_system_timestamp *sts)
  {
  	struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
-	struct mlx5_timer *timer = &clock->timer;
  	struct mlx5_core_dev *mdev;
-	unsigned long flags;
  	u64 cycles, ns;
 
  	mdev = container_of(clock, struct mlx5_core_dev, clock);
@@ -413,10 +411,8 @@ static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
  		goto out;

drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static int mlx5_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, · line 418

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -3
  	}
 
-	write_seqlock_irqsave(&clock->lock, flags);
  	cycles = mlx5_read_time(mdev, sts, false);
-	ns = timecounter_cyc2time(&timer->tc, cycles);
-	write_sequnlock_irqrestore(&clock->lock, flags);
+	ns = mlx5_timecounter_cyc2time(clock, cycles);
  	*ts = ns_to_timespec64(ns);
  out:
  	return 0;

The patch seems like a good cleanup to me. Like Vadim mentioned, we should not need to update the timecounter since this simply a read operation.

Quoted 1 line

Rahul, Tariq,

will you take it through mlx5-next, or should it go directly to net-next?

Thanks!

Acked-by
#3 lore raw
Quoted 42 lines · Vadim Fedorenko
Quoted 41 lines · Rahul Rameshbabu
Quoted 33 lines · On Mon, 14 Oct, 2024 10:01:03 -0700 Vadim Fedorenko <[email protected]> wrote:

The gettimex64() doesn't modify values in timecounter, that's why there is no need to update sequence counter. Reduce the contention on sequence lock for multi-thread PHC reading use-case.

---
  drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 +-----

  1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -5
index b306ae79bf97..4822d01123b4 100644
@@ -402,9 +402,7 @@ static int mlx5_ptp_gettimex(struct 
 ptp_clock_info *ptp, struct timespec64 *ts,
                    struct ptp_system_timestamp *sts)
   {
       struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
-    struct mlx5_timer *timer = &clock->timer;
       struct mlx5_core_dev *mdev;
-    unsigned long flags;
       u64 cycles, ns;
       mdev = container_of(clock, struct mlx5_core_dev, clock);
@@ -413,10 +411,8 @@ static int mlx5_ptp_gettimex(struct 
 ptp_clock_info *ptp, struct timespec64 *ts,
           goto out;
       }
-    write_seqlock_irqsave(&clock->lock, flags);
       cycles = mlx5_read_time(mdev, sts, false);
-    ns = timecounter_cyc2time(&timer->tc, cycles);
-    write_sequnlock_irqrestore(&clock->lock, flags);
+    ns = mlx5_timecounter_cyc2time(clock, cycles);
       *ts = ns_to_timespec64(ns);
Quoted 2 lines

  out:
      return 0;

The patch seems like a good cleanup to me. Like Vadim mentioned, we should not need to update the timecounter since this simply a read operation.

Quoted 9 lines
Quoted 1 line

Rahul, Tariq,

will you take it through mlx5-next, or should it go directly to net-next?

Thanks!

Hi,

Sorry for the late response, I missed this question previously.

Should go to net-next.

Regards,
Tariq

#4 lore raw
In reply to Vadim Fedorenko
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 14 Oct 2024 10:01:03 -0700 you wrote:

The gettimex64() doesn't modify values in timecounter, that's why there is no need to update sequence counter. Reduce the contention on sequence lock for multi-thread PHC reading use-case.

---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Here is the summary with links:
- [net-next] mlx5_en: use read sequence for gettimex64

    https://git.kernel.org/netdev/net-next/c/0452a2d8b8b9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html