mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-26 20:03:54 -06:00
util/event-loop-base: Introduce options to set the thread pool size
The thread pool regulates itself: when idle, it kills threads until empty, when in demand, it creates new threads until full. This behaviour doesn't play well with latency sensitive workloads where the price of creating a new thread is too high. For example, when paired with qemu's '-mlock', or using safety features like SafeStack, creating a new thread has been measured take multiple milliseconds. In order to mitigate this let's introduce a new 'EventLoopBase' property to set the thread pool size. The threads will be created during the pool's initialization or upon updating the property's value, remain available during its lifetime regardless of demand, and destroyed upon freeing it. A properly characterized workload will then be able to configure the pool to avoid any latency spikes. Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Acked-by: Markus Armbruster <armbru@redhat.com> Message-id: 20220425075723.20019-4-nsaenzju@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
70ac26b9e5
commit
71ad4713cc
10 changed files with 133 additions and 5 deletions
20
util/async.c
20
util/async.c
|
@ -563,6 +563,9 @@ AioContext *aio_context_new(Error **errp)
|
|||
|
||||
ctx->aio_max_batch = 0;
|
||||
|
||||
ctx->thread_pool_min = 0;
|
||||
ctx->thread_pool_max = THREAD_POOL_MAX_THREADS_DEFAULT;
|
||||
|
||||
return ctx;
|
||||
fail:
|
||||
g_source_destroy(&ctx->source);
|
||||
|
@ -696,3 +699,20 @@ void qemu_set_current_aio_context(AioContext *ctx)
|
|||
assert(!get_my_aiocontext());
|
||||
set_my_aiocontext(ctx);
|
||||
}
|
||||
|
||||
void aio_context_set_thread_pool_params(AioContext *ctx, int64_t min,
|
||||
int64_t max, Error **errp)
|
||||
{
|
||||
|
||||
if (min > max || !max || min > INT_MAX || max > INT_MAX) {
|
||||
error_setg(errp, "bad thread-pool-min/thread-pool-max values");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->thread_pool_min = min;
|
||||
ctx->thread_pool_max = max;
|
||||
|
||||
if (ctx->thread_pool) {
|
||||
thread_pool_update_params(ctx->thread_pool, ctx);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue