Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2936604rdb; Tue, 12 Sep 2023 17:53:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBmeFwFc023AbjCVjTlFPtLD4+uo332RcItEBipXycqfbX+X9EheJHjrCCHYuVYEozpO7T X-Received: by 2002:a05:6a00:1590:b0:682:4ef7:9b0b with SMTP id u16-20020a056a00159000b006824ef79b0bmr1883543pfk.0.1694566419855; Tue, 12 Sep 2023 17:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694566419; cv=none; d=google.com; s=arc-20160816; b=V8cyv2M1AmDGTg/x3dVQ6SmDPVEM5DZUr54WfZMDKk3Qhy84pTT1D6XbIDoovjuuo+ K4YwccW921YyGAZP40pVYB1rqteGnZsWYfBsLzqKktmWKsiCMkmVnOfWLdP5xGn9tHME 3rmDGzsosuXw4ryUo+Q4b+i3lCZsKpWjllnjetwqtgROv+mirhVTQaGCRLRj0G9r4y34 bWzepIADFMsMy3qVJtHE1xa7K3OmU0j7yCg0mGoLSsREJDzAW3LR74mr90z1ezjPU4VM L7D8QF48BA/HcacdF867UFQqW0AtY+RShdHApAj4VpmbptDuHF95Cc7LARmPlfe61VMV iy7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ltbshIgUZ3GxU8tCibnnL+HEfHX0Nv7hadU45yI7Sy8=; fh=3FqSAtdDZlHeNogW7Ogvr/+bh39HT/wkq0D3/3wCuBI=; b=uU4zd1FVWSgibuLygvIiVh91M1YDbAtfdwA14cvHiFDgKKPex10w4hACUQ/yrp/KRq gqrWXXr+00aa+s5+uwJlnkmDKSb/bbTs+deiCXrIEBwRZ1pzgqt/bEDP18SKoN1Dzk/4 HIWqAT1ZuAqwTBNj8lzp+CFBc8BU86Eqr2PMRKTAqQBbYk5m/nEu4GWqEqpQeXIU/LHD IYSSLpRMSe/OdG4qQPoBBdGOEk/CtVio21uK3vccnzOXHOhpHR7mNsJf6oG89gIdrHyg CMeXtgwiCS4Sx9R7r900XWnHdPAttDt94A8ieIej+PlOBo+n7gTrh3/uNLqaDWMFZNwy XVvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KfN+opur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a21-20020a056a000c9500b0068e39cd7acdsi9202169pfv.83.2023.09.12.17.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 17:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KfN+opur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3707080740CF; Tue, 12 Sep 2023 11:04:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237274AbjILSEL (ORCPT + 99 others); Tue, 12 Sep 2023 14:04:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233127AbjILSEL (ORCPT ); Tue, 12 Sep 2023 14:04:11 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F798115 for ; Tue, 12 Sep 2023 11:04:07 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-414ba610766so38091cf.0 for ; Tue, 12 Sep 2023 11:04:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694541846; x=1695146646; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ltbshIgUZ3GxU8tCibnnL+HEfHX0Nv7hadU45yI7Sy8=; b=KfN+opurEyItLHYtyyguBdu9hsqBm6LR5DZtVjpUAAEH44D/L4PQ2bTtfupbK5Wx8u wvXlnRV8/rpzMoKHt1RtmhajlYMZYDxVXsWu3a6t2Ffrnwn+mip8GFMWZlKKDgK8ht1x 3r8vAQjbOnAxsJGa4iaHMfBkyUlQ5gye7n9EmPnTny9CjMPzp8hlI8X9yjIiIbz7QTZV dr8TU9csq9qk5TPtxI3yCwmQ0IBseOLxWCfQG3N9k1pFpX3ytE4JBSeRcshxiWLcilXW W59UXNyFTzhdGe69egs1Rl+cJ5Sl9J+vc3H/MfOWkOzkNIeZvoyjsJmIRs5A/S6n2o4Q 89Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694541846; x=1695146646; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ltbshIgUZ3GxU8tCibnnL+HEfHX0Nv7hadU45yI7Sy8=; b=p3q/m550cntuaM1C6Rvom5bo+HXtozq2PZ1ZH1QBU5QJ1SxfIhthupmh2pYQgaT6qf IOaFvBUiyqbzXetrLO9MUnh4ENFwzUmpRuJiM7IIryxpdDWF9fuSDP2vWM+tei1gQclF WW7QbanzlxJc/IeFc1SQbU9IeCDg8RgsvBEzyoEpNhtdl0JvkxDqVT/FHcYV3D8N5O1v cEzOWz12WTFW+Rkmme8+EMG7IQhrGfSKTvwQoe3yUu49feqXB0yCHSjxj6huh2Gd38bS dOQHDeS+Dx4Ut/TcmaJ360jG0IcQJ0m9XOdGwrbmtVc/UsP8lC85qrbeSuN2MlKdE4K7 tOgg== X-Gm-Message-State: AOJu0Yw8ISPmOTFOkppz+dWn/Smal6D5BlA7rSFqfaywCTSERR8xyyNT IZMXl59YLeynUShquPf5TpQlZGHAYzyZfuRhFmSi+w== X-Received: by 2002:ac8:4e43:0:b0:412:16f:c44f with SMTP id e3-20020ac84e43000000b00412016fc44fmr17569qtw.6.1694541845921; Tue, 12 Sep 2023 11:04:05 -0700 (PDT) MIME-Version: 1.0 References: <20230911082016.3694700-1-yajun.deng@linux.dev> <39c906f6-910d-01c7-404a-8fe6a161ef2e@intel.com> <8bc6c1cd-50bb-44ef-5979-3bb50a70afcb@intel.com> In-Reply-To: <8bc6c1cd-50bb-44ef-5979-3bb50a70afcb@intel.com> From: Eric Dumazet Date: Tue, 12 Sep 2023 20:03:54 +0200 Message-ID: Subject: Re: [PATCH] net/core: Export dev_core_stats_rx_dropped_inc sets To: Alexander Lobakin Cc: Yajun Deng , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:04:25 -0700 (PDT) X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On Tue, Sep 12, 2023 at 7:44=E2=80=AFPM Alexander Lobakin wrote: > > From: Eric Dumazet > Date: Tue, 12 Sep 2023 19:28:50 +0200 > > > On Tue, Sep 12, 2023 at 7:16=E2=80=AFPM Alexander Lobakin > > wrote: > >> > >> From: Eric Dumazet > >> Date: Tue, 12 Sep 2023 18:04:44 +0200 > >> > >>> On Tue, Sep 12, 2023 at 5:58=E2=80=AFPM Alexander Lobakin > >>> wrote: > >>>> > >>>> From: Eric Dumazet > >>>> Date: Tue, 12 Sep 2023 06:23:24 +0200 > >>>> > >>>>> On Mon, Sep 11, 2023 at 10:20=E2=80=AFAM Yajun Deng wrote: > >>>>>> > >>>>>> Although there is a kfree_skb_reason() helper function that can be= used > >>>>>> to find the reason for dropped packets, but most callers didn't in= crease > >>>>>> one of rx_dropped, tx_dropped, rx_nohandler and rx_otherhost_dropp= ed. > >>>> > >>>> [...] > >>>> > >>>>>> EXPORT_SYMBOL(netdev_stats_to_stats64); > >>>>>> > >>>>>> -struct net_device_core_stats __percpu *netdev_core_stats_alloc(st= ruct net_device *dev) > >>>>>> +static struct net_device_core_stats __percpu *netdev_core_stats_a= lloc(struct net_device *dev) > >>>>>> { > >>>>>> struct net_device_core_stats __percpu *p; > >>>>>> > >>>>>> @@ -10488,7 +10488,33 @@ struct net_device_core_stats __percpu *ne= tdev_core_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 *dev_core_sta= ts(struct net_device *dev) > >>>>> > >>>>> Please remove this inline attritbute. Consider using __cold instead= . > >>>> > >>>> __cold? O_o I thought the author's inlining it as it's a couple > >>>> locs/intstructions, while the compilers would most likely keep it > >>>> non-inlined as it's referenced 4 times. __cold will for sure keep it > >>>> standalone and place it in .text.cold, i.e. far away from the call s= ites. > >>>> I realize dev_core_stats_*() aren't called frequently, but why makin= g > >>>> only one small helper cold rather than all of them then? > >>>> > >>> > >>> This helper is used at least one time per netdevice lifetime. > >>> This is definitely cold. > >> > >> But then each dev_stats_*_inc() (not cold) has to call it from a > >> completely different piece of .text far from their. I either don't > >> understand the idea or dunno. Why not make them cold as well then? > >> > > > > The __cold attribute is only applied to the helper _allocating_ the > > memory, once. > > Then it should be applied to netdev_core_stats_alloc(), not > dev_core_stats(). The latter only dereferences the already existing > pointer or calls the former, which actually does the allocation. > That's why I don't get why make one if/else non-inline or even cold. Sure, this was what was suggested (perhaps not _very_ precisely, but the general idea was pretty clear). v2 seems ok, right ? It seems we are all on the same page. +static __cold struct net_device_core_stats __percpu *dev_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_st= ats); + + if (likely(p)) + return p; + + return netdev_core_stats_alloc(dev); +} + +#define DEV_CORE_STATS_INC(FIELD) \ +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); \ +} \ +EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc)