diff mbox series

[net-next] ptp: ocp: Improve PCIe delay estimation

Message ID 20240904132842.559217-1-vadim.fedorenko@linux.dev (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ptp: ocp: Improve PCIe delay estimation | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: vadfed@linux.dev richardcochran@gmail.com
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 29 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-04--15-00 (tests: 718)

Commit Message

Vadim Fedorenko Sept. 4, 2024, 1:28 p.m. UTC
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(-)

Comments

Simon Horman Sept. 4, 2024, 8:20 p.m. UTC | #1
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
> 
>
Vadim Fedorenko Sept. 4, 2024, 10:42 p.m. UTC | #2
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
>>
>>
diff mbox series

Patch

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;
 }