Module: Mesa Branch: main Commit: 7357ce19a257fadb47a3b39b9b43a17658f7fe6f URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7357ce19a257fadb47a3b39b9b43a17658f7fe6f
Author: Pierre-Eric Pelloux-Prayer <[email protected]> Date: Mon May 2 13:25:03 2022 +0200 util/u_queue: rework UTIL_QUEUE_INIT_SCALE_THREADS to scale faster The original code waiting for the queue to be full before adding more threads. This makes the thread count grow slowly, especially if the queue also uses UTIL_QUEUE_INIT_RESIZE_IF_FULL. This commit changes this behavior: now a new thread is spawned if we're adding a job to a non-empty queue because this means that the existing threads fail to process jobs faster than they're queued. Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16273> --- src/util/u_queue.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/u_queue.c b/src/util/u_queue.c index 413f8aa019e..0a74119e2d6 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -569,14 +569,15 @@ util_queue_add_job(struct util_queue *queue, assert(queue->num_queued >= 0 && queue->num_queued <= queue->max_jobs); + /* 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 && + execute != util_queue_finish_execute && + queue->num_threads < queue->max_threads) { + util_queue_adjust_num_threads(queue, queue->num_threads + 1); + } if (queue->num_queued == queue->max_jobs) { - if ((queue->flags & UTIL_QUEUE_INIT_SCALE_THREADS) && - execute != util_queue_finish_execute && - queue->num_threads < queue->max_threads) { - util_queue_adjust_num_threads(queue, queue->num_threads + 1); - } - if (queue->flags & UTIL_QUEUE_INIT_RESIZE_IF_FULL && queue->total_jobs_size + job_size < S_256MB) { /* If the queue is full, make it larger to avoid waiting for a free
