From 32a93c197e17544eb7d43618bb2b81ab7d4d0b47 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 23 Dec 2024 13:17:25 +0100 Subject: [PATCH] rusticl/queue: add a life check to prevent applications dead locking Cc: mesa-stable Reviewed-by: Adam Jackson (cherry picked from commit ccfeda77bd01032fddd4b6d61c15ac1ab0da9bcc) Part-of: --- .pick_status.json | 2 +- src/gallium/frontends/rusticl/core/event.rs | 8 ++++++++ src/gallium/frontends/rusticl/core/queue.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index a89de072ab9..534217d5cae 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -104,7 +104,7 @@ "description": "rusticl/queue: add a life check to prevent applications dead locking", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/frontends/rusticl/core/event.rs b/src/gallium/frontends/rusticl/core/event.rs index 2ee27630715..23bfbbb8242 100644 --- a/src/gallium/frontends/rusticl/core/event.rs +++ b/src/gallium/frontends/rusticl/core/event.rs @@ -212,6 +212,14 @@ impl Event { .wait_timeout(lock, Duration::from_secs(1)) .unwrap() .0; + + if let Some(queue) = &self.queue { + // in case the queue worker thread exited abnormally we'll need to stop spinning on + // the cv here, because otherwise we'll end up spinning endlessly. + if queue.is_dead() { + return CL_OUT_OF_HOST_MEMORY; + } + } } lock.status } diff --git a/src/gallium/frontends/rusticl/core/queue.rs b/src/gallium/frontends/rusticl/core/queue.rs index af59d113016..7712c6e52c7 100644 --- a/src/gallium/frontends/rusticl/core/queue.rs +++ b/src/gallium/frontends/rusticl/core/queue.rs @@ -88,7 +88,7 @@ pub struct Queue { pub props: cl_command_queue_properties, pub props_v2: Option>, state: Mutex, - _thrd: JoinHandle<()>, + thrd: JoinHandle<()>, } impl_cl_type_trait!(cl_command_queue, Queue, CL_INVALID_COMMAND_QUEUE); @@ -122,7 +122,7 @@ impl Queue { last: Weak::new(), chan_in: tx_q, }), - _thrd: thread::Builder::new() + thrd: thread::Builder::new() .name("rusticl queue thread".into()) .spawn(move || { // Track the error of all executed events. This is only needed for in-order @@ -250,6 +250,10 @@ impl Queue { Ok(()) } + pub fn is_dead(&self) -> bool { + self.thrd.is_finished() + } + pub fn is_profiling_enabled(&self) -> bool { (self.props & (CL_QUEUE_PROFILING_ENABLE as u64)) != 0 }