diff mbox series

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

Message ID 20200121101728.14858-6-anju@linux.vnet.ibm.com (mailing list archive)
State Superseded
Headers show
Series Re-enable IMC trace-mode | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (20862247a368dbb75d6e97d82345999adaacf3cc)
snowpatch_ozlabs/build-ppc64le success Build succeeded
snowpatch_ozlabs/build-ppc64be success Build succeeded
snowpatch_ozlabs/build-ppc64e success Build succeeded
snowpatch_ozlabs/build-pmac32 success Build succeeded
snowpatch_ozlabs/checkpatch warning total: 0 errors, 6 warnings, 0 checks, 57 lines checked
snowpatch_ozlabs/needsstable success Patch has no Fixes tags

Commit Message

Anju T Sudhakar Jan. 21, 2020, 10:17 a.m. UTC
From: Madhavan Srinivasan <maddy@linux.ibm.com>

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

Patch

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)