Re: [PATCH v2 2/2] perf/x86/lbr: Move cpuc->lbr_xsave allocation out of sleeping region

From: Peter Zijlstra
Date: Tue May 18 2021 - 09:29:27 EST


On Tue, May 18, 2021 at 08:34:33PM +0800, Like Xu wrote:
> > > + if (!static_cpu_has(X86_FEATURE_ARCH_LBR))
> > > + return;
> > > +
> > > + for_each_possible_cpu(cpu) {
> > > + cpuc = per_cpu_ptr(&cpu_hw_events, cpu);
> > > + kmem_cache = x86_get_pmu(cpu)->task_ctx_cache;
> > > + if (kmem_cache && !cpuc->lbr_xsave && !event->attr.precise_ip)
> > > + cpuc->lbr_xsave =
> > > + kmem_cache_alloc_node(kmem_cache, GFP_KERNEL,
> > > + cpu_to_node(cpu));
> >
> > (coding style fail)
> >
> > But then I looked at this function, and srlsy that !precise_ip is the
> > only thing you need @event for? Why do we care?
>
> Kan once commented, we only need to alloc the buffer for the non-PEBS
> event. It seems the check "(cpuc->lbr_users != cpuc->lbr_pebs_users)"
> is implicitly removed.
>
> I think we still need to check !precision_ip, right ?

It's just a memory allocation; who cares if we allocate but not use it
ever?