Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1811428rdb; Mon, 9 Oct 2023 03:59:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSEjwB0g5WO6Ht/K6d4M64OIyW/cxJ7gu9umrO0pV4ZnMq6EVwcJYfCCKo6cDGVjpMV8ds X-Received: by 2002:a05:6808:1b0f:b0:3ad:ffa4:dfd0 with SMTP id bx15-20020a0568081b0f00b003adffa4dfd0mr21711202oib.47.1696849141351; Mon, 09 Oct 2023 03:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696849141; cv=none; d=google.com; s=arc-20160816; b=v2+XkKXjQ/1y7O/10OWnu62Uw/127LPV/kglyejFBbLnKRcSW2GXrER4KZYmMM31Fr wSnyieWOuVCq3By0yCNx3IBxizK9wbDXDT8jhqg0HFoPPRJWP18oxr0+D94D8zJp1pbv /rAFB1OXqiCmrv5COWJQ86nAT/hD8/YlWkmp8ihuUf90mrTqMKB5MURvK4OLxMqZkPH1 djl1aINcd7H4Y9nt68NfuMWHmEm/rRDflvbvCdwqjlbD50MyCys+r+14hj46rsRGHIWo WQd5w0hx4EZKy2oHs/ArB8b5gP3nZyRnv2A6TkUCstzL9AUpsg4fv6vV9fXzjTNEQqFo tgxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=Av797t4dNKwG+wqfE+a/y9KCDOqvnvEdbCJ5Vx3i870=; fh=9lnjb7JTN0l65BgPkDO22Q1L9bKvK9l1SCliKZFe27k=; b=tLmKwGEWYvTnzcfGzm6Ni+ZvHb8Ci0hkvctHwdC9SYfEVmALvcx/dJoEmD9YD8BCp7 fcDBf2TaBu6V1+wouHhYbyDkcjAzAXICKyHSs9bF1f7mzaBd3Tcu6EViYU8L+krfhiuZ ACDGAKESM3mQrHp9/GMmfwj231ZgGA++YTbGNKeuv76gcpwFNOfeDXOQhHRvsWJJSDmA BIkbOCt0PzjSTdgukL124OM7t0QF6Oa3FjFujrERttn+O/0uU6lEaY4/EBKO8tqqGznc +9i3h7z6iRzGG1BDjxdjp6UdM9tCnwuKA5tjCTEgdKhTdk7jjcMbRm8Zjl2/3io2qBYV tjAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=a0E96Jbi; 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=linux.dev Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id e65-20020a636944000000b005859d13f276si9498723pgc.569.2023.10.09.03.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 03:59:01 -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=@linux.dev header.s=key1 header.b=a0E96Jbi; 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=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D93A68072A3E; Mon, 9 Oct 2023 03:58:58 -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 S1346142AbjJIK6o (ORCPT + 99 others); Mon, 9 Oct 2023 06:58:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346159AbjJIK6m (ORCPT ); Mon, 9 Oct 2023 06:58:42 -0400 Received: from out-190.mta0.migadu.com (out-190.mta0.migadu.com [91.218.175.190]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DE4EB for ; Mon, 9 Oct 2023 03:58:40 -0700 (PDT) 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-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Mon, 09 Oct 2023 03:58:59 -0700 (PDT) X-Spam-Level: ** 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.