* [PATCH net-next] ptp: ocp: Improve PCIe delay estimation
@ 2024-09-04 13:28 Vadim Fedorenko
2024-09-04 20:20 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Vadim Fedorenko @ 2024-09-04 13:28 UTC (permalink / raw)
To: Jakub Kicinski, Jonathan Lemon, Paolo Abeni, David Ahern
Cc: Vadim Fedorenko, netdev
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.
Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
---
drivers/ptp/ptp_ocp.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index e7479b9b90cb..22b22e605781 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ptp: ocp: Improve PCIe delay estimation
2024-09-04 13:28 [PATCH net-next] ptp: ocp: Improve PCIe delay estimation Vadim Fedorenko
@ 2024-09-04 20:20 ` Simon Horman
2024-09-04 22:42 ` Vadim Fedorenko
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2024-09-04 20:20 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Jakub Kicinski, Jonathan Lemon, Paolo Abeni, David Ahern, netdev
On Wed, Sep 04, 2024 at 01:28:42PM +0000, Vadim Fedorenko wrote:
> 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.
>
> Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
> ---
> drivers/ptp/ptp_ocp.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index e7479b9b90cb..22b22e605781 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -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);
Hi Vadim,
It looks like delay is used uninitialised here
in the first iteration of this loop.
Flagged by Smatch.
> + }
> bp->ts_window_adjust = (delay >> 5) * 3;
> }
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ptp: ocp: Improve PCIe delay estimation
2024-09-04 20:20 ` Simon Horman
@ 2024-09-04 22:42 ` Vadim Fedorenko
0 siblings, 0 replies; 3+ messages in thread
From: Vadim Fedorenko @ 2024-09-04 22:42 UTC (permalink / raw)
To: Simon Horman
Cc: Jakub Kicinski, Jonathan Lemon, Paolo Abeni, David Ahern, netdev
On 04/09/2024 21:20, Simon Horman wrote:
> On Wed, Sep 04, 2024 at 01:28:42PM +0000, Vadim Fedorenko wrote:
>> 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.
>>
>> Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
>> ---
>> drivers/ptp/ptp_ocp.c | 17 ++++++++++-------
>> 1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
>> index e7479b9b90cb..22b22e605781 100644
>> --- a/drivers/ptp/ptp_ocp.c
>> +++ b/drivers/ptp/ptp_ocp.c
>> @@ -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);
>
> Hi Vadim,
>
> 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!
>
>> + }
>> bp->ts_window_adjust = (delay >> 5) * 3;
>> }
>>
>> --
>> 2.43.0
>>
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-04 22:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 13:28 [PATCH net-next] ptp: ocp: Improve PCIe delay estimation Vadim Fedorenko
2024-09-04 20:20 ` Simon Horman
2024-09-04 22:42 ` Vadim Fedorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).