LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Yabin Cui <yabinc@google.com>, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf/ring_buffer: Fix exposing a temporarily decreased data_head.
Date: Wed, 15 May 2019 12:51:24 +0200 [thread overview]
Message-ID: <20190515105124.GE2623@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <87bm04xcdb.fsf@ashishki-desk.ger.corp.intel.com>
On Wed, May 15, 2019 at 01:04:16PM +0300, Alexander Shishkin wrote:
> Peter Zijlstra <peterz@infradead.org> writes:
>
> > On Wed, May 15, 2019 at 09:51:07AM +0300, Alexander Shishkin wrote:
> >> Yabin Cui <yabinc@google.com> writes:
> >>
> >> > diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
> >> > index 674b35383491..0b9aefe13b04 100644
> >> > --- a/kernel/events/ring_buffer.c
> >> > +++ b/kernel/events/ring_buffer.c
> >> > @@ -54,8 +54,10 @@ static void perf_output_put_handle(struct perf_output_handle *handle)
> >> > * IRQ/NMI can happen here, which means we can miss a head update.
> >> > */
> >> >
> >> > - if (!local_dec_and_test(&rb->nest))
> >> > + if (local_read(&rb->nest) > 1) {
> >> > + local_dec(&rb->nest);
> >>
> >> What stops rb->nest changing between local_read() and local_dec()?
> >
> > Nothing, however it must remain the same :-)
> >
> > That is the cryptic way of saying that since these buffers are strictly
> > per-cpu, the only change can come from interrupts, and they must have a
> > net 0 change. Or rather, an equal amount of decrements to increments.
> >
> > So if it changes, it must also change back to where it was.
>
> Ah that's true. So the whole ->nest thing can be done with
> READ_ONCE()/WRITE_ONCE() instead?
> Because the use of local_dec_and_test() creates an impression that we
> rely on atomicity of it, which in actuality we don't.
Yes, I think we can get away with that. And that might be a worth-while
optimization for !x86.
next prev parent reply other threads:[~2019-05-15 10:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 0:30 Yabin Cui
2019-05-15 6:51 ` Alexander Shishkin
2019-05-15 9:43 ` Peter Zijlstra
2019-05-15 10:04 ` Alexander Shishkin
2019-05-15 10:51 ` Peter Zijlstra [this message]
2019-05-15 10:48 ` Peter Zijlstra
2019-05-16 18:37 ` Yabin Cui
2019-05-16 18:40 ` [PATCH v2] " Yabin Cui
2019-05-17 8:47 ` Peter Zijlstra
2019-05-17 17:59 ` [PATCH] " Yabin Cui
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=20190515105124.GE2623@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=yabinc@google.com \
--subject='Re: [PATCH] perf/ring_buffer: Fix exposing a temporarily decreased data_head.' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).