Skip to contentSkip to conversation

ice: Check for PTP HW lock more frequently

PATCH In review Karol Kolacinski 5 participants 9 messages Oct 3, 2022 – Nov 11, 2022

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

PATCH 1/2 ice: Check for PTP HW lock more frequently

It was observed that PTP HW semaphore can be held for ~50 ms in worst case.
SW should wait longer and check more frequently if the HW lock is held.

---
 drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +7 -5
index 772b1f566d6e..1f8dd50db524 100644
@@ -2963,16 +2963,18 @@ bool ice_ptp_lock(struct ice_hw *hw)
 	u32 hw_lock;
 	int i;
 
-#define MAX_TRIES 5
+#define MAX_TRIES 15
 
 	for (i = 0; i < MAX_TRIES; i++) {
 		hw_lock = rd32(hw, PFTSYN_SEM + (PFTSYN_SEM_BYTES * hw->pf_id));
 		hw_lock = hw_lock & PFTSYN_SEM_BUSY_M;
-		if (!hw_lock)
-			break;
+		if (hw_lock) {
+			/* Somebody is holding the lock */
+			usleep_range(5000, 6000);
+			continue;
+		}
 
-		/* Somebody is holding the lock */
-		usleep_range(10000, 20000);
+		break;
 	}
 
 	return !hw_lock;
Signature · 6 lines
2.34.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#1 lore raw

PATCH 2/2 ice: Remove gettime HW semaphore

Reading the time should not block other accesses to the PTP hardware. There isn't a significant risk of reading bad values while another thread is modifying the clock. Removing the hardware lock around the gettime allows multiple application threads to read the clock time with less contention.

---
 drivers/net/ethernet/intel/ice/ice_ptp.c | 31 +++---------------------
 1 file changed, 3 insertions(+), 28 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +3 -28
index 9d1afeca9624..1f481d455134 100644
@@ -979,26 +979,6 @@ static void ice_ptp_reset_cached_phctime(struct ice_pf *pf)
 	ice_ptp_flush_tx_tracker(pf, &pf->ptp.port.tx);
 }
 
-/**
- * ice_ptp_read_time - Read the time from the device
- * @pf: Board private structure
- * @ts: timespec structure to hold the current time value
- * @sts: Optional parameter for holding a pair of system timestamps from
- *       the system clock. Will be ignored if NULL is given.
- *
- * This function reads the source clock registers and stores them in a timespec.
- * However, since the registers are 64 bits of nanoseconds, we must convert the
- * result to a timespec before we can return.
- */
-static void
-ice_ptp_read_time(struct ice_pf *pf, struct timespec64 *ts,
-		  struct ptp_system_timestamp *sts)
-{
-	u64 time_ns = ice_ptp_read_src_clk_reg(pf, sts);
-
-	*ts = ns_to_timespec64(time_ns);
-}
-
 /**
  * ice_ptp_write_init - Set PHC time to provided value
  * @pf: Board private structure
@@ -1835,15 +1815,10 @@ ice_ptp_gettimex64(struct ptp_clock_info *info, struct timespec64 *ts,
 		   struct ptp_system_timestamp *sts)
 {
 	struct ice_pf *pf = ptp_info_to_pf(info);
-	struct ice_hw *hw = &pf->hw;
+	u64 time_ns;
 
-	if (!ice_ptp_lock(hw)) {
-		dev_err(ice_pf_to_dev(pf), "PTP failed to get time\n");
-		return -EBUSY;
-	}
-
-	ice_ptp_read_time(pf, ts, sts);
-	ice_ptp_unlock(hw);
+	time_ns = ice_ptp_read_src_clk_reg(pf, sts);
+	*ts = ns_to_timespec64(time_ns);
 
 	return 0;
 }
Signature · 6 lines
2.34.1

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
maintainer
#2 lore raw

Re: [Intel-wired-lan] [PATCH net-next 2/2] ice: Remove gettime HW semaphore

Quoted 8 lines · Karol Kolacinski

Reading the time should not block other accesses to the PTP hardware. There isn't a significant risk of reading bad values while another thread is modifying the clock. Removing the hardware lock around the gettime allows multiple application threads to read the clock time with less contention.

---

Vinicius had a comment/concern on this. Adding him to this and bringing the comment over.

"
I think the problem is less about concurrent writes/reads than concurrent reads: the fact that the registers are latched when the "lower" register is read, makes me worried that there's a (very narrow) window during rollover in which the "losing" read (of multiple threads doing reads) can return a wrong value.

I could be missing something.
"

Thanks,
Tony

Quoted 43 lines
  drivers/net/ethernet/intel/ice/ice_ptp.c | 31 +++---------------------
  1 file changed, 3 insertions(+), 28 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -23
index 9d1afeca9624..1f481d455134 100644
@@ -979,26 +979,6 @@ static void ice_ptp_reset_cached_phctime(struct ice_pf *pf)
  	ice_ptp_flush_tx_tracker(pf, &pf->ptp.port.tx);
  }
 
-/**
- * ice_ptp_read_time - Read the time from the device
- * @pf: Board private structure
- * @ts: timespec structure to hold the current time value
- * @sts: Optional parameter for holding a pair of system timestamps from
- *       the system clock. Will be ignored if NULL is given.
- *
- * This function reads the source clock registers and stores them in a timespec.
- * However, since the registers are 64 bits of nanoseconds, we must convert the
- * result to a timespec before we can return.
- */
-static void
-ice_ptp_read_time(struct ice_pf *pf, struct timespec64 *ts,
-		  struct ptp_system_timestamp *sts)
-{
-	u64 time_ns = ice_ptp_read_src_clk_reg(pf, sts);
-
-	*ts = ns_to_timespec64(time_ns);
-}
-
  /**
   * ice_ptp_write_init - Set PHC time to provided value
   * @pf: Board private structure
@@ -1835,15 +1815,10 @@ ice_ptp_gettimex64(struct ptp_clock_info *info, struct timespec64 *ts,
  		   struct ptp_system_timestamp *sts)
  {
  	struct ice_pf *pf = ptp_info_to_pf(info);
-	struct ice_hw *hw = &pf->hw;
+	u64 time_ns;
 
-	if (!ice_ptp_lock(hw)) {
-		dev_err(ice_pf_to_dev(pf), "PTP failed to get time\n");

drivers/net/ethernet/intel/ice/ice_ptp.c ice_ptp_gettimex64(struct ptp_clock_info *info, struct timespec64 *ts, · line 1824

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +2 -5
-		return -EBUSY;
-	}
-
-	ice_ptp_read_time(pf, ts, sts);
-	ice_ptp_unlock(hw);
+	time_ns = ice_ptp_read_src_clk_reg(pf, sts);
+	*ts = ns_to_timespec64(time_ns);
 
  	return 0;
  }

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#3 lore raw

PATCH 2/2 ice: Remove gettime HW semaphore

Hi Vinicius,

Quoted 5 lines

I think the problem is less about concurrent writes/reads than concurrent reads: the fact that the registers are latched when the "lower" register is read, makes me worried that there's a (very narrow) window during rollover in which the "losing" read (of multiple threads doing reads) can return a wrong value.

The issue in this case is, it's either risk of reading slightly wrong value or having multiple timeouts and errors.
We experienced a lot of simultaneous reads on multiple PFs (especially on E822 HW with 8 ports) and even with increased timeout to acquire the HW semaphore, it still failed.

Thanks,
Karol
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#4 lore raw

Re: [Intel-wired-lan] [PATCH net-next 2/2] ice: Remove gettime HW semaphore

Quoted 8 lines · Karol

Hi Vinicius,

Quoted 5 lines

I think the problem is less about concurrent writes/reads than concurrent reads: the fact that the registers are latched when the "lower" register is read, makes me worried that there's a (very narrow) window during rollover in which the "losing" read (of multiple threads doing reads) can return a wrong value.

Quoted 5 lines

The issue in this case is, it's either risk of reading slightly wrong value or having multiple timeouts and errors.
We experienced a lot of simultaneous reads on multiple PFs (especially on E822 HW with 8 ports) and even with increased timeout to acquire the HW semaphore, it still failed.

I am wondering if using a hw semaphore is making the problem worse than it needs to be. Why a kernel spinlock can't be used?

Cheers,

Signature · 5 lines
Vinicius
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
#5 lore raw

Re: [Intel-wired-lan] [PATCH net-next 2/2] ice: Remove gettime HW semaphore

Quoted 16 lines · Vinicius Costa Gomes
Quoted 8 lines · Karol

Hi Vinicius,

Quoted 5 lines

I think the problem is less about concurrent writes/reads than concurrent reads: the fact that the registers are latched when the "lower" register is read, makes me worried that there's a (very narrow) window during rollover in which the "losing" read (of multiple threads doing reads) can return a wrong value.

Quoted 5 lines

The issue in this case is, it's either risk of reading slightly wrong value or having multiple timeouts and errors.
We experienced a lot of simultaneous reads on multiple PFs (especially on E822 HW with 8 ports) and even with increased timeout to acquire the HW semaphore, it still failed.

Quoted 5 lines

I am wondering if using a hw semaphore is making the problem worse than it needs to be. Why a kernel spinlock can't be used?

Cheers,

The same clock is shared across multiple ports which operate as independent PCIe devices, hence having their own instance of the ice driver structures. A spinlock doesn't work because they wouldn't be using the same lock.

We could try to share the lock in software between PFs, but its actually quite difficult to do that with the existing PCIe driver model.
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#6 lore raw

Re: [Intel-wired-lan] [PATCH net-next 2/2] ice: Remove gettime HW semaphore

Quoted 21 lines · Jacob Keller
Quoted 20 lines · Vinicius Costa Gomes
Quoted 8 lines · Karol

Hi Vinicius,

Quoted 5 lines

I think the problem is less about concurrent writes/reads than concurrent reads: the fact that the registers are latched when the "lower" register is read, makes me worried that there's a (very narrow) window during rollover in which the "losing" read (of multiple threads doing reads) can return a wrong value.

Quoted 5 lines

The issue in this case is, it's either risk of reading slightly wrong value or having multiple timeouts and errors.
We experienced a lot of simultaneous reads on multiple PFs (especially on E822 HW with 8 ports) and even with increased timeout to acquire the HW semaphore, it still failed.

I am wondering if using a hw semaphore is making the problem worse than it needs to be. Why a kernel spinlock can't be used?

Quoted 7 lines
Quoted 1 line

Cheers,

The same clock is shared across multiple ports which operate as independent PCIe devices, hence having their own instance of the ice driver structures. A spinlock doesn't work because they wouldn't be using the same lock.

Oh! I should have realized that. The thought that there could be multiple devices/ports sharing some resources didn't cross my mind.

Quoted 2 lines

We could try to share the lock in software between PFs, but its actually quite difficult to do that with the existing PCIe driver model.

I can see how that would be difficult, yeah.

Did you happen to test if my fears were true or not? For example, 'phc2sys' running in parallel with a few (4?) 'while true { phc_ctl get }'. Do you notice any weirdness?

Cheers,

Signature · 5 lines
Vinicius
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Tested-by on v1 2/2
#7 lore raw

Re: [Intel-wired-lan] [PATCH net-next 2/2] ice: Remove gettime HW semaphore

In reply to Karol Kolacinski
Quoted 16 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Karol Kolacinski
Sent: Monday, October 3, 2022 3:25 PM
To: [email protected]
Cc: Kolacinski, Karol <[email protected]>
Subject: [Intel-wired-lan] [PATCH net-next 2/2] ice: Remove gettime HW semaphore

Reading the time should not block other accesses to the PTP hardware. There isn't a significant risk of reading bad values while another thread is modifying the clock. Removing the hardware lock around the gettime allows multiple application threads to read the clock time with less contention.

Quoted 5 lines
---
 drivers/net/ethernet/intel/ice/ice_ptp.c | 31 +++---------------------
 1 file changed, 3 insertions(+), 28 deletions(-)

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

Tested-by on v1 1/2
#8 lore raw
In reply to Karol Kolacinski
Quoted 11 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Karol Kolacinski
Sent: Monday, October 3, 2022 3:25 PM
To: [email protected]
Cc: Kolacinski, Karol <[email protected]>
Subject: [Intel-wired-lan] [PATCH net-next 1/2] ice: Check for PTP HW lock more frequently

Quoted 9 lines

It was observed that PTP HW semaphore can be held for ~50 ms in worst case.
SW should wait longer and check more frequently if the HW lock is held.

---
 drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan