From: Ingo Molnar <mingo@kernel.org>
To: Waiman Long <longman@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Will Deacon <will@kernel.org>, Boqun Feng <boqun.feng@gmail.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] locking/percpu-rwsem: Trigger contention tracepoints only if contended
Date: Wed, 28 Feb 2024 13:50:20 +0100 [thread overview]
Message-ID: <Zd8sDKX8XtdrMuMb@gmail.com> (raw)
In-Reply-To: <c29d648c-451a-42af-81d3-e1660e3af46f@redhat.com>
* Waiman Long <longman@redhat.com> wrote:
>
> On 2/27/24 18:02, Namhyung Kim wrote:
> > Hello,
> >
> > On Mon, Nov 20, 2023 at 12:28 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > > Ping!
> > >
> > > On Wed, Nov 8, 2023 at 1:53 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > > > It mistakenly fires lock contention tracepoints always in the writer path.
> > > > It should be conditional on the try lock result.
> > Can anybody take a look at this? This makes a large noise
> > in the lock contention result.
> >
> > Thanks,
> > Namhyung
> >
> > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > > > ---
> > > > kernel/locking/percpu-rwsem.c | 11 ++++++++---
> > > > 1 file changed, 8 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
> > > > index 185bd1c906b0..6083883c4fe0 100644
> > > > --- a/kernel/locking/percpu-rwsem.c
> > > > +++ b/kernel/locking/percpu-rwsem.c
> > > > @@ -223,9 +223,10 @@ static bool readers_active_check(struct percpu_rw_semaphore *sem)
> > > >
> > > > void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
> > > > {
> > > > + bool contended = false;
> > > > +
> > > > might_sleep();
> > > > rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
> > > > - trace_contention_begin(sem, LCB_F_PERCPU | LCB_F_WRITE);
> > > >
> > > > /* Notify readers to take the slow path. */
> > > > rcu_sync_enter(&sem->rss);
> > > > @@ -234,8 +235,11 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
> > > > * Try set sem->block; this provides writer-writer exclusion.
> > > > * Having sem->block set makes new readers block.
> > > > */
> > > > - if (!__percpu_down_write_trylock(sem))
> > > > + if (!__percpu_down_write_trylock(sem)) {
> > > > + trace_contention_begin(sem, LCB_F_PERCPU | LCB_F_WRITE);
> > > > percpu_rwsem_wait(sem, /* .reader = */ false);
> > > > + contended = true;
> > > > + }
> > > >
> > > > /* smp_mb() implied by __percpu_down_write_trylock() on success -- D matches A */
> > > >
> > > > @@ -247,7 +251,8 @@ void __sched percpu_down_write(struct percpu_rw_semaphore *sem)
> > > >
> > > > /* Wait for all active readers to complete. */
> > > > rcuwait_wait_event(&sem->writer, readers_active_check(sem), TASK_UNINTERRUPTIBLE);
> > > > - trace_contention_end(sem, 0);
> > > > + if (contended)
> > > > + trace_contention_end(sem, 0);
> > > > }
> > > > EXPORT_SYMBOL_GPL(percpu_down_write);
> > > >
> > > > --
> > > > 2.42.0.869.gea05f2083d-goog
>
> Yes, that makes sense. Sorry for missing this patch.
>
> Reviewed-by: Waiman Long <longman@redhat.com>
Applied to tip:locking/core, thanks guys!
Ingo
next prev parent reply other threads:[~2024-02-28 12:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 21:53 [PATCH] locking/percpu-rwsem: Trigger contention tracepoints only if contended Namhyung Kim
2023-11-20 20:28 ` Namhyung Kim
2024-02-27 23:02 ` Namhyung Kim
2024-02-28 0:18 ` Waiman Long
2024-02-28 0:49 ` Namhyung Kim
2024-02-28 12:50 ` Ingo Molnar [this message]
2024-02-28 12:53 ` [tip: locking/core] " tip-bot2 for Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zd8sDKX8XtdrMuMb@gmail.com \
--to=mingo@kernel.org \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.