[PATCH RFC] igb: Use TAI clock to reset PHC value

Yoann Congal posted 1 patch 2 years, 7 months ago
drivers/net/ethernet/intel/igb/igb_ptp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH RFC] igb: Use TAI clock to reset PHC value
Posted by Yoann Congal 2 years, 7 months ago
The PHC is usually synchronised in TAI (from PTP). By resetting it with
the kernel TAI clock we avoid having to correct the PHC from REALTIME
(usually UTC) to TAI (37s as of today).

RFC: While this patch looks trivial and it does make linuxptp/ptp4l
complain about a driver bug:
  timed out while polling for tx timestamp
  increasing tx_timestamp_timeout may correct this issue, but it is likely caused by a driver bug
  port 1: send peer delay response failed

Increasing tx_timestamp_timeout to 1s does nothing different so I guess
the driver does indeed freeze with this change but I can't figure out
why... 

Do you have any idea/pointers? Thanks!

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 drivers/net/ethernet/intel/igb/igb_ptp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 15e57460e19ea..65e5de2ccb279 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -1526,12 +1526,12 @@ void igb_ptp_reset(struct igb_adapter *adapter)
 
 	/* Re-initialize the timer. */
 	if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) {
-		struct timespec64 ts = ktime_to_timespec64(ktime_get_real());
+		struct timespec64 ts = ktime_to_timespec64(ktime_get_clocktai());
 
 		igb_ptp_write_i210(adapter, &ts);
 	} else {
 		timecounter_init(&adapter->tc, &adapter->cc,
-				 ktime_to_ns(ktime_get_real()));
+				 ktime_to_ns(ktime_get_clocktai()));
 	}
 out:
 	spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
-- 
2.30.2
Re: [PATCH RFC] igb: Use TAI clock to reset PHC value
Posted by Richard Cochran 2 years, 7 months ago
On Fri, Jun 30, 2023 at 05:41:38PM +0200, Yoann Congal wrote:
> The PHC is usually synchronised in TAI (from PTP). By resetting it with
> the kernel TAI clock we avoid having to correct the PHC from REALTIME
> (usually UTC) to TAI (37s as of today).

Nothing guarantees that the kernel's time is correct.

When initializing a PHC, it is better to reset it to zero.  That way,
the fact that the clock is unsynchronized is obvious.  Otherwise,
people may believe the PHC is synchronized when in fact it is not.
 
> RFC: While this patch looks trivial and it does make linuxptp/ptp4l
> complain about a driver bug:
>   timed out while polling for tx timestamp
>   increasing tx_timestamp_timeout may correct this issue, but it is likely caused by a driver bug
>   port 1: send peer delay response failed
> 
> Increasing tx_timestamp_timeout to 1s does nothing different so I guess
> the driver does indeed freeze with this change but I can't figure out
> why... 
> 
> Do you have any idea/pointers? Thanks!

No idea, but you should figure that out before posting a "fix".

Thanks,
Richard