From nobody Mon Feb 9 00:43:04 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 1505375864471168.4232038136655; Thu, 14 Sep 2017 00:57:44 -0700 (PDT) Received: from localhost ([::1]:46210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP1q-0004BL-Kw for importer@patchew.org; Thu, 14 Sep 2017 03:57:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOw5-0006n8-Mw for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOw2-0007Fe-Ih for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOw2-0007F0-AG for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:42 -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 448EF155E2; Thu, 14 Sep 2017 07:51:41 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85AC3619BE; Thu, 14 Sep 2017 07:51:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 448EF155E2 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 14 Sep 2017 15:50:29 +0800 Message-Id: <1505375436-28439-9-git-send-email-peterx@redhat.com> In-Reply-To: <1505375436-28439-1-git-send-email-peterx@redhat.com> References: <1505375436-28439-1-git-send-email-peterx@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.29]); Thu, 14 Sep 2017 07:51:41 +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] [RFC 08/15] monitor: create IO thread 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: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , "Dr . David Alan Gilbert" 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" Create one IO thread for the monitors, prepared to handle all the input/output IOs. Only adding the thread, loop and context, but doing nothing else yet. Signed-off-by: Peter Xu --- monitor.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/monitor.c b/monitor.c index 7bd2e90..9e9a32e 100644 --- a/monitor.c +++ b/monitor.c @@ -208,6 +208,14 @@ struct Monitor { QLIST_ENTRY(Monitor) entry; }; =20 +struct MonitorGlobal { + QemuThread mon_io_thread; + GMainContext *mon_context; + GMainLoop *mon_loop; +}; + +static struct MonitorGlobal mon_global; + /* QMP checker flags */ #define QMP_ACCEPT_UNKNOWNS 1 =20 @@ -4043,12 +4051,32 @@ static void sortcmdlist(void) qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); } =20 +static void *monitor_io_thread(void *data) +{ + rcu_register_thread(); + + g_main_loop_run(mon_global.mon_loop); + + rcu_unregister_thread(); + + return NULL; +} + +static void monitor_io_thread_init(void) +{ + mon_global.mon_context =3D g_main_context_new(); + mon_global.mon_loop =3D g_main_loop_new(mon_global.mon_context, TRUE); + qemu_thread_create(&mon_global.mon_io_thread, "mon-io-thr", + monitor_io_thread, NULL, QEMU_THREAD_JOINABLE); +} + void monitor_init_globals(void) { monitor_init_qmp_commands(); monitor_qapi_event_init(); sortcmdlist(); qemu_mutex_init(&monitor_lock); + monitor_io_thread_init(); } =20 /* These functions just adapt the readline interface in a typesafe way. We @@ -4122,6 +4150,25 @@ void monitor_init(Chardev *chr, int flags) qemu_mutex_unlock(&monitor_lock); } =20 +static void monitor_io_thread_destroy(void) +{ + /* Notify the monitor IO thread to quit. */ + g_main_loop_quit(mon_global.mon_loop); + /* + * Make sure the context will get the quit message since it's in + * another thread. Without this, it may not be able to respond to + * the quit message immediately. + */ + g_main_context_wakeup(mon_global.mon_context); + qemu_thread_join(&mon_global.mon_io_thread); + + g_main_loop_unref(mon_global.mon_loop); + mon_global.mon_loop =3D NULL; + + g_main_context_unref(mon_global.mon_context); + mon_global.mon_context =3D NULL; +} + void monitor_cleanup(void) { Monitor *mon, *next; @@ -4133,6 +4180,8 @@ void monitor_cleanup(void) g_free(mon); } qemu_mutex_unlock(&monitor_lock); + + monitor_io_thread_destroy(); } =20 QemuOptsList qemu_mon_opts =3D { --=20 2.7.4