Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3174310rdh; Thu, 28 Sep 2023 05:06:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyzSQv/C8UezQ5lXUZ+Gc0PjwXdb9QVp155yQ6W/Ne0YbL0aiOEmcXjOPpvxNA8zXj645+ X-Received: by 2002:a17:90a:2a42:b0:268:b64b:f684 with SMTP id d2-20020a17090a2a4200b00268b64bf684mr934431pjg.33.1695902776088; Thu, 28 Sep 2023 05:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695902776; cv=none; d=google.com; s=arc-20160816; b=u9VV3vjNXJAAtmCzCRMj/MlEAL4UU9mCqUhdkppIxzao7fLz+xCZetrk6BmsveMnXX CcctNK1Cxxhz5k6Dk1jo2FIpoPSIJtRCsXVGDRI+kyc051Xdllg+iLAiaF/dDEFPYxL7 kjT6jU8tKv3SUJDO6J9QMNwce9iT383uGjeCK0jRDucG04BlLTzVazV50XQ4Mfz2PZlc DXiwpNAllJFwzFJi9kYrtLBNhqaqdhLjOrxe3gdB8i7pUfo2McWUv/5Yid3+xpf8aCp5 2wnxI0bUu3CKzzc/UjVYyt5Fo4QWF9jQ9e6m04uAmEe/UADZFv1W/OprFJr7vJCVZx7J NCNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=TM7F2V+whzsqECetEhOwq9nYpakVVR6ES249GfF2OOE=; fh=xWbqcn27VHZ4a/49qCK8C2oHcRPbNr7kRctzGz1PkIM=; b=iIj6F91jXNLvVsoCFtW3WFgYfumxQyvZFk0GuNew1KLcgOEg8ZZrTIe4zaXg3J9pTs DO316SJawUewyos8zfA5/5p8CBtCmTKB3nKpxiN9tqTq2P8e6U7u8BEPOL4vFGcN1kn/ sKhYNPijXUADlWjzrpAhnCY04RfjOQMNtmhhZxdRHUafx+nXw1NMH8winPGYuV9LAGsc L9MIRgDFYpMcVCA/kY3RotMWuUxn9i1hm0KiZjHH71/InEkWI4kjTBwi/oIUPMIMYjyU KF6AHOyC5axvXxZIfHXPbdRwG1OWjSWb+wBuro6xKDdeCvGcoLtguzCdqJTrCj+Ioy4r 0Y2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LdPPCiPZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id o17-20020a17090aac1100b00274c6997c25si18105518pjq.110.2023.09.28.05.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:06:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LdPPCiPZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8BB1E8317EA1; Thu, 28 Sep 2023 01:24:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbjI1IYn (ORCPT + 99 others); Thu, 28 Sep 2023 04:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjI1IYm (ORCPT ); Thu, 28 Sep 2023 04:24:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D137192 for ; Thu, 28 Sep 2023 01:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695889435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TM7F2V+whzsqECetEhOwq9nYpakVVR6ES249GfF2OOE=; b=LdPPCiPZ8PtIcYZ+tJ3J46jdif1hnX9tf+Fw7wVb/F9M9cUeOsVRmFwM6oHEkmWydCcaG4 08P84VGEmd0SIVj2rQ61G9O07xKxMnvSFktQV/uWtlYcEy/vMkrAkfqC6TWERQaKyutbYW +/D6O4xWfCQbene/4nrluRrZZWb2Iww= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-326-07kxruJ8Nemwv_hQpsF5XQ-1; Thu, 28 Sep 2023 04:23:54 -0400 X-MC-Unique: 07kxruJ8Nemwv_hQpsF5XQ-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9ae660b4e41so283602066b.1 for ; Thu, 28 Sep 2023 01:23:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695889433; x=1696494233; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TM7F2V+whzsqECetEhOwq9nYpakVVR6ES249GfF2OOE=; b=PK4OTlrm0JTiQIQyJg008M4+3TA4C0ot2H0oliTS9WMOK9NgIFWhU1RrAADQCFbQLB xFhu2bEgC4bpduCKwe5KpQ2eyPKf6cCBjkThO08Ir1iQ3dMXU5zyOeLApCmbic42n8Js 8UGWhCAdRjDriR7mOar1J3Il34J7cO5o7PMa2k1V9qY8a8Zy4W57wc8w3I51A1RzubLx kPqu64Q/mE25VfUW3nZXrKDElE/Hti/gBGNBtcCB0XjnL4nk26Vj6XT8pE17PvK/MRfy QKTY2TRAk2orjUHjenQDOmREJKjyfGeNillOX5rwD81eO0juKYUrzDTmEjP3xQni1ht7 Tfkw== X-Gm-Message-State: AOJu0YxzMm06PjeSo+8QNccB6DHECZXIKKU+qTuJthUvY+ZPlshmQ2Fr l7+P+dZ9xFM4evhPoXlmPSFJPEgLr4FpsTNqSh5ZH/0HUtvRyXVVvo5muZCqyfoIJQcUPhuRSNI 8WnuySspyIDmjeNZzV12D4q7I X-Received: by 2002:a17:906:2258:b0:9ad:e66a:413f with SMTP id 24-20020a170906225800b009ade66a413fmr522600ejr.3.1695889432886; Thu, 28 Sep 2023 01:23:52 -0700 (PDT) X-Received: by 2002:a17:906:2258:b0:9ad:e66a:413f with SMTP id 24-20020a170906225800b009ade66a413fmr522583ejr.3.1695889432534; Thu, 28 Sep 2023 01:23:52 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-233-183.dyn.eolo.it. [146.241.233.183]) by smtp.gmail.com with ESMTPSA id ck17-20020a170906c45100b00992e14af9c3sm10557001ejb.143.2023.09.28.01.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 01:23:51 -0700 (PDT) Message-ID: <619e3735d99c8642b7b84a151515c2fee99ff694.camel@redhat.com> Subject: Re: [PATCH net-next v5] net/core: Introduce netdev_core_stats_inc() for trace From: Paolo Abeni To: Yajun Deng , davem@davemloft.net, edumazet@google.com, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Lobakin Date: Thu, 28 Sep 2023 10:23:50 +0200 In-Reply-To: <20230919135517.286766-1-yajun.deng@linux.dev> References: <20230919135517.286766-1-yajun.deng@linux.dev> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 01:24:47 -0700 (PDT) On Tue, 2023-09-19 at 21:55 +0800, Yajun Deng wrote: > Although there is a kfree_skb_reason() helper function that can be used t= o > find the reason why this skb is dropped, but most callers didn't increase > one of rx_dropped, tx_dropped, rx_nohandler and rx_otherhost_dropped. >=20 > For the users, people are more concerned about why the dropped in ip > is increasing. >=20 > Introduce netdev_core_stats_inc() for trace. Also, move dev_core_stats() > and netdev_core_stats_alloc() to dev.c, as they are not called externally= . >=20 > Signed-off-by: Yajun Deng > Suggested-by: Alexander Lobakin > --- > v5: Access the per cpu pointer before reach the relevant offset. > v4: Introduce netdev_core_stats_inc() instead of export dev_core_stats_*_= inc() > v3: __cold should be added to the netdev_core_stats_alloc(). > v2: use __cold instead of inline in dev_core_stats(). > v1: https://lore.kernel.org/netdev/20230911082016.3694700-1-yajun.deng@li= nux.dev/ > --- > include/linux/netdevice.h | 21 ++++----------------- > net/core/dev.c | 26 ++++++++++++++++++++++++-- > 2 files changed, 28 insertions(+), 19 deletions(-) >=20 > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > index db3d8429d50d..4c258d44c7d2 100644 > --- a/include/linux/netdevice.h > +++ b/include/linux/netdevice.h > @@ -4001,32 +4001,19 @@ static __always_inline bool __is_skb_forwardable(= const struct net_device *dev, > return false; > } > =20 > -struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct ne= t_device *dev); > - > -static inline struct net_device_core_stats __percpu *dev_core_stats(stru= ct net_device *dev) > -{ > - /* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() *= / > - struct net_device_core_stats __percpu *p =3D READ_ONCE(dev->core_stats)= ; > - > - if (likely(p)) > - return p; > - > - return netdev_core_stats_alloc(dev); > -} > +void netdev_core_stats_inc(struct net_device *dev, u32 offset); > =20 > #define DEV_CORE_STATS_INC(FIELD) \ > static inline void dev_core_stats_##FIELD##_inc(struct net_device *dev) = \ > { \ > - struct net_device_core_stats __percpu *p; \ > - \ > - p =3D dev_core_stats(dev); \ > - if (p) \ > - this_cpu_inc(p->FIELD); \ > + netdev_core_stats_inc(dev, \ > + offsetof(struct net_device_core_stats, FIELD)); \ > } > DEV_CORE_STATS_INC(rx_dropped) > DEV_CORE_STATS_INC(tx_dropped) > DEV_CORE_STATS_INC(rx_nohandler) > DEV_CORE_STATS_INC(rx_otherhost_dropped) > +#undef DEV_CORE_STATS_INC > =20 > static __always_inline int ____dev_forward_skb(struct net_device *dev, > struct sk_buff *skb, > diff --git a/net/core/dev.c b/net/core/dev.c > index 606a366cc209..4bc0161bc0d6 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -10497,7 +10497,8 @@ void netdev_stats_to_stats64(struct rtnl_link_sta= ts64 *stats64, > } > EXPORT_SYMBOL(netdev_stats_to_stats64); > =20 > -struct net_device_core_stats __percpu *netdev_core_stats_alloc(struct ne= t_device *dev) > +static __cold struct net_device_core_stats __percpu *netdev_core_stats_a= lloc( > + struct net_device *dev) > { > struct net_device_core_stats __percpu *p; > =20 > @@ -10510,7 +10511,28 @@ struct net_device_core_stats __percpu *netdev_co= re_stats_alloc(struct net_device > /* This READ_ONCE() pairs with the cmpxchg() above */ > return READ_ONCE(dev->core_stats); > } > -EXPORT_SYMBOL(netdev_core_stats_alloc); > + > +static inline struct net_device_core_stats __percpu *netdev_core_stats( > + struct net_device *dev) I'm sorry for the delayed feedback - conference and traveling in the way. It looks like the 'inline' keyword above is a left-over of a previous revision? The compiler should generate the same code even without it, right? If so, it should be better drop it. Cheers, Paolo