powerpc/perf: Add support for caps under sysfs in powerpc
PATCH v3 1/2 powerpc/perf: Add support for caps under sysfs in powerpc
Add caps support under "/sys/bus/event_source/devices/<pmu>/" for powerpc. This directory can be used to expose some of the specific features that powerpc PMU supports to the user.
Example: pmu_name. The name of PMU registered will depend on platform, say power9 or power10 or it could be Generic Compat PMU.
Currently the only way to know which is the registered PMU is from the dmesg logs. But clearing the dmesg will make it difficult to know exact PMU backend used. And even extracting from dmesg will be complicated, as we need to parse the dmesg logs and add filters for pmu name. Whereas by exposing it via caps will make it easy as we just need to directly read it from the sysfs.
Add a caps directory to /sys/bus/event_source/devices/cpu/ for power8, power9, power10 and generic compat PMU in respective PMU driver code. Update the pmu_name file under caps folder in core-book3s using "attr_update".
The information exposed currently:
- pmu_name : Underlying PMU name from the driver
Example result with power9 pmu:
# ls /sys/bus/event_source/devices/cpu/caps pmu_name
# cat /sys/bus/event_source/devices/cpu/caps/pmu_name POWER9
---
Changelog:
v2 -> v3:
Removed the newline in sysfs_emit.
v1 -> v2:
Move the show function as generic in core-book3s
and update show function using sysfs_emit and ppmu->name
Added Documention for this ABI in patch 2.
Notes: The caps directory is implemented in PMU for other architectures already. Reference commit for x86:
commit b00233b53065 ("perf/x86: Export some PMU attributes in caps/ directory")
arch/powerpc/perf/core-book3s.c | 31 ++++++++++++++++++++++++++ arch/powerpc/perf/generic-compat-pmu.c | 10 +++++++++ arch/powerpc/perf/power10-pmu.c | 10 +++++++++ arch/powerpc/perf/power8-pmu.c | 10 +++++++++ arch/powerpc/perf/power9-pmu.c | 10 +++++++++ 5 files changed, 71 insertions(+)
arch/powerpc/perf/core-book3s.c +31 -0
@@ -2488,6 +2488,33 @@ static int power_pmu_prepare_cpu(unsigned int cpu)return 0 ; } +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +if (ppmu) +return sysfs_emit (buf,"%s" , ppmu->name); + +return 0 ; +} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +NULL +}; + +static const struct attribute_group pmu_caps_group = { + .name ="caps" , + .attrs = pmu_caps_attrs, +}; + +static const struct attribute_group *pmu_caps_groups[] = { + &pmu_caps_group, +NULL , +}; +int __init register_power_pmu (struct power_pmu *pmu) {if (ppmu)
@@ -2498,6 +2525,10 @@ int __init register_power_pmu(struct power_pmu *pmu) pmu->name); power_pmu.attr_groups = ppmu->attr_groups; + +if (ppmu->flags &PPMU_ARCH_207S ) + power_pmu.attr_update = pmu_caps_groups; + power_pmu.capabilities |= (ppmu->capabilities &PERF_PMU_CAP_EXTENDED_REGS );#ifdef MSR_HV
arch/powerpc/perf/generic-compat-pmu.c +10 -0
@@ -151,9 +151,19 @@ static const struct attribute_group generic_compat_pmu_format_group = { .attrs = generic_compat_pmu_format_attr, }; +static struct attribute *generic_compat_pmu_caps_attrs[] = { +NULL +}; + +static struct attribute_group generic_compat_pmu_caps_group = { + .name ="caps" , + .attrs = generic_compat_pmu_caps_attrs, +}; +static const struct attribute_group *generic_compat_pmu_attr_groups[] = { &generic_compat_pmu_format_group, &generic_compat_pmu_events_group, + &generic_compat_pmu_caps_group,NULL , };
arch/powerpc/perf/power10-pmu.c +10 -0
@@ -258,6 +258,15 @@ static const struct attribute_group power10_pmu_format_group = { .attrs = power10_pmu_format_attr, }; +static struct attribute *power10_pmu_caps_attrs[] = { +NULL +}; + +static struct attribute_group power10_pmu_caps_group = { + .name ="caps" , + .attrs = power10_pmu_caps_attrs, +}; +static const struct attribute_group *power10_pmu_attr_groups_dd1[] = { &power10_pmu_format_group, &power10_pmu_events_group_dd1,
@@ -267,6 +276,7 @@ static const struct attribute_group *power10_pmu_attr_groups_dd1[] = {static const struct attribute_group *power10_pmu_attr_groups[] = { &power10_pmu_format_group, &power10_pmu_events_group, + &power10_pmu_caps_group,NULL , };
arch/powerpc/perf/power8-pmu.c +10 -0
@@ -187,9 +187,19 @@ static const struct attribute_group power8_pmu_events_group = { .attrs = power8_events_attr, }; +static struct attribute *power8_pmu_caps_attrs[] = { +NULL +}; + +static struct attribute_group power8_pmu_caps_group = { + .name ="caps" , + .attrs = power8_pmu_caps_attrs, +}; +static const struct attribute_group *power8_pmu_attr_groups[] = { &isa207_pmu_format_group, &power8_pmu_events_group, + &power8_pmu_caps_group,NULL , };
arch/powerpc/perf/power9-pmu.c +10 -0
@@ -258,9 +258,19 @@ static const struct attribute_group power9_pmu_format_group = { .attrs = power9_pmu_format_attr, }; +static struct attribute *power9_pmu_caps_attrs[] = { +NULL +}; + +static struct attribute_group power9_pmu_caps_group = { + .name ="caps" , + .attrs = power9_pmu_caps_attrs, +}; +static const struct attribute_group *power9_pmu_attr_groups[] = { &power9_pmu_format_group, &power9_pmu_events_group, + &power9_pmu_caps_group,NULL , };
Signature · 1 line
2.35.1
PATCH v3 2/2 docs: ABI: sysfs-bus-event_source-devices: Document sysfs caps entry for PMU
Details is added about "caps" attribute group in the ABI documentation. This is used to expose some of the PMU attributes in "caps" directory under : /sys/bus/event_source/devices/<dev>/. The dev/caps will contain information about features that platform specific PMU supports.
--- .../sysfs-bus-event_source-devices-caps | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-event_source-devices-caps
Documentation/ABI/testing/sysfs-bus-event_source-devices-caps new file +18 -0
@@ -0,0 +1,18 @@ +What: /sys/bus/event_source/devices/<dev>/caps +Date: May 2022 +KernelVersion: 5.19 +Contact: Linux kernel mailing list <[email protected]> +Description: + Attribute group to describe the capabilities exposed + for a particular pmu. Each attribute of this group can + expose information specific to a PMU, say pmu_name, so that + userspace can understand some of the feature which the + platform specific PMU supports. + + One of the example available capability in supported platform + like Intel is pmu_name, which exposes underlying CPU name known + to the PMU driver. + + Example output in powerpc: + grep . /sys/bus/event_source/devices/cpu/caps/* + /sys/bus/event_source/devices/cpu/caps/pmu_name:POWER9
Signature · 1 line
2.35.1
Michael Ellerman
AppliedQuoted 8 lines · Athira Rajeev
Add caps support under "/sys/bus/event_source/devices/<pmu>/" for powerpc. This directory can be used to expose some of the specific features that powerpc PMU supports to the user.
Example:pmu_name. The name of PMU registered will depend on platform, say power9 or power10 or it could be Generic Compat PMU.[...]
Applied to powerpc/next.
[1/2] powerpc/perf: Add support for caps under sysfs in powerpc
https://git.kernel.org/powerpc/c/6320e693d98c7430653866b7ca6679338134cb79 [2/2] docs: ABI: sysfs-bus-event_source-devices: Document sysfs caps entry for PMU https://git.kernel.org/powerpc/c/999d7c47a0f737157608b9b0d2d37bdd1afec58c
cheers