Skip to contentSkip to conversation

ptp: Allow exposing cycles only for clocks with free-running counter

PATCH Applied Carolina Jubran 4 participants 4 messages Oct 29, 2025 – Oct 31, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ptp: Allow exposing cycles only for clocks with free-running counter

The PTP core falls back to gettimex64 and getcrosststamp when getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES ioctls to retrieve PHC real time instead of free-running cycles.

Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without free-running counter support since the result would represent PHC real time and system time rather than cycles and system time.

Fixes faf23f54d366 ("ptp: Add ioctl commands to expose raw cycle counter values")
---
 drivers/ptp/ptp_chardev.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/ptp/ptp_chardev.c +4 -0
index 8106eb617c8c..c61cf9edac48 100644
@@ -561,10 +561,14 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
 		return ptp_mask_en_single(pccontext->private_clkdata, argptr);
 
 	case PTP_SYS_OFFSET_PRECISE_CYCLES:
+		if (!ptp->has_cycles)
+			return -EOPNOTSUPP;
 		return ptp_sys_offset_precise(ptp, argptr,
 					      ptp->info->getcrosscycles);
 
 	case PTP_SYS_OFFSET_EXTENDED_CYCLES:
+		if (!ptp->has_cycles)
+			return -EOPNOTSUPP;
 		return ptp_sys_offset_extended(ptp, argptr,
 					       ptp->info->getcyclesx64);
 	default:
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Carolina Jubran

The PTP core falls back to gettimex64 and getcrosststamp when getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES ioctls to retrieve PHC real time instead of free-running cycles.

Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without free-running counter support since the result would represent PHC real time and system time rather than cycles and system time.

Fixes faf23f54d366 ("ptp: Add ioctl commands to expose raw cycle counter values")
---
 drivers/ptp/ptp_chardev.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/ptp/ptp_chardev.c +1 -0
index 8106eb617c8c..c61cf9edac48 100644
@@ -561,10 +561,14 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
                return ptp_mask_en_single(pccontext->private_clkdata, argptr);
 
        case PTP_SYS_OFFSET_PRECISE_CYCLES:
+               if (!ptp->has_cycles)

drivers/ptp/ptp_chardev.c long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, · line 574

Quoted 10 lines
drivers/ptp/ptp_chardev.c +3 -0
+                       return -EOPNOTSUPP;
                return ptp_sys_offset_precise(ptp, argptr,
                                              ptp->info->getcrosscycles);
 
        case PTP_SYS_OFFSET_EXTENDED_CYCLES:
+               if (!ptp->has_cycles)
+                       return -EOPNOTSUPP;
                return ptp_sys_offset_extended(ptp, argptr,
                                               ptp->info->getcyclesx64);
        default:

LGTM.

Quoted 4 lines

--
2.38.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Carolina Jubran
Quoted 25 lines · Carolina Jubran

The PTP core falls back to gettimex64 and getcrosststamp when getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES ioctls to retrieve PHC real time instead of free-running cycles.

Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without free-running counter support since the result would represent PHC real time and system time rather than cycles and system time.

Fixes faf23f54d366 ("ptp: Add ioctl commands to expose raw cycle counter values")
---
  drivers/ptp/ptp_chardev.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/ptp/ptp_chardev.c +1 -0
index 8106eb617c8c..c61cf9edac48 100644
@@ -561,10 +561,14 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
  		return ptp_mask_en_single(pccontext->private_clkdata, argptr);
 
  	case PTP_SYS_OFFSET_PRECISE_CYCLES:
+		if (!ptp->has_cycles)

drivers/ptp/ptp_chardev.c long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, · line 574

Quoted 10 lines
drivers/ptp/ptp_chardev.c +3 -0
+			return -EOPNOTSUPP;
  		return ptp_sys_offset_precise(ptp, argptr,
  					      ptp->info->getcrosscycles);
 
  	case PTP_SYS_OFFSET_EXTENDED_CYCLES:
+		if (!ptp->has_cycles)
+			return -EOPNOTSUPP;
  		return ptp_sys_offset_extended(ptp, argptr,
  					       ptp->info->getcyclesx64);
  	default:

Fair point.

#3 lore raw
In reply to Carolina Jubran
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 29 Oct 2025 10:38:13 +0200 you wrote:

The PTP core falls back to gettimex64 and getcrosststamp when getcycles64 or getcyclesx64 are not implemented. This causes the CYCLES ioctls to retrieve PHC real time instead of free-running cycles.

Reject PTP_SYS_OFFSET_{PRECISE,EXTENDED}_CYCLES for clocks without free-running counter support since the result would represent PHC real time and system time rather than cycles and system time.

[...]

Here is the summary with links:
- [net] ptp: Allow exposing cycles only for clocks with free-running counter

    https://git.kernel.org/netdev/net/c/5a89b27afd3d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html