From patchwork Fri Sep 21 08:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Bumiller X-Patchwork-Id: 972955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=proxmox.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42GnQB2SdYz9sC7 for ; Fri, 21 Sep 2018 18:51:30 +1000 (AEST) Received: from localhost ([::1]:54557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3H9r-00011Z-MQ for incoming@patchwork.ozlabs.org; Fri, 21 Sep 2018 04:51:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3GoB-0005HX-1V for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:29:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Go7-0003JG-S7 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:29:02 -0400 Received: from proxmox-new.maurer-it.com ([212.186.127.180]:18528) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g3Go7-0003HJ-JG for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:28:59 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A322741A6A; Fri, 21 Sep 2018 10:28:57 +0200 (CEST) From: Wolfgang Bumiller To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 10:28:55 +0200 Message-Id: <20180921082856.1000-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.186.127.180 Subject: [Qemu-devel] [PATCH 1/2] monitor: guard iothread access by mon->use_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: Markus Armbruster , Peter Xu , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" monitor_resume() and monitor_suspend() both want to "kick" the I/O thread if it is there, but in monitor_suspend() lacked the use_io_thread flag condition. This is required when we later only spawn the thread on first use. Signed-off-by: Wolfgang Bumiller Reviewed-by: Eric Blake Reviewed-by: Peter Xu --- monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index 021c11b1bf..4802148c82 100644 --- a/monitor.c +++ b/monitor.c @@ -4380,7 +4380,7 @@ int monitor_suspend(Monitor *mon) atomic_inc(&mon->suspend_cnt); - if (monitor_is_qmp(mon)) { + if (monitor_is_qmp(mon) && mon->use_io_thread) { /* * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. From patchwork Fri Sep 21 08:28:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Bumiller X-Patchwork-Id: 972984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=proxmox.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Gnz636SRz9s4Z for ; Fri, 21 Sep 2018 19:16:34 +1000 (AEST) Received: from localhost ([::1]:54718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HY8-0007RI-01 for incoming@patchwork.ozlabs.org; Fri, 21 Sep 2018 05:16:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3GoB-0005HY-1b for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:29:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Go8-0003JQ-0S for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:29:02 -0400 Received: from proxmox-new.maurer-it.com ([212.186.127.180]:18814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g3Go7-0003HP-Kx for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:28:59 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F3A09416A8; Fri, 21 Sep 2018 10:28:57 +0200 (CEST) From: Wolfgang Bumiller To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 10:28:56 +0200 Message-Id: <20180921082856.1000-2-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180921082856.1000-1-w.bumiller@proxmox.com> References: <20180921082856.1000-1-w.bumiller@proxmox.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.186.127.180 Subject: [Qemu-devel] [PATCH 2/2] monitor: delay monitor iothread creation 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: Markus Armbruster , Peter Xu , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Commit d32749deb615 moved the call to monitor_init_globals() to before os_daemonize(), making it an unsuitable place to spawn the monitor iothread as it won't be inherited over the fork() in os_daemonize(). We now spawn the thread the first time we instantiate a monitor which actually has use_io_thread == true. Instantiation of monitors happens only after os_daemonize(). We still need to create the qmp_dispatcher_bh when not using iothreads, so this now still happens in monitor_init_globals(). Signed-off-by: Wolfgang Bumiller Fixes: d32749deb615 ("monitor: move init global earlier") --- monitor.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/monitor.c b/monitor.c index 4802148c82..e9d44b443b 100644 --- a/monitor.c +++ b/monitor.c @@ -806,9 +806,14 @@ static void monitor_qapi_event_init(void) static void handle_hmp_command(Monitor *mon, const char *cmdline); +static void monitor_iothread_init(void); + static void monitor_data_init(Monitor *mon, bool skip_flush, bool use_io_thread) { + if (use_io_thread && !mon_iothread) { + monitor_iothread_init(); + } memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->mon_lock); qemu_mutex_init(&mon->qmp.qmp_queue_lock); @@ -4551,15 +4556,6 @@ static void monitor_iothread_init(void) mon_iothread = iothread_create("mon_iothread", &error_abort); /* - * The dispatcher BH must run in the main loop thread, since we - * have commands assuming that context. It would be nice to get - * rid of those assumptions. - */ - qmp_dispatcher_bh = aio_bh_new(iohandler_get_aio_context(), - monitor_qmp_bh_dispatcher, - NULL); - - /* * The responder BH must be run in the monitor I/O thread, so that * monitors that are using the I/O thread have their output * written by the I/O thread. @@ -4576,7 +4572,15 @@ void monitor_init_globals(void) sortcmdlist(); qemu_mutex_init(&monitor_lock); qemu_mutex_init(&mon_fdsets_lock); - monitor_iothread_init(); + + /* + * The dispatcher BH must run in the main loop thread, since we + * have commands assuming that context. It would be nice to get + * rid of those assumptions. + */ + qmp_dispatcher_bh = aio_bh_new(iohandler_get_aio_context(), + monitor_qmp_bh_dispatcher, + NULL); } /* These functions just adapt the readline interface in a typesafe way. We @@ -4717,7 +4721,9 @@ void monitor_cleanup(void) * we need to unregister from chardev below in * monitor_data_destroy(), and chardev is not thread-safe yet */ - iothread_stop(mon_iothread); + if (mon_iothread) { + iothread_stop(mon_iothread); + } /* * Flush all response queues. Note that even after this flush, @@ -4738,11 +4744,13 @@ void monitor_cleanup(void) /* QEMUBHs needs to be deleted before destroying the I/O thread */ qemu_bh_delete(qmp_dispatcher_bh); qmp_dispatcher_bh = NULL; - qemu_bh_delete(qmp_respond_bh); - qmp_respond_bh = NULL; + if (mon_iothread) { + qemu_bh_delete(qmp_respond_bh); + qmp_respond_bh = NULL; - iothread_destroy(mon_iothread); - mon_iothread = NULL; + iothread_destroy(mon_iothread); + mon_iothread = NULL; + } } QemuOptsList qemu_mon_opts = {