Skip to content

Commit 847f326

Browse files
sandip4nPeter Zijlstra
authored andcommitted
perf/x86/amd/uncore: Use attr_update for format attributes
Use the update_attrs attribute group introduced by commit f3a3a82 ("perf/core: Add attr_groups_update into struct pmu") and the is_visible() callback to populate the family specifc attributes for uncore events. The changes apply to attributes that are unique to families such as slicemask for Family 17h and coreid for Family 19h. The addition of common attributes such as event and umask, whose formats change across families, remain unchanged. Signed-off-by: Sandipan Das <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/a5e4f4dd5c459199fc497e82b858ba09dc91c064.1652954372.git.sandipan.das@amd.com
1 parent 39621c5 commit 847f326

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

arch/x86/events/amd/uncore.c

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ static int amd_uncore_event_init(struct perf_event *event)
246246
return 0;
247247
}
248248

249+
static umode_t
250+
amd_f17h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, int i)
251+
{
252+
return boot_cpu_data.x86 >= 0x17 && boot_cpu_data.x86 < 0x19 ?
253+
attr->mode : 0;
254+
}
255+
256+
static umode_t
257+
amd_f19h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, int i)
258+
{
259+
return boot_cpu_data.x86 >= 0x19 ? attr->mode : 0;
260+
}
261+
249262
static ssize_t amd_uncore_attr_show_cpumask(struct device *dev,
250263
struct device_attribute *attr,
251264
char *buf)
@@ -296,20 +309,33 @@ DEFINE_UNCORE_FORMAT_ATTR(enallslices, enallslices, "config:46"); /* F19h L3
296309
DEFINE_UNCORE_FORMAT_ATTR(enallcores, enallcores, "config:47"); /* F19h L3 */
297310
DEFINE_UNCORE_FORMAT_ATTR(sliceid, sliceid, "config:48-50"); /* F19h L3 */
298311

312+
/* Common DF and NB attributes */
299313
static struct attribute *amd_uncore_df_format_attr[] = {
300-
&format_attr_event12.attr, /* event14 if F17h+ */
301-
&format_attr_umask.attr,
314+
&format_attr_event12.attr, /* event */
315+
&format_attr_umask.attr, /* umask */
302316
NULL,
303317
};
304318

319+
/* Common L2 and L3 attributes */
305320
static struct attribute *amd_uncore_l3_format_attr[] = {
306-
&format_attr_event12.attr, /* event8 if F17h+ */
307-
&format_attr_umask.attr,
308-
NULL, /* slicemask if F17h, coreid if F19h */
309-
NULL, /* threadmask8 if F17h, enallslices if F19h */
310-
NULL, /* enallcores if F19h */
311-
NULL, /* sliceid if F19h */
312-
NULL, /* threadmask2 if F19h */
321+
&format_attr_event12.attr, /* event */
322+
&format_attr_umask.attr, /* umask */
323+
NULL, /* threadmask */
324+
NULL,
325+
};
326+
327+
/* F17h unique L3 attributes */
328+
static struct attribute *amd_f17h_uncore_l3_format_attr[] = {
329+
&format_attr_slicemask.attr, /* slicemask */
330+
NULL,
331+
};
332+
333+
/* F19h unique L3 attributes */
334+
static struct attribute *amd_f19h_uncore_l3_format_attr[] = {
335+
&format_attr_coreid.attr, /* coreid */
336+
&format_attr_enallslices.attr, /* enallslices */
337+
&format_attr_enallcores.attr, /* enallcores */
338+
&format_attr_sliceid.attr, /* sliceid */
313339
NULL,
314340
};
315341

@@ -323,6 +349,18 @@ static struct attribute_group amd_uncore_l3_format_group = {
323349
.attrs = amd_uncore_l3_format_attr,
324350
};
325351

352+
static struct attribute_group amd_f17h_uncore_l3_format_group = {
353+
.name = "format",
354+
.attrs = amd_f17h_uncore_l3_format_attr,
355+
.is_visible = amd_f17h_uncore_is_visible,
356+
};
357+
358+
static struct attribute_group amd_f19h_uncore_l3_format_group = {
359+
.name = "format",
360+
.attrs = amd_f19h_uncore_l3_format_attr,
361+
.is_visible = amd_f19h_uncore_is_visible,
362+
};
363+
326364
static const struct attribute_group *amd_uncore_df_attr_groups[] = {
327365
&amd_uncore_attr_group,
328366
&amd_uncore_df_format_group,
@@ -335,6 +373,12 @@ static const struct attribute_group *amd_uncore_l3_attr_groups[] = {
335373
NULL,
336374
};
337375

376+
static const struct attribute_group *amd_uncore_l3_attr_update[] = {
377+
&amd_f17h_uncore_l3_format_group,
378+
&amd_f19h_uncore_l3_format_group,
379+
NULL,
380+
};
381+
338382
static struct pmu amd_nb_pmu = {
339383
.task_ctx_nr = perf_invalid_context,
340384
.attr_groups = amd_uncore_df_attr_groups,
@@ -352,6 +396,7 @@ static struct pmu amd_nb_pmu = {
352396
static struct pmu amd_llc_pmu = {
353397
.task_ctx_nr = perf_invalid_context,
354398
.attr_groups = amd_uncore_l3_attr_groups,
399+
.attr_update = amd_uncore_l3_attr_update,
355400
.name = "amd_l2",
356401
.event_init = amd_uncore_event_init,
357402
.add = amd_uncore_add,
@@ -632,15 +677,10 @@ static int __init amd_uncore_init(void)
632677
if (boot_cpu_data.x86 >= 0x19) {
633678
*l3_attr++ = &format_attr_event8.attr;
634679
*l3_attr++ = &format_attr_umask.attr;
635-
*l3_attr++ = &format_attr_coreid.attr;
636-
*l3_attr++ = &format_attr_enallslices.attr;
637-
*l3_attr++ = &format_attr_enallcores.attr;
638-
*l3_attr++ = &format_attr_sliceid.attr;
639680
*l3_attr++ = &format_attr_threadmask2.attr;
640681
} else if (boot_cpu_data.x86 >= 0x17) {
641682
*l3_attr++ = &format_attr_event8.attr;
642683
*l3_attr++ = &format_attr_umask.attr;
643-
*l3_attr++ = &format_attr_slicemask.attr;
644684
*l3_attr++ = &format_attr_threadmask8.attr;
645685
}
646686

0 commit comments

Comments
 (0)