[patch 2/3] ptp: Use ktime_get_clock_ts64() for timestamping

Thomas Gleixner posted 3 patches 3 months, 2 weeks ago
There is a newer version of this series
[patch 2/3] ptp: Use ktime_get_clock_ts64() for timestamping
Posted by Thomas Gleixner 3 months, 2 weeks ago
The inlined ptp_read_system_[pre|post]ts() switch cases expand to a copious
amount of text in drivers, e.g. ~500 bytes in e1000e. Adding auxiliary
clock support to the inlines would increase it further.

Replace the inline switch case with a call to ktime_get_clock_ts64(), which
reduces the code size in drivers and allows to access auxiliary clocks once
they are enabled in the IOCTL parameter filter.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/ptp_clock_kernel.h |   34 ++++------------------------------
 1 file changed, 4 insertions(+), 30 deletions(-)

--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -477,40 +477,14 @@ static inline ktime_t ptp_convert_timest
 
 static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts)
 {
-	if (sts) {
-		switch (sts->clockid) {
-		case CLOCK_REALTIME:
-			ktime_get_real_ts64(&sts->pre_ts);
-			break;
-		case CLOCK_MONOTONIC:
-			ktime_get_ts64(&sts->pre_ts);
-			break;
-		case CLOCK_MONOTONIC_RAW:
-			ktime_get_raw_ts64(&sts->pre_ts);
-			break;
-		default:
-			break;
-		}
-	}
+	if (sts)
+		ktime_get_clock_ts64(sts->clockid, &sts->pre_ts);
 }
 
 static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
 {
-	if (sts) {
-		switch (sts->clockid) {
-		case CLOCK_REALTIME:
-			ktime_get_real_ts64(&sts->post_ts);
-			break;
-		case CLOCK_MONOTONIC:
-			ktime_get_ts64(&sts->post_ts);
-			break;
-		case CLOCK_MONOTONIC_RAW:
-			ktime_get_raw_ts64(&sts->post_ts);
-			break;
-		default:
-			break;
-		}
-	}
+	if (sts)
+		ktime_get_clock_ts64(sts->clockid, &sts->post_ts);
 }
 
 #endif
Re: [patch 2/3] ptp: Use ktime_get_clock_ts64() for timestamping
Posted by Vadim Fedorenko 3 months, 1 week ago
On 26/06/2025 14:27, Thomas Gleixner wrote:
> The inlined ptp_read_system_[pre|post]ts() switch cases expand to a copious
> amount of text in drivers, e.g. ~500 bytes in e1000e. Adding auxiliary
> clock support to the inlines would increase it further.
> 
> Replace the inline switch case with a call to ktime_get_clock_ts64(), which
> reduces the code size in drivers and allows to access auxiliary clocks once
> they are enabled in the IOCTL parameter filter.
> 
> No functional change.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>   include/linux/ptp_clock_kernel.h |   34 ++++------------------------------
>   1 file changed, 4 insertions(+), 30 deletions(-)
> 
> --- a/include/linux/ptp_clock_kernel.h
> +++ b/include/linux/ptp_clock_kernel.h
> @@ -477,40 +477,14 @@ static inline ktime_t ptp_convert_timest
>   
>   static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts)
>   {
> -	if (sts) {
> -		switch (sts->clockid) {
> -		case CLOCK_REALTIME:
> -			ktime_get_real_ts64(&sts->pre_ts);
> -			break;
> -		case CLOCK_MONOTONIC:
> -			ktime_get_ts64(&sts->pre_ts);
> -			break;
> -		case CLOCK_MONOTONIC_RAW:
> -			ktime_get_raw_ts64(&sts->pre_ts);
> -			break;
> -		default:
> -			break;
> -		}
> -	}
> +	if (sts)
> +		ktime_get_clock_ts64(sts->clockid, &sts->pre_ts);
>   }
>   
>   static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
>   {
> -	if (sts) {
> -		switch (sts->clockid) {
> -		case CLOCK_REALTIME:
> -			ktime_get_real_ts64(&sts->post_ts);
> -			break;
> -		case CLOCK_MONOTONIC:
> -			ktime_get_ts64(&sts->post_ts);
> -			break;
> -		case CLOCK_MONOTONIC_RAW:
> -			ktime_get_raw_ts64(&sts->post_ts);
> -			break;
> -		default:
> -			break;
> -		}
> -	}
> +	if (sts)
> +		ktime_get_clock_ts64(sts->clockid, &sts->post_ts);
>   }
>   
>   #endif
> 
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Re: [patch 2/3] ptp: Use ktime_get_clock_ts64() for timestamping
Posted by John Stultz 3 months, 1 week ago
On Thu, Jun 26, 2025 at 6:27 AM Thomas Gleixner <tglx@linutronix.de> wrote:
>
> The inlined ptp_read_system_[pre|post]ts() switch cases expand to a copious
> amount of text in drivers, e.g. ~500 bytes in e1000e. Adding auxiliary
> clock support to the inlines would increase it further.
>
> Replace the inline switch case with a call to ktime_get_clock_ts64(), which
> reduces the code size in drivers and allows to access auxiliary clocks once
> they are enabled in the IOCTL parameter filter.
>
> No functional change.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Acked-by: John Stultz <jstultz@google.com>