From patchwork Tue Jan 12 09:54:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent MAILHOL X-Patchwork-Id: 362726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A8EBC433E0 for ; Tue, 12 Jan 2021 09:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 366BC23107 for ; Tue, 12 Jan 2021 09:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389438AbhALJ5c (ORCPT ); Tue, 12 Jan 2021 04:57:32 -0500 Received: from smtp05.smtpout.orange.fr ([80.12.242.127]:21601 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728810AbhALJ5c (ORCPT ); Tue, 12 Jan 2021 04:57:32 -0500 Received: from localhost.localdomain ([153.202.107.157]) by mwinf5d28 with ME id Flvf240043PnFJp03lvkoN; Tue, 12 Jan 2021 10:55:47 +0100 X-ME-Helo: localhost.localdomain X-ME-Auth: bWFpbGhvbC52aW5jZW50QHdhbmFkb28uZnI= X-ME-Date: Tue, 12 Jan 2021 10:55:47 +0100 X-ME-IP: 153.202.107.157 From: Vincent Mailhol To: Marc Kleine-Budde , linux-can@vger.kernel.org, Jeroen Hofstee , Richard Cochran Cc: Wolfgang Grandegger , "David S . Miller" , Jakub Kicinski , "open list : NETWORKING DRIVERS" , Vincent Mailhol Subject: [PATCH v4 1/1] can: dev: add software tx timestamps Date: Tue, 12 Jan 2021 18:54:37 +0900 Message-Id: <20210112095437.6488-2-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210112095437.6488-1-mailhol.vincent@wanadoo.fr> References: <20210112095437.6488-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- 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 {