Module: Mesa Branch: main Commit: 52e41d4c97947a1b0c2c86c3b6491958716e998b URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=52e41d4c97947a1b0c2c86c3b6491958716e998b
Author: Karol Herbst <kher...@redhat.com> Date: Sun Nov 5 19:28:49 2023 +0100 rusticl/queue: do not send empty lists of event to worker queue This saves us a few CPU cycles and makes properly fixing implicit flushes less expensive. Fixes: 8616c0a52c7 ("rusticl/event: flush queues from dependencies") Signed-off-by: Karol Herbst <kher...@redhat.com> Reviewed-by: @LingMan <18294-ling...@users.noreply.gitlab.freedesktop.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26053> --- src/gallium/frontends/rusticl/core/queue.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/queue.rs b/src/gallium/frontends/rusticl/core/queue.rs index 4a4cb223949..8fa9e5fcd53 100644 --- a/src/gallium/frontends/rusticl/core/queue.rs +++ b/src/gallium/frontends/rusticl/core/queue.rs @@ -10,6 +10,7 @@ use mesa_rust_util::properties::*; use rusticl_opencl_gen::*; use std::collections::HashSet; +use std::mem; use std::sync::mpsc; use std::sync::Arc; use std::sync::Mutex; @@ -131,19 +132,20 @@ impl Queue { pub fn flush(&self, wait: bool) -> CLResult<()> { let mut state = self.state.lock().unwrap(); + let events = mem::take(&mut state.pending); // Update last if and only if we get new events, this prevents breaking application code // doing things like `clFlush(q); clFinish(q);` - if let Some(last) = state.pending.last() { + if let Some(last) = events.last() { state.last = Arc::downgrade(last); + + // This should never ever error, but if it does return an error + state + .chan_in + .send(events) + .map_err(|_| CL_OUT_OF_HOST_MEMORY)?; } - let events = state.pending.drain(0..).collect(); - // This should never ever error, but if it does return an error - state - .chan_in - .send(events) - .map_err(|_| CL_OUT_OF_HOST_MEMORY)?; if wait { // Waiting on the last event is good enough here as the queue will process it in order // It's not a problem if the weak ref is invalid as that means the work is already done