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 48D87E95A91 for ; Mon, 9 Oct 2023 09:44:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D311A8D0038; Mon, 9 Oct 2023 05:43:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE1C78D0031; Mon, 9 Oct 2023 05:43:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCFA08D0038; Mon, 9 Oct 2023 05:43:59 -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 AD2608D0031 for ; Mon, 9 Oct 2023 05:43:59 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7AB491401AE for ; Mon, 9 Oct 2023 09:43:59 +0000 (UTC) X-FDA: 81325436598.20.F1F3889 Received: from out-197.mta1.migadu.com (out-197.mta1.migadu.com [95.215.58.197]) by imf12.hostedemail.com (Postfix) with ESMTP id 7637D40013 for ; Mon, 9 Oct 2023 09:43:57 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bG99yCTa; spf=pass (imf12.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.197 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696844637; a=rsa-sha256; cv=none; b=hKavim4bVVXIcukG1mVCMcz+qRa315sapC6OmNMqr6oSEXndBT2ZAH4PWhmKF5Sj91DtpQ YvFAnRY3wxunrNvaGKuoAOkcd0SGQDHagtlMUm+OYpEqYxqUF4Uz13yRn9Wsi06+dkUThP 6Tje6mslGNmghob88lw4M7fGvGTYMRo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bG99yCTa; spf=pass (imf12.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.197 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696844637; 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=O0YOF8WiqWV3qWEelhaf9YObeiYly4thXLasaoZJfXw=; b=kMyuR3tDZR8kwVSqsDAZ5MxetVwCslHPmfwTekyAnTdDk9CQN3s+02apIgAIhPGq8tKFvs mYZZdhxFOhxUAJr7JqrHZhNgWdsJ4ORfKNJn4Ph82atIRZWeEafrH1YYG79fRg4OftbcT5 m9krQPSIejqrm+UkSdYh4XiU5h+GZmo= Message-ID: <68eb65c5-1870-0776-0878-694a8b002a6d@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1696844635; 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=O0YOF8WiqWV3qWEelhaf9YObeiYly4thXLasaoZJfXw=; b=bG99yCTavxE57bN/sitJRBv3pvuXgFF9RvNFfRAPaLA/yw7LIq18IbInFcZFQahAQDzbrG YgvZMtphcWgi9sGRwruSxGXFM+LmJ86HtdVKsvysqZ+OcE7hl+tnmhZ1Sj7OAQv3ooAkqC ZxCWXIA1dcG1z4QhUKfmSa6R6xxV+UY= Date: Mon, 9 Oct 2023 17:43:43 +0800 MIME-Version: 1.0 Subject: Re: [PATCH net-next v7] net/core: Introduce netdev_core_stats_inc() Content-Language: en-US To: Eric Dumazet 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 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> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yajun Deng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7637D40013 X-Stat-Signature: 44y1oc181tde4r97a7hrc1yfzmhuaaqs X-Rspam-User: X-HE-Tag: 1696844637-278575 X-HE-Meta: U2FsdGVkX19lrA5bylhR6HUQLw7guyZTgUkDey1HCwJRyyZ310iJc05KRXrPPVCOyXjZMqmXLW4HV8kwYKeEfyPu2mr6Ye+upRgNofQOJ+/cpDzKQpohmDc5UU+l++CJSTiX4Xq5TmWbUb7U6sIvAHYp19frZAHqN7pPXgT8WbPp/T7oTRVTqpCrzuDMt3JJ0M47i2lR6KSLzj62c/hVBqS2soM5O4JvCOXMWo7uw+mcgMIbtCXh9ahxRu1RSFGUTggjR9ZXTTdDa+NvnGuAndGi469OBUIgP2C8x3wwr9EHzDzl8gawC5sp1aY9DtbV1fdnbw46vw+MctvqXU6KuUrpfJUxa8GyYrUb1V6kXzNzbEPU8LGz76oe6HMYgNzhhC526ElmBpPXLjJsMBLsFZeARFG26Cd4Ab6jOY/mGu5KqfbRQbuveg5vnJ7+dO6wCmFfx/uHBqq/i08gRJXwxp+KhBKLQ6z4y2LN/OHZ/VA3qDNhxysLnAYWz9BsMJcNiQmc731Ju/1M2K/YVpQhMbc7TxEGrEp6KGRSd8Ns7/ZI+gxHgPh7UoY1kNOPIALUgWwHQNAMXHsG8G0KxtGGcx2xNvY29iqGLdRtjsYbA6UV7MZybUCKwT2cjnKWYgPzK/8IKgCswC0LgbuLM647Knazz6XhIljXjzx/h5vIiOzVRSVl2upr00TMbImt5XI1mdnhDXF5xYdE40+hdk9YBAaB50rHTJ3D1jiyPEY9IHuBQTrRdEZshVDCjHo0iwrncvYufZX+1pFCyK82OyjNrx/cjupQa3vmCiKJMUM9wRlI3dNCkLf2b6Cc4l0LEaJ5Kc4UDsgWju+oF6LWtk2IxHwShGD/VcjiUqphHi3UEt9WFn5FjwI0YyegEO0xu8AX9MC3AKtiQNh+SwVUGSsMj9LfQYDjn/oqiw8gHEyhRYHQ/OvS2/+2WS2kFkpR2nPzpB3KjJ4zJwk7vvOgwNJ 7uQKtYR7 ZV1isITxBL1T8v+wynb3lzdajtfuJJPJrSLxUzCsfQrKbaJS0l5SB6AIO72k/NTnWp48M+E6wQXNU07enj1pitXQShwTjNL7pPW0o+3W+jn/JPWHN1F9HD6a6izBD+P4qG8IeH1v1qITwk6M= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000022, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2023/10/9 17:30, Eric Dumazet wrote: > On Mon, Oct 9, 2023 at 10:36 AM Yajun Deng wrote: >> >> On 2023/10/9 16:20, Eric Dumazet wrote: >>> On Mon, Oct 9, 2023 at 10:14 AM Yajun Deng wrote: >>>> On 2023/10/9 15:53, Eric Dumazet wrote: >>>>> On Mon, Oct 9, 2023 at 5:07 AM 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 making >>>>>> 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 inlined. >>>>> >>>>> 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 the >> 'noinline' prefix. >> >> + field = (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 = (__force unsigned long __percpu *)((__force void *)p + offset); +                                       this_cpu_inc(*field); with + field = (unsigned long *)((void *)this_cpu_ptr(p) + offset); + 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 = (__force unsigned long __percpu *)((__force void *)p + offset); +               this_cpu_inc(*field);