From patchwork Thu Sep 14 07:50:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 813729 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=) 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 3xt9pZ0dpHz9sRm for ; Thu, 14 Sep 2017 17:56:38 +1000 (AEST) Received: from localhost ([::1]:46206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP0m-0002x6-4I for incoming@patchwork.ozlabs.org; Thu, 14 Sep 2017 03:56:36 -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) 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 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) 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_Lure?= =?utf-8?q?au?= , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; }; +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 @@ -4043,12 +4051,32 @@ static void sortcmdlist(void) qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); } +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 = g_main_context_new(); + mon_global.mon_loop = 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(); } /* 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); } +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 = NULL; + + g_main_context_unref(mon_global.mon_context); + mon_global.mon_context = 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(); } QemuOptsList qemu_mon_opts = {