mbox series

[v4,0/1] Add software TX timestamps to the CAN devices

Message ID 20210112095437.6488-1-mailhol.vincent@wanadoo.fr
Headers show
Series Add software TX timestamps to the CAN devices | expand

Message

Vincent MAILHOL Jan. 12, 2021, 9:54 a.m. UTC
With the ongoing work to add BQL to Socket CAN, I figured out that it
would be nice to have an easy way to mesure the latency.

And one easy way to do so it to check the round trip time of the
packet by doing the difference between the software rx timestamp and
the software tx timestamp.

rx timestamps are already available. This patch gives the missing
piece: add a tx software timestamp feature to the CAN devices.

Of course, the tx software timestamp might also be used for other
purposes such as performance measurements of the different queuing
disciplines (e.g. by checking the difference between the kernel tx
software timestamp and the userland tx software timestamp).

v2 was a mistake, please ignore it (fogot to do git add, changes were
not reflected...)

v3 reflects the comments that Jeroen made in
https://lkml.org/lkml/2021/1/10/54

v4 rebases the patch on linux-can-next/testing and suppress the
comment related to SOF_TIMESTAMPING_TX_HARDWARE.
Reference: https://lore.kernel.org/linux-can/20210111171152.GB11715@hoboy.vegasvil.org/

Vincent Mailhol (1):
  can: dev: add software tx timestamps

 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.

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |