lkml.org 
[lkml]   [2019]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v1 4/6] perf: Allow using AUX data in perf samples
Date
Peter Zijlstra <peterz@infradead.org> writes:

> On Fri, Aug 09, 2019 at 03:32:39PM +0300, Alexander Shishkin wrote:
>> The other problem is sampling SW events, that would require a ctx->lock
>> to prevent racing with event_function_call()s from other cpus, resulting
>> in somewhat cringy "if (!in_nmi()) raw_spin_lock(...)", but I don't have
>> better idea as to how to handle that.
>
>> +int perf_pmu_aux_sample_output(struct perf_event *event,
>> + struct perf_output_handle *handle,
>> + unsigned long size)
>> +{
>> + unsigned long flags;
>> + int ret;
>> +
>> + /*
>> + * NMI vs IRQ
>> + *
>> + * Normal ->start()/->stop() callbacks run in IRQ mode in scheduler
>> + * paths. If we start calling them in NMI context, they may race with
>> + * the IRQ ones, that is, for example, re-starting an event that's just
>> + * been stopped.
>> + */
>> + if (!in_nmi())
>> + raw_spin_lock_irqsave(&event->ctx->lock, flags);
>> +
>> + ret = event->pmu->snapshot_aux(event, handle, size);
>> +
>> + if (!in_nmi())
>> + raw_spin_unlock_irqrestore(&event->ctx->lock, flags);
>> +
>> + return ret;
>> +}
>
> I'm confused... would not something like:
>
> unsigned long flags;
>
> local_irq_save(flags);
> ret = event->pmu->snapshot_aux(...);
> local_irq_restore(flags);
>
> return ret;
>
> Be sufficient? By disabling IRQs we already hold off remote
> event_function_call()s.
>
> Or am I misunderstanding the race here?

No, you're right, disabling IRQs covers our bases.

Thanks,
--
Alex

\
 
 \ /
  Last update: 2019-09-30 13:51    [W:0.116 / U:0.812 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site