Re: [PATCH v2 03/13] perf/x86/amd: add AMD Fam19h Branch Sampling support

From: Peter Zijlstra
Date: Fri Nov 12 2021 - 11:23:34 EST


On Thu, Nov 11, 2021 at 12:44:05AM -0800, Stephane Eranian wrote:

> +static void amd_pmu_enable_event(struct perf_event *event)
> +{
> + x86_pmu_enable_event(event);
> +
> + if (__this_cpu_read(cpu_hw_events.enabled)) {
> + if (is_amd_brs(&event->hw))
> + amd_brs_enable();
> + }

Does this path actually trigger? I thought we always use the enable_all
path these days. Could easily be I misremember though.

> +}
> +
> +static void amd_pmu_enable_all(int added)
> +{
> + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
> + struct hw_perf_event *hwc;
> + int idx;
> +
> + for (idx = 0; idx < x86_pmu.num_counters; idx++) {
> + hwc = &cpuc->events[idx]->hw;
> +
> + /* only activate events which are marked as active */
> + if (!test_bit(idx, cpuc->active_mask))
> + continue;
> +
> + amd_pmu_enable_event(cpuc->events[idx]);
> + }
> +}

The thing is, since te BRS is a 'global' state, it doesn't really make
sense to enable it per-event.

Anyway, I think the above actually works, just wondering if we can
perhaps simplify it.