lkml.org 
[lkml]   [2019]   [Sep]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 4/6] perf: Allow using AUX data in perf samples
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?

\
 
 \ /
  Last update: 2019-09-26 16:46    [W:0.102 / U:0.728 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site