From 4b93ae7e7a7559d70f62e2ce8f649c399e7733cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 16 Jul 2023 03:44:53 -0400 Subject: [PATCH] util/u_queue: always enable UTIL_QUEUE_INIT_SCALE_THREADS, remove the flag It means that threads are created on demand except for the first one. It reduces process startup time. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/drivers/radeonsi/si_pipe.c | 2 -- src/gallium/drivers/zink/zink_screen.c | 2 +- src/util/disk_cache.c | 1 - src/util/u_queue.c | 10 +++++----- src/util/u_queue.h | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index f11cd2256b9..4165f3bd5b4 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -1290,7 +1290,6 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, if (!util_queue_init(&sscreen->shader_compiler_queue, "sh", num_slots, num_comp_hi_threads, UTIL_QUEUE_INIT_RESIZE_IF_FULL | - UTIL_QUEUE_INIT_SCALE_THREADS | UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY, NULL)) { si_destroy_shader_cache(sscreen); FREE(sscreen->nir_options); @@ -1302,7 +1301,6 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, if (!util_queue_init(&sscreen->shader_compiler_queue_low_priority, "shlo", num_slots, num_comp_lo_threads, UTIL_QUEUE_INIT_RESIZE_IF_FULL | - UTIL_QUEUE_INIT_SCALE_THREADS | UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY | UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY, NULL)) { si_destroy_shader_cache(sscreen); diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index bc1318b0605..08b564e2c50 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -3025,7 +3025,7 @@ zink_internal_create_screen(const struct pipe_screen_config *config) goto fail; } if (!util_queue_init(&screen->cache_get_thread, "zcfq", 8, 4, - UTIL_QUEUE_INIT_RESIZE_IF_FULL | UTIL_QUEUE_INIT_SCALE_THREADS, screen)) + UTIL_QUEUE_INIT_RESIZE_IF_FULL, screen)) goto fail; populate_format_props(screen); diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index c4872e59ee2..8298f9d7b32 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -87,7 +87,6 @@ disk_cache_init_queue(struct disk_cache *cache) * doesn't stall. */ return util_queue_init(&cache->cache_queue, "disk$", 32, 4, - UTIL_QUEUE_INIT_SCALE_THREADS | UTIL_QUEUE_INIT_RESIZE_IF_FULL | UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY | UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY, NULL); diff --git a/src/util/u_queue.c b/src/util/u_queue.c index ed1e96b10f7..750dd2015a6 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -442,9 +442,10 @@ util_queue_init(struct util_queue *queue, snprintf(queue->name, sizeof(queue->name), "%s", name); } + queue->create_threads_on_demand = true; queue->flags = flags; queue->max_threads = num_threads; - queue->num_threads = (flags & UTIL_QUEUE_INIT_SCALE_THREADS) ? 1 : num_threads; + queue->num_threads = 1; queue->max_jobs = max_jobs; queue->global_data = global_data; @@ -582,7 +583,7 @@ util_queue_add_job_locked(struct util_queue *queue, /* Scale the number of threads up if there's already one job waiting. */ if (queue->num_queued > 0 && - queue->flags & UTIL_QUEUE_INIT_SCALE_THREADS && + queue->create_threads_on_demand && execute != util_queue_finish_execute && queue->num_threads < queue->max_threads) { util_queue_adjust_num_threads(queue, queue->num_threads + 1, true); @@ -719,8 +720,7 @@ util_queue_finish(struct util_queue *queue) * Also note that util_queue_add_job can unlock the mutex if there is not * enough space in the queue and wait for space. */ - unsigned saved_flags = queue->flags; - queue->flags &= ~UTIL_QUEUE_INIT_SCALE_THREADS; + queue->create_threads_on_demand = false; fences = malloc(queue->num_threads * sizeof(*fences)); util_barrier_init(&barrier, queue->num_threads); @@ -730,7 +730,7 @@ util_queue_finish(struct util_queue *queue) util_queue_add_job_locked(queue, &barrier, &fences[i], util_queue_finish_execute, NULL, 0, true); } - queue->flags = saved_flags; + queue->create_threads_on_demand = true; mtx_unlock(&queue->lock); for (unsigned i = 0; i < queue->num_threads; ++i) { diff --git a/src/util/u_queue.h b/src/util/u_queue.h index 25f2c1589ed..ae7516c03ec 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -50,7 +50,6 @@ extern "C" { #define UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY (1 << 0) #define UTIL_QUEUE_INIT_RESIZE_IF_FULL (1 << 1) #define UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY (1 << 2) -#define UTIL_QUEUE_INIT_SCALE_THREADS (1 << 3) #if UTIL_FUTEX_SUPPORTED #define UTIL_QUEUE_FENCE_FUTEX @@ -206,6 +205,7 @@ struct util_queue_job { struct util_queue { char name[14]; /* 13 characters = the thread name without the index */ mtx_t lock; + bool create_threads_on_demand; cnd_t has_queued_cond; cnd_t has_space_cond; thrd_t *threads;