Skip to content

Commit 8053f2d

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/uncore: Add alias PMU name
A perf PMU may have two PMU names. For example, Intel Sapphire Rapids server supports the discovery mechanism. Without the platform-specific support, an uncore PMU is named by a type ID plus a box ID, e.g., uncore_type_0_0, because the real name of the uncore PMU cannot be retrieved from the discovery table. With the platform-specific support later, perf has the mapping information from a type ID to a specific uncore unit. Just like the previous platforms, the uncore PMU is named by the real PMU name, e.g., uncore_cha_0. The user scripts which work well with the old numeric name may not work anymore. Add a new attribute "alias" to indicate the old numeric name. The following userspace perf tool patch will handle both names. The user scripts should work properly with the updated perf tool. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0d771ca commit 8053f2d

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
What: /sys/bus/event_source/devices/uncore_*/alias
2+
Date: June 2021
3+
KernelVersion: 5.15
4+
Contact: Linux kernel mailing list <[email protected]>
5+
Description: Read-only. An attribute to describe the alias name of
6+
the uncore PMU if an alias exists on some platforms.
7+
The 'perf(1)' tool should treat both names the same.
8+
They both can be used to access the uncore PMU.
9+
10+
Example:
11+
12+
$ cat /sys/devices/uncore_cha_2/alias
13+
uncore_type_0_2

arch/x86/events/intel/uncore.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,18 @@ static const struct attribute_group uncore_pmu_attr_group = {
842842
.attrs = uncore_pmu_attrs,
843843
};
844844

845+
void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu)
846+
{
847+
struct intel_uncore_type *type = pmu->type;
848+
849+
if (type->num_boxes == 1)
850+
sprintf(pmu_name, "uncore_type_%u", type->type_id);
851+
else {
852+
sprintf(pmu_name, "uncore_type_%u_%d",
853+
type->type_id, type->box_ids[pmu->pmu_idx]);
854+
}
855+
}
856+
845857
static void uncore_get_pmu_name(struct intel_uncore_pmu *pmu)
846858
{
847859
struct intel_uncore_type *type = pmu->type;
@@ -851,12 +863,7 @@ static void uncore_get_pmu_name(struct intel_uncore_pmu *pmu)
851863
* Use uncore_type_&typeid_&boxid as name.
852864
*/
853865
if (!type->name) {
854-
if (type->num_boxes == 1)
855-
sprintf(pmu->name, "uncore_type_%u", type->type_id);
856-
else {
857-
sprintf(pmu->name, "uncore_type_%u_%d",
858-
type->type_id, type->box_ids[pmu->pmu_idx]);
859-
}
866+
uncore_get_alias_name(pmu->name, pmu);
860867
return;
861868
}
862869

arch/x86/events/intel/uncore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ struct event_constraint *
561561
uncore_get_constraint(struct intel_uncore_box *box, struct perf_event *event);
562562
void uncore_put_constraint(struct intel_uncore_box *box, struct perf_event *event);
563563
u64 uncore_shared_reg_config(struct intel_uncore_box *box, int idx);
564+
void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu);
564565

565566
extern struct intel_uncore_type *empty_uncore[];
566567
extern struct intel_uncore_type **uncore_msr_uncores;

arch/x86/events/intel/uncore_snbep.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5587,20 +5587,42 @@ static const struct attribute_group spr_uncore_chabox_format_group = {
55875587
.attrs = spr_uncore_cha_formats_attr,
55885588
};
55895589

5590+
static ssize_t alias_show(struct device *dev,
5591+
struct device_attribute *attr,
5592+
char *buf)
5593+
{
5594+
struct intel_uncore_pmu *pmu = dev_to_uncore_pmu(dev);
5595+
char pmu_name[UNCORE_PMU_NAME_LEN];
5596+
5597+
uncore_get_alias_name(pmu_name, pmu);
5598+
return sysfs_emit(buf, "%s\n", pmu_name);
5599+
}
5600+
5601+
static DEVICE_ATTR_RO(alias);
5602+
5603+
static struct attribute *uncore_alias_attrs[] = {
5604+
&dev_attr_alias.attr,
5605+
NULL
5606+
};
5607+
5608+
ATTRIBUTE_GROUPS(uncore_alias);
5609+
55905610
static struct intel_uncore_type spr_uncore_chabox = {
55915611
.name = "cha",
55925612
.event_mask = SPR_CHA_PMON_EVENT_MASK,
55935613
.event_mask_ext = SPR_RAW_EVENT_MASK_EXT,
55945614
.num_shared_regs = 1,
55955615
.ops = &spr_uncore_chabox_ops,
55965616
.format_group = &spr_uncore_chabox_format_group,
5617+
.attr_update = uncore_alias_groups,
55975618
};
55985619

55995620
static struct intel_uncore_type spr_uncore_iio = {
56005621
.name = "iio",
56015622
.event_mask = SNBEP_PMON_RAW_EVENT_MASK,
56025623
.event_mask_ext = SNR_IIO_PMON_RAW_EVENT_MASK_EXT,
56035624
.format_group = &snr_uncore_iio_format_group,
5625+
.attr_update = uncore_alias_groups,
56045626
};
56055627

56065628
static struct attribute *spr_uncore_raw_formats_attr[] = {
@@ -5620,7 +5642,8 @@ static const struct attribute_group spr_uncore_raw_format_group = {
56205642
#define SPR_UNCORE_COMMON_FORMAT() \
56215643
.event_mask = SNBEP_PMON_RAW_EVENT_MASK, \
56225644
.event_mask_ext = SPR_RAW_EVENT_MASK_EXT, \
5623-
.format_group = &spr_uncore_raw_format_group
5645+
.format_group = &spr_uncore_raw_format_group, \
5646+
.attr_update = uncore_alias_groups
56245647

56255648
static struct intel_uncore_type spr_uncore_irp = {
56265649
SPR_UNCORE_COMMON_FORMAT(),
@@ -5635,6 +5658,7 @@ static struct intel_uncore_type spr_uncore_m2pcie = {
56355658

56365659
static struct intel_uncore_type spr_uncore_pcu = {
56375660
.name = "pcu",
5661+
.attr_update = uncore_alias_groups,
56385662
};
56395663

56405664
static void spr_uncore_mmio_enable_event(struct intel_uncore_box *box,
@@ -5760,6 +5784,8 @@ static void uncore_type_customized_copy(struct intel_uncore_type *to_type,
57605784
to_type->event_descs = from_type->event_descs;
57615785
if (from_type->format_group)
57625786
to_type->format_group = from_type->format_group;
5787+
if (from_type->attr_update)
5788+
to_type->attr_update = from_type->attr_update;
57635789
}
57645790

57655791
static struct intel_uncore_type **

0 commit comments

Comments
 (0)