[Mesa-dev] [PATCH 3/4] gallium/u_threaded: implement set_context_param for thread pinning (v2)

Marek Olšák maraeo at gmail.com
Fri Sep 7 01:04:41 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

v2: - use set_context_param
    - set set_context_param even if the driver doesn't implement it
---
 .../auxiliary/util/u_threaded_context.c       | 40 +++++++++++++++++++
 .../auxiliary/util/u_threaded_context_calls.h |  1 +
 2 files changed, 41 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c
index fc7eb138835..8e3bceae18d 100644
--- a/src/gallium/auxiliary/util/u_threaded_context.c
+++ b/src/gallium/auxiliary/util/u_threaded_context.c
@@ -1892,20 +1892,58 @@ tc_create_video_codec(UNUSED struct pipe_context *_pipe,
 }
 
 static struct pipe_video_buffer *
 tc_create_video_buffer(UNUSED struct pipe_context *_pipe,
                        UNUSED const struct pipe_video_buffer *templ)
 {
    unreachable("Threaded context should not be enabled for video APIs");
    return NULL;
 }
 
+struct tc_context_param {
+   enum pipe_context_param param;
+   unsigned value;
+};
+
+static void
+tc_call_set_context_param(struct pipe_context *pipe,
+                          union tc_payload *payload)
+{
+   struct tc_context_param *p = (struct tc_context_param*)payload;
+
+   if (pipe->set_context_param)
+      pipe->set_context_param(pipe, p->param, p->value);
+}
+
+static void
+tc_set_context_param(struct pipe_context *_pipe,
+                           enum pipe_context_param param,
+                           unsigned value)
+{
+   struct threaded_context *tc = threaded_context(_pipe);
+
+   if (tc->pipe->set_context_param) {
+      struct tc_context_param *payload =
+         tc_add_struct_typed_call(tc, TC_CALL_set_context_param,
+                                  tc_context_param);
+
+      payload->param = param;
+      payload->value = value;
+   }
+
+   if (param == PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE) {
+      /* Pin the gallium thread as requested. */
+      util_pin_thread_to_L3(tc->queue.threads[0], value,
+                            util_cpu_caps.cores_per_L3);
+   }
+}
+
 
 /********************************************************************
  * draw, launch, clear, blit, copy, flush
  */
 
 struct tc_flush_payload {
    struct threaded_context *tc;
    struct pipe_fence_handle *fence;
    unsigned flags;
 };
@@ -2573,20 +2611,22 @@ threaded_context_create(struct pipe_context *pipe,
    for (unsigned i = 0; i < TC_MAX_BATCHES; i++) {
       tc->batch_slots[i].sentinel = TC_SENTINEL;
       tc->batch_slots[i].pipe = pipe;
       util_queue_fence_init(&tc->batch_slots[i].fence);
    }
 
    LIST_INITHEAD(&tc->unflushed_queries);
 
    slab_create_child(&tc->pool_transfers, parent_transfer_pool);
 
+   tc->base.set_context_param = tc_set_context_param; /* always set this */
+
 #define CTX_INIT(_member) \
    tc->base._member = tc->pipe->_member ? tc_##_member : NULL
 
    CTX_INIT(flush);
    CTX_INIT(draw_vbo);
    CTX_INIT(launch_grid);
    CTX_INIT(resource_copy_region);
    CTX_INIT(blit);
    CTX_INIT(clear);
    CTX_INIT(clear_render_target);
diff --git a/src/gallium/auxiliary/util/u_threaded_context_calls.h b/src/gallium/auxiliary/util/u_threaded_context_calls.h
index 921b86a67f0..e6ea1b5747c 100644
--- a/src/gallium/auxiliary/util/u_threaded_context_calls.h
+++ b/src/gallium/auxiliary/util/u_threaded_context_calls.h
@@ -42,20 +42,21 @@ CALL(set_stencil_ref)
 CALL(set_clip_state)
 CALL(set_sample_mask)
 CALL(set_min_samples)
 CALL(set_polygon_stipple)
 CALL(texture_barrier)
 CALL(memory_barrier)
 CALL(delete_texture_handle)
 CALL(make_texture_handle_resident)
 CALL(delete_image_handle)
 CALL(make_image_handle_resident)
+CALL(set_context_param)
 
 CALL(bind_blend_state)
 CALL(bind_rasterizer_state)
 CALL(bind_depth_stencil_alpha_state)
 CALL(bind_compute_state)
 CALL(bind_fs_state)
 CALL(bind_vs_state)
 CALL(bind_gs_state)
 CALL(bind_tcs_state)
 CALL(bind_tes_state)
-- 
2.17.1



More information about the mesa-dev mailing list