Peter Zijlstra <pet...@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

Reply via email to