]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/perf: Use PVR rather than oprofile field to determine CPU version
authorRashmica Gupta <rashmica.g@gmail.com>
Thu, 7 Jul 2022 14:37:17 +0000 (16:37 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 27 Jul 2022 11:36:05 +0000 (21:36 +1000)
Currently the perf CPU backend drivers detect what CPU they're on using
cur_cpu_spec->oprofile_cpu_type.

Although that works, it's a bit crufty to be using oprofile related fields,
especially seeing as oprofile is more or less unused these days.

It also means perf is reliant on the fragile logic in setup_cpu_spec()
which detects when we're using a logical PVR and copies back the PMU
related fields from the raw CPU entry. So lets check the PVR directly.

Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
[chleroy: Added power10 and fixed checkpatch issues]
Reviewed-and-tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-and-tested-By: Kajol Jain <kjain@linux.ibm.com> [For 24x7 side changes]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20c0ee7f99dbf0dbf8658df6b39f84753e6db1ef.1657204631.git.christophe.leroy@csgroup.eu
12 files changed:
arch/powerpc/perf/e500-pmu.c
arch/powerpc/perf/e6500-pmu.c
arch/powerpc/perf/hv-24x7.c
arch/powerpc/perf/mpc7450-pmu.c
arch/powerpc/perf/power10-pmu.c
arch/powerpc/perf/power5+-pmu.c
arch/powerpc/perf/power5-pmu.c
arch/powerpc/perf/power6-pmu.c
arch/powerpc/perf/power7-pmu.c
arch/powerpc/perf/power8-pmu.c
arch/powerpc/perf/power9-pmu.c
arch/powerpc/perf/ppc970-pmu.c

index a59c33bed32a38c4b014252962953fab9b15e516..e3e1a68eb1d55c75bfe5f26280772e5e9d0ed3f5 100644 (file)
@@ -118,12 +118,13 @@ static struct fsl_emb_pmu e500_pmu = {
 
 static int init_e500_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type)
-               return -ENODEV;
+       unsigned int pvr = mfspr(SPRN_PVR);
 
-       if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500mc"))
+       /* ec500mc */
+       if (PVR_VER(pvr) == PVR_VER_E500MC || PVR_VER(pvr) == PVR_VER_E5500)
                num_events = 256;
-       else if (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500"))
+       /* e500 */
+       else if (PVR_VER(pvr) != PVR_VER_E500V1 && PVR_VER(pvr) != PVR_VER_E500V2)
                return -ENODEV;
 
        return register_fsl_emb_pmu(&e500_pmu);
index 44ad65da82ed9d1d5100cfd428b1eb85def32d25..bd779a2338f8994bf722a24bb50a134888afcb64 100644 (file)
@@ -107,8 +107,9 @@ static struct fsl_emb_pmu e6500_pmu = {
 
 static int init_e6500_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-               strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e6500"))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_VER_E6500)
                return -ENODEV;
 
        return register_fsl_emb_pmu(&e6500_pmu);
index cf5406b31e27fb7bac0cb2cae31e7125383a5cea..33c23225fd54515c8be1635c0648ded02ecb6eca 100644 (file)
@@ -1718,16 +1718,16 @@ static int hv_24x7_init(void)
 {
        int r;
        unsigned long hret;
+       unsigned int pvr = mfspr(SPRN_PVR);
        struct hv_perf_caps caps;
 
        if (!firmware_has_feature(FW_FEATURE_LPAR)) {
                pr_debug("not a virtualized system, not enabling\n");
                return -ENODEV;
-       } else if (!cur_cpu_spec->oprofile_cpu_type)
-               return -ENODEV;
+       }
 
        /* POWER8 only supports v1, while POWER9 only supports v2. */
-       if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power8"))
+       if (PVR_VER(pvr) == PVR_POWER8)
                interface_version = 1;
        else {
                interface_version = 2;
index e39b15b79a8340cc8c93ec950f0dee74e4a4d751..552d51a925d3761d61cc85fc9699bcc9260bc2d7 100644 (file)
@@ -417,8 +417,9 @@ struct power_pmu mpc7450_pmu = {
 
 static int __init init_mpc7450_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/7450"))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_7450)
                return -ENODEV;
 
        return register_power_pmu(&mpc7450_pmu);
index d1adcd9f52e234148c0cbbfb5206fa5e58b3c1f7..403ba3a69512b1057aed5a37b9a2c5737142cc31 100644 (file)
@@ -607,12 +607,10 @@ int __init init_power10_pmu(void)
        unsigned int pvr;
        int rc;
 
-       /* Comes from cpu_specs[] */
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power10"))
+       pvr = mfspr(SPRN_PVR);
+       if (PVR_VER(pvr) != PVR_POWER10)
                return -ENODEV;
 
-       pvr = mfspr(SPRN_PVR);
        /* Add the ppmu flag for power10 DD1 */
        if ((PVR_CFG(pvr) == 1))
                power10_pmu.flags |= PPMU_P10_DD1;
index 753b4740ef64f38e6bf4b8663fc43b21cc33f421..b4708ab73145efcc222cc5e33307fcf9ca942f02 100644 (file)
@@ -679,9 +679,9 @@ static struct power_pmu power5p_pmu = {
 
 int __init init_power5p_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5+")
-            && strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5++")))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_POWER5p)
                return -ENODEV;
 
        return register_power_pmu(&power5p_pmu);
index 1f83c4cba0aac8e366b655a949197472803b7544..c6aefd0a1cc8369f4d8de79a47189c464ce8d10e 100644 (file)
@@ -620,8 +620,9 @@ static struct power_pmu power5_pmu = {
 
 int __init init_power5_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5"))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_POWER5)
                return -ENODEV;
 
        return register_power_pmu(&power5_pmu);
index aec746f868046f8611dea1e095cf8ae948c75248..5729b6e059de05caecc5da69cca09072280ca992 100644 (file)
@@ -541,8 +541,9 @@ static struct power_pmu power6_pmu = {
 
 int __init init_power6_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power6"))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_POWER6)
                return -ENODEV;
 
        return register_power_pmu(&power6_pmu);
index a74211410b8db8aa0f7b96613882a40ab548528f..c95ccf2e28da09f640c829ced18287688f72a054 100644 (file)
@@ -447,11 +447,12 @@ static struct power_pmu power7_pmu = {
 
 int __init init_power7_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power7"))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_POWER7 && PVR_VER(pvr) != PVR_POWER7p)
                return -ENODEV;
 
-       if (pvr_version_is(PVR_POWER7p))
+       if (PVR_VER(pvr) == PVR_POWER7p)
                power7_pmu.flags |= PPMU_SIAR_VALID;
 
        return register_power_pmu(&power7_pmu);
index 2518f5375d4aeae53851659fb82116a653c0b262..ef9685065aaf96634158527b2a5610b39e6c8397 100644 (file)
@@ -391,9 +391,10 @@ static struct power_pmu power8_pmu = {
 int __init init_power8_pmu(void)
 {
        int rc;
+       unsigned int pvr = mfspr(SPRN_PVR);
 
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power8"))
+       if (PVR_VER(pvr) != PVR_POWER8E && PVR_VER(pvr) != PVR_POWER8NVL &&
+           PVR_VER(pvr) != PVR_POWER8)
                return -ENODEV;
 
        rc = register_power_pmu(&power8_pmu);
index bc6d76bce97bfa6edb5da34062100a26220666e1..cb6a7dc02dd764d26cb7947fcdaacf6cf8feeacb 100644 (file)
@@ -467,9 +467,7 @@ int __init init_power9_pmu(void)
        int rc = 0;
        unsigned int pvr = mfspr(SPRN_PVR);
 
-       /* Comes from cpu_specs[] */
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power9"))
+       if (PVR_VER(pvr) != PVR_POWER9)
                return -ENODEV;
 
        /* Blacklist events */
index 09802482ba7266d198aaa9659e96649ec6e28d1c..762676fb839e7b840309f42e92ffff11bf66ac9b 100644 (file)
@@ -491,9 +491,10 @@ static struct power_pmu ppc970_pmu = {
 
 int __init init_ppc970_pmu(void)
 {
-       if (!cur_cpu_spec->oprofile_cpu_type ||
-           (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/970")
-            && strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/970MP")))
+       unsigned int pvr = mfspr(SPRN_PVR);
+
+       if (PVR_VER(pvr) != PVR_970 && PVR_VER(pvr) != PVR_970MP &&
+           PVR_VER(pvr) != PVR_970FX && PVR_VER(pvr) != PVR_970GX)
                return -ENODEV;
 
        return register_power_pmu(&ppc970_pmu);