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

From: Liang, Kan
Date: Thu Oct 19 2023 - 09:58:38 EST




On 2023-10-19 5:26 a.m., Peter Zijlstra wrote:
> 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?

Sure, I will implement a separate patch to re-organize it.

It seems there are only two attribute groups which have both .attrs and
.is_visible, group_default and group_caps_lbr. I will re-organize for
both of them.

Thanks,
Kan