[igt-dev] [PATCH i-g-t v2 2/3] benchmarks/gem_syslatency: don't die with SIGSEGV

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Thu May 19 12:23:44 UTC 2022


From: Mauro Carvalho Chehab <mchehab at kernel.org>

Fix the pthread_create() logic for it to properly handle temporary
issues returned with EAGAIN and ensure that thread creation
won't fail, as, if it fails, it will cause a Segmentation fault:

	Received signal SIGSEGV.
	Stack trace:
	 #0 [fatal_sig_handler+0x163]
	 #1 [__sigaction+0x50]
	 #2 [__pthread_clockjoin_ex+0x22]
	 #3 [main+0x346]
	 #4 [__libc_start_call_main+0x80]
	 #5 [__libc_start_main+0x89]
	 #6 [_start+0x25]
	Segmentation fault

Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
---
 benchmarks/gem_syslatency.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/benchmarks/gem_syslatency.c b/benchmarks/gem_syslatency.c
index 035ee9346251..4b097e1c9316 100644
--- a/benchmarks/gem_syslatency.c
+++ b/benchmarks/gem_syslatency.c
@@ -351,7 +351,7 @@ int main(int argc, char **argv)
 	bool leak = false;
 	bool interrupts = false;
 	long batch = 0;
-	int n, c;
+	int ret, n, c;
 
 	while ((c = getopt(argc, argv, "r:t:f:bmni1")) != -1) {
 		switch (c) {
@@ -409,8 +409,11 @@ int main(int argc, char **argv)
 			busy[n].sz = batch;
 			busy[n].leak = leak;
 			busy[n].interrupts = interrupts;
-			pthread_create(&busy[n].thread, &attr,
-				       gem_busyspin, &busy[n]);
+			do {
+				ret = pthread_create(&busy[n].thread, &attr,
+						     gem_busyspin, &busy[n]);
+			} while (ret == EAGAIN);
+			igt_assert_f(!ret, "Can't create task on CPU#%d\n", n);
 		}
 	}
 
@@ -420,7 +423,10 @@ int main(int argc, char **argv)
 	for (n = 0; n < ncpus; n++) {
 		igt_mean_init(&wait[n].mean);
 		bind_cpu(&attr, n);
-		pthread_create(&wait[n].thread, &attr, sys_fn, &wait[n]);
+		do {
+			ret = pthread_create(&wait[n].thread, &attr, sys_fn, &wait[n]);
+		} while (ret == EAGAIN);
+		igt_assert_f(!ret, "Can't create task on CPU#%d\n", n);
 	}
 
 	sleep(time);
-- 
2.36.1



More information about the igt-dev mailing list