From nobody Sun Feb 8 19:59:43 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 150537606976946.45664322437767; Thu, 14 Sep 2017 01:01:09 -0700 (PDT) Received: from localhost ([::1]:46229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP5A-0007kV-Us for importer@patchew.org; Thu, 14 Sep 2017 04:01:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwF-00072W-7w for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwC-0007RF-3T for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwB-0007PF-JJ for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:51 -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 8B1F881DF1; Thu, 14 Sep 2017 07:51:50 +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 B6806619BE; Thu, 14 Sep 2017 07:51:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B1F881DF1 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=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 14 Sep 2017 15:50:30 +0800 Message-Id: <1505375436-28439-10-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.25]); Thu, 14 Sep 2017 07:51:50 +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 09/15] monitor: allow to use IO thread for parsing 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" For each Monitor, add one field "use_io_thr" to show whether it will be using the dedicated monitor IO thread to handle input/output. When set, monitor IO parsing work will be offloaded to dedicated monitor IO thread, rather than the original main loop thread. This only works for QMP. HMP will always be run on main loop thread. Currently we're still keeping use_io_thr to off always. Will turn it on later at some point. Signed-off-by: Peter Xu --- monitor.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 9e9a32e..83f5e87 100644 --- a/monitor.c +++ b/monitor.c @@ -190,6 +190,7 @@ struct Monitor { int flags; int suspend_cnt; bool skip_flush; + bool use_io_thr; =20 QemuMutex out_lock; QString *outbuf; @@ -576,7 +577,8 @@ static void monitor_qapi_event_init(void) =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 -static void monitor_data_init(Monitor *mon, bool skip_flush) +static void monitor_data_init(Monitor *mon, bool skip_flush, + bool use_io_thr) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); @@ -584,6 +586,7 @@ static void monitor_data_init(Monitor *mon, bool skip_f= lush) /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; mon->skip_flush =3D skip_flush; + mon->use_io_thr =3D use_io_thr; } =20 static void monitor_data_destroy(Monitor *mon) @@ -603,7 +606,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; Monitor *old_mon, hmp; =20 - monitor_data_init(&hmp, true); + monitor_data_init(&hmp, true, false); =20 old_mon =3D cur_mon; cur_mon =3D &hmp; @@ -4122,8 +4125,9 @@ void error_vprintf_unless_qmp(const char *fmt, va_lis= t ap) void monitor_init(Chardev *chr, int flags) { Monitor *mon =3D g_malloc(sizeof(*mon)); + GMainContext *context; =20 - monitor_data_init(mon, false); + monitor_data_init(mon, false, false); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; @@ -4135,9 +4139,22 @@ void monitor_init(Chardev *chr, int flags) monitor_read_command(mon, 0); } =20 + if (mon->use_io_thr) { + /* + * When use_io_thr is set, we use the global shared dedicated + * IO thread for this monitor to handle input/output. + */ + context =3D mon_global.mon_context; + /* We should have inited globals before reaching here. */ + assert(context); + } else { + /* The default main loop, which is the main thread */ + context =3D NULL; + } + if (monitor_is_qmp(mon)) { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, - monitor_qmp_event, NULL, mon, NULL, true); + monitor_qmp_event, NULL, mon, context, tr= ue); qemu_chr_fe_set_echo(&mon->chr, true); json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon= ); } else { --=20 2.7.4