mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-27 13:30:52 +00:00
71ad4713cc
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>
41 lines
1.1 KiB
C
41 lines
1.1 KiB
C
/*
|
|
* QEMU block layer thread pool
|
|
*
|
|
* Copyright IBM, Corp. 2008
|
|
* Copyright Red Hat, Inc. 2012
|
|
*
|
|
* Authors:
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
* Paolo Bonzini <pbonzini@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
* the COPYING file in the top-level directory.
|
|
*
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
|
*/
|
|
|
|
#ifndef QEMU_THREAD_POOL_H
|
|
#define QEMU_THREAD_POOL_H
|
|
|
|
#include "block/block.h"
|
|
|
|
#define THREAD_POOL_MAX_THREADS_DEFAULT 64
|
|
|
|
typedef int ThreadPoolFunc(void *opaque);
|
|
|
|
typedef struct ThreadPool ThreadPool;
|
|
|
|
ThreadPool *thread_pool_new(struct AioContext *ctx);
|
|
void thread_pool_free(ThreadPool *pool);
|
|
|
|
BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool,
|
|
ThreadPoolFunc *func, void *arg,
|
|
BlockCompletionFunc *cb, void *opaque);
|
|
int coroutine_fn thread_pool_submit_co(ThreadPool *pool,
|
|
ThreadPoolFunc *func, void *arg);
|
|
void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg);
|
|
void thread_pool_update_params(ThreadPool *pool, struct AioContext *ctx);
|
|
|
|
#endif
|