Add software TX timestamps to the CAN devices

Started by Vincent Mailhol on Jan 12, 2021 · 6 messages from 3 authors · Last reply Jan 13, 2021

Series

1 patch, 1 file

+2 −0

Subsystems (2)

Maintainers (3)

STALE2148d LANDED

Status: Landed in mainline.

Revision v4 (4 revisions archived).

Revisions (4)
  1. v1
  2. v2 [diff against previous]
  3. v3 [diff against previous]
  4. v4 current [diff against previous]

open the first message on its own page

  1. [PATCH v4 1/1] can: dev: add software tx timestamps
    Revisions and related patches
    Revisions (4)
    1. v1
    2. v2 [diff against previous]
    3. v3 [diff against previous]
    4. v4 current [diff against previous]
Message details and related content
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

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

Message details and related content
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 <redacted>
---
 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

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

Message details and related content
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 <redacted>
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 |

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

Message details and related content
On Tue, 12 Jan 2021 11:03:00 +0100 Marc Kleine-Budde wrote:
On 1/12/21 10:54 AM, Vincent Mailhol wrote:
quoted
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 <redacted>  
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..?

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

Message details and related content
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:
quoted
On 1/12/21 10:54 AM, Vincent Mailhol wrote:  
quoted
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 <redacted>    
Applied to linux-can-next/testing  
Please make sure to address the warnings before this hits net-next:

4 more quoted lines

Erm, apologies, I confused different CAN patches, this one did not get
build tested.

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

Message details and related content
On 1/13/21 2:48 AM, Jakub Kicinski wrote:
quoted
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 |
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help