[PATCH v2 5/5] selftest/powerpc/pmu: Testcase for imc global lock mechanism

Anju T Sudhakar anju at linux.vnet.ibm.com
Tue Jan 21 21:17:28 AEDT 2020


From: Madhavan Srinivasan <maddy at linux.ibm.com>

Signed-off-by: Madhavan Srinivasan <maddy at linux.ibm.com>
---
 .../pmu/mem_counters/imc_global_lock_test.c   | 49 ++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/pmu/mem_counters/imc_global_lock_test.c b/tools/testing/selftests/powerpc/pmu/mem_counters/imc_global_lock_test.c
index ea687ffc1990..f643dba8ecc0 100644
--- a/tools/testing/selftests/powerpc/pmu/mem_counters/imc_global_lock_test.c
+++ b/tools/testing/selftests/powerpc/pmu/mem_counters/imc_global_lock_test.c
@@ -5,9 +5,56 @@
 
 #include "mem_counters.h"
 
+static  bool check_imc_interface_glob_lck(void)
+{
+	if (!access("/sys/devices/thread_imc/interface/glob_lck", F_OK))
+		return true;
+
+	return false;
+}
+
 static int testcase(void)
 {
-	return 0;
+	struct event events[2];
+
+	if (!check_imc_interface_glob_lck()) {
+		printf("Test not supported\n");
+		return MAGIC_SKIP_RETURN_VALUE;
+	}
+
+	if (!is_mem_counters_device_enabled(CORE) || !is_mem_counters_device_enabled(THREAD)) {
+		printf("%s: IMC device not found. So exiting the test\n", __FUNCTION__);
+		return -1;
+	}
+
+	if (setup_mem_counters_event(THREAD, &events[0], 0xe0, "thread_imc/cycles")) {
+		printf("%s setup_mem_counters_event for thread_imc failed\n", __FUNCTION__);
+		return -1;
+	}
+
+	if (setup_mem_counters_event(CORE, &events[1], 0xe0, "core_imc/cycles")) {
+		printf("%s setup_mem_counters_event for core_imc failed\n", __FUNCTION__);
+		return -1;
+	}
+
+	if (event_open(&events[0])) {
+		perror("thread_imc: perf_event_open");
+		return -1;
+	}
+
+	/*
+	 * If we have the Global lock patchset applied to kernel
+	 * event_open for events[1] should fail with resource busy
+	 */
+	if (event_open_with_cpu(&events[1], 0)) {
+		/*
+		 * Check for the errno to certify the test result
+		 */
+		if (errno == 16) // Resource busy (EBUSY)
+			return 0;
+	}
+
+	return -1;
 }
 
 static int imc_global_lock_test(void)
-- 
2.20.1



More information about the Linuxppc-dev mailing list