Re: [PATCH V4 4/7] perf/x86/intel: Support LBR event logging

From: Peter Zijlstra
Date: Thu Oct 19 2023 - 05:26:06 EST


On Wed, Oct 04, 2023 at 11:40:41AM -0700, kan.liang@xxxxxxxxxxxxxxx wrote:

> diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
> index c3b0d15a9841..1e80a551a4c2 100644
> --- a/arch/x86/events/intel/lbr.c
> +++ b/arch/x86/events/intel/lbr.c
> @@ -676,6 +676,21 @@ void intel_pmu_lbr_del(struct perf_event *event)
> WARN_ON_ONCE(cpuc->lbr_users < 0);
> WARN_ON_ONCE(cpuc->lbr_pebs_users < 0);
> perf_sched_cb_dec(event->pmu);
> +
> + /*
> + * The logged occurrences information is only valid for the
> + * current LBR group. If another LBR group is scheduled in
> + * later, the information from the stale LBRs will be wrongly
> + * interpreted. Reset the LBRs here.
> + * For the context switch, the LBR will be unconditionally
> + * flushed when a new task is scheduled in. If both the new task
> + * and the old task are monitored by a LBR event group. The
> + * reset here is redundant. But the extra reset doesn't impact
> + * the functionality. It's hard to distinguish the above case.
> + * Keep the unconditionally reset for a LBR event group for now.
> + */

I found this really hard to read, also should this not rely on
!cpuc->lbr_users ?

As is, you'll reset the lbr for every event in the group.

> + if (is_branch_counters_group(event))
> + intel_pmu_lbr_reset();
> }