diff mbox series

[v4,1/1] can: dev: add software tx timestamps

Message ID 20210112095437.6488-2-mailhol.vincent@wanadoo.fr (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series Add software TX timestamps to the CAN devices | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Vincent Mailhol Jan. 12, 2021, 9:54 a.m. UTC
Call skb_tx_timestamp() within can_put_echo_skb() so that a software
tx timestamp gets attached on the skb.

There two main reasons to include this call in can_put_echo_skb():

  * It easily allow to enable the tx timestamp on all devices with
    just one small change.

  * According to Documentation/networking/timestamping.rst, the tx
    timestamps should be generated in the device driver as close as
    possible, but always prior to passing the packet to the network
    interface. During the call to can_put_echo_skb(), the skb gets
    cloned meaning that the driver should not dereference the skb
    variable anymore after can_put_echo_skb() returns. This makes
    can_put_echo_skb() the very last place we can use the skb without
    having to access the echo_skb[] array.

Remark: by default, skb_tx_timestamp() does nothing. It needs to be
activated by passing the SOF_TIMESTAMPING_TX_SOFTWARE flag either
through socket options or control messages.

References:

 * Support for the error queue in CAN RAW sockets (which is needed for
   tx timestamps) was introduced in:
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eb88531bdbfaafb827192d1fc6c5a3fcc4fadd96

  * Put the call to skb_tx_timestamp() just before adding it to the
    array: https://lkml.org/lkml/2021/1/10/54

  * About Tx hardware timestamps
    https://lore.kernel.org/linux-can/20210111171152.GB11715@hoboy.vegasvil.org/

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
 drivers/net/can/dev/skb.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Marc Kleine-Budde Jan. 12, 2021, 10:03 a.m. UTC | #1
On 1/12/21 10:54 AM, Vincent Mailhol wrote:
> Call skb_tx_timestamp() within can_put_echo_skb() so that a software
> tx timestamp gets attached on the skb.
> 
> There two main reasons to include this call in can_put_echo_skb():
> 
>   * It easily allow to enable the tx timestamp on all devices with
>     just one small change.
> 
>   * According to Documentation/networking/timestamping.rst, the tx
>     timestamps should be generated in the device driver as close as
>     possible, but always prior to passing the packet to the network
>     interface. During the call to can_put_echo_skb(), the skb gets
>     cloned meaning that the driver should not dereference the skb
>     variable anymore after can_put_echo_skb() returns. This makes
>     can_put_echo_skb() the very last place we can use the skb without
>     having to access the echo_skb[] array.
> 
> Remark: by default, skb_tx_timestamp() does nothing. It needs to be
> activated by passing the SOF_TIMESTAMPING_TX_SOFTWARE flag either
> through socket options or control messages.
> 
> References:
> 
>  * Support for the error queue in CAN RAW sockets (which is needed for
>    tx timestamps) was introduced in:
>    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eb88531bdbfaafb827192d1fc6c5a3fcc4fadd96
> 
>   * Put the call to skb_tx_timestamp() just before adding it to the
>     array: https://lkml.org/lkml/2021/1/10/54
> 
>   * About Tx hardware timestamps
>     https://lore.kernel.org/linux-can/20210111171152.GB11715@hoboy.vegasvil.org/
> 
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

Applied to linux-can-next/testing

tnx,
Marc
Jakub Kicinski Jan. 13, 2021, 1:46 a.m. UTC | #2
On Tue, 12 Jan 2021 11:03:00 +0100 Marc Kleine-Budde wrote:
> On 1/12/21 10:54 AM, Vincent Mailhol wrote:
> > Call skb_tx_timestamp() within can_put_echo_skb() so that a software
> > tx timestamp gets attached on the skb.
> > 
> > There two main reasons to include this call in can_put_echo_skb():
> > 
> >   * It easily allow to enable the tx timestamp on all devices with
> >     just one small change.
> > 
> >   * According to Documentation/networking/timestamping.rst, the tx
> >     timestamps should be generated in the device driver as close as
> >     possible, but always prior to passing the packet to the network
> >     interface. During the call to can_put_echo_skb(), the skb gets
> >     cloned meaning that the driver should not dereference the skb
> >     variable anymore after can_put_echo_skb() returns. This makes
> >     can_put_echo_skb() the very last place we can use the skb without
> >     having to access the echo_skb[] array.
> > 
> > Remark: by default, skb_tx_timestamp() does nothing. It needs to be
> > activated by passing the SOF_TIMESTAMPING_TX_SOFTWARE flag either
> > through socket options or control messages.
> > 
> > References:
> > 
> >  * Support for the error queue in CAN RAW sockets (which is needed for
> >    tx timestamps) was introduced in:
> >    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eb88531bdbfaafb827192d1fc6c5a3fcc4fadd96
> > 
> >   * Put the call to skb_tx_timestamp() just before adding it to the
> >     array: https://lkml.org/lkml/2021/1/10/54
> > 
> >   * About Tx hardware timestamps
> >     https://lore.kernel.org/linux-can/20210111171152.GB11715@hoboy.vegasvil.org/
> > 
> > Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>  
> 
> Applied to linux-can-next/testing

Please make sure to address the warnings before this hits net-next:

https://patchwork.kernel.org/project/netdevbpf/patch/20210112130538.14912-2-mailhol.vincent@wanadoo.fr/

Actually it appears not to build with allmodconfig..?
Jakub Kicinski Jan. 13, 2021, 1:48 a.m. UTC | #3
On Tue, 12 Jan 2021 17:46:25 -0800 Jakub Kicinski wrote:
> On Tue, 12 Jan 2021 11:03:00 +0100 Marc Kleine-Budde wrote:
> > On 1/12/21 10:54 AM, Vincent Mailhol wrote:  
> > > Call skb_tx_timestamp() within can_put_echo_skb() so that a software
> > > tx timestamp gets attached on the skb.
> > > 
> > > There two main reasons to include this call in can_put_echo_skb():
> > > 
> > >   * It easily allow to enable the tx timestamp on all devices with
> > >     just one small change.
> > > 
> > >   * According to Documentation/networking/timestamping.rst, the tx
> > >     timestamps should be generated in the device driver as close as
> > >     possible, but always prior to passing the packet to the network
> > >     interface. During the call to can_put_echo_skb(), the skb gets
> > >     cloned meaning that the driver should not dereference the skb
> > >     variable anymore after can_put_echo_skb() returns. This makes
> > >     can_put_echo_skb() the very last place we can use the skb without
> > >     having to access the echo_skb[] array.
> > > 
> > > Remark: by default, skb_tx_timestamp() does nothing. It needs to be
> > > activated by passing the SOF_TIMESTAMPING_TX_SOFTWARE flag either
> > > through socket options or control messages.
> > > 
> > > References:
> > > 
> > >  * Support for the error queue in CAN RAW sockets (which is needed for
> > >    tx timestamps) was introduced in:
> > >    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eb88531bdbfaafb827192d1fc6c5a3fcc4fadd96
> > > 
> > >   * Put the call to skb_tx_timestamp() just before adding it to the
> > >     array: https://lkml.org/lkml/2021/1/10/54
> > > 
> > >   * About Tx hardware timestamps
> > >     https://lore.kernel.org/linux-can/20210111171152.GB11715@hoboy.vegasvil.org/
> > > 
> > > Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>    
> > 
> > Applied to linux-can-next/testing  
> 
> Please make sure to address the warnings before this hits net-next:
> 
> https://patchwork.kernel.org/project/netdevbpf/patch/20210112130538.14912-2-mailhol.vincent@wanadoo.fr/
> 
> Actually it appears not to build with allmodconfig..?

Erm, apologies, I confused different CAN patches, this one did not get
build tested.
Marc Kleine-Budde Jan. 13, 2021, 8:27 a.m. UTC | #4
On 1/13/21 2:48 AM, Jakub Kicinski wrote:
>> Please make sure to address the warnings before this hits net-next:
>>
>> https://patchwork.kernel.org/project/netdevbpf/patch/20210112130538.14912-2-mailhol.vincent@wanadoo.fr/
>>
>> Actually it appears not to build with allmodconfig..?
> 
> Erm, apologies, I confused different CAN patches, this one did not get
> build tested.

For the record:

The patch that was tested by the kbuild robot and failed to build, failed
because the patch didn't include a git base reference [1] and was applied to the
wrong tree. Using the correct tree it compiles.

regards,
Marc

[1] The submitter already knows to include that next time.
diff mbox series

Patch

diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c
index 53683d4312f1..6a64fe410987 100644
--- a/drivers/net/can/dev/skb.c
+++ b/drivers/net/can/dev/skb.c
@@ -65,6 +65,8 @@  int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
 		/* save frame_len to reuse it when transmission is completed */
 		can_skb_prv(skb)->frame_len = frame_len;
 
+		skb_tx_timestamp(skb);
+
 		/* save this skb for tx interrupt echo handling */
 		priv->echo_skb[idx] = skb;
 	} else {