diff options
author | Marek Olšák <[email protected]> | 2016-06-11 13:10:49 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2016-06-15 21:07:34 +0200 |
commit | 562cb03d76e4788d1d832f069e2c2f716e344fa4 (patch) | |
tree | 2f5fdd72f2822805aa28745c22c4f746252c5268 /src/gallium/winsys | |
parent | 44e0c0e6ecbe578281e0aff3fbffb29116b42d1b (diff) |
gallium/util: import the multithreaded job queue from amdgpu winsys (v2)
v2: rename the event to util_queue_fence
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/gallium/winsys')
-rw-r--r-- | src/gallium/winsys/amdgpu/drm/amdgpu_cs.c | 23 | ||||
-rw-r--r-- | src/gallium/winsys/amdgpu/drm/amdgpu_cs.h | 4 | ||||
-rw-r--r-- | src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 63 | ||||
-rw-r--r-- | src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h | 11 |
4 files changed, 18 insertions, 83 deletions
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c index fefa5d6db53..4a7302ab2cb 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c @@ -605,7 +605,7 @@ amdgpu_cs_create(struct radeon_winsys_ctx *rwctx, return NULL; } - pipe_semaphore_init(&cs->flush_completed, 1); + util_queue_fence_init(&cs->flush_completed); cs->ctx = ctx; cs->flush_cs = flush; @@ -872,8 +872,9 @@ static void amdgpu_add_fence_dependencies(struct amdgpu_cs *acs) } } -void amdgpu_cs_submit_ib(struct amdgpu_cs *acs) +void amdgpu_cs_submit_ib(void *job) { + struct amdgpu_cs *acs = (struct amdgpu_cs*)job; struct amdgpu_winsys *ws = acs->ctx->ws; struct amdgpu_cs_context *cs = acs->cst; int i, r; @@ -957,14 +958,11 @@ cleanup: void amdgpu_cs_sync_flush(struct radeon_winsys_cs *rcs) { struct amdgpu_cs *cs = amdgpu_cs(rcs); + struct amdgpu_winsys *ws = cs->ctx->ws; /* Wait for any pending ioctl of this CS to complete. */ - if (cs->ctx->ws->thread) { - /* wait and set the semaphore to "busy" */ - pipe_semaphore_wait(&cs->flush_completed); - /* set the semaphore to "idle" */ - pipe_semaphore_signal(&cs->flush_completed); - } + if (util_queue_is_initialized(&ws->cs_queue)) + util_queue_job_wait(&cs->flush_completed); } DEBUG_GET_ONCE_BOOL_OPTION(noop, "RADEON_NOOP", FALSE) @@ -1052,10 +1050,9 @@ static void amdgpu_cs_flush(struct radeon_winsys_cs *rcs, cs->cst = cur; /* Submit. */ - if (ws->thread && (flags & RADEON_FLUSH_ASYNC)) { - /* Set the semaphore to "busy". */ - pipe_semaphore_wait(&cs->flush_completed); - amdgpu_ws_queue_cs(ws, cs); + if ((flags & RADEON_FLUSH_ASYNC) && + util_queue_is_initialized(&ws->cs_queue)) { + util_queue_add_job(&ws->cs_queue, cs, &cs->flush_completed); } else { amdgpu_cs_submit_ib(cs); } @@ -1077,7 +1074,7 @@ static void amdgpu_cs_destroy(struct radeon_winsys_cs *rcs) struct amdgpu_cs *cs = amdgpu_cs(rcs); amdgpu_cs_sync_flush(rcs); - pipe_semaphore_destroy(&cs->flush_completed); + util_queue_fence_destroy(&cs->flush_completed); p_atomic_dec(&cs->ctx->ws->num_cs); pb_reference(&cs->main.big_ib_buffer, NULL); FREE(cs->main.base.prev); diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h index cc1516cfbf2..354e403fa36 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.h @@ -111,7 +111,7 @@ struct amdgpu_cs { void (*flush_cs)(void *ctx, unsigned flags, struct pipe_fence_handle **fence); void *flush_data; - pipe_semaphore flush_completed; + struct util_queue_fence flush_completed; }; struct amdgpu_fence { @@ -218,6 +218,6 @@ bool amdgpu_fence_wait(struct pipe_fence_handle *fence, uint64_t timeout, bool absolute); void amdgpu_cs_sync_flush(struct radeon_winsys_cs *rcs); void amdgpu_cs_init_functions(struct amdgpu_winsys *ws); -void amdgpu_cs_submit_ib(struct amdgpu_cs *cs); +void amdgpu_cs_submit_ib(void *job); #endif diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c index 701622184c8..7ef35298aa8 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c @@ -308,14 +308,9 @@ static void amdgpu_winsys_destroy(struct radeon_winsys *rws) { struct amdgpu_winsys *ws = (struct amdgpu_winsys*)rws; - if (ws->thread) { - ws->kill_thread = 1; - pipe_semaphore_signal(&ws->cs_queued); - pipe_thread_wait(ws->thread); - } - pipe_semaphore_destroy(&ws->cs_queue_has_space); - pipe_semaphore_destroy(&ws->cs_queued); - pipe_mutex_destroy(ws->cs_queue_lock); + if (util_queue_is_initialized(&ws->cs_queue)) + util_queue_destroy(&ws->cs_queue); + pipe_mutex_destroy(ws->bo_fence_lock); pb_cache_deinit(&ws->bo_cache); pipe_mutex_destroy(ws->global_bo_list_lock); @@ -400,53 +395,7 @@ static int compare_dev(void *key1, void *key2) return key1 != key2; } -void amdgpu_ws_queue_cs(struct amdgpu_winsys *ws, struct amdgpu_cs *cs) -{ - pipe_semaphore_wait(&ws->cs_queue_has_space); - - pipe_mutex_lock(ws->cs_queue_lock); - assert(ws->num_enqueued_cs < ARRAY_SIZE(ws->cs_queue)); - ws->cs_queue[ws->num_enqueued_cs++] = cs; - pipe_mutex_unlock(ws->cs_queue_lock); - pipe_semaphore_signal(&ws->cs_queued); -} - -static PIPE_THREAD_ROUTINE(amdgpu_cs_thread_func, param) -{ - struct amdgpu_winsys *ws = (struct amdgpu_winsys *)param; - struct amdgpu_cs *cs; - unsigned i; - - while (1) { - pipe_semaphore_wait(&ws->cs_queued); - if (ws->kill_thread) - break; - - pipe_mutex_lock(ws->cs_queue_lock); - cs = ws->cs_queue[0]; - for (i = 1; i < ws->num_enqueued_cs; i++) - ws->cs_queue[i - 1] = ws->cs_queue[i]; - ws->cs_queue[--ws->num_enqueued_cs] = NULL; - pipe_mutex_unlock(ws->cs_queue_lock); - - pipe_semaphore_signal(&ws->cs_queue_has_space); - - if (cs) { - amdgpu_cs_submit_ib(cs); - pipe_semaphore_signal(&cs->flush_completed); - } - } - pipe_mutex_lock(ws->cs_queue_lock); - for (i = 0; i < ws->num_enqueued_cs; i++) { - pipe_semaphore_signal(&ws->cs_queue[i]->flush_completed); - ws->cs_queue[i] = NULL; - } - pipe_mutex_unlock(ws->cs_queue_lock); - return 0; -} - DEBUG_GET_ONCE_BOOL_OPTION(thread, "RADEON_THREAD", TRUE) -static PIPE_THREAD_ROUTINE(amdgpu_cs_thread_func, param); static bool amdgpu_winsys_unref(struct radeon_winsys *rws) { @@ -541,14 +490,10 @@ amdgpu_winsys_create(int fd, radeon_screen_create_t screen_create) LIST_INITHEAD(&ws->global_bo_list); pipe_mutex_init(ws->global_bo_list_lock); - pipe_mutex_init(ws->cs_queue_lock); pipe_mutex_init(ws->bo_fence_lock); - pipe_semaphore_init(&ws->cs_queue_has_space, ARRAY_SIZE(ws->cs_queue)); - pipe_semaphore_init(&ws->cs_queued, 0); - if (sysconf(_SC_NPROCESSORS_ONLN) > 1 && debug_get_option_thread()) - ws->thread = pipe_thread_create(amdgpu_cs_thread_func, ws); + util_queue_init(&ws->cs_queue, amdgpu_cs_submit_ib); /* Create the screen at the end. The winsys must be initialized * completely. diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h index d6734f7bfbc..b13a17e119c 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h @@ -35,7 +35,7 @@ #include "pipebuffer/pb_cache.h" #include "gallium/drivers/radeon/radeon_winsys.h" #include "addrlib/addrinterface.h" -#include "os/os_thread.h" +#include "util/u_queue.h" #include <amdgpu.h> struct amdgpu_cs; @@ -59,13 +59,7 @@ struct amdgpu_winsys { struct radeon_info info; /* multithreaded IB submission */ - pipe_mutex cs_queue_lock; - pipe_semaphore cs_queue_has_space; - pipe_semaphore cs_queued; - pipe_thread thread; - int kill_thread; - int num_enqueued_cs; - struct amdgpu_cs *cs_queue[8]; + struct util_queue cs_queue; struct amdgpu_gpu_info amdinfo; ADDR_HANDLE addrlib; @@ -84,7 +78,6 @@ amdgpu_winsys(struct radeon_winsys *base) return (struct amdgpu_winsys*)base; } -void amdgpu_ws_queue_cs(struct amdgpu_winsys *ws, struct amdgpu_cs *cs); void amdgpu_surface_init_functions(struct amdgpu_winsys *ws); ADDR_HANDLE amdgpu_addr_create(struct amdgpu_winsys *ws); |