From: Peter Zijlstra <peterz@infradead.org>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
linux-kernel@vger.kernel.org, jolsa@redhat.com
Subject: Re: [PATCH v1 4/6] perf: Allow using AUX data in perf samples
Date: Thu, 14 Jun 2018 22:20:22 +0200 [thread overview]
Message-ID: <20180614202022.GC12217@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180612075117.65420-5-alexander.shishkin@linux.intel.com>
On Tue, Jun 12, 2018 at 10:51:15AM +0300, Alexander Shishkin wrote:
> +static unsigned long perf_aux_sample_size(struct perf_event *event,
> + struct perf_sample_data *data,
> + size_t size)
> +{
> + struct perf_event *sampler = event->sample_event;
> + struct ring_buffer *rb;
> + int *disable_count;
> +
> + data->aux.size = 0;
> +
> + if (!sampler || READ_ONCE(sampler->state) != PERF_EVENT_STATE_ACTIVE)
> + goto out;
> +
> + if (READ_ONCE(sampler->oncpu) != smp_processor_id())
> + goto out;
Should those not be WARNs ? If we allow a configuration where that is
possible, we're doing it wrong I think.
> + /*
> + * Non-zero disable count here means that we, being the NMI
> + * context, are racing with pmu::add, pmu::del or address filter
> + * adjustment, which we want to avoid.
> + */
> + disable_count = this_cpu_ptr(sampler->pmu->pmu_disable_count);
> + if (*disable_count)
> + goto out;
> +
> + /* Re-enabled in perf_aux_sample_output() */
> + perf_pmu_disable(sampler->pmu);
This is disguisting.. and also broken I think. Imagine what happens
when the NMI hits in middle of perf_pmu_enable(), right where count
dropped to 0, but we've not yet done pmu->pmu_enable() yet.
Then we end up with a double disable and double enable.
> +
> + rb = ring_buffer_get(sampler);
> + if (!rb) {
> + perf_pmu_enable(sampler->pmu);
> + goto out;
> + }
> +
> + /* Restarted in perf_aux_sample_output() */
> + sampler->pmu->stop(sampler, PERF_EF_UPDATE);
More yuck...
You rreally should not be calling these pmu::methods, they're meant to
be used from _interrupt_ not NMI context. Using them like this is asking
for tons of trouble.
Why can't you just snapshot the current location and let the thing
'run' ?
> + data->aux.to = rb->aux_head;
> +
> + size = min(size, perf_aux_size(rb));
> +
> + if (data->aux.to < size)
> + data->aux.from = rb->aux_nr_pages * PAGE_SIZE + data->aux.to -
> + size;
> + else
> + data->aux.from = data->aux.to - size;
> + data->aux.size = ALIGN(size, sizeof(u64));
> + ring_buffer_put(rb);
> +
> +out:
> + return data->aux.size;
> +}
> +
> +static void perf_aux_sample_output(struct perf_event *event,
> + struct perf_output_handle *handle,
> + struct perf_sample_data *data)
> +{
> + ring_buffer_put(rb);
> + sampler->pmu->start(sampler, 0);
> +
> +out_enable:
> + perf_pmu_enable(sampler->pmu);
More of that... really yuck stuff.
> +}
next prev parent reply other threads:[~2018-06-14 20:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-12 7:51 [PATCH v1 0/6] perf: Add AUX data sampling Alexander Shishkin
2018-06-12 7:51 ` [PATCH v1 1/6] perf: Disable PMU around address filter adjustment Alexander Shishkin
2018-06-12 20:11 ` Peter Zijlstra
2018-06-12 7:51 ` [PATCH v1 2/6] perf: Disable IRQs in address filter sync path Alexander Shishkin
2018-06-12 7:51 ` [PATCH v1 3/6] perf: Add an iterator for AUX data Alexander Shishkin
2018-06-12 7:51 ` [PATCH v1 4/6] perf: Allow using AUX data in perf samples Alexander Shishkin
2018-06-14 19:25 ` Peter Zijlstra
2018-06-14 19:39 ` Peter Zijlstra
2018-06-19 10:51 ` Alexander Shishkin
2018-06-14 19:30 ` Peter Zijlstra
2018-06-14 19:47 ` Peter Zijlstra
2018-06-19 11:00 ` Alexander Shishkin
2018-06-14 20:03 ` Peter Zijlstra
2018-06-14 20:20 ` Peter Zijlstra [this message]
2018-06-19 10:47 ` Alexander Shishkin
2018-06-21 20:16 ` Peter Zijlstra
2018-10-02 14:00 ` Alexander Shishkin
2019-08-09 12:32 ` Alexander Shishkin
2019-09-26 12:04 ` Alexander Shishkin
2019-09-26 14:44 ` Peter Zijlstra
2019-09-30 11:50 ` Alexander Shishkin
2018-06-12 7:51 ` [PATCH v1 5/6] perf: Drop PERF_FLAG_FD_OUTPUT Alexander Shishkin
2018-06-12 7:51 ` [PATCH v1 6/6] perf: Allow set-output for task contexts of different types Alexander Shishkin
2018-06-14 19:36 ` Peter Zijlstra
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=20180614202022.GC12217@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@redhat.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
/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