From patchwork Thu Dec 1 19:26:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 701647 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tV6sL4wNJz9t1T for ; Fri, 2 Dec 2016 06:33:42 +1100 (AEDT) Received: from localhost ([::1]:58501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCX6x-0001H8-UZ for incoming@patchwork.ozlabs.org; Thu, 01 Dec 2016 14:33:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCX0g-0004GM-Kv for qemu-devel@nongnu.org; Thu, 01 Dec 2016 14:27:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCX0f-0002dV-KQ for qemu-devel@nongnu.org; Thu, 01 Dec 2016 14:27:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49682) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCX0f-0002cy-Df for qemu-devel@nongnu.org; Thu, 01 Dec 2016 14:27:09 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACFA4CA639; Thu, 1 Dec 2016 19:27:08 +0000 (UTC) Received: from localhost (ovpn-112-59.ams2.redhat.com [10.36.112.59]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB1JR7Ia003551; Thu, 1 Dec 2016 14:27:08 -0500 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Thu, 1 Dec 2016 19:26:45 +0000 Message-Id: <20161201192652.9509-7-stefanha@redhat.com> In-Reply-To: <20161201192652.9509-1-stefanha@redhat.com> References: <20161201192652.9509-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 01 Dec 2016 19:27:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 06/13] iothread: add polling parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, Karl Rister , Fam Zheng , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- include/sysemu/iothread.h | 3 +++ iothread.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index 68ac2de..314e163 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -28,6 +28,9 @@ typedef struct { QemuCond init_done_cond; /* is thread initialization done? */ bool stopping; int thread_id; + + /* AioContext poll parameters */ + int64_t poll_max_ns; } IOThread; #define IOTHREAD(obj) \ diff --git a/iothread.c b/iothread.c index bd70344..8dfd10d 100644 --- a/iothread.c +++ b/iothread.c @@ -98,6 +98,15 @@ static void iothread_complete(UserCreatable *obj, Error **errp) 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_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); } +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) { UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); 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 = {