浏览代码

iothread: add polling parameters

Poll mode can be configured with -object iothread,poll-max-ns=NUM.
Polling is disabled with a value of 0 nanoseconds.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20161201192652.9509-7-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Stefan Hajnoczi 8 年之前
父节点
当前提交
0d9d86fb4d
共有 2 个文件被更改,包括 53 次插入0 次删除
  1. 3 0
      include/sysemu/iothread.h
  2. 50 0
      iothread.c

+ 3 - 0
include/sysemu/iothread.h

@@ -28,6 +28,9 @@ typedef struct {
     QemuCond init_done_cond;    /* is thread initialization done? */
     QemuCond init_done_cond;    /* is thread initialization done? */
     bool stopping;
     bool stopping;
     int thread_id;
     int thread_id;
+
+    /* AioContext poll parameters */
+    int64_t poll_max_ns;
 } IOThread;
 } IOThread;
 
 
 #define IOTHREAD(obj) \
 #define IOTHREAD(obj) \

+ 50 - 0
iothread.c

@@ -98,6 +98,15 @@ static void iothread_complete(UserCreatable *obj, Error **errp)
         return;
         return;
     }
     }
 
 
+    aio_context_set_poll_params(iothread->ctx, iothread->poll_max_ns,
+                                &local_error);
+    if (local_error) {
+        error_propagate(errp, local_error);
+        aio_context_unref(iothread->ctx);
+        iothread->ctx = NULL;
+        return;
+    }
+
     qemu_mutex_init(&iothread->init_done_lock);
     qemu_mutex_init(&iothread->init_done_lock);
     qemu_cond_init(&iothread->init_done_cond);
     qemu_cond_init(&iothread->init_done_cond);
 
 
@@ -120,10 +129,51 @@ static void iothread_complete(UserCreatable *obj, Error **errp)
     qemu_mutex_unlock(&iothread->init_done_lock);
     qemu_mutex_unlock(&iothread->init_done_lock);
 }
 }
 
 
+static void iothread_get_poll_max_ns(Object *obj, Visitor *v,
+        const char *name, void *opaque, Error **errp)
+{
+    IOThread *iothread = IOTHREAD(obj);
+
+    visit_type_int64(v, name, &iothread->poll_max_ns, errp);
+}
+
+static void iothread_set_poll_max_ns(Object *obj, Visitor *v,
+        const char *name, void *opaque, Error **errp)
+{
+    IOThread *iothread = IOTHREAD(obj);
+    Error *local_err = NULL;
+    int64_t value;
+
+    visit_type_int64(v, name, &value, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    if (value < 0) {
+        error_setg(&local_err, "poll_max_ns value must be in range "
+                   "[0, %"PRId64"]", INT64_MAX);
+        goto out;
+    }
+
+    iothread->poll_max_ns = value;
+
+    if (iothread->ctx) {
+        aio_context_set_poll_params(iothread->ctx, value, &local_err);
+    }
+
+out:
+    error_propagate(errp, local_err);
+}
+
 static void iothread_class_init(ObjectClass *klass, void *class_data)
 static void iothread_class_init(ObjectClass *klass, void *class_data)
 {
 {
     UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass);
     UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass);
     ucc->complete = iothread_complete;
     ucc->complete = iothread_complete;
+
+    object_class_property_add(klass, "poll-max-ns", "int",
+                              iothread_get_poll_max_ns,
+                              iothread_set_poll_max_ns,
+                              NULL, NULL, &error_abort);
 }
 }
 
 
 static const TypeInfo iothread_info = {
 static const TypeInfo iothread_info = {