Module: Mesa
Branch: staging/23.3
Commit: 984d8051ef4546c8515b6911b0fc60ec9ede69fb
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=984d8051ef4546c8515b6911b0fc60ec9ede69fb

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>
(cherry picked from commit 52e41d4c97947a1b0c2c86c3b6491958716e998b)

---

 .pick_status.json                           |  2 +-
 src/gallium/frontends/rusticl/core/queue.rs | 16 +++++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 28a61b306e9..cd4535db7a4 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -54,7 +54,7 @@
         "description": "rusticl/queue: do not send empty lists of event to 
worker queue",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "8616c0a52c776ecc7d0e946207ab35213b5ba985",
         "notes": null
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

Reply via email to