[LTP] [PATCH] syscalls/perf_event_open03: skip test on slower systems

Jan Stancek jstancek@redhat.com
Thu Feb 17 12:18:22 CET 2022


Some systems (specially with combination of -debug kernel
with KASAN enabled) have trouble completing this test
in specified timeout.

Lowering number of iterations would make the test condition
less accurate as it's based on global counter.

Instead, calculate the rate of iterations system can do in
first 5 seconds and used that to decide whether to continue
to run the test. If the rate is too slow, TCONF after 5
seconds.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../perf_event_open/perf_event_open03.c       | 43 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 2 deletions(-)

.needs_cmds = NULL gets rid of compile warning.

diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c
index dcb70962771c..c7bf123a04b4 100644
--- a/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c
@@ -16,13 +16,16 @@
 
 #include "config.h"
 #include "tst_test.h"
+#include "tst_timer_test.h"
 #include "lapi/syscalls.h"
 
 #include "perf_event_open.h"
 
 #define INTEL_PT_PATH "/sys/bus/event_source/devices/intel_pt/type"
 
+const int iterations = 12000000;
 static int fd = -1;
+static int timeout;
 
 static void setup(void)
 {
@@ -39,6 +42,38 @@ static void setup(void)
 
 	SAFE_FILE_SCANF(INTEL_PT_PATH, "%d", &ev.type);
 	fd = perf_event_open(&ev, getpid(), -1, -1, 0);
+
+	timeout = tst_timeout_remaining();
+}
+
+/*
+ * Check how fast we can do the iterations after 5 seconds of runtime.
+ * If the rate is too small to complete for current timeout then
+ * stop the test.
+ */
+static void check_progress(int i)
+{
+	static float iter_per_ms;
+	long long elapsed_ms;
+
+	if (iter_per_ms)
+		return;
+
+	if (i % 1000 != 0)
+		return;
+
+	tst_timer_stop();
+	elapsed_ms = tst_timer_elapsed_ms();
+	if (elapsed_ms > 5000) {
+		iter_per_ms = (float) i / elapsed_ms;
+		tst_res(TINFO, "rate: %f iters/ms", iter_per_ms);
+		tst_res(TINFO, "needed rate for current test timeout: %f iters/ms",
+			(float) iterations / (timeout * 1000));
+
+		if (iter_per_ms * 1000 * (timeout - 1) < iterations)
+			tst_brk(TCONF, "System too slow to complete"
+				" test in specified timeout");
+	}
 }
 
 static void run(void)
@@ -47,10 +82,13 @@ static void run(void)
 	int i;
 
 	diff = SAFE_READ_MEMINFO("MemAvailable:");
+	tst_timer_start(CLOCK_MONOTONIC);
 
 	/* leak about 100MB of RAM */
-	for (i = 0; i < 12000000; i++)
+	for (i = 0; i < iterations; i++) {
 		ioctl(fd, PERF_EVENT_IOC_SET_FILTER, "filter,0/0@abcd");
+		check_progress(i);
+	}
 
 	diff -= SAFE_READ_MEMINFO("MemAvailable:");
 
@@ -75,5 +113,6 @@ static struct tst_test test = {
 		{"linux-git", "7bdb157cdebb"},
 		{"CVE", "2020-25704"},
 		{}
-	}
+	},
+	.needs_cmds = NULL,
 };
-- 
2.27.0



More information about the ltp mailing list