powerpc/perf: Add support for caps under sysfs in powerpc
PATCH 1/1 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.
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
--- arch/powerpc/perf/generic-compat-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power10-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power8-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power9-pmu.c | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+)
arch/powerpc/perf/generic-compat-pmu.c +20 -0
@@ -151,9 +151,29 @@ static const struct attribute_group generic_compat_pmu_format_group = { .attrs = generic_compat_pmu_format_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"generic_compat_pmu" ); +} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *generic_compat_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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 +20 -0
@@ -258,6 +258,25 @@ static const struct attribute_group power10_pmu_format_group = { .attrs = power10_pmu_format_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"power10" ); +} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *power10_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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 +286,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 +20 -0
@@ -187,9 +187,29 @@ static const struct attribute_group power8_pmu_events_group = { .attrs = power8_events_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"power8" ); +} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *power8_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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 +20 -0
@@ -258,9 +258,29 @@ static const struct attribute_group power9_pmu_format_group = { .attrs = power9_pmu_format_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"power9" ); +} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *power9_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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.31.1
Michael Ellerman
reviewerHi Athira,
Some comments below :)
Quoted 6 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.
Is there precedent for adding a "caps" directory? ie. do other PMUs on other architectures already do that?
Is there precedent for adding "pmu_name"?
I don't see any mention of them in Documentation/ABI anywhere.
If we're the first to do that we should add it to the documentation.
As this would set a precedent for other PMUs, please Cc the perf maintainers on v2.
Quoted 36 lines
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.The information exposed currently:
-pmu_name: Underlying PMU name from the driverExample result with power9 pmu:
# ls /sys/bus/event_source/devices/cpu/caps pmu_name# cat /sys/bus/event_source/devices/cpu/caps/pmu_name power9Signed-off-by Athira Rajeev <[email protected]>Reviewed-by Madhavan Srinivasan <[email protected]>--- arch/powerpc/perf/generic-compat-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power10-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power8-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power9-pmu.c | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+)arch/powerpc/perf/generic-compat-pmu.c +0
-0
arch/powerpc/perf/generic-compat-pmu.c static const struct attribute_group generic_compat_pmu_format_group = { · line 159
Quoted 9 lines
arch/powerpc/perf/generic-compat-pmu.c +6
-0@@ -151,9 +151,29 @@ static const struct attribute_group generic_compat_pmu_format_group = { .attrs = generic_compat_pmu_format_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"generic_compat_pmu" ); +}
That's not a great name, now that it's exposed to userspace.
For starters it's only generic on Book3S, and if you look at init_generic_compat_pmu() it's really a "ISA >= v3.0 fallback PMU" - or something like that.
Quoted 24 lines
arch/powerpc/perf/generic-compat-pmu.c +13
-0+static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *generic_compat_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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 +0
-0
arch/powerpc/perf/power10-pmu.c static const struct attribute_group power10_pmu_format_group = { · line 265
Quoted 8 lines
arch/powerpc/perf/power10-pmu.c +5
-0@@ -258,6 +258,25 @@ static const struct attribute_group power10_pmu_format_group = { .attrs = power10_pmu_format_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"power10" );
I believe that should use sysfs_emit().
Quoted 18 lines
arch/powerpc/perf/power10-pmu.c +14
-0+} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *power10_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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,
arch/powerpc/perf/power10-pmu.c static const struct attribute_group *power10_pmu_attr_groups_dd1[] = { · line 291
Quoted 6 lines
arch/powerpc/perf/power10-pmu.c +1
-0@@ -267,6 +286,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 , };
There's a lot of boiler plate repeated for each PMU.
We already have power_pmu->name, can we use that and make the show function generic at least in core-book3s.c ?
cheers
Quoted 16 lines · Michael Ellerman
Hi Athira,
Some comments below :)
Quoted 6 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.
Quoted 2 lines
Is there precedent for adding a "caps" directory? ie. do other PMUs on other architectures already do that?
Hi Michael,
Thanks for the review comments.
Yes, There are other PMU’s on other architectures already having “caps” support. I will add them in changelog for reference in V2.
Quoted 89 lines
Is there precedent for adding "
pmu_name"?I don't see any mention of them in
Documentation/ABIanywhere.If we're the first to do that we should add it to the documentation.
As this would set a precedent for other PMUs, please Cc the perf maintainers on v2.
Quoted 36 lines
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.The information exposed currently:
-pmu_name: Underlying PMU name from the driverExample result with power9 pmu:
# ls /sys/bus/event_source/devices/cpu/caps pmu_name# cat /sys/bus/event_source/devices/cpu/caps/pmu_name power9Signed-off-by Athira Rajeev <[email protected]>Reviewed-by Madhavan Srinivasan <[email protected]>---
arch/powerpc/perf/generic-compat-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power10-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power8-pmu.c | 20 ++++++++++++++++++++ arch/powerpc/perf/power9-pmu.c | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+)arch/powerpc/perf/generic-compat-pmu.c +0
-0arch/powerpc/perf/generic-compat-pmu.c static const struct attribute_group generic_compat_pmu_format_group = { · line 159
Quoted 9 lines
arch/powerpc/perf/generic-compat-pmu.c +6
-0@@ -151,9 +151,29 @@ static const struct attribute_group generic_compat_pmu_format_group = { .attrs = generic_compat_pmu_format_attr, }; +static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"generic_compat_pmu" ); +}That's not a great name, now that it's exposed to userspace.
For starters it's only generic on Book3S, and if you look at
init_generic_compat_pmu()it's really a "ISA >= v3.0 fallback PMU" - or something like that.Quoted 27 lines
arch/powerpc/perf/generic-compat-pmu.c +13
-0+static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *generic_compat_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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 +0
-0@@ -258,6 +258,25 @@ static const struct attribute_group power10_pmu_format_group = { .attrs = power10_pmu_format_attr, };
Quoted 7 lines
arch/powerpc/perf/power10-pmu.c static const struct attribute_group power10_pmu_format_group = { · line 265
Quoted 5 lines
arch/powerpc/perf/power10-pmu.c +5
-0+static ssize_t pmu_name_show (struct device *cdev, +struct device_attribute *attr, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"power10" );I believe that should use
sysfs_emit().
Sure will change this.
Quoted 28 lines
Quoted 19 lines
arch/powerpc/perf/power10-pmu.c +14
-0+} + +static DEVICE_ATTR_RO (pmu_name); + +static struct attribute *power10_pmu_caps_attrs[] = { + &dev_attr_pmu_name.attr, +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,arch/powerpc/perf/power10-pmu.c static const struct attribute_group *power10_pmu_attr_groups_dd1[] = { · line 291
Quoted 6 lines
arch/powerpc/perf/power10-pmu.c +1
-0@@ -267,6 +286,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 , };There's a lot of boiler plate repeated for each PMU.
Quoted 2 lines
We already have
power_pmu->name, can we use that and make the show function generic at least incore-book3s.c?
Sure, I will rework on V2 to make the show function generic in core-book3s. For the Generic Compat PMU, now that I am going to use show function from core-book3s, the name exposed will be that of power_pmu->name
Thanks
Athira
Quoted 2 lines
cheers