Re: [PATCH v2] perf/core: Optimize event reschedule for a PMU
From: Namhyung Kim
Date: Tue Aug 06 2024 - 15:29:23 EST
On Tue, Aug 6, 2024 at 1:08 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Tue, Aug 06, 2024 at 09:56:30AM +0200, Peter Zijlstra wrote:
>
> > Does this help? What would be an easy reproducer?
Yep, it helps! I guess you can reproduce it easily with:
$ sudo perf stat -a sleep 1
> >
> > ---
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index c67fc43fe877..4a04611333d9 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -179,23 +179,27 @@ static void perf_ctx_lock(struct perf_cpu_context *cpuctx,
> > }
> > }
> >
> > +static inline void __perf_ctx_unlock(struct perf_event_context *ctx)
> > +{
> > + /*
> > + * If ctx_sched_in() didn't again set any ALL flags, clean up
> > + * after ctx_sched_out() by clearing is_active.
> > + */
> > + if (ctx->is_active & EVENT_FROZEN) {
> > + if (!(ctx->is_active & EVENT_ALL))
> > + ctx->is_active = 0;
> > + else
> > + ctx->is_active &= ~EVENT_FROZEN;
> > + }
> > + raw_spin_unlock(&ctx->lock);
> > +}
> > +
> > static void perf_ctx_unlock(struct perf_cpu_context *cpuctx,
> > struct perf_event_context *ctx)
> > {
> > - if (ctx) {
> > - /*
> > - * If ctx_sched_in() didn't again set any ALL flags, clean up
> > - * after ctx_sched_out() by clearing is_active.
> > - */
> > - if (ctx->is_active & EVENT_FROZEN) {
> > - if (!(ctx->is_active & EVENT_ALL))
> > - ctx->is_active = 0;
> > - else
> > - ctx->is_active &= ~EVENT_FROZEN;
> > - }
> > - raw_spin_unlock(&ctx->lock);
> > - }
> > - raw_spin_unlock(&cpuctx->ctx.lock);
> > + if (ctx)
> > + __perf_ctx_unlock(ctx);
> > + __perf_ctx_unlock(&cpuctx->ctx.lock);
>
> Obviously that wants to be just: &cpuctx->ctx :-)
Sure. And I think we need this for perf_ctx_lock() too.
Thanks,
Namhyung
>
> > }
> >
> > #define TASK_TOMBSTONE ((void *)-1L)