From 7357ce19a257fadb47a3b39b9b43a17658f7fe6f Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Mon, 2 May 2022 13:25:03 +0200 Subject: [PATCH] util/u_queue: rework UTIL_QUEUE_INIT_SCALE_THREADS to scale faster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Part-of: --- 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