]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/perf: Add support for caps under sysfs in powerpc
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 20 May 2022 08:46:29 +0000 (14:16 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 18 Jul 2022 00:39:54 +0000 (10:39 +1000)
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

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220520084630.15181-1-atrajeev@linux.vnet.ibm.com
arch/powerpc/perf/core-book3s.c
arch/powerpc/perf/generic-compat-pmu.c
arch/powerpc/perf/power10-pmu.c
arch/powerpc/perf/power8-pmu.c
arch/powerpc/perf/power9-pmu.c

index 03c64a0195df29f636fdda915add6876d80ba13e..13919eb96931b352958c27feadf7d3c769bc3d3b 100644 (file)
@@ -2483,6 +2483,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)
@@ -2493,6 +2520,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
index 16392962c511400f8497cff56cb776cd97de1672..b5c414876ed57a357fe9e5bee48f4f4ea7d9701d 100644 (file)
@@ -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,
 };
 
index c6d51e7093cf1191d4af1527d07a8d9e9f979b42..d1adcd9f52e234148c0cbbfb5206fa5e58b3c1f7 100644 (file)
@@ -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,
 };
 
index e37b1e714d2b65baebf698991f9458f1e6d7cb9b..2518f5375d4aeae53851659fb82116a653c0b262 100644 (file)
@@ -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,
 };
 
index 3ad40ffb92569cb71fc8c57ecca431feb826e384..bc6d76bce97bfa6edb5da34062100a26220666e1 100644 (file)
@@ -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,
 };