selftests/powerpc/pmu: Refactor the platform check and add macros to find array size/PVR
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 10 Jun 2022 13:40:47 +0000 (19:10 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 28 Jun 2022 22:57:39 +0000 (08:57 +1000)
The platform check for selftest support "check_pvr_for_sampling_tests"
is specific to sampling tests which includes PVR check, presence of
PMU and extended regs support. Extended regs support is needed for
sampling tests which tests whether PMU registers are programmed
correctly. There could be other sampling tests which may not need
extended regs, example, bhrb filter tests which only needs validity
check via event open.

Hence refactor the platform check to have a common function
"platform_check_for_tests" that checks only for PVR check
and presence of PMU. The existing function
"check_pvr_for_sampling_tests" will invoke the common function
and also will include checks for extended regs specific for
sampling. The common function can also be used by tests other
than sampling like event code tests.

Add macro to find array size ("ARRAY_SIZE") to sampling
tests "misc.h" file. This can be used in next tests to
find event array size. Also update "include/reg.h" to
add macros to find minor and major version from PVR which
will be used in testcases.

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/20220610134113.62991-10-atrajeev@linux.vnet.ibm.com
tools/testing/selftests/powerpc/include/reg.h
tools/testing/selftests/powerpc/pmu/sampling_tests/misc.c
tools/testing/selftests/powerpc/pmu/sampling_tests/misc.h

index c422be8a42b22ca23f551044e9563f1ad4898162..2ac7a4c7749cb4b8f7dea2c8f792a37efef889bd 100644 (file)
 #define PVR_VER(pvr)   (((pvr) >>  16) & 0xFFFF)
 #define SPRN_PVR       0x11F
 
+#define PVR_CFG(pvr)    (((pvr) >>  8) & 0xF)   /* Configuration field */
+#define PVR_MAJ(pvr)    (((pvr) >>  4) & 0xF)   /* Major revision field */
+#define PVR_MIN(pvr)    (((pvr) >>  0) & 0xF)   /* Minor revision field */
+
 #define SPRN_DSCR_PRIV 0x11    /* Privilege State DSCR */
 #define SPRN_DSCR      0x03    /* Data Stream Control Register */
 #define SPRN_PPR       896     /* Program Priority Register */
index 5a26fc3a970681108486fa1c56598131699ef845..eac6420abdf118697f0feb385308faaa3d3e41c0 100644 (file)
@@ -121,12 +121,10 @@ int check_extended_regs_support(void)
        return -1;
 }
 
-int check_pvr_for_sampling_tests(void)
+int platform_check_for_tests(void)
 {
        pvr = PVR_VER(mfspr(SPRN_PVR));
 
-       platform_extended_mask = perf_get_platform_reg_mask();
-
        /*
         * Check for supported platforms
         * for sampling test
@@ -138,19 +136,33 @@ int check_pvr_for_sampling_tests(void)
         * Check PMU driver registered by looking for
         * PPC_FEATURE2_EBB bit in AT_HWCAP2
         */
-       if (!have_hwcap2(PPC_FEATURE2_EBB))
+       if (!have_hwcap2(PPC_FEATURE2_EBB) || !have_hwcap2(PPC_FEATURE2_ARCH_3_00))
                goto out;
 
+       return 0;
+
+out:
+       printf("%s: Tests unsupported for this platform\n", __func__);
+       return -1;
+}
+
+int check_pvr_for_sampling_tests(void)
+{
+       SKIP_IF(platform_check_for_tests());
+
+       platform_extended_mask = perf_get_platform_reg_mask();
        /* check if platform supports extended regs */
        if (check_extended_regs_support())
                goto out;
 
        init_ev_encodes();
        return 0;
+
 out:
        printf("%s: Sampling tests un-supported\n", __func__);
        return -1;
 }
+
 /*
  * Allocate mmap buffer of "mmap_pages" number of
  * pages.
index 874a1596add8dea03eeeadc1723b0263a1d21581..4181755cf5a09ad5ef6fa4b58f803e501a0be316 100644 (file)
@@ -18,6 +18,8 @@
 #define MMCR1_RSQ       0x200000000000ULL /* radix scope qual field */
 #define BHRB_DISABLE    0x2000000000ULL /* MMCRA BHRB DISABLE bit */
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 extern int ev_mask_pmcxsel, ev_shift_pmcxsel;
 extern int ev_mask_marked, ev_shift_marked;
 extern int ev_mask_comb, ev_shift_comb;
@@ -36,6 +38,7 @@ extern int ev_mask_mmcr3_src, ev_shift_mmcr3_src;
 extern int pvr;
 extern u64 platform_extended_mask;
 extern int check_pvr_for_sampling_tests(void);
+extern int platform_check_for_tests(void);
 
 /*
  * Event code field extraction macro.