From: Matthias Brugger <matthias.bgg@gmail.com>
To: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>, "Alex Bligh" <alex@alex.org.uk>,
malc <av1474@comtv.ru>,
"Liu Ping Fan" <pingfank@linux.vnet.ibm.com>,
"Andreas Färber" <afaerber@suse.de>,
"Anthony Liguori" <anthony@codemonkey.ws>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Michael Tokarev" <mjt@tls.msk.ru>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"Stefan Weil" <sw@weilnetz.de>,
"Luiz Capitulino" <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] Make thread pool implementation modular
Date: Sat, 2 Nov 2013 00:34:05 +0100 [thread overview]
Message-ID: <1383348847-14153-2-git-send-email-matthias.bgg@gmail.com> (raw)
In-Reply-To: <1383348847-14153-1-git-send-email-matthias.bgg@gmail.com>
This patch introduces function pointers for the thread pool, so that
it's implementation can be set at run-time.
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
---
include/block/thread-pool.h | 9 +++++++++
thread-pool.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/include/block/thread-pool.h b/include/block/thread-pool.h
index 32afcdd..53a779f 100644
--- a/include/block/thread-pool.h
+++ b/include/block/thread-pool.h
@@ -38,4 +38,13 @@ int coroutine_fn thread_pool_submit_co(ThreadPool *pool,
ThreadPoolFunc *func, void *arg);
void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg);
+ThreadPoolFuncArr *thread_pool_probe(void);
+void thread_pool_delete(ThreadPoolFuncArr *tpf);
+
+struct ThreadPoolFuncArr {
+ BlockDriverAIOCB *(*thread_pool_submit_aio)(ThreadPool *pool, ThreadPoolFunc *func, void *arg, BlockDriverCompletionFunc *cb, void *opaque);
+ ThreadPool *(*thread_pool_new)(AioContext *ctx);
+};
+
+
#endif
diff --git a/thread-pool.c b/thread-pool.c
index 3735fd3..8c5d1a2 100644
--- a/thread-pool.c
+++ b/thread-pool.c
@@ -26,6 +26,7 @@
#include "qemu/main-loop.h"
static void do_spawn_thread(ThreadPool *pool);
+void thread_pool_aio_free(ThreadPool *pool);
typedef struct ThreadPoolElement ThreadPoolElement;
@@ -77,6 +78,7 @@ struct ThreadPool {
int pending_threads; /* threads created but not running yet */
int pending_cancellations; /* whether we need a cond_broadcast */
bool stopping;
+ void (*thread_pool_free)(ThreadPool *pool);
};
static void *worker_thread(void *opaque)
@@ -300,6 +302,7 @@ static void thread_pool_init_one(ThreadPool *pool, AioContext *ctx)
qemu_sem_init(&pool->sem, 0);
pool->max_threads = 64;
pool->new_thread_bh = aio_bh_new(ctx, spawn_thread_bh_fn, pool);
+ pool->thread_pool_free = &thread_pool_aio_free;
QLIST_INIT(&pool->head);
QTAILQ_INIT(&pool->request_list);
@@ -316,6 +319,11 @@ ThreadPool *thread_pool_new(AioContext *ctx)
void thread_pool_free(ThreadPool *pool)
{
+ pool->thread_pool_free(pool);
+}
+
+void thread_pool_aio_free(ThreadPool *pool)
+{
if (!pool) {
return;
}
@@ -346,3 +354,27 @@ void thread_pool_free(ThreadPool *pool)
event_notifier_cleanup(&pool->notifier);
g_free(pool);
}
+
+ThreadPoolFuncArr *thread_pool_probe(void)
+{
+ ThreadPoolFuncArr *tpf_pool = NULL;
+
+ if (tpf_pool)
+ return tpf_pool;
+
+ tpf_pool = g_new(ThreadPoolFuncArr, 1); //TODO right now, this leaks!
+ if (!tpf_pool) {
+ printf("error allocating thread pool\n");
+ return NULL;
+ }
+
+ tpf_pool->thread_pool_submit_aio = thread_pool_submit_aio;
+ tpf_pool->thread_pool_new = thread_pool_new;
+
+ return tpf_pool;
+}
+
+void thread_pool_delete(ThreadPoolFuncArr *tpf)
+{
+ g_free(tpf);
+}
--
1.8.1.2
next prev parent reply other threads:[~2013-11-01 23:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-01 23:34 [Qemu-devel] Make thread pool implementation modular Matthias Brugger
2013-11-01 23:34 ` Matthias Brugger [this message]
2013-11-01 23:34 ` [Qemu-devel] [PATCH 2/3] Block layer uses modular thread pool Matthias Brugger
2013-11-01 23:34 ` [Qemu-devel] [PATCH 3/3] Add workerthreads configuration option Matthias Brugger
2013-11-02 7:17 ` [Qemu-devel] Make thread pool implementation modular Stefan Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383348847-14153-2-git-send-email-matthias.bgg@gmail.com \
--to=matthias.bgg@gmail.com \
--cc=afaerber@suse.de \
--cc=alex@alex.org.uk \
--cc=anthony@codemonkey.ws \
--cc=armbru@redhat.com \
--cc=av1474@comtv.ru \
--cc=ehabkost@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=pingfank@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).