diff mbox series

[net-next,v1,2/6] ptp: Request cycles for TX timestamp

Message ID 20220322210722.6405-3-gerhard@engleder-embedded.com (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series ptp: Support hardware clocks with additional free running time | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5928 this patch: 5928
netdev/cc_maintainers warning 4 maintainers not CCed: imagedong@tencent.com edumazet@google.com keescook@chromium.org pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 868 this patch: 868
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6079 this patch: 6079
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 35 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Gerhard Engleder March 22, 2022, 9:07 p.m. UTC
The free running time of physical clocks called cycles shall be used for
hardware timestamps to enable synchronisation.

Introduce new flag SKBTX_HW_TSTAMP_USE_CYCLES, which signals driver to
provide a TX timestamp based on cycles if cycles are supported.

Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
---
 include/linux/skbuff.h |  3 +++
 net/core/skbuff.c      |  2 ++
 net/socket.c           | 10 +++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

Comments

Richard Cochran March 24, 2022, 1:49 p.m. UTC | #1
On Tue, Mar 22, 2022 at 10:07:18PM +0100, Gerhard Engleder wrote:
> The free running time of physical clocks called cycles shall be used for
> hardware timestamps to enable synchronisation.
> 
> Introduce new flag SKBTX_HW_TSTAMP_USE_CYCLES, which signals driver to
> provide a TX timestamp based on cycles if cycles are supported.
> 
> Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
> ---
>  include/linux/skbuff.h |  3 +++
>  net/core/skbuff.c      |  2 ++
>  net/socket.c           | 10 +++++++++-
>  3 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 26538ceb4b01..f494ddbfc826 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -578,6 +578,9 @@ enum {
>  	/* device driver is going to provide hardware time stamp */
>  	SKBTX_IN_PROGRESS = 1 << 2,
>  
> +	/* generate hardware time stamp based on cycles if supported */
> +	SKBTX_HW_TSTAMP_USE_CYCLES = 1 << 3,

Bit 4 used, but 3 was unused... interesting!

>  	/* generate wifi status information (where possible) */
>  	SKBTX_WIFI_STATUS = 1 << 4,
>  
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 10bde7c6db44..c0f8f1341c3f 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -4847,6 +4847,8 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
>  		skb_shinfo(skb)->tx_flags |= skb_shinfo(orig_skb)->tx_flags &
>  					     SKBTX_ANY_TSTAMP;
>  		skb_shinfo(skb)->tskey = skb_shinfo(orig_skb)->tskey;
> +	} else {
> +		skb_shinfo(skb)->tx_flags &= ~SKBTX_HW_TSTAMP_USE_CYCLES;
>  	}
>  
>  	if (hwtstamps)
> diff --git a/net/socket.c b/net/socket.c
> index 982eecad464c..1acebcb19e8f 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -683,9 +683,17 @@ void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags)
>  {
>  	u8 flags = *tx_flags;
>  
> -	if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE)
> +	if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE) {
>  		flags |= SKBTX_HW_TSTAMP;
>  
> +		/* PTP hardware clocks can provide a free running time called
> +		 * cycles as base for virtual clocks.

"PTP hardware clocks can provide a free running cycle counter as a
time base for virtual clocks."


Thanks,
Richard
Miroslav Lichvar March 24, 2022, 1:55 p.m. UTC | #2
On Thu, Mar 24, 2022 at 06:49:34AM -0700, Richard Cochran wrote:
> On Tue, Mar 22, 2022 at 10:07:18PM +0100, Gerhard Engleder wrote:
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -578,6 +578,9 @@ enum {
> >  	/* device driver is going to provide hardware time stamp */
> >  	SKBTX_IN_PROGRESS = 1 << 2,
> >  
> > +	/* generate hardware time stamp based on cycles if supported */
> > +	SKBTX_HW_TSTAMP_USE_CYCLES = 1 << 3,
> 
> Bit 4 used, but 3 was unused... interesting!

It seems the bit 3 and 5 were removed in commit 06b4feb37e64
("net: group skb_shinfo zerocopy related bits together.").
Gerhard Engleder March 24, 2022, 7:43 p.m. UTC | #3
> > @@ -683,9 +683,17 @@ void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags)
> >  {
> >       u8 flags = *tx_flags;
> >
> > -     if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE)
> > +     if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE) {
> >               flags |= SKBTX_HW_TSTAMP;
> >
> > +             /* PTP hardware clocks can provide a free running time called
> > +              * cycles as base for virtual clocks.
>
> "PTP hardware clocks can provide a free running cycle counter as a
> time base for virtual clocks."

I'll use your wording here. I'll also update other comments and commit messages
with this wording.

Thanks,
Gerhard
diff mbox series

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 26538ceb4b01..f494ddbfc826 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -578,6 +578,9 @@  enum {
 	/* device driver is going to provide hardware time stamp */
 	SKBTX_IN_PROGRESS = 1 << 2,
 
+	/* generate hardware time stamp based on cycles if supported */
+	SKBTX_HW_TSTAMP_USE_CYCLES = 1 << 3,
+
 	/* generate wifi status information (where possible) */
 	SKBTX_WIFI_STATUS = 1 << 4,
 
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 10bde7c6db44..c0f8f1341c3f 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -4847,6 +4847,8 @@  void __skb_tstamp_tx(struct sk_buff *orig_skb,
 		skb_shinfo(skb)->tx_flags |= skb_shinfo(orig_skb)->tx_flags &
 					     SKBTX_ANY_TSTAMP;
 		skb_shinfo(skb)->tskey = skb_shinfo(orig_skb)->tskey;
+	} else {
+		skb_shinfo(skb)->tx_flags &= ~SKBTX_HW_TSTAMP_USE_CYCLES;
 	}
 
 	if (hwtstamps)
diff --git a/net/socket.c b/net/socket.c
index 982eecad464c..1acebcb19e8f 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -683,9 +683,17 @@  void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags)
 {
 	u8 flags = *tx_flags;
 
-	if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE)
+	if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE) {
 		flags |= SKBTX_HW_TSTAMP;
 
+		/* PTP hardware clocks can provide a free running time called
+		 * cycles as base for virtual clocks. Tell driver to use cycles
+		 * for timestamp if socket is bound to virtual clock.
+		 */
+		if (tsflags & SOF_TIMESTAMPING_BIND_PHC)
+			flags |= SKBTX_HW_TSTAMP_USE_CYCLES;
+	}
+
 	if (tsflags & SOF_TIMESTAMPING_TX_SOFTWARE)
 		flags |= SKBTX_SW_TSTAMP;