From: James Clark <james.clark@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@redhat.com,
namhyung@kernel.org, linux-perf-users@vger.kernel.org,
leo.yan@linaro.com, Suzuki.Poulose@arm.com,
Ruben Ayrapetyan <Ruben.Ayrapetyan@arm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] perf/core: Wake up parent event if inherited event has no ring buffer
Date: Mon, 24 Jan 2022 14:58:18 +0000 [thread overview]
Message-ID: <a4b64cff-f3f1-e6ad-38e9-b65a113ce561@arm.com> (raw)
In-Reply-To: <Ye6SR0yxTrkNUQF6@hirez.programming.kicks-ass.net>
On 24/01/2022 11:49, Peter Zijlstra wrote:
> On Mon, Dec 06, 2021 at 11:38:40AM +0000, James Clark wrote:
>> When using per-process mode and event inheritance is set to true, forked
>> processes will create a new perf events via inherit_event() ->
>> perf_event_alloc(). But these events will not have ring buffers assigned
>> to them. Any call to wakeup will be dropped if it's called on an event
>> with no ring buffer assigned because that's the object that holds the
>> wakeup list.
>>
>> If the child event is disabled due to a call to perf_aux_output_begin()
>> or perf_aux_output_end(), the wakeup is dropped leaving userspace
>> hanging forever on the poll.
>>
>> Normally the event is explicitly re-enabled by userspace after it wakes
>> up to read the aux data, but in this case it does not get woken up so
>> the event remains disabled.
>>
>> This can be reproduced when using Arm SPE and 'stress' which forks once
>> before running the workload. By looking at the list of aux buffers read,
>> it's apparent that they stop after the fork:
>>
>> perf record -e arm_spe// -vvv -- stress -c 1
>>
>> With this patch applied they continue to be printed. This behaviour
>> doesn't happen when using systemwide or per-cpu mode.
>>
>> Reported-by: Ruben Ayrapetyan <Ruben.Ayrapetyan@arm.com>
>> Signed-off-by: James Clark <james.clark@arm.com>
>> ---
>
> Would this be the better patch?
Yes I tested this and it also works. There is one other suspicious access
of ->rb followed by if(rb) here in perf_poll(), but maybe it works out ok?
mutex_lock(&event->mmap_mutex);
rb = event->rb;
if (rb)
events = atomic_xchg(&rb->poll, 0);
We also have a Perf self test that covers this failure for Arm SPE now, I'm not
sure if I should post that separately or with your new version of this fix?
Thanks
James
>
>
> ---
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 479c9e672ec4..b1c1928c0e7c 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -5985,6 +5985,8 @@ static void ring_buffer_attach(struct perf_event *event,
> struct perf_buffer *old_rb = NULL;
> unsigned long flags;
>
> + WARN_ON_ONCE(event->parent);
> +
> if (event->rb) {
> /*
> * Should be impossible, we set this when removing
> @@ -6042,6 +6044,9 @@ static void ring_buffer_wakeup(struct perf_event *event)
> {
> struct perf_buffer *rb;
>
> + if (event->parent)
> + event = event->parent;
> +
> rcu_read_lock();
> rb = rcu_dereference(event->rb);
> if (rb) {
> @@ -6055,6 +6060,9 @@ struct perf_buffer *ring_buffer_get(struct perf_event *event)
> {
> struct perf_buffer *rb;
>
> + if (event->parent)
> + event = event->parent;
> +
> rcu_read_lock();
> rb = rcu_dereference(event->rb);
> if (rb) {
> @@ -6763,7 +6771,7 @@ static unsigned long perf_prepare_sample_aux(struct perf_event *event,
> if (WARN_ON_ONCE(READ_ONCE(sampler->oncpu) != smp_processor_id()))
> goto out;
>
> - rb = ring_buffer_get(sampler->parent ? sampler->parent : sampler);
> + rb = ring_buffer_get(sampler);
> if (!rb)
> goto out;
>
> @@ -6829,7 +6837,7 @@ static void perf_aux_sample_output(struct perf_event *event,
> if (WARN_ON_ONCE(!sampler || !data->aux_size))
> return;
>
> - rb = ring_buffer_get(sampler->parent ? sampler->parent : sampler);
> + rb = ring_buffer_get(sampler);
> if (!rb)
> return;
>
>
next prev parent reply other threads:[~2022-01-24 14:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-06 11:38 [RFC PATCH 0/1] perf/core: Wake up parent event if inherited event has no ring buffer James Clark
2021-12-06 11:38 ` [RFC PATCH 1/1] " James Clark
2022-01-24 11:37 ` Ruben Ayrapetyan
2022-01-24 11:49 ` Peter Zijlstra
2022-01-24 14:58 ` James Clark [this message]
2022-01-25 19:12 ` Peter Zijlstra
2022-01-26 16:15 ` James Clark
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=a4b64cff-f3f1-e6ad-38e9-b65a113ce561@arm.com \
--to=james.clark@arm.com \
--cc=Ruben.Ayrapetyan@arm.com \
--cc=Suzuki.Poulose@arm.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=leo.yan@linaro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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 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).