From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 853B9E95A91 for ; Mon, 9 Oct 2023 10:16:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FF608D004C; Mon, 9 Oct 2023 06:16:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A068D0031; Mon, 9 Oct 2023 06:16:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029B78D004C; Mon, 9 Oct 2023 06:16:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E04E68D0031 for ; Mon, 9 Oct 2023 06:16:43 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B9BECA01C8 for ; Mon, 9 Oct 2023 10:16:43 +0000 (UTC) X-FDA: 81325519086.15.49F658E Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf11.hostedemail.com (Postfix) with ESMTP id E3B0940011 for ; Mon, 9 Oct 2023 10:16:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fOBRwknQ; spf=pass (imf11.hostedemail.com: domain of edumazet@google.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=edumazet@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696846602; a=rsa-sha256; cv=none; b=kRraXGgUm19DiOUseecWBTzw1OOMXRQ/keMhgor6Vh2oE9D3okdp42NJXz6GSOahgNRCp7 d/UpFMNSuinp9+w94eZUpobQlOTeCnr3SPKnjPjVGtaTSzW71+8jGbYYKfRGE2gcvsJt1f BIBMjSVGebbmNbcB2MsIWu/1TghAeJI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fOBRwknQ; spf=pass (imf11.hostedemail.com: domain of edumazet@google.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=edumazet@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696846602; h=from:from:sender: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:dkim-signature; bh=rNSWC1NcEQWATBxO3PFnKpkKdXA2Vi1W1PLFHkk8mKY=; b=eMVHybybqLVfxoa1C5bc3BPvgEOKRrQUSs3SBOQN7VR46m49EcCce/EWQvpxp4RhrIemYX VWiwHSGB76z5GuHj4bSiB8z1vlsnSnoA+RpG54j+D1U3KcuzMsWvIBAYejdP3a/tO2eMrz mhAmGDUtJeuE1B6klZLnahvl/hhbJaM= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4053f24c900so75905e9.1 for ; Mon, 09 Oct 2023 03:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696846600; x=1697451400; darn=kvack.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=rNSWC1NcEQWATBxO3PFnKpkKdXA2Vi1W1PLFHkk8mKY=; b=fOBRwknQ9oNUaBjF/mHnHBonVMUmo1bkIaAIrBBjM3m88upCtTes4nwgpRmcG9RJ8J lmzGd0LdfGSaQFGlIMahdSCUKeWTxAsHiQ5AURMFJi0ltok3ZKT8u62Cv7dXClfErBMl kuK8Eer/FBDBiAXP8A0maMtgWsarCtMB0XPh8rV7NL03TSSe5L0Y0xGdM6WX002oh+/m onRfuyHNkgbz6oYGnC/Iw0c+mdD8MFV/hGjmlIFjbb5tAbEBCYzA7tu7AjAEg0u5G14e 9MJAIrsHicUeCT1hAmEtUpT3U9kewCaV3+t7XrcBZjEQ5CordYtLDa1kjOcSye99H4qh hmLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696846600; x=1697451400; 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=rNSWC1NcEQWATBxO3PFnKpkKdXA2Vi1W1PLFHkk8mKY=; b=AgOapZ+sSZLaVo/w0xX84TjzL/yEmaJsgxIU51NSGkg3sxCJ0GLpVDP0c1Jxusm6Hp EHqci4+hGfxJqU8jsVmJhBzfFgqojxu94pbKVq1U+vioea/m0G6jkrKpxVKC5tq2sUgK BBnHyHrFnBpfb6nxyw2xojmN5BU4/WRSU5tpYywDU1aMi0dRCp0Ry1YZTVn1MdzGExm7 yVIUy9WYR1HFmWxty8QQfKCe4fnCZTAz9/ASwwp+RoVqsqhxH3mALgCtLRSjsZYpvKFd uSkruiGx3HthRiRKIltR/mia7WQj/lC3OAaIVbg+8p9riJ4xn1Z30Xo9l13yZLg2ePIT iQYw== X-Gm-Message-State: AOJu0Ywz3IMaN477nNVDfhw7KS2UYcsZUfkRRGgOH1LwcANpDbB0pKIN LDxbJXrRwTEaU5k6o1xogNTO7LmG3RPNETzHUGYonA== X-Google-Smtp-Source: AGHT+IHu8cp7BHI0j2KjaoQYwoQVJwgOi+YC/g3+z5dc7ANthPGOUQ19ZO5iRT4b5xLRPaPsqTwcVoJW9QtBAl4LAuU= X-Received: by 2002:a05:600c:2301:b0:405:38d1:e146 with SMTP id 1-20020a05600c230100b0040538d1e146mr320547wmo.4.1696846600202; Mon, 09 Oct 2023 03:16:40 -0700 (PDT) MIME-Version: 1.0 References: <20231007050621.1706331-1-yajun.deng@linux.dev> <917708b5-cb86-f233-e878-9233c4e6c707@linux.dev> <9f4fb613-d63f-9b86-fe92-11bf4dfb7275@linux.dev> <4a747fda-2bb9-4231-66d6-31306184eec2@linux.dev> <814b5598-5284-9558-8f56-12a6f7a67187@linux.dev> <508b33f7-3dc0-4536-21f6-4a5e7ade2b5c@linux.dev> <296ca17d-cff0-2d19-f620-eedab004ddde@linux.dev> <68eb65c5-1870-0776-0878-694a8b002a6d@linux.dev> In-Reply-To: <68eb65c5-1870-0776-0878-694a8b002a6d@linux.dev> From: Eric Dumazet Date: Mon, 9 Oct 2023 12:16:25 +0200 Message-ID: Subject: Re: [PATCH net-next v7] net/core: Introduce netdev_core_stats_inc() To: Yajun Deng Cc: rostedt@goodmis.org, mhiramat@kernel.org, dennis@kernel.org, tj@kernel.org, cl@linux.com, mark.rutland@arm.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Lobakin , linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E3B0940011 X-Stat-Signature: e4f6rjnhp9jw7z4g8cxgwz9fbzdtqk56 X-Rspam-User: X-HE-Tag: 1696846601-347654 X-HE-Meta: U2FsdGVkX18nMwuCKER2ARfd9m9b8+LYY715HfVGQZ6qL9VUzDMBaThtiM4hjrBti+gFywHgAIbCoPywpctSUEpFDPPDLywI8nOIOOQT5YaJXs5pFReTNCy0xr5P5aNjKRdthys3uTqeHGo5J4s08qne4CsNKtHmTsIC7u27sQHbsrbTy1liNasi8/330DKKKxE+TC4v/EExJ71eSSW2teOopIprwmGPBMrVgEZqzhENzpFO2QGWcvUf+x39t1hbKYU0XIRB0t6XKKCd+hO1csaadi5i1uuL+lnoeoZ/9mPO6n7MC643Td4D5HYFOYqxWbyIu5ixFrCiG5ziAQ9/q3B1C7UIGSI8xh7DmIRuOf5bQqcF4RqA4ZlkxgKI/A8d8sGCDOOAcPGGpKMoMym4OdbwBqo5L5MnFvqkAAebyjGJfWhVSUNrZKm9/u7onAyNdAkfNXROa874mk0HgXUc5oWI5UHiLwkcsCNr6hsyLp/hXvpidr9xQ1X3PYPFvqLKG/eKSidd7Q8yxo5wgGtY4MUm/DwU/aUZ7gYLMusxkpwJ8NRrIi6dUpbkw6A/v4u/1V8Br64rARCWJavtymvOD1X77F9sWRHvntm3hIGckPLtua9QVT8Z74mr65Tdy3LXAkYwmBTUjuz/iqJBvFdRuuOqnZCOI5ontC8k2L3j8vwqzHXhzs1oo12J+wJ28nRPK1FTJo42oinMDWpGsJOzGDto7GbXFta6rJSC0rcJjTVwk/wychUrylUKdx/C06RDCfAdgbNiQ+zWvg/mz6c8otR6dX5QbA7ICPBgVixCoeqH51HilfPntWeBxYvZPGuMUGit6b/rHZc/2An7igV6YFSKUioyH/DFpABOvpJfeIxpra3S0dBHPIrD6+2RR3thLDd7yhZCT6bnnI3wZWQ8f4qtMY8FbUjfiKGtiwQ3vuKFudcZGEn3Ep1sO8xO31XALFeukfoVbXMJX2QJILl 3HBxc5pS UBGaLpRQm89VAYqnprJFZdJKmlrNlba8DYS09xWxENskx4D0PLqBFbxroPLwQxIgByn1Bbx1FUWk+WZBE/UUZ4AeIqKGOnz0dxpuOt5sgbc/kXczEPZ1od4Qo4hxzmOxVDdKbUrqTSk2GfmkJovBKgpO/yIMFpQni4uXCh1yFLjJdWDdfOtFDn36j0h9PIRN3FHrc86K1qe3l3/ceyBa5WjgEt/MpmIbhyiL6FnfmFEwc2Ugr491PIs9awQqU7vEA0mmhBwdeEd1jSEAygS1nQbT2Rg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.026908, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 9, 2023 at 11:43=E2=80=AFAM Yajun Deng w= rote: > > > On 2023/10/9 17:30, Eric Dumazet wrote: > > On Mon, Oct 9, 2023 at 10:36=E2=80=AFAM Yajun Deng wrote: > >> > >> On 2023/10/9 16:20, Eric Dumazet wrote: > >>> On Mon, Oct 9, 2023 at 10:14=E2=80=AFAM Yajun Deng wrote: > >>>> On 2023/10/9 15:53, Eric Dumazet wrote: > >>>>> On Mon, Oct 9, 2023 at 5:07=E2=80=AFAM Yajun Deng wrote: > >>>>> > >>>>>> 'this_cpu_read + this_cpu_write' and 'pr_info + this_cpu_inc' will= make > >>>>>> the trace work well. > >>>>>> > >>>>>> They all have 'pop' instructions in them. This may be the key to m= aking > >>>>>> the trace work well. > >>>>>> > >>>>>> Hi all, > >>>>>> > >>>>>> I need your help on percpu and ftrace. > >>>>>> > >>>>> I do not think you made sure netdev_core_stats_inc() was never inli= ned. > >>>>> > >>>>> Adding more code in it is simply changing how the compiler decides = to > >>>>> inline or not. > >>>> Yes, you are right. It needs to add the 'noinline' prefix. The > >>>> disassembly code will have 'pop' > >>>> > >>>> instruction. > >>>> > >>> The function was fine, you do not need anything like push or pop. > >>> > >>> The only needed stuff was the call __fentry__. > >>> > >>> The fact that the function was inlined for some invocations was the > >>> issue, because the trace point > >>> is only planted in the out of line function. > >> > >> But somehow the following code isn't inline? They didn't need to add t= he > >> 'noinline' prefix. > >> > >> + field =3D (unsigned long *)((void *)this_cpu_ptr(p) + = offset); > >> + WRITE_ONCE(*field, READ_ONCE(*field) + 1); > >> > >> Or > >> + (*(unsigned long *)((void *)this_cpu_ptr(p) + offset))= ++; > >> > > I think you are very confused. > > > > You only want to trace netdev_core_stats_inc() entry point, not > > arbitrary pieces of it. > > > Yes, I will trace netdev_core_stats_inc() entry point. I mean to replace > > + field =3D (__force unsigned long > __percpu *)((__force void *)p + offset); > + this_cpu_inc(*field); > > with > > + field =3D (unsigned long *)((void *)this_cpu_ptr(p) + off= set); > + WRITE_ONCE(*field, READ_ONCE(*field) + 1); > > Or > + (*(unsigned long *)((void *)this_cpu_ptr(p) + offset))++; > > The netdev_core_stats_inc() entry point will work fine even if it doesn't > have 'noinline' prefix. > > I don't know why this code needs to add 'noinline' prefix. > + field =3D (__force unsigned long __percpu *)((__force voi= d *)p + offset); > + this_cpu_inc(*field); > C compiler decides to inline or not, depending on various factors. The most efficient (and small) code is generated by this_cpu_inc() version, allowing the compiler to inline it. If you copy/paste this_cpu_inc() twenty times, then the compiler would not inline the function anymore.