]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests/powerpc/pmu: Add selftest to check PERF_SAMPLE_REGS_INTR option will not...
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 10 Jun 2022 13:40:49 +0000 (19:10 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 28 Jun 2022 22:57:42 +0000 (08:57 +1000)
With sampling, --intr-regs option is used for capturing
interrupt regs. When --intr-regs option is used, PMU code
uses is_sier_available() function which uses PMU flags in
the code. In environment where platform specific PMU is
not registered, PMU flags is not defined. A fix was added
in kernel to address crash while accessing is_sier_available()
function when pmu is not set. commit 6d2cbbc46623 ("powerpc/perf:
Fix crash with is_sier_available when pmu is not set").

Add perf sampling test to exercise this code and make sure
enabling intr_regs shouldn't crash in any platform. Testcase
uses software event cycles since software event will work even
in cases without PMU.

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-12-atrajeev@linux.vnet.ibm.com
tools/testing/selftests/powerpc/pmu/sampling_tests/Makefile
tools/testing/selftests/powerpc/pmu/sampling_tests/intr_regs_no_crash_wo_pmu_test.c [new file with mode: 0644]

index 8d4839cde0136c0224a3302b2cb3fdddd835010e..8d4566dac440e990c5b067cd1d453d9686ac19de 100644 (file)
@@ -6,7 +6,7 @@ TEST_GEN_PROGS := mmcr0_exceptionbits_test mmcr0_cc56run_test mmcr0_pmccext_test
                   mmcr1_comb_test mmcr2_l2l3_test mmcr2_fcs_fch_test \
                   mmcr3_src_test mmcra_thresh_marked_sample_test mmcra_thresh_cmp_test \
                   mmcra_bhrb_ind_call_test mmcra_bhrb_any_test mmcra_bhrb_cond_test \
-                  mmcra_bhrb_disable_test bhrb_no_crash_wo_pmu_test
+                  mmcra_bhrb_disable_test bhrb_no_crash_wo_pmu_test intr_regs_no_crash_wo_pmu_test
 
 top_srcdir = ../../../../../..
 include ../../../lib.mk
diff --git a/tools/testing/selftests/powerpc/pmu/sampling_tests/intr_regs_no_crash_wo_pmu_test.c b/tools/testing/selftests/powerpc/pmu/sampling_tests/intr_regs_no_crash_wo_pmu_test.c
new file mode 100644 (file)
index 0000000..839d2d2
--- /dev/null
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2022, Athira Rajeev, IBM Corp.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../event.h"
+#include "misc.h"
+#include "utils.h"
+
+/*
+ * A perf sampling test for making sure
+ * sampling with -intr-regs doesn't crash
+ * in any environment, say:
+ *  - With generic compat PMU
+ *  - without any PMU registered
+ *  - With platform specific PMU.
+ *  A fix for crash with intr_regs was
+ *  addressed in commit: f75e7d73bdf7 in kernel.
+ *
+ * This testcase exercises this code path by doing
+ * intr_regs using software event. Software event is
+ * used since s/w event will work even in platform
+ * without PMU.
+ */
+static int intr_regs_no_crash_wo_pmu_test(void)
+{
+       struct event event;
+
+       /*
+        * Init the event for the sampling test.
+        * This uses software event which works on
+        * any platform.
+        */
+       event_init_opts(&event, 0, PERF_TYPE_SOFTWARE, "cycles");
+
+       event.attr.sample_period = 1000;
+       event.attr.sample_type = PERF_SAMPLE_REGS_INTR;
+       event.attr.disabled = 1;
+
+       /*
+        * Return code of event_open is not considered
+        * since test just expects no crash from using
+        * PERF_SAMPLE_REGS_INTR.
+        */
+       event_open(&event);
+
+       event_close(&event);
+       return 0;
+}
+
+int main(void)
+{
+       return test_harness(intr_regs_no_crash_wo_pmu_test, "intr_regs_no_crash_wo_pmu_test");
+}