Message ID | 20230412035905.3184199-1-jstultz@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp51282vqo; Tue, 11 Apr 2023 21:06:16 -0700 (PDT) X-Google-Smtp-Source: AKy350ZfGwseDGWFSL0B4T9z+2J+IUtONmt7RXIo2eivrw2UhfDj0RMXJSW93iA/tdSLUB+oSJQa X-Received: by 2002:aa7:d8d9:0:b0:501:c547:2135 with SMTP id k25-20020aa7d8d9000000b00501c5472135mr10255366eds.36.1681272376251; Tue, 11 Apr 2023 21:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681272376; cv=none; d=google.com; s=arc-20160816; b=tQP1+S+on6MlQPhrXMKdveOad9Q26/HtuCkJOhVRHsFSJ8JcEbkmU+jAfxGV+znlWV zsce8aSAgy6XxHtrWrBJQ+M7lETULyZiKm4VjGtG9A2LsQV81nXMvW5yEchK4c578HFV CKHwTNsUSS3ANk/t4QHzdLJ79PPUjgTMa+reEfPv7atzYzZqJRRbyDBhBo8+kkdbbkMw Pud3bvngAi6g9XIE8e0a55wFWuU9FdweV9b45Xs3cvzN6klZv+UqQJ62H2HbRR0BFIAB ZZHsP0OVECuzGidHDJXqzsH+cK3GEoMe1wPQh4ge1yqHYMCE2H+fBfoxHj8rM0U2ey52 cWjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=fyiqpLvToGpX9zbSN0SmDzV1gui0tF1l+0pOfCKBwUY=; b=Gug+i57tcTICGDIZiq7Oefz1AkmwrLThOVK6LRtYYDiyDP/QSB2s1tQqP+X4hiboHU 0RMH6ghpz239jq3mvWbuivpe+7+W3/y/5mcMtrWPuLTuEPOLJUPt+qQbh2Z7UN8OQutB oBsj5h1bymRIWFxmu9JBA8gw2GRIQOztqBmvSO5FU/osLdmhHvMsTikMA7hvCtP9Fqhi HBNKSuJ5gMR41gkfYEB4+fj3n5j9jUUm0Ip4IpudOdwechMjsqNjmVKjaEhjsQsO6Gg3 ibXYmhlWSVBIBwwO/a7pz4OIILq2c3mRZCXEtGKtsPsj26TvorPm079Q1BaoiPYeielF a2kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=qLE2elCx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt1-20020a0564020a4100b00501ea9c03cbsi3992759edb.656.2023.04.11.21.05.52; Tue, 11 Apr 2023 21:06:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=qLE2elCx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229517AbjDLD7M (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Tue, 11 Apr 2023 23:59:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjDLD7K (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Apr 2023 23:59:10 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 641F644B1 for <linux-kernel@vger.kernel.org>; Tue, 11 Apr 2023 20:59:09 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54efad677cbso97372307b3.6 for <linux-kernel@vger.kernel.org>; Tue, 11 Apr 2023 20:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681271948; x=1683863948; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fyiqpLvToGpX9zbSN0SmDzV1gui0tF1l+0pOfCKBwUY=; b=qLE2elCx/bFwG+/CQp/dg66GoBw4Ge7nInCKKielTmGl9IJxhqm8otj0WWoOXBr49L G5VdoyGtTSE09rWAd06Z1vgXPRplhAEKo+VI9ZNmVbpZnzyEexvwmAQC+vMFUjECVwXm 7TSLiL2FTAxAXj48fiSRHfnHLr4PJOtHvUTySmVSYaxsIA1COHxXvzIjfReGb2Rc7SQz rm0cCu3vFTpGPlyOS3GhJgfj9R8+3dgCE+wYmuNBUkLJxNu1bcavBTQIvi2PFgwc9t+J tzFiaRX1iRUm5GSpL5kFzSa/1jQVoFFZmwwRLvN6wirPEImzKpsd4OiDQ8mCeycC5UP5 YzXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681271948; x=1683863948; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fyiqpLvToGpX9zbSN0SmDzV1gui0tF1l+0pOfCKBwUY=; b=slFz2KJ23iOF1Nik+s4thhSUpMkC6BoOn/WQE5g95SGPTLVELrrRQW6aoaYweWvG3+ xYqduKNxephFQC3FJkQakVzx3Y4X3nefQ42kcdC13owcdeh2JyHdOiXWf2KhhEoT2aIm imqCoWkOykhonKn8DjwvgwNVSSbzbB9cPHeCSjs4OP0kvvs1DmM2sCQEZin7yozkKujr u3cDmm4y8lBz1nazYd00R5yBi9TqsZ0iU/4h8rw2CO1c8ot8R1KAY5490fo78dGz76ej GdqIwFkDeyVskHEQtb4m4D1XfUX9+MaEuYh8KVObMoSoT0BHIr57xwMYId8s0YyXy21T 5ZpQ== X-Gm-Message-State: AAQBX9cTXwwgUyhID6wJZbzcO6RVmcZd3t5YoiGCIvElWQKp8ebneji+ I40o0RyDxTw/3EomIujjLqPF5ZaUmKduJEHD0G7BgOqs2GyQeIzE3V0iSmbD/f3afOVK6hlRgmg PBLBRk5xnFeo1eGbRQMhCVYaZ+aw7VckpX2rjhpnv0DUq3uZxuVxnGaEgPAcXl94ba2aij9I= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:d002:0:b0:533:9185:fc2c with SMTP id v2-20020a81d002000000b005339185fc2cmr3181437ywi.7.1681271948571; Tue, 11 Apr 2023 20:59:08 -0700 (PDT) Date: Wed, 12 Apr 2023 03:59:05 +0000 In-Reply-To: <20230412023839.2869114-1-jstultz@google.com> Mime-Version: 1.0 References: <20230412023839.2869114-1-jstultz@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230412035905.3184199-1-jstultz@google.com> Subject: [PATCH v2] locking/rwsem: Add __always_inline annotation to __down_read_common() From: John Stultz <jstultz@google.com> To: LKML <linux-kernel@vger.kernel.org> Cc: John Stultz <jstultz@google.com>, Minchan Kim <minchan@kernel.org>, Tim Murray <timmurray@google.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>, Waiman Long <longman@redhat.com>, Boqun Feng <boqun.feng@gmail.com>, kernel-team@android.com, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762941862914275610?= X-GMAIL-MSGID: =?utf-8?q?1762941862914275610?= |
Series |
[v2] locking/rwsem: Add __always_inline annotation to __down_read_common()
|
|
Commit Message
John Stultz
April 12, 2023, 3:59 a.m. UTC
Apparently despite it being marked inline, the compiler
may not inline __down_read_common() which makes it difficult
to identify the cause of lock contention, as the blocked
function will always be listed as __down_read_common().
So this patch adds __always_inline annotation to the
function to force it to be inlines so the calling function
will be listed.
Cc: Minchan Kim <minchan@kernel.org>
Cc: Tim Murray <timmurray@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: kernel-team@android.com
Cc: stable@vger.kernel.org
Fixes: c995e638ccbb ("locking/rwsem: Fold __down_{read,write}*()")
Reported-by: Tim Murray <timmurray@google.com>
Signed-off-by: John Stultz <jstultz@google.com>
---
v2: Reworked to use __always_inline instead of __sched as
suggested by Waiman Long
---
kernel/locking/rwsem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 4/11/23 23:59, John Stultz wrote: > Apparently despite it being marked inline, the compiler > may not inline __down_read_common() which makes it difficult > to identify the cause of lock contention, as the blocked > function will always be listed as __down_read_common(). > > So this patch adds __always_inline annotation to the > function to force it to be inlines so the calling function > will be listed. > > Cc: Minchan Kim <minchan@kernel.org> > Cc: Tim Murray <timmurray@google.com> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Will Deacon <will@kernel.org> > Cc: Waiman Long <longman@redhat.com> > Cc: Boqun Feng <boqun.feng@gmail.com> > Cc: kernel-team@android.com > Cc: stable@vger.kernel.org > Fixes: c995e638ccbb ("locking/rwsem: Fold __down_{read,write}*()") > Reported-by: Tim Murray <timmurray@google.com> > Signed-off-by: John Stultz <jstultz@google.com> > --- > v2: Reworked to use __always_inline instead of __sched as > suggested by Waiman Long > --- > kernel/locking/rwsem.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c > index acb5a50309a1..e99eef8ea552 100644 > --- a/kernel/locking/rwsem.c > +++ b/kernel/locking/rwsem.c > @@ -1240,7 +1240,7 @@ static struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) > /* > * lock for reading > */ > -static inline int __down_read_common(struct rw_semaphore *sem, int state) > +static __always_inline int __down_read_common(struct rw_semaphore *sem, int state) > { > int ret = 0; > long count; Reviewed-by: Waiman Long <longman@redhat.com>
On Wed, Apr 12, 2023 at 03:59:05AM +0000, John Stultz wrote: > Apparently despite it being marked inline, the compiler > may not inline __down_read_common() which makes it difficult > to identify the cause of lock contention, as the blocked > function will always be listed as __down_read_common(). > > So this patch adds __always_inline annotation to the > function to force it to be inlines so the calling function > will be listed. I'm a wee bit confused; what are you looking at? Wchan? What is stopping the compiler from now handing you __down_read{,_interruptible,_killable}() instead? Is that fine?
On 4/17/23 07:19, Peter Zijlstra wrote: > On Wed, Apr 12, 2023 at 03:59:05AM +0000, John Stultz wrote: >> Apparently despite it being marked inline, the compiler >> may not inline __down_read_common() which makes it difficult >> to identify the cause of lock contention, as the blocked >> function will always be listed as __down_read_common(). >> >> So this patch adds __always_inline annotation to the >> function to force it to be inlines so the calling function >> will be listed. > I'm a wee bit confused; what are you looking at? Wchan? What is stopping > the compiler from now handing you > __down_read{,_interruptible,_killable}() instead? Is that fine? > My theory is that the compiler may refuse to inline __down_read_common() because it is called 3 times in order to reduce overall code size. The other __down_read*() functions you listed are only called once. My 2 cents. Cheers, Longman
On Mon, Apr 17, 2023 at 1:19 PM Peter Zijlstra <peterz@infradead.org> wrote: > > On Wed, Apr 12, 2023 at 03:59:05AM +0000, John Stultz wrote: > > Apparently despite it being marked inline, the compiler > > may not inline __down_read_common() which makes it difficult > > to identify the cause of lock contention, as the blocked > > function will always be listed as __down_read_common(). > > > > So this patch adds __always_inline annotation to the > > function to force it to be inlines so the calling function > > will be listed. > > I'm a wee bit confused; what are you looking at? Wchan? Apologies! Yes, traceevent data via wchan, sorry I didn't make that clear. > What is stopping > the compiler from now handing you > __down_read{,_interruptible,_killable}() instead? Is that fine? No, we want to make the blocked calling function, rather than the locking functions, visible in the tracepoints captured. That said, the other __down_read* functions seem to be properly inlined in practice (Waiman's theory as to why sounds convincing to me). If you'd like I can add those as well to be always_inline, as well so it's more consistent? thanks -john
On Mon, Apr 17, 2023 at 06:22:14PM +0200, John Stultz wrote: > On Mon, Apr 17, 2023 at 1:19 PM Peter Zijlstra <peterz@infradead.org> wrote: > > > > On Wed, Apr 12, 2023 at 03:59:05AM +0000, John Stultz wrote: > > > Apparently despite it being marked inline, the compiler > > > may not inline __down_read_common() which makes it difficult > > > to identify the cause of lock contention, as the blocked > > > function will always be listed as __down_read_common(). > > > > > > So this patch adds __always_inline annotation to the > > > function to force it to be inlines so the calling function > > > will be listed. > > > > I'm a wee bit confused; what are you looking at? Wchan? > > Apologies! Yes, traceevent data via wchan, sorry I didn't make that clear. No worries; good addition to the v3 Changelog ;-) > > What is stopping > > the compiler from now handing you > > __down_read{,_interruptible,_killable}() instead? Is that fine? > > No, we want to make the blocked calling function, rather than the > locking functions, visible in the tracepoints captured. That said, the > other __down_read* functions seem to be properly inlined in practice > (Waiman's theory as to why sounds convincing to me). Right, but we should not rely on the compiler heuristics for correctness :-) > If you'd like I can add those as well to be always_inline, as well so > it's more consistent? Yes please. I'm not sure I care much about the whole 'inline __sched' vs '__always_inline' thing, but I do feel it should all be consistently applied.
On Tue, Apr 18, 2023 at 12:30 PM Peter Zijlstra <peterz@infradead.org> wrote: > > On Mon, Apr 17, 2023 at 06:22:14PM +0200, John Stultz wrote: > > On Mon, Apr 17, 2023 at 1:19 PM Peter Zijlstra <peterz@infradead.org> wrote: > > > > > > On Wed, Apr 12, 2023 at 03:59:05AM +0000, John Stultz wrote: > > > > Apparently despite it being marked inline, the compiler > > > > may not inline __down_read_common() which makes it difficult > > > > to identify the cause of lock contention, as the blocked > > > > function will always be listed as __down_read_common(). > > > > > > > > So this patch adds __always_inline annotation to the > > > > function to force it to be inlines so the calling function > > > > will be listed. > > > > > > I'm a wee bit confused; what are you looking at? Wchan? > > > > Apologies! Yes, traceevent data via wchan, sorry I didn't make that clear. > > No worries; good addition to the v3 Changelog ;-) > > > > What is stopping > > > the compiler from now handing you > > > __down_read{,_interruptible,_killable}() instead? Is that fine? > > > > No, we want to make the blocked calling function, rather than the > > locking functions, visible in the tracepoints captured. That said, the > > other __down_read* functions seem to be properly inlined in practice > > (Waiman's theory as to why sounds convincing to me). > > Right, but we should not rely on the compiler heuristics for correctness > :-) > > > If you'd like I can add those as well to be always_inline, as well so > > it's more consistent? > > Yes please. I'm not sure I care much about the whole 'inline __sched' vs > '__always_inline' thing, but I do feel it should all be consistently > applied. Sounds good. I'll respin with this. Thanks so much for the review! -john
diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index acb5a50309a1..e99eef8ea552 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -1240,7 +1240,7 @@ static struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) /* * lock for reading */ -static inline int __down_read_common(struct rw_semaphore *sem, int state) +static __always_inline int __down_read_common(struct rw_semaphore *sem, int state) { int ret = 0; long count;