Skip to contentSkip to conversation

ptp: ocp: Improve PCIe delay estimation

PATCH Superseded Vadim Fedorenko 2 participants 3 messages Sep 4, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vadim Fedorenko

author maintainer
#0 lore raw

PATCH 1/1 ptp: ocp: Improve PCIe delay estimation

The PCIe bus can be pretty busy during boot and probe function can see excessive delays. Let's find the minimal value out of several tests and use it as estimated value.

---
 drivers/ptp/ptp_ocp.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/ptp/ptp_ocp.c +10 -7
index e7479b9b90cb..22b22e605781 100644
@@ -1561,19 +1561,22 @@ ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp)
 	ktime_t start, end;
 	ktime_t delay;
 	u32 ctrl;
+	int i;
 
-	ctrl = ioread32(&bp->reg->ctrl);
-	ctrl = OCP_CTRL_READ_TIME_REQ | OCP_CTRL_ENABLE;
+	for (i = 0; i < 3; i++) {
+		ctrl = ioread32(&bp->reg->ctrl);
+		ctrl = OCP_CTRL_READ_TIME_REQ | OCP_CTRL_ENABLE;
 
-	iowrite32(ctrl, &bp->reg->ctrl);
+		iowrite32(ctrl, &bp->reg->ctrl);
 
-	start = ktime_get_ns();
+		start = ktime_get_ns();
 
-	ctrl = ioread32(&bp->reg->ctrl);
+		ctrl = ioread32(&bp->reg->ctrl);
 
-	end = ktime_get_ns();
+		end = ktime_get_ns();
 
-	delay = end - start;
+		delay = min(delay, end - start);
+	}
 	bp->ts_window_adjust = (delay >> 5) * 3;
 }
 
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 29 lines · Vadim Fedorenko

The PCIe bus can be pretty busy during boot and probe function can see excessive delays. Let's find the minimal value out of several tests and use it as estimated value.

---
 drivers/ptp/ptp_ocp.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/ptp/ptp_ocp.c +5 -4
index e7479b9b90cb..22b22e605781 100644
@@ -1561,19 +1561,22 @@ ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp)
 	ktime_t start, end;
 	ktime_t delay;
 	u32 ctrl;
+	int i;
 
-	ctrl = ioread32(&bp->reg->ctrl);
-	ctrl = OCP_CTRL_READ_TIME_REQ | OCP_CTRL_ENABLE;
+	for (i = 0; i < 3; i++) {
+		ctrl = ioread32(&bp->reg->ctrl);
+		ctrl = OCP_CTRL_READ_TIME_REQ | OCP_CTRL_ENABLE;
 
-	iowrite32(ctrl, &bp->reg->ctrl);
+		iowrite32(ctrl, &bp->reg->ctrl);
 
-	start = ktime_get_ns();

drivers/ptp/ptp_ocp.c ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp) · line 1578

Quoted 10 lines
drivers/ptp/ptp_ocp.c +4 -3
+		start = ktime_get_ns();
 
-	ctrl = ioread32(&bp->reg->ctrl);
+		ctrl = ioread32(&bp->reg->ctrl);
 
-	end = ktime_get_ns();
+		end = ktime_get_ns();
 
-	delay = end - start;
+		delay = min(delay, end - start);

Hi Vadim,

It looks like delay is used uninitialised here
in the first iteration of this loop.

Flagged by Smatch.

Quoted 8 lines
drivers/ptp/ptp_ocp.c +1 -0
+	}
 	bp->ts_window_adjust = (delay >> 5) * 3;
 }
 
Signature · 1 line
2.43.0
author maintainer
#2 lore raw
Quoted 43 lines · Simon Horman
Quoted 29 lines · Vadim Fedorenko

The PCIe bus can be pretty busy during boot and probe function can see excessive delays. Let's find the minimal value out of several tests and use it as estimated value.

---
  drivers/ptp/ptp_ocp.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
drivers/ptp/ptp_ocp.c +5 -4
index e7479b9b90cb..22b22e605781 100644
@@ -1561,19 +1561,22 @@ ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp)
  	ktime_t start, end;
  	ktime_t delay;
  	u32 ctrl;
+	int i;
 
-	ctrl = ioread32(&bp->reg->ctrl);
-	ctrl = OCP_CTRL_READ_TIME_REQ | OCP_CTRL_ENABLE;
+	for (i = 0; i < 3; i++) {
+		ctrl = ioread32(&bp->reg->ctrl);
+		ctrl = OCP_CTRL_READ_TIME_REQ | OCP_CTRL_ENABLE;
 
-	iowrite32(ctrl, &bp->reg->ctrl);
+		iowrite32(ctrl, &bp->reg->ctrl);
 
-	start = ktime_get_ns();

drivers/ptp/ptp_ocp.c ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp) · line 1578

Quoted 10 lines
drivers/ptp/ptp_ocp.c +4 -3
+		start = ktime_get_ns();
 
-	ctrl = ioread32(&bp->reg->ctrl);
+		ctrl = ioread32(&bp->reg->ctrl);
 
-	end = ktime_get_ns();
+		end = ktime_get_ns();
 
-	delay = end - start;
+		delay = min(delay, end - start);

Hi Vadim,

Quoted 4 lines

It looks like delay is used uninitialised here
in the first iteration of this loop.

Flagged by Smatch.

Oh, yes, you are right, Simon. I'll send v2 with INT_MAX init for delay.

Thanks!

Quoted 9 lines
Quoted 9 lines
drivers/ptp/ptp_ocp.c +1 -0
+	}
  	bp->ts_window_adjust = (delay >> 5) * 3;
  }
 
Signature · 1 line
2.43.0