* [PATCH 0/1] Add software TX timestamps to the CAN devices
@ 2021-01-10 10:35 Vincent Mailhol
2021-01-10 10:35 ` [PATCH 1/1] can: dev: add software tx timestamps Vincent Mailhol
0 siblings, 1 reply; 4+ messages in thread
From: Vincent Mailhol @ 2021-01-10 10:35 UTC (permalink / raw)
To: Marc Kleine-Budde, linux-can
Cc: Vincent Mailhol, Wolfgang Grandegger, David S. Miller,
Jakub Kicinski, open list:NETWORKING DRIVERS, open list
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).
Vincent Mailhol (1):
can: dev: add software tx timestamps
drivers/net/can/dev.c | 2 ++
1 file changed, 2 insertions(+)
--
2.26.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] can: dev: add software tx timestamps
2021-01-10 10:35 [PATCH 0/1] Add software TX timestamps to the CAN devices Vincent Mailhol
@ 2021-01-10 10:35 ` Vincent Mailhol
2021-01-10 11:29 ` Jeroen Hofstee
0 siblings, 1 reply; 4+ messages in thread
From: Vincent Mailhol @ 2021-01-10 10:35 UTC (permalink / raw)
To: Marc Kleine-Budde, linux-can
Cc: Vincent Mailhol, Wolfgang Grandegger, David S. Miller,
Jakub Kicinski, open list:NETWORKING DRIVERS, open list
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.
Remarks:
* 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.
* The hardware rx timestamp of a local loopback message is the
hardware tx timestamp. This means that there are no needs to
implement SOF_TIMESTAMPING_TX_HARDWARE for CAN sockets.
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
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
drivers/net/can/dev.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 3486704c8a95..3904e0874543 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -484,6 +484,8 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
/* save this skb for tx interrupt echo handling */
priv->echo_skb[idx] = skb;
+
+ skb_tx_timestamp(skb);
} else {
/* locking problem with netif_stop_queue() ?? */
netdev_err(dev, "%s: BUG! echo_skb %d is occupied!\n", __func__, idx);
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] can: dev: add software tx timestamps
2021-01-10 10:35 ` [PATCH 1/1] can: dev: add software tx timestamps Vincent Mailhol
@ 2021-01-10 11:29 ` Jeroen Hofstee
2021-01-10 12:32 ` Vincent MAILHOL
0 siblings, 1 reply; 4+ messages in thread
From: Jeroen Hofstee @ 2021-01-10 11:29 UTC (permalink / raw)
To: Vincent Mailhol, Marc Kleine-Budde, linux-can
Cc: Wolfgang Grandegger, David S. Miller, Jakub Kicinski,
open list:NETWORKING DRIVERS, open list
Hello Vincent,
On 1/10/21 11:35 AM, Vincent Mailhol wrote:
> Call skb_tx_timestamp() within can_put_echo_skb() so that a software
> tx timestamp gets attached on the skb.
>
[..]
>
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index 3486704c8a95..3904e0874543 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -484,6 +484,8 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
>
> /* save this skb for tx interrupt echo handling */
> priv->echo_skb[idx] = skb;
> +
> + skb_tx_timestamp(skb);
> } else {
> /* locking problem with netif_stop_queue() ?? */
> netdev_err(dev, "%s: BUG! echo_skb %d is occupied!\n", __func__, idx);
Personally, I would put the skb_tx_timestamp, before adding it to the array:
/* make settings for echo to reduce code in irq context */
skb->pkt_type = PACKET_BROADCAST;
skb->ip_summed = CHECKSUM_UNNECESSARY;
skb->dev = dev;
+ skb_tx_timestamp(skb);
/* save this skb for tx interrupt echo handling */
priv->echo_skb[idx] = skb;
I don't think it actually matters though.
Regards,
Jeroen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] can: dev: add software tx timestamps
2021-01-10 11:29 ` Jeroen Hofstee
@ 2021-01-10 12:32 ` Vincent MAILHOL
0 siblings, 0 replies; 4+ messages in thread
From: Vincent MAILHOL @ 2021-01-10 12:32 UTC (permalink / raw)
To: Jeroen Hofstee
Cc: Marc Kleine-Budde, linux-can, Wolfgang Grandegger,
David S. Miller, Jakub Kicinski, open list:NETWORKING DRIVERS,
open list
Hello Jeroen,
On Sun. 10 Jan 2021 at 20:29, Jeroen Hofstee <jhofstee@victronenergy.com> wrote:
>
> Hello Vincent,
>
> On 1/10/21 11:35 AM, Vincent Mailhol wrote:
> > Call skb_tx_timestamp() within can_put_echo_skb() so that a software
> > tx timestamp gets attached on the skb.
> >
> [..]
> >
> > diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> > index 3486704c8a95..3904e0874543 100644
> > --- a/drivers/net/can/dev.c
> > +++ b/drivers/net/can/dev.c
> > @@ -484,6 +484,8 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
> >
> > /* save this skb for tx interrupt echo handling */
> > priv->echo_skb[idx] = skb;
> > +
> > + skb_tx_timestamp(skb);
> > } else {
> > /* locking problem with netif_stop_queue() ?? */
> > netdev_err(dev, "%s: BUG! echo_skb %d is occupied!\n", __func__, idx);
>
> Personally, I would put the skb_tx_timestamp, before adding it to the array:
>
> /* make settings for echo to reduce code in irq context */
> skb->pkt_type = PACKET_BROADCAST;
> skb->ip_summed = CHECKSUM_UNNECESSARY;
> skb->dev = dev;
> + skb_tx_timestamp(skb);
>
> /* save this skb for tx interrupt echo handling */
> priv->echo_skb[idx] = skb;
I agree that it is better like that from an aesthetic point of
view. The reason to put it at the very end was to really to
blindly follow the doc and do the timestamp as late as possible.
>
> I don't think it actually matters though.
Indeed, but will still follow your suggestion though. Putting it
before would just delay the timestamp by a few assembly
instructions: it is negligible enough.
Yours sincerely,
Vincent Mailhol
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-10 12:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-10 10:35 [PATCH 0/1] Add software TX timestamps to the CAN devices Vincent Mailhol
2021-01-10 10:35 ` [PATCH 1/1] can: dev: add software tx timestamps Vincent Mailhol
2021-01-10 11:29 ` Jeroen Hofstee
2021-01-10 12:32 ` Vincent MAILHOL
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).