diff options
author | Nicolas Saenz Julienne <nsaenzju@redhat.com> | 2022-04-25 09:57:23 +0200 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2022-05-09 10:43:23 +0100 |
commit | 71ad4713cc1d7fca24388b828ef31ae6cb38a31c (patch) | |
tree | baf49f521c85ffa4551b2cb73083562570b3c857 /util/main-loop.c | |
parent | 70ac26b9e5ca8374bb3ef3f30b871726673c9f27 (diff) |
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>
Diffstat (limited to 'util/main-loop.c')
-rw-r--r-- | util/main-loop.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/util/main-loop.c b/util/main-loop.c index e30f034815..f00a25451b 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -30,6 +30,7 @@ #include "sysemu/replay.h" #include "qemu/main-loop.h" #include "block/aio.h" +#include "block/thread-pool.h" #include "qemu/error-report.h" #include "qemu/queue.h" #include "qemu/compiler.h" @@ -187,12 +188,20 @@ int qemu_init_main_loop(Error **errp) static void main_loop_update_params(EventLoopBase *base, Error **errp) { + ERRP_GUARD(); + if (!qemu_aio_context) { error_setg(errp, "qemu aio context not ready"); return; } aio_context_set_aio_params(qemu_aio_context, base->aio_max_batch, errp); + if (*errp) { + return; + } + + aio_context_set_thread_pool_params(qemu_aio_context, base->thread_pool_min, + base->thread_pool_max, errp); } MainLoop *mloop; |