netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/1] Add software TX timestamps to the CAN devices
@ 2021-01-12  9:54 Vincent Mailhol
  2021-01-12  9:54 ` [PATCH v4 1/1] can: dev: add software tx timestamps Vincent Mailhol
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Mailhol @ 2021-01-12  9:54 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can, Jeroen Hofstee, Richard Cochran
  Cc: Wolfgang Grandegger, David S . Miller, Jakub Kicinski,
	open list : NETWORKING DRIVERS, Vincent Mailhol

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(+)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 1/1] can: dev: add software tx timestamps
  2021-01-12  9:54 [PATCH v4 0/1] Add software TX timestamps to the CAN devices Vincent Mailhol
@ 2021-01-12  9:54 ` Vincent Mailhol
  2021-01-12 10:03   ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Mailhol @ 2021-01-12  9:54 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can, Jeroen Hofstee, Richard Cochran
  Cc: Wolfgang Grandegger, David S . Miller, Jakub Kicinski,
	open list : NETWORKING DRIVERS, Vincent Mailhol

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(+)

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 {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/1] can: dev: add software tx timestamps
  2021-01-12  9:54 ` [PATCH v4 1/1] can: dev: add software tx timestamps Vincent Mailhol
@ 2021-01-12 10:03   ` Marc Kleine-Budde
  2021-01-13  1:46     ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2021-01-12 10:03 UTC (permalink / raw)
  To: Vincent Mailhol, linux-can, Jeroen Hofstee, Richard Cochran
  Cc: Wolfgang Grandegger, David S . Miller, Jakub Kicinski,
	open list : NETWORKING DRIVERS


[-- Attachment #1.1: Type: text/plain, Size: 1972 bytes --]

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

-- 
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 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/1] can: dev: add software tx timestamps
  2021-01-12 10:03   ` Marc Kleine-Budde
@ 2021-01-13  1:46     ` Jakub Kicinski
  2021-01-13  1:48       ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2021-01-13  1:46 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Vincent Mailhol, linux-can, Jeroen Hofstee, Richard Cochran,
	Wolfgang Grandegger, David S . Miller,
	open list : NETWORKING DRIVERS

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..?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/1] can: dev: add software tx timestamps
  2021-01-13  1:46     ` Jakub Kicinski
@ 2021-01-13  1:48       ` Jakub Kicinski
  2021-01-13  8:27         ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2021-01-13  1:48 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Vincent Mailhol, linux-can, Jeroen Hofstee, Richard Cochran,
	Wolfgang Grandegger, David S . Miller,
	open list : NETWORKING DRIVERS

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/1] can: dev: add software tx timestamps
  2021-01-13  1:48       ` Jakub Kicinski
@ 2021-01-13  8:27         ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2021-01-13  8:27 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Vincent Mailhol, linux-can, Jeroen Hofstee, Richard Cochran,
	Wolfgang Grandegger, David S . Miller,
	open list : NETWORKING DRIVERS


[-- Attachment #1.1: Type: text/plain, Size: 964 bytes --]

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 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-13  8:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12  9:54 [PATCH v4 0/1] Add software TX timestamps to the CAN devices Vincent Mailhol
2021-01-12  9:54 ` [PATCH v4 1/1] can: dev: add software tx timestamps Vincent Mailhol
2021-01-12 10:03   ` Marc Kleine-Budde
2021-01-13  1:46     ` Jakub Kicinski
2021-01-13  1:48       ` Jakub Kicinski
2021-01-13  8:27         ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).