Skip to content

Commit 9603aa7

Browse files
sandip4nPeter Zijlstra
authored andcommitted
perf/x86/amd/core: Refactor branch attributes
AMD processors that are capable of recording branches support either Branch Sampling (BRS) or Last Branch Record (LBR). In preparation for adding Last Branch Record Extension Version 2 (LbrExtV2) support, reuse the "branches" capability to advertise information about both BRS and LBR but make the "branch-brs" event exclusive to Family 19h processors that support BRS. Signed-off-by: Sandipan Das <sandipan.das@amd.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/ba4a4cde6db79b1c65c49834027bbdb8a915546b.1660211399.git.sandipan.das@amd.com
1 parent b40d015 commit 9603aa7

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

arch/x86/events/amd/core.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,23 +1247,25 @@ static ssize_t branches_show(struct device *cdev,
12471247

12481248
static DEVICE_ATTR_RO(branches);
12491249

1250-
static struct attribute *amd_pmu_brs_attrs[] = {
1250+
static struct attribute *amd_pmu_branches_attrs[] = {
12511251
&dev_attr_branches.attr,
12521252
NULL,
12531253
};
12541254

12551255
static umode_t
1256-
amd_brs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
1256+
amd_branches_is_visible(struct kobject *kobj, struct attribute *attr, int i)
12571257
{
12581258
return x86_pmu.lbr_nr ? attr->mode : 0;
12591259
}
12601260

1261-
static struct attribute_group group_caps_amd_brs = {
1261+
static struct attribute_group group_caps_amd_branches = {
12621262
.name = "caps",
1263-
.attrs = amd_pmu_brs_attrs,
1264-
.is_visible = amd_brs_is_visible,
1263+
.attrs = amd_pmu_branches_attrs,
1264+
.is_visible = amd_branches_is_visible,
12651265
};
12661266

1267+
#ifdef CONFIG_PERF_EVENTS_AMD_BRS
1268+
12671269
EVENT_ATTR_STR(branch-brs, amd_branch_brs,
12681270
"event=" __stringify(AMD_FAM19H_BRS_EVENT)"\n");
12691271

@@ -1272,15 +1274,26 @@ static struct attribute *amd_brs_events_attrs[] = {
12721274
NULL,
12731275
};
12741276

1277+
static umode_t
1278+
amd_brs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
1279+
{
1280+
return static_cpu_has(X86_FEATURE_BRS) && x86_pmu.lbr_nr ?
1281+
attr->mode : 0;
1282+
}
1283+
12751284
static struct attribute_group group_events_amd_brs = {
12761285
.name = "events",
12771286
.attrs = amd_brs_events_attrs,
12781287
.is_visible = amd_brs_is_visible,
12791288
};
12801289

1290+
#endif /* CONFIG_PERF_EVENTS_AMD_BRS */
1291+
12811292
static const struct attribute_group *amd_attr_update[] = {
1282-
&group_caps_amd_brs,
1293+
&group_caps_amd_branches,
1294+
#ifdef CONFIG_PERF_EVENTS_AMD_BRS
12831295
&group_events_amd_brs,
1296+
#endif
12841297
NULL,
12851298
};
12861299

0 commit comments

Comments
 (0)