summaryrefslogtreecommitdiff
path: root/lib/intel_allocator.c
diff options
context:
space:
mode:
authorZbigniew Kempczyński <zbigniew.kempczynski@intel.com>2020-10-23 09:30:12 +0200
committerZbigniew Kempczyński <zbigniew.kempczynski@intel.com>2021-04-13 15:44:38 +0200
commit9960e3d39e9e35636806f6e039b729b6dea7bdbb (patch)
treef0df9ad56e5e24383cb832b9d1ff5cf765653244 /lib/intel_allocator.c
parente4d8b8b01d25d507cf850c69a3da3ec08ec6c88e (diff)
lib/intel_allocator: Try to stop smoothly instead of deinit
Avoid race when stop was send to allocator thread. We wait around 100 ms to give thread chance to stop smoothly instead of removing queue and enforcing exiting all blocked message syscalls. Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Acked-by: Petri Latvala <petri.latvala@intel.com>
Diffstat (limited to 'lib/intel_allocator.c')
-rw-r--r--lib/intel_allocator.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
index 9ab541d1..466776bc 100644
--- a/lib/intel_allocator.c
+++ b/lib/intel_allocator.c
@@ -106,6 +106,7 @@ 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;
@@ -725,6 +726,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);
@@ -758,6 +761,8 @@ static void *allocator_thread_loop(void *data)
}
}
+ WRITE_ONCE(allocator_thread_running, false);
+
return NULL;
}
@@ -797,15 +802,24 @@ void intel_allocator_multiprocess_start(void)
* Function turns off intel_allocator multiprocess mode what means
* stopping allocator thread and deinitializing its data.
*/
+#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);
+
+ /* Give allocator thread time to complete */
+ while (time_left-- > 0 && READ_ONCE(allocator_thread_running))
+ usleep(1000); /* coarse calculation */
+
/* Deinit, this should stop all blocked syscalls, if any */
channel->deinit(channel);
pthread_join(allocator_thread, NULL);
+
/* But we're not sure does child will stuck */
igt_waitchildren_timeout(5, "Stopping children");
multiprocess = false;