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

From: Peter Zijlstra
Date: Thu Oct 19 2023 - 05:29:00 EST


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

> +
> static struct attribute *lbr_attrs[] = {
> &dev_attr_branches.attr,
> + &dev_attr_branch_counter_nr.attr,
> + &dev_attr_branch_counter_width.attr,
> NULL
> };
>
> @@ -5590,7 +5665,11 @@ mem_is_visible(struct kobject *kobj, struct attribute *attr, int i)
> static umode_t
> lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
> {
> - return x86_pmu.lbr_nr ? attr->mode : 0;
> + /* branches */
> + if (i == 0)
> + return x86_pmu.lbr_nr ? attr->mode : 0;
> +
> + return (x86_pmu.flags & PMU_FL_LBR_EVENT) ? attr->mode : 0;
> }

As in the patch this is fairly readable, but I just checked and in the
code lbr_attrs and lbr_is_visible() are rather far away from one another
which makes the whole i thing hard to interpret.

Should we re-organize that a little?