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 35E2BE95A91 for ; Mon, 9 Oct 2023 10:58:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B47168D0054; Mon, 9 Oct 2023 06:58:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF7178D0031; Mon, 9 Oct 2023 06:58:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BF1D8D0054; Mon, 9 Oct 2023 06:58:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8C5168D0031 for ; Mon, 9 Oct 2023 06:58:44 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 819BD1CA642 for ; Mon, 9 Oct 2023 10:58:43 +0000 (UTC) X-FDA: 81325624926.04.BA6FDBB Received: from out-207.mta0.migadu.com (out-207.mta0.migadu.com [91.218.175.207]) by imf06.hostedemail.com (Postfix) with ESMTP id 9674F180002 for ; Mon, 9 Oct 2023 10:58:40 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=a0E96Jbi; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.207 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696849121; 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=Av797t4dNKwG+wqfE+a/y9KCDOqvnvEdbCJ5Vx3i870=; b=twd6pEpzY3olvVk6wUo7aFBv/36e7/LMT5LDjfawUk1nPbNMEb1kNOBew2Z4Npx51+eeIz ZecZ4Osi9n9XUrGFyqsn4zHmPFo0u1ZV0sQNbrNvGhQ+AEKqlDdMIg2oljVC1YGnFREXeT IJJ54Ocihy+Y+eptyYGBzIdErQEuLRY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=a0E96Jbi; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of yajun.deng@linux.dev designates 91.218.175.207 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696849121; a=rsa-sha256; cv=none; b=2UPyhNFvJDq3ePN10H9GjlWTkKKQ9cXhjTspZ7J9bq05Z7OrQMWrJQZiP96eC2rrO4s1aL t8PjkG8GDAb2sUx6M1VMv/fCfL8XqZicRbY/CTm1LlM7M6Ah+wUxG6JVhpzgUa67X5H3C0 MH2evimbp8nr2xEsYHOt2p4oZeZ3gIM= Message-ID: <078f662d-a73f-766b-3a07-c82cd37026c5@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1696849118; 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=Av797t4dNKwG+wqfE+a/y9KCDOqvnvEdbCJ5Vx3i870=; b=a0E96JbiIRUyr8kY6MLTFtyZD2JisWG5Z99r291YdCB/sA+9C95xpPHYIAFDuYrAKHxVw/ VBzt4GQCWFGkGwPFJgpHq/brUy2mq0076TvrN4TuHPx++JScChCtAhUqLG0DnxsA3r92tT QK54+aT2duzdyTkkS3ijpXRVZm7O0r0= Date: Mon, 9 Oct 2023 18:58:27 +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> <68eb65c5-1870-0776-0878-694a8b002a6d@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-Queue-Id: 9674F180002 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6w9ib5fdpct7kh4koxxqgmt3bx75578s X-HE-Tag: 1696849120-723549 X-HE-Meta: U2FsdGVkX1/inawqvn8YEvlMJnt607mLKNuAdpTxHi8UCG+ns/QTnzIAO4eqjb0XcAd+gN2hLw1mDJP1eLiGkx7jR11hfJ69kuEbv80TEgo8Nmu4q/nTYGrxF4u3Mp3eniSLj9zOy40ShXxOlg/kzNDuBZRgaPNbMTh4u33r4a16B71e4CiXJqTkii+ODdQrsm7z+7+/txEi3HN+OlFeMSAOORI3ntDA0oC7ODtuKcbvZ1TphPC0az85of7Pmudju80/y3MMAQZOHkKPHITvaILj7lka7Uh8cCyMo2I5mQDInGBFK8GFoL/EvExe/hb0ADFVaWtsdSQ4gPxMGenqMDzzDBXmKfnviKOwmXVNnpZDHfvQC+okVT//sItlZCnMCVhKFU8Dn3tIPYDVGJKFA9Rm+fANVCnBsVa0CUEbA0PU0zEwqsTxNzG7Wg7yys9JerLUdc1V837CiFlHzQa0hGU3NVCaFx7GKWcV525b+gOvd9MF3Omu92Sod3lQQY00phZIaUTCq4qrGtD6i4vBNvptxfPBnvpiEmGQo79ME1AijpIsNFGsPa8XQp4u5DUYfF+vAUuahpfBoT9nGBl8ap/S90u03fqNA8aFFEq8PaG3zfDm8sUjHPzL5JfCmgi/hOg0bjr6btV4KzMtQ1N1QWZ13CTlnSYNNY72Q0wb/ZZMG/DsNS12qhuE63Z//Zg3VTTBSzMhmPcYderH3LqC/RV7MN1ptI3vp2srCMpbsgUmXYgsG2eRN0+QYeqFnvWy2h5hEbeoqjChItrqf+LOpHhKyHHoTkJitJjWh2P6bbwLrF5cfdMY/CthVeyEfATHzdGxSuumv55onLjaiJZSIfPUIVsOOJnBf7Tc+VFVJ541cj6unTT2Jnqxv9wIlmGdtMA4z3cuuRaFaOKsEp7DBWVjRPIpf/8mPZbxANj9bo5EZvdvkEl7IUMbOeEqaPHzbVwu5cJQfTR0Omxs99f c62xEC+s celgJOdYyHQNw9//55hVjanjiTZLlVPI2fpy59R4TEzXX+8BqWSEll7wmL1fvjvGeVT91xZuzJ9fCTXocMxXlSG3wj49UAdESjTnPbggzsPJD21fQa/d4F2GKoJf/bStni+Ap X-Bogosity: Ham, tests=bogofilter, spamicity=0.000037, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2023/10/9 18:16, Eric Dumazet wrote: > On Mon, Oct 9, 2023 at 11:43 AM Yajun Deng wrote: >> >> 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); >> > 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. Got it. Thank you.