[PATCH i-g-t v5 07/28] lib/intel_allocator: Try to stop softly instead of deinit

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Oct 16 16:25:02 UTC 2020


Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/intel_allocator.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
index f51f7fcb..420148c3 100644
--- a/lib/intel_allocator.c
+++ b/lib/intel_allocator.c
@@ -70,6 +70,7 @@ static struct igt_map *allocators_map;
 static pthread_mutex_t map_mutex = PTHREAD_MUTEX_INITIALIZER;
 static bool multiprocess;
 static pthread_t allocator_thread;
+static bool allocator_thread_running;
 
 static bool warn_if_not_empty;
 
@@ -486,6 +487,8 @@ static void *allocator_thread_loop(void *data)
 		   (long) allocator_pid, (long) gettid());
 	alloc_info("Entering allocator loop\n");
 
+	WRITE_ONCE(allocator_thread_running, true);
+
 	while (1) {
 		ret = recv_req(channel, &req);
 
@@ -519,6 +522,8 @@ static void *allocator_thread_loop(void *data)
 		}
 	}
 
+	WRITE_ONCE(allocator_thread_running, false);
+
 	return NULL;
 }
 
@@ -535,15 +540,30 @@ void intel_allocator_multiprocess_start(void)
 		       allocator_thread_loop, NULL);
 }
 
+#define STOP_TIMEOUT_MS 100
 void intel_allocator_multiprocess_stop(void)
 {
+	int time_left = STOP_TIMEOUT_MS;
+
 	alloc_info("allocator multiprocess stop\n");
 
 	if (multiprocess) {
 		send_alloc_stop(channel);
-		/* Deinit, this should stop all blocked syscalls, if any */
-		channel->deinit(channel);
-		pthread_join(allocator_thread, NULL);
+
+		/* We prefer joining thread when it is stopped */
+		while (time_left-- > 0 && READ_ONCE(allocator_thread_running))
+			usleep(1000); /* coarse calculation */
+
+		/* Thread has stuck somewhere */
+		if (READ_ONCE(allocator_thread_running)) {
+			/* Deinit, this should stop all blocked syscalls, if any */
+			channel->deinit(channel);
+			pthread_join(allocator_thread, NULL);
+		} else {
+			pthread_join(allocator_thread, NULL);
+			channel->deinit(channel);
+		}
+
 		/* But we're not sure does child will stuck */
 		kill_children(SIGINT);
 		igt_waitchildren_timeout(5, "Stopping children");
-- 
2.26.0



More information about the Intel-gfx-trybot mailing list