Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp662601rdb; Tue, 19 Sep 2023 06:51:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSWtiXlGb1igPrA/moKEfN7rF6NCgg0Zgt3PT40MtAvXgCLV4dHV0pWDYjRk+UbbYOB/Qk X-Received: by 2002:a05:6a21:1f25:b0:141:a70:6c26 with SMTP id ry37-20020a056a211f2500b001410a706c26mr11508115pzb.57.1695131516401; Tue, 19 Sep 2023 06:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695131516; cv=none; d=google.com; s=arc-20160816; b=i5ArQ1nQexaEZKXhApLzy1euNSd6hSofuZue5+7RLsAKH4QMrXEZmZ9aIbiI1kqTGS Xz23NNuaM2z2xFJLaY2BY5AOANMn9suIoAZqBavA04xLCH0Q/xOMiaCDRuIrwQ4HCFH7 xhcL7hHzNSoUCr2JYD9FsQPzP+XshfqmCYO+XQG7ozcY9NavOC1GZsTXynUjQVuMJRop 8mUI6m/oBgYmqVPR92osow34CQ9puygfUgi6pE4Ef9ZIM7x68OLOeukBldvVQDhzwNQq fB6Yy54Js3GXXtYV8/y7mUTg9yhFZlUK+Ad5BJ0culpjL87luPl9XZ6QBT7yF8XGfoML pSrg== 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=fcHdjnvsZl7BjaN6uuW5yFHe3gIRLmoYmXk7ZuAeIGM=; fh=xWbqcn27VHZ4a/49qCK8C2oHcRPbNr7kRctzGz1PkIM=; b=lXni9VOayoDAxto4WOr/1i1q+cTGzd71GKfc+77Q25a/QSFHODUsSl6eHg2hum9IBT EGouoZEenEKths8P2n5QGcMzRRLLxhy31LCf8Wh+FP+z9NzdsOucUlGL2tvkXgGQCvbH QpHpWGzeQL+YVtaDPRdELagRMg48fXlIt4mMmgk8v9XCaJt5VwvJWJBVl2730Uq+MWbw n9ps1I7g+T/9Rok1D4TYS/V8rtbymsLgjp3bnUn59mlEcsgdg2eLNdT8RP08q2QpuVxM TrMebr9G6JLsSMXTh85LhScrVVpqifW1RAxgs89bDrI0HGLOfzcMekG76hT2uWFEtbYW V+YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DJGyWRHb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id k17-20020a056a00135100b0068fb9890700si9999654pfu.332.2023.09.19.06.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 06:51:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DJGyWRHb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 4A724825B539; Tue, 19 Sep 2023 02:11:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbjISJLw (ORCPT + 99 others); Tue, 19 Sep 2023 05:11:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjISJLt (ORCPT ); Tue, 19 Sep 2023 05:11:49 -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 B6A30E6 for ; Tue, 19 Sep 2023 02:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695114661; 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=fcHdjnvsZl7BjaN6uuW5yFHe3gIRLmoYmXk7ZuAeIGM=; b=DJGyWRHbbic97mLpI1gy1P0MC7+jYeWJ2khPvVkRFMYfnLxujqIU3IZgB1Q2kr6CPNDDSm HB5aym4SoxOTuIRACbspnZzX0HxHzsir6lr83KHRcwipVx5sbFWP538FdsEeqmVkKdeVjD jvZtxRmyqIGYd1HeipEPBVYcpvC/BaA= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-1HTzO1IjPCmjem-Rnq7s6Q-1; Tue, 19 Sep 2023 05:10:59 -0400 X-MC-Unique: 1HTzO1IjPCmjem-Rnq7s6Q-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2a7a6393ba6so8740721fa.1 for ; Tue, 19 Sep 2023 02:10:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695114658; x=1695719458; 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=fcHdjnvsZl7BjaN6uuW5yFHe3gIRLmoYmXk7ZuAeIGM=; b=SWVbBE2OPuXhf0PNd4G1JCtO6agWGC6byMpcDih/gx8D39Tn3bLZEw78qcOUskOVnP 70+XGkkmNejeoA/HqSU4ieyMArhow8tSQPEH/dcZmR5LYYHN+8/hI5N/W1tTQGNT+tEu kv8y+fpoaT+P2GQUxgGGHJQI59CoYG9/7upPlQrvk4YTfpg1+NMuLPgyW2ydz0ID3u1A 6R+XFqIRxh/lQfSnO0kfHs1wYFowY8rfp2TysA6XFuT4bx0w6rrM5O9qgaE/Rfq6RvCj FefAuUnYswKa9XyZKPlkF0nf2frpbqegOy63V/Dk15g+c9EDo/Sb0j39TN55gOHiuGAb qCQg== X-Gm-Message-State: AOJu0YxmUshobiW8qUImd5Evlq7x56VBNo+0vV2kmdrjcRPmEY/6BFu3 IVaG1v9+Tr8ehfrLsD+YRo1S1GMbWmBNXMXjwjBWRRW1NaB9PLXg7y7RbcCg+OVu/LQIYU+fFkY q5RCPIEr48vh0M6TubqeQePY9 X-Received: by 2002:a2e:9cc1:0:b0:2b6:cd7f:5ea8 with SMTP id g1-20020a2e9cc1000000b002b6cd7f5ea8mr8870057ljj.1.1695114658063; Tue, 19 Sep 2023 02:10:58 -0700 (PDT) X-Received: by 2002:a2e:9cc1:0:b0:2b6:cd7f:5ea8 with SMTP id g1-20020a2e9cc1000000b002b6cd7f5ea8mr8870037ljj.1.1695114657663; Tue, 19 Sep 2023 02:10:57 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-241-221.dyn.eolo.it. [146.241.241.221]) by smtp.gmail.com with ESMTPSA id g5-20020a170906394500b0099bc038eb2bsm7488645eje.58.2023.09.19.02.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 02:10:57 -0700 (PDT) Message-ID: <37c2c3163c053138da40be6713914c8bb103dada.camel@redhat.com> Subject: Re: [PATCH net-next v4] 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: Tue, 19 Sep 2023 11:10:56 +0200 In-Reply-To: <20230918024055.221900-1-yajun.deng@linux.dev> References: <20230918024055.221900-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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:11:53 -0700 (PDT) On Mon, 2023-09-18 at 10:40 +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 > --- > 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 0896aaa91dd7..cddd4873b5b0 100644 > --- a/include/linux/netdevice.h > +++ b/include/linux/netdevice.h > @@ -3980,32 +3980,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 ccff2b6ef958..f4cccdf05450 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -10475,7 +10475,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 > @@ -10488,7 +10489,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) > +{ > + /* 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) > +{ > + struct net_device_core_stats __percpu *p; > + > + p =3D netdev_core_stats(dev); > + if (p) > + this_cpu_inc(*(unsigned long *)((void *)p + offset)); The above is causing a lot of compile warning, as it's discarding the (required) __percpu annotation. You need to first access the per cpu pointer and then reach for the relevant offset. Cheers, Paolo