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 2/3] Block layer uses modular thread pool
Date: Sat, 2 Nov 2013 00:34:06 +0100 [thread overview]
Message-ID: <1383348847-14153-3-git-send-email-matthias.bgg@gmail.com> (raw)
In-Reply-To: <1383348847-14153-1-git-send-email-matthias.bgg@gmail.com>
With this patch, the calls to the thread pool functions pass through the
new modular thread pool implementation.
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
---
async.c | 4 ++--
block/raw-posix.c | 15 +++++++++++----
block/raw-win32.c | 9 +++++++--
include/block/aio.h | 2 +-
include/qemu-common.h | 2 ++
5 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/async.c b/async.c
index 5fb3fa6..e66f70f 100644
--- a/async.c
+++ b/async.c
@@ -232,10 +232,10 @@ GSource *aio_get_g_source(AioContext *ctx)
return &ctx->source;
}
-ThreadPool *aio_get_thread_pool(AioContext *ctx)
+ThreadPool *aio_get_thread_pool(AioContext *ctx, ThreadPoolFuncArr *tpf)
{
if (!ctx->thread_pool) {
- ctx->thread_pool = thread_pool_new(ctx);
+ ctx->thread_pool = tpf->thread_pool_new(ctx);
}
return ctx->thread_pool;
}
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6f03fbf..22842ed 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -142,6 +142,7 @@ typedef struct BDRVRawState {
bool is_xfs : 1;
#endif
bool has_discard : 1;
+ ThreadPoolFuncArr *tpf;
} BDRVRawState;
typedef struct BDRVRawReopenState {
@@ -345,6 +346,9 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
int ret;
s->type = FTYPE_FILE;
+
+ s->tpf = thread_pool_probe();
+
ret = raw_open_common(bs, options, flags, 0, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
@@ -792,6 +796,7 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque, int type)
{
+ BDRVRawState *s = bs->opaque;
RawPosixAIOData *acb = g_slice_new(RawPosixAIOData);
ThreadPool *pool;
@@ -807,8 +812,8 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
acb->aio_offset = sector_num * 512;
trace_paio_submit(acb, opaque, sector_num, nb_sectors, type);
- pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
- return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
+ pool = aio_get_thread_pool(bdrv_get_aio_context(bs), s->tpf);
+ return s->tpf->thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
}
static BlockDriverAIOCB *raw_aio_submit(BlockDriverState *bs,
@@ -874,6 +879,8 @@ static void raw_close(BlockDriverState *bs)
qemu_close(s->fd);
s->fd = -1;
}
+
+ thread_pool_delete(s->tpf);
}
static int raw_truncate(BlockDriverState *bs, int64_t offset)
@@ -1490,8 +1497,8 @@ static BlockDriverAIOCB *hdev_aio_ioctl(BlockDriverState *bs,
acb->aio_offset = 0;
acb->aio_ioctl_buf = buf;
acb->aio_ioctl_cmd = req;
- pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
- return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
+ pool = aio_get_thread_pool(bdrv_get_aio_context(bs), s->tpf);
+ return s->tpf->thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 676b570..dad1255 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -46,6 +46,7 @@ typedef struct RawWin32AIOData {
size_t aio_nbytes;
off64_t aio_offset;
int aio_type;
+ ThreadPoolFuncArr *tpf;
} RawWin32AIOData;
typedef struct BDRVRawState {
@@ -159,8 +160,8 @@ static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile,
acb->aio_offset = sector_num * 512;
trace_paio_submit(acb, opaque, sector_num, nb_sectors, type);
- pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
- return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
+ pool = aio_get_thread_pool(bdrv_get_aio_context(bs), s->tpf);
+ return s->tpf->thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque);
}
int qemu_ftruncate64(int fd, int64_t length)
@@ -248,6 +249,8 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
s->type = FTYPE_FILE;
+ s->tpf = thread_pool_probe();
+
opts = qemu_opts_create_nofail(&raw_runtime_opts);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (error_is_set(&local_err)) {
@@ -339,6 +342,8 @@ static void raw_close(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
CloseHandle(s->hfile);
+
+ thread_pool_delete(s->tpf);
}
static int raw_truncate(BlockDriverState *bs, int64_t offset)
diff --git a/include/block/aio.h b/include/block/aio.h
index 2efdf41..22d6fa0 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -231,7 +231,7 @@ void aio_set_event_notifier(AioContext *ctx,
GSource *aio_get_g_source(AioContext *ctx);
/* Return the ThreadPool bound to this AioContext */
-struct ThreadPool *aio_get_thread_pool(AioContext *ctx);
+struct ThreadPool *aio_get_thread_pool(AioContext *ctx, ThreadPoolFuncArr *tpf);
/* Functions to operate on the main QEMU AioContext. */
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 5054836..594a53b 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -478,4 +478,6 @@ size_t buffer_find_nonzero_offset(const void *buf, size_t len);
*/
int parse_debug_env(const char *name, int max, int initial);
+typedef struct ThreadPoolFuncArr ThreadPoolFuncArr;
+
#endif
--
1.8.1.2
next prev parent reply other threads:[~2013-11-01 23:51 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 ` [Qemu-devel] [PATCH 1/3] " Matthias Brugger
2013-11-01 23:34 ` Matthias Brugger [this message]
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-3-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).