From nobody Mon Feb 9 02:33:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499671353510245.80362256248884; Mon, 10 Jul 2017 00:22:33 -0700 (PDT) Received: from localhost ([::1]:38959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT1b-0001Mm-4F for importer@patchew.org; Mon, 10 Jul 2017 03:22:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUSzo-0000Kz-Tl for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUSzn-0000jX-36 for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUSzm-0000hu-PJ for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A661B81227 for ; Mon, 10 Jul 2017 07:20:37 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BB1A7D571; Mon, 10 Jul 2017 07:20:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A661B81227 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A661B81227 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 15:20:23 +0800 Message-Id: <20170710072027.7948-2-famz@redhat.com> In-Reply-To: <20170710072027.7948-1-famz@redhat.com> References: <20170710072027.7948-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Jul 2017 07:20:37 +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 RFC 1/5] aio: Wrap poll parameters into AioContextPollParams 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: pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Stefan Hajnoczi --- 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); =20 +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 par= ams, Error **errp); =20 #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; =20 - /* AioContext poll parameters */ - int64_t poll_max_ns; - int64_t poll_grow; - int64_t poll_shrink; + AioContextPollParams poll_params; } IOThread; =20 #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 =3D IOTHREAD(obj); =20 - iothread->poll_max_ns =3D IOTHREAD_POLL_MAX_NS_DEFAULT; + iothread->poll_params.max_ns =3D IOTHREAD_POLL_MAX_NS_DEFAULT; } =20 static void iothread_instance_finalize(Object *obj) @@ -111,10 +111,7 @@ static void iothread_complete(UserCreatable *obj, Erro= r **errp) return; } =20 - 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; =20 static PollParamInfo poll_max_ns_info =3D { - "poll-max-ns", offsetof(IOThread, poll_max_ns), + "poll-max-ns", offsetof(IOThread, poll_params.max_ns), }; static PollParamInfo poll_grow_info =3D { - "poll-grow", offsetof(IOThread, poll_grow), + "poll-grow", offsetof(IOThread, poll_params.grow), }; static PollParamInfo poll_shrink_info =3D { - "poll-shrink", offsetof(IOThread, poll_shrink), + "poll-shrink", offsetof(IOThread, poll_params.shrink), }; =20 static void iothread_get_poll_param(Object *obj, Visitor *v, @@ -193,10 +190,7 @@ static void iothread_set_poll_param(Object *obj, Visit= or *v, *field =3D value; =20 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); } =20 @@ -268,9 +262,9 @@ static int query_one_iothread(Object *object, void *opa= que) info =3D g_new0(IOThreadInfo, 1); info->id =3D iothread_get_id(iothread); info->thread_id =3D iothread->thread_id; - info->poll_max_ns =3D iothread->poll_max_ns; - info->poll_grow =3D iothread->poll_grow; - info->poll_shrink =3D iothread->poll_shrink; + info->poll_max_ns =3D iothread->poll_params.max_ns; + info->poll_grow =3D iothread->poll_params.grow; + info->poll_shrink =3D iothread->poll_params.shrink; =20 elem =3D g_new0(IOThreadInfoList, 1); elem->value =3D 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 } =20 -void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, - int64_t grow, int64_t shrink, Error **err= p) +void aio_context_set_poll_params(AioContext *ctx, AioContextPollParams par= ams, + Error **errp) { /* No thread synchronization here, it doesn't matter if an incorrect v= alue * is used once. */ - ctx->poll_max_ns =3D max_ns; + ctx->poll_max_ns =3D params.max_ns; ctx->poll_ns =3D 0; - ctx->poll_grow =3D grow; - ctx->poll_shrink =3D shrink; + ctx->poll_grow =3D params.grow; + ctx->poll_shrink =3D params.shrink; =20 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) { } =20 -void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, - int64_t grow, int64_t shrink, Error **err= p) +void aio_context_set_poll_params(AioContext *ctx, AioContextPollParams par= ams, + Error **errp) { error_setg(errp, "AioContext polling is not implemented on Windows"); } --=20 2.9.4 From nobody Mon Feb 9 02:33:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499671469813875.5545610110876; Mon, 10 Jul 2017 00:24:29 -0700 (PDT) Received: from localhost ([::1]:38966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT3U-0002xx-I0 for importer@patchew.org; Mon, 10 Jul 2017 03:24:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUSzq-0000LB-Sj for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUSzp-0000mh-Ib for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUSzp-0000lJ-BG for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AC25C057FAB for ; Mon, 10 Jul 2017 07:20:40 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32CBF77DC4; Mon, 10 Jul 2017 07:20:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4AC25C057FAB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4AC25C057FAB From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 15:20:24 +0800 Message-Id: <20170710072027.7948-3-famz@redhat.com> In-Reply-To: <20170710072027.7948-1-famz@redhat.com> References: <20170710072027.7948-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 10 Jul 2017 07:20:40 +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 RFC 2/5] iothread: Don't error on windows 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: pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" aio_context_set_poll_params is called unconditionally from iothread initialization code and the contract is that if max_ns =3D=3D 0 polling is disabled, or otherwise windows reports and error. The current default being non-zero will always make win32 to exit on an "-object iothread" option, which is not nice. Default to zero on windows and keep going. (While we are at it, move the definition to the header, because it will be shared with iothread-group.) Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- include/sysemu/iothread.h | 12 ++++++++++++ iothread.c | 6 ------ util/aio-win32.c | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index eecfc19..37f033b 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -39,4 +39,16 @@ char *iothread_get_id(IOThread *iothread); AioContext *iothread_get_aio_context(IOThread *iothread); void iothread_stop_all(void); =20 +#ifndef _WIN32 +/* Benchmark results from 2016 on NVMe SSD drives show max polling times a= round + * 16-32 microseconds yield IOPS improvements for both iodepth=3D1 and iod= epth=3D32 + * workloads. + */ +#define IOTHREAD_POLL_MAX_NS_DEFAULT 32768ULL +#else +/* Our aio implementation on Windows doesn't support polling, don't enable= it + * by default. */ +#define IOTHREAD_POLL_MAX_NS_DEFAULT 0 +#endif + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index f5a01bb..ce56724 100644 --- a/iothread.c +++ b/iothread.c @@ -30,12 +30,6 @@ typedef ObjectClass IOThreadClass; #define IOTHREAD_CLASS(klass) \ OBJECT_CLASS_CHECK(IOThreadClass, klass, TYPE_IOTHREAD) =20 -/* Benchmark results from 2016 on NVMe SSD drives show max polling times a= round - * 16-32 microseconds yield IOPS improvements for both iodepth=3D1 and iod= epth=3D32 - * workloads. - */ -#define IOTHREAD_POLL_MAX_NS_DEFAULT 32768ULL - static __thread IOThread *my_iothread; =20 AioContext *qemu_get_current_aio_context(void) diff --git a/util/aio-win32.c b/util/aio-win32.c index d8a1b20..3d2de11 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -403,5 +403,7 @@ void aio_context_setup(AioContext *ctx) void aio_context_set_poll_params(AioContext *ctx, AioContextPollParams par= ams, Error **errp) { - error_setg(errp, "AioContext polling is not implemented on Windows"); + if (params.max_ns) { + error_setg(errp, "AioContext polling is not implemented on Windows= "); + } } --=20 2.9.4 From nobody Mon Feb 9 02:33:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499671484720845.6594177558562; Mon, 10 Jul 2017 00:24:44 -0700 (PDT) Received: from localhost ([::1]:38967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT3j-00038k-8Y for importer@patchew.org; Mon, 10 Jul 2017 03:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUSzw-0000P9-79 for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUSzt-0000rs-1c for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUSzs-0000qN-NS for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A98B44DD49 for ; Mon, 10 Jul 2017 07:20:43 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1A8777DC4; Mon, 10 Jul 2017 07:20:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A98B44DD49 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A98B44DD49 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 15:20:25 +0800 Message-Id: <20170710072027.7948-4-famz@redhat.com> In-Reply-To: <20170710072027.7948-1-famz@redhat.com> References: <20170710072027.7948-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jul 2017 07:20:43 +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 RFC 3/5] iothread: Extract iothread_start 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: pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is the "create and start the thread" part of iothread spawning. Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- include/sysemu/iothread.h | 1 + iothread.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index 37f033b..a3a03e8 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -36,6 +36,7 @@ typedef struct { OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD) =20 char *iothread_get_id(IOThread *iothread); +void iothread_start(IOThread *iothread, const char *thread_name, Error **e= rrp); AioContext *iothread_get_aio_context(IOThread *iothread); void iothread_stop_all(void); =20 diff --git a/iothread.c b/iothread.c index ce56724..8d703db 100644 --- a/iothread.c +++ b/iothread.c @@ -76,6 +76,10 @@ static void iothread_instance_init(Object *obj) IOThread *iothread =3D IOTHREAD(obj); =20 iothread->poll_params.max_ns =3D IOTHREAD_POLL_MAX_NS_DEFAULT; + iothread->stopping =3D false; + iothread->thread_id =3D -1; + qemu_mutex_init(&iothread->init_done_lock); + qemu_cond_init(&iothread->init_done_cond); } =20 static void iothread_instance_finalize(Object *obj) @@ -91,14 +95,26 @@ static void iothread_instance_finalize(Object *obj) aio_context_unref(iothread->ctx); } =20 +void iothread_start(IOThread *iothread, const char *thread_name, Error **e= rrp) +{ + qemu_thread_create(&iothread->thread, thread_name, iothread_run, + iothread, QEMU_THREAD_JOINABLE); + + /* Wait for initialization to complete */ + qemu_mutex_lock(&iothread->init_done_lock); + while (iothread->thread_id =3D=3D -1) { + qemu_cond_wait(&iothread->init_done_cond, + &iothread->init_done_lock); + } + qemu_mutex_unlock(&iothread->init_done_lock); +} + static void iothread_complete(UserCreatable *obj, Error **errp) { Error *local_error =3D NULL; IOThread *iothread =3D IOTHREAD(obj); char *name, *thread_name; =20 - iothread->stopping =3D false; - iothread->thread_id =3D -1; iothread->ctx =3D aio_context_new(&local_error); if (!iothread->ctx) { error_propagate(errp, local_error); @@ -114,26 +130,15 @@ static void iothread_complete(UserCreatable *obj, Err= or **errp) return; } =20 - qemu_mutex_init(&iothread->init_done_lock); - qemu_cond_init(&iothread->init_done_cond); =20 /* This assumes we are called from a thread with useful CPU affinity f= or us * to inherit. */ name =3D object_get_canonical_path_component(OBJECT(obj)); thread_name =3D g_strdup_printf("IO %s", name); - qemu_thread_create(&iothread->thread, thread_name, iothread_run, - iothread, QEMU_THREAD_JOINABLE); + iothread_start(iothread, thread_name, errp); g_free(thread_name); g_free(name); - - /* Wait for initialization to complete */ - qemu_mutex_lock(&iothread->init_done_lock); - while (iothread->thread_id =3D=3D -1) { - qemu_cond_wait(&iothread->init_done_cond, - &iothread->init_done_lock); - } - qemu_mutex_unlock(&iothread->init_done_lock); } =20 typedef struct { --=20 2.9.4 From nobody Mon Feb 9 02:33:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499671432732119.16968795349919; Mon, 10 Jul 2017 00:23:52 -0700 (PDT) Received: from localhost ([::1]:38964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT2t-0002Ia-2x for importer@patchew.org; Mon, 10 Jul 2017 03:23:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUSzx-0000Pw-4G for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUSzv-0000ws-NI for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41122) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUSzv-0000uU-Cj for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54BF781233 for ; Mon, 10 Jul 2017 07:20:46 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C5C67D5B6; Mon, 10 Jul 2017 07:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 54BF781233 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 54BF781233 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 15:20:26 +0800 Message-Id: <20170710072027.7948-5-famz@redhat.com> In-Reply-To: <20170710072027.7948-1-famz@redhat.com> References: <20170710072027.7948-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Jul 2017 07:20:46 +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 RFC 4/5] Introduce iothread-group 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: pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- Makefile.objs | 2 +- include/sysemu/iothread.h | 17 ++++ iothread-group.c | 210 ++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 iothread-group.c diff --git a/Makefile.objs b/Makefile.objs index b2e6322..b7ee479 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -40,7 +40,7 @@ io-obj-y =3D io/ =20 ifeq ($(CONFIG_SOFTMMU),y) common-obj-y =3D blockdev.o blockdev-nbd.o block/ -common-obj-y +=3D iothread.o +common-obj-y +=3D iothread.o iothread-group.o common-obj-y +=3D net/ common-obj-y +=3D qdev-monitor.o device-hotplug.o common-obj-$(CONFIG_WIN32) +=3D os-win32.o diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index a3a03e8..0cb28c0 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -32,12 +32,29 @@ typedef struct { AioContextPollParams poll_params; } IOThread; =20 +#define TYPE_IOTHREAD_GROUP "iothread-group" + +typedef struct { + Object parent_obj; + + int running_threads; + AioContext *ctx; + AioContextPollParams poll_params; + /* Number of iothreads */ + int64_t size; + IOThread **iothreads; +} IOThreadGroup; + #define IOTHREAD(obj) \ OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD) =20 +#define IOTHREAD_GROUP(obj) \ + OBJECT_CHECK(IOThreadGroup, obj, TYPE_IOTHREAD_GROUP) + char *iothread_get_id(IOThread *iothread); void iothread_start(IOThread *iothread, const char *thread_name, Error **e= rrp); AioContext *iothread_get_aio_context(IOThread *iothread); +AioContext *iothread_group_get_aio_context(IOThreadGroup *group); void iothread_stop_all(void); =20 #ifndef _WIN32 diff --git a/iothread-group.c b/iothread-group.c new file mode 100644 index 0000000..163ca2b --- /dev/null +++ b/iothread-group.c @@ -0,0 +1,210 @@ +/* + * Event loop thread group + * + * Copyright Red Hat Inc., 2013, 2017 + * + * Authors: + * Stefan Hajnoczi + * Fam Zheng + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "qom/object_interfaces.h" +#include "qemu/module.h" +#include "block/aio.h" +#include "block/block.h" +#include "sysemu/iothread.h" +#include "qmp-commands.h" +#include "qemu/error-report.h" +#include "qemu/rcu.h" +#include "qemu/main-loop.h" + +static int iothread_group_stop(Object *object, void *opaque) +{ + /* XXX: stop each iothread */ + return 0; +} + +static void iothread_group_instance_init(Object *obj) +{ + IOThreadGroup *group =3D IOTHREAD_GROUP(obj); + + group->poll_params.max_ns =3D IOTHREAD_POLL_MAX_NS_DEFAULT; + group->size =3D 1; +} + +static void iothread_group_instance_finalize(Object *obj) +{ + IOThreadGroup *group =3D IOTHREAD_GROUP(obj); + + iothread_group_stop(obj, NULL); + if (!group->ctx) { + return; + } + aio_context_unref(group->ctx); +} + +static void iothread_group_complete(UserCreatable *obj, Error **errp) +{ + Error *local_err =3D NULL; + IOThreadGroup *group =3D IOTHREAD_GROUP(obj); + char *name, *thread_name; + int i; + + group->ctx =3D aio_context_new(&local_err); + if (!group->ctx) { + error_propagate(errp, local_err); + return; + } + + aio_context_set_poll_params(group->ctx, group->poll_params, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + aio_context_unref(group->ctx); + group->ctx =3D NULL; + return; + } + + /* This assumes we are called from a thread with useful CPU affinity f= or us + * to inherit. + */ + name =3D object_get_canonical_path_component(OBJECT(obj)); + group->iothreads =3D g_new0(IOThread *, group->size); + for (i =3D 0; i < group->size; ++i) { + IOThread *iothread =3D (IOThread *)object_new(TYPE_IOTHREAD); + + /* We've already set up the shared aio context so this should do + * nothing, but better be consistent. */ + iothread->poll_params =3D group->poll_params; + iothread->ctx =3D group->ctx; + + thread_name =3D g_strdup_printf("IO %s[%d]", name, i); + iothread_start(iothread, thread_name, &local_err); + g_free(thread_name); + if (local_err) { + object_unref(OBJECT(iothread)); + break; + } + group->iothreads[i] =3D iothread; + } + g_free(name); + if (local_err) { + error_propagate(errp, local_err); + } +} + +typedef struct { + const char *name; + ptrdiff_t offset; /* field's byte offset in IOThreadGroup struct */ +} PropInfo; + +static PropInfo size_info =3D { + "size", offsetof(IOThreadGroup, size), +}; +static PropInfo poll_max_ns_info =3D { + "poll-max-ns", offsetof(IOThreadGroup, poll_params.max_ns), +}; +static PropInfo poll_grow_info =3D { + "poll-grow", offsetof(IOThreadGroup, poll_params.grow), +}; +static PropInfo poll_shrink_info =3D { + "poll-shrink", offsetof(IOThreadGroup, poll_params.shrink), +}; + +static void iothread_group_get_prop(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + IOThreadGroup *group =3D IOTHREAD_GROUP(obj); + PropInfo *info =3D opaque; + int64_t *field =3D (void *)group + info->offset; + + visit_type_int64(v, name, field, errp); +} + +static void iothread_group_set_prop(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + IOThreadGroup *group =3D IOTHREAD_GROUP(obj); + PropInfo *info =3D opaque; + int64_t *field =3D (void *)group + info->offset; + Error *local_err =3D NULL; + int64_t value; + + visit_type_int64(v, name, &value, &local_err); + if (local_err) { + goto out; + } + + if (value < 0) { + error_setg(&local_err, "%s value must be in range [0, %"PRId64"]", + info->name, INT64_MAX); + goto out; + } + + *field =3D value; + + if (group->ctx) { + aio_context_set_poll_params(group->ctx, + group->poll_params, + &local_err); + } + +out: + error_propagate(errp, local_err); +} + +static void iothread_group_class_init(ObjectClass *klass, void *class_data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); + ucc->complete =3D iothread_group_complete; + + object_class_property_add(klass, "size", "int", + iothread_group_get_prop, + iothread_group_set_prop, + NULL, &size_info, &error_abort); + object_class_property_add(klass, "poll-max-ns", "int", + iothread_group_get_prop, + iothread_group_set_prop, + NULL, &poll_max_ns_info, &error_abort); + object_class_property_add(klass, "poll-grow", "int", + iothread_group_get_prop, + iothread_group_set_prop, + NULL, &poll_grow_info, &error_abort); + object_class_property_add(klass, "poll-shrink", "int", + iothread_group_get_prop, + iothread_group_set_prop, + NULL, &poll_shrink_info, &error_abort); +} + +static const TypeInfo iothread_group_info =3D { + .name =3D TYPE_IOTHREAD_GROUP, + .parent =3D TYPE_OBJECT, + .class_init =3D iothread_group_class_init, + .instance_size =3D sizeof(IOThreadGroup), + .instance_init =3D iothread_group_instance_init, + .instance_finalize =3D iothread_group_instance_finalize, + .interfaces =3D (InterfaceInfo[]) { + {TYPE_USER_CREATABLE}, + {} + }, +}; + +static void iothread_group_register_types(void) +{ + type_register_static(&iothread_group_info); +} + +type_init(iothread_group_register_types) + +AioContext *iothread_group_get_aio_context(IOThreadGroup *group) +{ + return group->ctx; +} --=20 2.9.4 From nobody Mon Feb 9 02:33:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499671547701531.8624572893714; Mon, 10 Jul 2017 00:25:47 -0700 (PDT) Received: from localhost ([::1]:38984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT4k-000420-HR for importer@patchew.org; Mon, 10 Jul 2017 03:25:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT05-0000Uo-5V for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUT02-00010r-0z for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50772) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUT01-00010f-NF for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:53 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8C50C04B32C for ; Mon, 10 Jul 2017 07:20:52 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA9347D571; Mon, 10 Jul 2017 07:20:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A8C50C04B32C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A8C50C04B32C From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 15:20:27 +0800 Message-Id: <20170710072027.7948-6-famz@redhat.com> In-Reply-To: <20170710072027.7948-1-famz@redhat.com> References: <20170710072027.7948-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 10 Jul 2017 07:20:52 +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 RFC 5/5] virtio-blk: Add iothread-group property 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: pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do I/O on the IOThreadGroup's aio context. This is mutually exclusive to iothread property. Signed-off-by: Fam Zheng --- hw/block/dataplane/virtio-blk.c | 18 +++++++++++------- hw/block/virtio-blk.c | 6 ++++++ include/hw/virtio/virtio-blk.h | 2 ++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 6fdc6f6..4b76f8b 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -40,7 +40,6 @@ struct VirtIOBlockDataPlane { * (because you don't own the file descriptor or handle; you just * use it). */ - IOThread *iothread; AioContext *ctx; }; =20 @@ -86,7 +85,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, Vir= tIOBlkConf *conf, =20 *dataplane =3D NULL; =20 - if (conf->iothread) { + if (conf->iothread || conf->iothread_group) { if (!k->set_guest_notifiers || !k->ioeventfd_assign) { error_setg(errp, "device is incompatible with iothread " @@ -116,9 +115,11 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, = VirtIOBlkConf *conf, s->conf =3D conf; =20 if (conf->iothread) { - s->iothread =3D IOTHREAD(conf->iothread); - object_ref(OBJECT(s->iothread)); - s->ctx =3D iothread_get_aio_context(s->iothread); + object_ref(conf->iothread); + s->ctx =3D iothread_get_aio_context(IOTHREAD(conf->iothread)); + } else if (conf->iothread_group) { + object_ref(conf->iothread_group); + s->ctx =3D iothread_group_get_aio_context(IOTHREAD_GROUP(conf->iot= hread_group)); } else { s->ctx =3D qemu_get_aio_context(); } @@ -141,8 +142,11 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlan= e *s) assert(!vblk->dataplane_started); g_free(s->batch_notify_vqs); qemu_bh_delete(s->bh); - if (s->iothread) { - object_unref(OBJECT(s->iothread)); + if (s->conf->iothread) { + object_unref(s->conf->iothread); + } + if (s->conf->iothread_group) { + object_unref(s->conf->iothread_group); } g_free(s); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8146306..cfd847b 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -918,6 +918,10 @@ static void virtio_blk_device_realize(DeviceState *dev= , Error **errp) error_setg(errp, "drive property not set"); return; } + if (conf->iothread && conf->iothread_group) { + error_setg(errp, "iothread and iothread-group cannot be used toget= her"); + return; + } if (!blk_is_inserted(conf->conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); return; @@ -1011,6 +1015,8 @@ static Property virtio_blk_properties[] =3D { true), DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD= ), + DEFINE_PROP_LINK("iothread-group", VirtIOBlock, conf.iothread_group, + TYPE_IOTHREAD_GROUP), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 2452074..16e72e0 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -35,6 +35,8 @@ struct VirtIOBlkConf BlockConf conf; /* IOThread pointer to be filled by link property */ Object *iothread; + /* IOThreadGroup pointer to be filled by link property */ + Object *iothread_group; char *serial; uint32_t scsi; uint32_t config_wce; --=20 2.9.4