Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1537538pxb; Tue, 8 Feb 2022 21:31:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+x/aseyPrHEEESfIlshCzP2+f9wGqnJH9hmTVZrt2fG3PqSr1jq4WBdQv7b1GDyaU+dcF X-Received: by 2002:a17:902:8641:: with SMTP id y1mr523814plt.115.1644384701974; Tue, 08 Feb 2022 21:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644384701; cv=none; d=google.com; s=arc-20160816; b=mzt5+y/IAIqhoLdUud7xS885PGyqqs2DdL08F+sg6bKFyzB52IF+Y1qqYln/pddlQB Bqdqo9dpgRBBLB0MXXaTnEfgSHc/rjXGZlXBHFxtW0PDyFmxVShO5I6U8s7ZX3sEda8c BDkDBiYQeX5RRT7FwJ+Q1YxoD14aRniuIPlRvH3XvkivJwjqlhBrKC5PDwXlg9F2sdAU W6fP8qQWNTzFercC/3JHtP6DSEhLr9XhkiVS41RKQ9mV0UC1OOvioXUeKo7X2tzPNGiM RdhfLyHCnWyVMltT0eSM4iKo9IJivR2rHLQfNC4/SUukeWRrV6wvQKbWeJIvd6YZiehS Dixw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=6xP7BZ9F1nyN1TcSc1tGHcFJ8ICMaLqoqWx8tQJUo2A=; b=fuIqkImVH3lFCwYlSbmjbzH9AdxAiKZ03bSjUE65i6B3NDR557uefF+qS3ZeHd9WZB in3TusDeY/w+J6h5DkvnstxVSvCiPPOIC/38+9UZLsoEZSsCHAkNryXkqvDyj3nsupNX Dl85f71afEMEHLfkO7L05ldiqYfpDjmiyPFDERvxcUECy1kYxhXtsflPOfjxgSb1LhQd 08rkFoPszZBimlkVbe23UYa+VbcjFwLmcd0xEZF6I7KMJktoZLjOtA1vuCM2lMjShXl5 ubn5wBLzXguU6HLSTFF85cwvv4tcRURemy86SbqTG0a0vuzgQruDgMLVkoPf4tdRokk0 4OIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="r+f6T/gD"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e63si15314403pgc.53.2022.02.08.21.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:31:41 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="r+f6T/gD"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54C29C033255; Tue, 8 Feb 2022 21:31:27 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347689AbiBHGns (ORCPT + 99 others); Tue, 8 Feb 2022 01:43:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233449AbiBHGnq (ORCPT ); Tue, 8 Feb 2022 01:43:46 -0500 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E267C0401EF for ; Mon, 7 Feb 2022 22:43:45 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1644302623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6xP7BZ9F1nyN1TcSc1tGHcFJ8ICMaLqoqWx8tQJUo2A=; b=r+f6T/gDP8BMOnpfH0BmxVlmXVTD1aGOZCNLe5DtJwSohhmL3l6KOpkhJ2hcHTZn9l0Wnu a1/bwYabzPUEjWUmCXj/vIy/bE9wuI73R4pi66hEfLRpZrNAsgK+vpoc33Bcmn6bpglz55 fNcW01CyBxVUDjFSpifrrGbRMZ349NA= From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org, rostedt@goodmis.org, mingo@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH net-next] net: dev: introduce netdev_drop_inc() Date: Tue, 8 Feb 2022 14:43:18 +0800 Message-Id: <20220208064318.1075849-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We will use 'sudo perf record -g -a -e skb:kfree_skb' command to trace the dropped packets when dropped increase in the output of ifconfig. But there are two cases, one is only called kfree_skb(), another is increasing the dropped and called kfree_skb(). The latter is what we need. So we need to separate these two cases. From the other side, the dropped packet came from the core network and the driver, we also need to separate these two cases. Add netdev_drop_inc() and add a tracepoint for the core network dropped packets. use 'sudo perf record -g -a -e net:netdev_drop' and 'sudo perf script' will recored the dropped packets by the core network. Signed-off-by: Yajun Deng --- include/linux/netdevice.h | 7 +++++++ include/trace/events/net.h | 27 +++++++++++++++++++++++++++ net/core/dev.c | 30 ++++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3fb6fb67ed77..f7e8b1e33076 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2285,6 +2285,13 @@ struct net_device { }; #define to_net_dev(d) container_of(d, struct net_device, dev) +enum netdev_drop { + NETDEV_RX_DROPPED, + NETDEV_TX_DROPPED, + NETDEV_RX_NOHANDLER, +}; +void netdev_drop_inc(struct net_device *dev, enum netdev_drop drop); + static inline bool netif_elide_gro(const struct net_device *dev) { if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog) diff --git a/include/trace/events/net.h b/include/trace/events/net.h index 78c448c6ab4c..0f8e9762a856 100644 --- a/include/trace/events/net.h +++ b/include/trace/events/net.h @@ -118,6 +118,33 @@ TRACE_EVENT(net_dev_xmit_timeout, __get_str(name), __get_str(driver), __entry->queue_index) ); +TRACE_EVENT(netdev_drop, + + TP_PROTO(struct net_device *dev, void *location), + + TP_ARGS(dev, location), + + TP_STRUCT__entry( + __string(name, dev->name) + __field(void *, location) + __field(unsigned long, rx_dropped) + __field(unsigned long, tx_dropped) + __field(unsigned long, rx_nohandler) + ), + + TP_fast_assign( + __assign_str(name, dev->name); + __entry->location = location; + __entry->rx_dropped = (unsigned long)atomic_long_read(&dev->rx_dropped); + __entry->tx_dropped = (unsigned long)atomic_long_read(&dev->tx_dropped); + __entry->rx_nohandler = (unsigned long)atomic_long_read(&dev->rx_nohandler); + ), + + TP_printk("dev=%s rx_dropped=%lu tx_dropped=%lu rx_nohandler=%lu location=%p", + __get_str(name), __entry->rx_dropped, __entry->tx_dropped, __entry->rx_nohandler, + __entry->location) +); + DECLARE_EVENT_CLASS(net_dev_template, TP_PROTO(struct sk_buff *skb), diff --git a/net/core/dev.c b/net/core/dev.c index f662c6a7d7b4..213f9d1eaa8d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -392,6 +392,24 @@ static void unlist_netdevice(struct net_device *dev) dev_base_seq_inc(dev_net(dev)); } +void netdev_drop_inc(struct net_device *dev, enum netdev_drop drop) +{ + switch (drop) { + case NETDEV_RX_DROPPED: + atomic_long_inc(&dev->rx_dropped); + break; + case NETDEV_TX_DROPPED: + atomic_long_inc(&dev->tx_dropped); + break; + case NETDEV_RX_NOHANDLER: + atomic_long_inc(&dev->rx_nohandler); + break; + default: + break; + } + trace_netdev_drop(dev, __builtin_return_address(0)); +} +EXPORT_SYMBOL(netdev_drop_inc); /* * Our notifier list */ @@ -3586,7 +3604,7 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device out_kfree_skb: kfree_skb(skb); out_null: - atomic_long_inc(&dev->tx_dropped); + netdev_drop_inc(dev, NETDEV_TX_DROPPED); return NULL; } @@ -4136,7 +4154,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev) rc = -ENETDOWN; rcu_read_unlock_bh(); - atomic_long_inc(&dev->tx_dropped); + netdev_drop_inc(dev, NETDEV_TX_DROPPED); kfree_skb_list(skb); return rc; out: @@ -4188,7 +4206,7 @@ int __dev_direct_xmit(struct sk_buff *skb, u16 queue_id) local_bh_enable(); return ret; drop: - atomic_long_inc(&dev->tx_dropped); + netdev_drop_inc(dev, NETDEV_TX_DROPPED); kfree_skb_list(skb); return NET_XMIT_DROP; } @@ -4557,7 +4575,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu, local_irq_restore(flags); - atomic_long_inc(&skb->dev->rx_dropped); + netdev_drop_inc(skb->dev, NETDEV_RX_DROPPED); kfree_skb(skb); return NET_RX_DROP; } @@ -5319,9 +5337,9 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, } else { drop: if (!deliver_exact) - atomic_long_inc(&skb->dev->rx_dropped); + netdev_drop_inc(skb->dev, NETDEV_RX_DROPPED); else - atomic_long_inc(&skb->dev->rx_nohandler); + netdev_drop_inc(skb->dev, NETDEV_RX_NOHANDLER); kfree_skb(skb); /* Jamal, now you will not able to escape explaining * me how you were going to use this. :-) -- 2.25.1