[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC 1/5] aio: Wrap poll parameters into AioContextPo
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH RFC 1/5] aio: Wrap poll parameters into AioContextPollParams |
Date: |
Mon, 10 Jul 2017 15:20:23 +0800 |
The same set of parameters will also be wanted by the coming iothread
group object, make a structure to slightly reduce the code duplication.
Signed-off-by: Fam Zheng <address@hidden>
---
include/block/aio.h | 18 ++++++++++++------
include/sysemu/iothread.h | 5 +----
iothread.c | 24 +++++++++---------------
util/aio-posix.c | 10 +++++-----
util/aio-win32.c | 4 ++--
5 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/include/block/aio.h b/include/block/aio.h
index e9aeeae..fcf1faf 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -551,17 +551,23 @@ static inline bool aio_context_in_iothread(AioContext
*ctx)
*/
void aio_context_setup(AioContext *ctx);
+typedef struct {
+ /* how long to busy poll for, in nanoseconds. 0 means don't poll */
+ int64_t max_ns;
+ /* polling time growth factor */
+ int64_t grow;
+ /* polling time shrink factor */
+ int64_t shrink;
+} AioContextPollParams;
+
/**
* aio_context_set_poll_params:
* @ctx: the aio context
- * @max_ns: how long to busy poll for, in nanoseconds
- * @grow: polling time growth factor
- * @shrink: polling time shrink factor
+ * @params: the new params to update to
*
- * Poll mode can be disabled by setting poll_max_ns to 0.
+ * Poll mode can be disabled by setting params.max_ns to 0.
*/
-void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
- int64_t grow, int64_t shrink,
+void aio_context_set_poll_params(AioContext *ctx, AioContextPollParams params,
Error **errp);
#endif
diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h
index e6da1a4..eecfc19 100644
--- a/include/sysemu/iothread.h
+++ b/include/sysemu/iothread.h
@@ -29,10 +29,7 @@ typedef struct {
bool stopping;
int thread_id;
- /* AioContext poll parameters */
- int64_t poll_max_ns;
- int64_t poll_grow;
- int64_t poll_shrink;
+ AioContextPollParams poll_params;
} IOThread;
#define IOTHREAD(obj) \
diff --git a/iothread.c b/iothread.c
index beeb870..f5a01bb 100644
--- a/iothread.c
+++ b/iothread.c
@@ -81,7 +81,7 @@ static void iothread_instance_init(Object *obj)
{
IOThread *iothread = IOTHREAD(obj);
- iothread->poll_max_ns = IOTHREAD_POLL_MAX_NS_DEFAULT;
+ iothread->poll_params.max_ns = IOTHREAD_POLL_MAX_NS_DEFAULT;
}
static void iothread_instance_finalize(Object *obj)
@@ -111,10 +111,7 @@ static void iothread_complete(UserCreatable *obj, Error
**errp)
return;
}
- aio_context_set_poll_params(iothread->ctx,
- iothread->poll_max_ns,
- iothread->poll_grow,
- iothread->poll_shrink,
+ aio_context_set_poll_params(iothread->ctx, iothread->poll_params,
&local_error);
if (local_error) {
error_propagate(errp, local_error);
@@ -151,13 +148,13 @@ typedef struct {
} PollParamInfo;
static PollParamInfo poll_max_ns_info = {
- "poll-max-ns", offsetof(IOThread, poll_max_ns),
+ "poll-max-ns", offsetof(IOThread, poll_params.max_ns),
};
static PollParamInfo poll_grow_info = {
- "poll-grow", offsetof(IOThread, poll_grow),
+ "poll-grow", offsetof(IOThread, poll_params.grow),
};
static PollParamInfo poll_shrink_info = {
- "poll-shrink", offsetof(IOThread, poll_shrink),
+ "poll-shrink", offsetof(IOThread, poll_params.shrink),
};
static void iothread_get_poll_param(Object *obj, Visitor *v,
@@ -193,10 +190,7 @@ static void iothread_set_poll_param(Object *obj, Visitor
*v,
*field = value;
if (iothread->ctx) {
- aio_context_set_poll_params(iothread->ctx,
- iothread->poll_max_ns,
- iothread->poll_grow,
- iothread->poll_shrink,
+ aio_context_set_poll_params(iothread->ctx, iothread->poll_params,
&local_err);
}
@@ -268,9 +262,9 @@ static int query_one_iothread(Object *object, void *opaque)
info = g_new0(IOThreadInfo, 1);
info->id = iothread_get_id(iothread);
info->thread_id = iothread->thread_id;
- info->poll_max_ns = iothread->poll_max_ns;
- info->poll_grow = iothread->poll_grow;
- info->poll_shrink = iothread->poll_shrink;
+ info->poll_max_ns = iothread->poll_params.max_ns;
+ info->poll_grow = iothread->poll_params.grow;
+ info->poll_shrink = iothread->poll_params.shrink;
elem = g_new0(IOThreadInfoList, 1);
elem->value = info;
diff --git a/util/aio-posix.c b/util/aio-posix.c
index 2d51239..1db8f3c 100644
--- a/util/aio-posix.c
+++ b/util/aio-posix.c
@@ -713,16 +713,16 @@ void aio_context_setup(AioContext *ctx)
#endif
}
-void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
- int64_t grow, int64_t shrink, Error **errp)
+void aio_context_set_poll_params(AioContext *ctx, AioContextPollParams params,
+ Error **errp)
{
/* No thread synchronization here, it doesn't matter if an incorrect value
* is used once.
*/
- ctx->poll_max_ns = max_ns;
+ ctx->poll_max_ns = params.max_ns;
ctx->poll_ns = 0;
- ctx->poll_grow = grow;
- ctx->poll_shrink = shrink;
+ ctx->poll_grow = params.grow;
+ ctx->poll_shrink = params.shrink;
aio_notify(ctx);
}
diff --git a/util/aio-win32.c b/util/aio-win32.c
index bca496a..d8a1b20 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -400,8 +400,8 @@ void aio_context_setup(AioContext *ctx)
{
}
-void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,
- int64_t grow, int64_t shrink, Error **errp)
+void aio_context_set_poll_params(AioContext *ctx, AioContextPollParams params,
+ Error **errp)
{
error_setg(errp, "AioContext polling is not implemented on Windows");
}
--
2.9.4
- [Qemu-devel] [PATCH RFC 0/5] Introduce "-object iothread-group", Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 1/5] aio: Wrap poll parameters into AioContextPollParams,
Fam Zheng <=
- [Qemu-devel] [PATCH RFC 2/5] iothread: Don't error on windows, Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 3/5] iothread: Extract iothread_start, Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 4/5] Introduce iothread-group, Fam Zheng, 2017/07/10
- [Qemu-devel] [PATCH RFC 5/5] virtio-blk: Add iothread-group property, Fam Zheng, 2017/07/10
- Re: [Qemu-devel] [PATCH RFC 0/5] Introduce "-object iothread-group", Fam Zheng, 2017/07/10