From nobody Sat Apr 27 22:48:51 2024 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 1503302066384373.76936433221874; Mon, 21 Aug 2017 00:54:26 -0700 (PDT) Received: from localhost ([::1]:51558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhXV-0007lG-55 for importer@patchew.org; Mon, 21 Aug 2017 03:54:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhWY-0007Dv-A5 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:53:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djhWQ-0001Oa-3f for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:53:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djhWP-0001OH-TK for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:53:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21BD62027C; Mon, 21 Aug 2017 07:44:32 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56D3D5D6A6; Mon, 21 Aug 2017 07:44:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 21BD62027C 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: Mon, 21 Aug 2017 15:44:19 +0800 Message-Id: <1503301464-27886-2-git-send-email-peterx@redhat.com> In-Reply-To: <1503301464-27886-1-git-send-email-peterx@redhat.com> References: <1503301464-27886-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 21 Aug 2017 07:44:32 +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 1/6] monitor: move skip_flush into monitor_data_init 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 , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , 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" It's part of the data init. Collect it. Signed-off-by: Peter Xu --- monitor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index e0f8801..7c90df7 100644 --- a/monitor.c +++ b/monitor.c @@ -568,13 +568,14 @@ 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) +static void monitor_data_init(Monitor *mon, bool skip_flush) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); mon->outbuf =3D qstring_new(); /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; + mon->skip_flush =3D skip_flush; } =20 static void monitor_data_destroy(Monitor *mon) @@ -594,8 +595,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); - hmp.skip_flush =3D true; + monitor_data_init(&hmp, true); =20 old_mon =3D cur_mon; cur_mon =3D &hmp; @@ -4098,7 +4098,7 @@ void monitor_init(Chardev *chr, int flags) } =20 mon =3D g_malloc(sizeof(*mon)); - monitor_data_init(mon); + monitor_data_init(mon, false); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; --=20 2.7.4 From nobody Sat Apr 27 22:48:51 2024 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 1503301577525877.0571500542746; Mon, 21 Aug 2017 00:46:17 -0700 (PDT) Received: from localhost ([::1]:51150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhPb-0002Px-Do for importer@patchew.org; Mon, 21 Aug 2017 03:46:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhO7-0001NF-F0 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djhO2-00058p-Ho for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djhO2-00057T-86 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B819E80464; Mon, 21 Aug 2017 07:44:35 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 931685D6A6; Mon, 21 Aug 2017 07:44:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B819E80464 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 15:44:20 +0800 Message-Id: <1503301464-27886-3-git-send-email-peterx@redhat.com> In-Reply-To: <1503301464-27886-1-git-send-email-peterx@redhat.com> References: <1503301464-27886-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 21 Aug 2017 07:44:35 +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 2/6] monitor: allow monitor to create thread to poll 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 , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , 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" Firstly, introduce Monitor.use_thread, and set it for monitors that are using non-mux typed backend chardev. We only do this for monitors, so mux-typed chardevs are not suitable (when it connects to, e.g., serials and the monitor together). When use_thread is set, we create standalone thread to poll the monitor events, isolated from the main loop thread. Here we still need to take the BQL before dispatching the tasks since some of the monitor commands are not allowed to execute without the protection of BQL. Then this gives us the chance to avoid taking the BQL for some monitor commands in the future. * Why this change? We need these per-monitor threads to make sure we can have at least one monitor that will never stuck (that can receive further monitor commands). * So when will monitors stuck? And, how do they stuck? After we have postcopy and remote page faults, it's simple to achieve a stuck in the monitor (which is also a stuck in main loop thread): (1) Monitor deadlock on BQL As we may know, when postcopy is running on destination VM, the vcpu threads can stuck merely any time as long as it tries to access an uncopied guest page. Meanwhile, when the stuck happens, it is possible that the vcpu thread is holding the BQL. If the page fault is not handled quickly, you'll find that monitors stop working, which is trying to take the BQL. If the page fault cannot be handled correctly (one case is a paused postcopy, when network is temporarily down), monitors will hang forever. Without current patch, that means the main loop hanged. We'll never find a way to talk to VM again. (2) Monitor tries to run codes page-faulted vcpus The HMP command "info cpus" is one of the good example - it tries to kick all the vcpus and sync status from them. However, if there is any vcpu that stuck at an unhandled page fault, it can never achieve the sync, then the HMP hangs. Again, it hangs the main loop thread as well. After either (1) or (2), we can see the deadlock problem: - On one hand, if monitor hangs, we cannot do the postcopy recovery, because postcopy recovery needs user to specify new listening port on destination monitor. - On the other hand, if we cannot recover the paused postcopy, then page faults cannot be serviced, and the monitors will possibly hang forever then. * How this patch helps? - Firstly, we'll have our own thread for each dedicated monitor (or say, the backend chardev is only used for monitor), so even main loop thread hangs (it is always possible), this monitor thread may still survive. - Not all monitor commands need the BQL. We can selectively take the BQL (depends on which command we are running) to avoid waiting on a page-faulted vcpu thread that has taken the BQL (this will be done in following up patches). Signed-off-by: Peter Xu --- monitor.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++= ---- qapi/qmp-dispatch.c | 15 ++++++++++++ 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index 7c90df7..18504ef 100644 --- a/monitor.c +++ b/monitor.c @@ -36,6 +36,7 @@ #include "net/net.h" #include "net/slirp.h" #include "chardev/char-fe.h" +#include "chardev/char-mux.h" #include "ui/qemu-spice.h" #include "sysemu/numa.h" #include "monitor/monitor.h" @@ -190,6 +191,8 @@ struct Monitor { int flags; int suspend_cnt; bool skip_flush; + /* Whether the monitor wants to be polled in standalone thread */ + bool use_thread; =20 QemuMutex out_lock; QString *outbuf; @@ -206,6 +209,11 @@ struct Monitor { mon_cmd_t *cmd_table; QLIST_HEAD(,mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; + + /* Only used when "use_thread" is used */ + QemuThread mon_thread; + GMainContext *mon_context; + GMainLoop *mon_loop; }; =20 /* QMP checker flags */ @@ -568,7 +576,7 @@ 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_thre= ad) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); @@ -576,6 +584,16 @@ static void monitor_data_init(Monitor *mon, bool skip_= flush) /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; mon->skip_flush =3D skip_flush; + mon->use_thread =3D use_thread; + if (use_thread) { + /* + * For monitors that use isolated threads, they'll need their + * own GMainContext and GMainLoop. Otherwise, these pointers + * will be NULL, which means the default context will be used. + */ + mon->mon_context =3D g_main_context_new(); + mon->mon_loop =3D g_main_loop_new(mon->mon_context, TRUE); + } } =20 static void monitor_data_destroy(Monitor *mon) @@ -587,6 +605,13 @@ static void monitor_data_destroy(Monitor *mon) g_free(mon->rs); QDECREF(mon->outbuf); qemu_mutex_destroy(&mon->out_lock); + if (mon->use_thread) { + /* Notify the per-monitor thread to quit. */ + g_main_loop_quit(mon->mon_loop); + qemu_thread_join(&mon->mon_thread); + g_main_loop_unref(mon->mon_loop); + g_main_context_unref(mon->mon_context); + } } =20 char *qmp_human_monitor_command(const char *command_line, bool has_cpu_ind= ex, @@ -595,7 +620,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; @@ -3101,6 +3126,11 @@ static void handle_hmp_command(Monitor *mon, const c= har *cmdline) { QDict *qdict; const mon_cmd_t *cmd; + /* + * If we haven't take the BQL (when called by per-monitor + * threads), we need to take care of the BQL on our own. + */ + bool take_bql =3D !qemu_mutex_iothread_locked(); =20 trace_handle_hmp_command(mon, cmdline); =20 @@ -3116,7 +3146,16 @@ static void handle_hmp_command(Monitor *mon, const c= har *cmdline) return; } =20 + if (take_bql) { + qemu_mutex_lock_iothread(); + } + cmd->cmd(mon, qdict); + + if (take_bql) { + qemu_mutex_unlock_iothread(); + } + QDECREF(qdict); } =20 @@ -4086,6 +4125,15 @@ static void __attribute__((constructor)) monitor_loc= k_init(void) qemu_mutex_init(&monitor_lock); } =20 +static void *monitor_thread(void *data) +{ + Monitor *mon =3D data; + + g_main_loop_run(mon->mon_loop); + + return NULL; +} + void monitor_init(Chardev *chr, int flags) { static int is_first_init =3D 1; @@ -4098,7 +4146,9 @@ void monitor_init(Chardev *chr, int flags) } =20 mon =3D g_malloc(sizeof(*mon)); - monitor_data_init(mon, false); + + /* For non-mux typed monitors, we create dedicated threads. */ + monitor_data_init(mon, false, !CHARDEV_IS_MUX(chr)); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; @@ -4112,12 +4162,19 @@ void monitor_init(Chardev *chr, int flags) =20 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, + mon->mon_context, true); qemu_chr_fe_set_echo(&mon->chr, true); json_message_parser_init(&mon->qmp.parser, handle_qmp_command); } else { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read, - monitor_event, NULL, mon, NULL, true); + monitor_event, NULL, mon, + mon->mon_context, true); + } + + if (mon->use_thread) { + qemu_thread_create(&mon->mon_thread, chr->label, monitor_thread, + mon, QEMU_THREAD_JOINABLE); } =20 qemu_mutex_lock(&monitor_lock); diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 5ad36f8..3b6b224 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -19,6 +19,7 @@ #include "qapi/qmp/qjson.h" #include "qapi-types.h" #include "qapi/qmp/qerror.h" +#include "qemu/main-loop.h" =20 static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) { @@ -75,6 +76,11 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QO= bject *request, QDict *args, *dict; QmpCommand *cmd; QObject *ret =3D NULL; + /* + * If we haven't take the BQL (when called by per-monitor + * threads), we need to take care of the BQL on our own. + */ + bool take_bql =3D !qemu_mutex_iothread_locked(); =20 dict =3D qmp_dispatch_check_obj(request, errp); if (!dict) { @@ -101,7 +107,16 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, QINCREF(args); } =20 + if (take_bql) { + qemu_mutex_lock_iothread(); + } + cmd->fn(args, &ret, &local_err); + + if (take_bql) { + qemu_mutex_unlock_iothread(); + } + if (local_err) { error_propagate(errp, local_err); } else if (cmd->options & QCO_NO_SUCCESS_RESP) { --=20 2.7.4 From nobody Sat Apr 27 22:48:51 2024 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 1503301577587614.8834306524689; Mon, 21 Aug 2017 00:46:17 -0700 (PDT) Received: from localhost ([::1]:51149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhPb-0002Po-CH for importer@patchew.org; Mon, 21 Aug 2017 03:46:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhO7-0001NG-Fw for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djhO5-0005AR-9I for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34950) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djhO4-0005A8-Vx for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4F07356D7; Mon, 21 Aug 2017 07:44:39 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 320B85D6A6; Mon, 21 Aug 2017 07:44:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E4F07356D7 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 15:44:21 +0800 Message-Id: <1503301464-27886-4-git-send-email-peterx@redhat.com> In-Reply-To: <1503301464-27886-1-git-send-email-peterx@redhat.com> References: <1503301464-27886-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 21 Aug 2017 07:44: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] [RFC 3/6] QAPI: new QMP command option "without-bql" 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 , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , 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" Introducing this new parameter for QMP commands in general to mark out when the command does not need BQL. Normally QMP command executions are done with the protection of BQL in QEMU. However the truth is that not all the QMP commands require the BQL. This new parameter provides a way to allow QMP commands to run in parallel when possible, without the contention on the BQL. Since the default value of "without-bql" is still false, so now all QMP commands are still protected by BQL still. Signed-off-by: Peter Xu --- docs/devel/qapi-code-gen.txt | 10 +++++++++- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-dispatch.c | 11 +++++++++++ scripts/qapi-commands.py | 18 +++++++++++++----- scripts/qapi-introspect.py | 2 +- scripts/qapi.py | 15 ++++++++++----- scripts/qapi2texi.py | 2 +- 7 files changed, 46 insertions(+), 13 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 9903ac4..4960d00 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -556,7 +556,8 @@ following example objects: =20 Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, '*returns': TYPE-NAME, '*boxed': true, - '*gen': false, '*success-response': false } + '*gen': false, '*success-response': false, + '*without-bql': false } =20 Commands are defined by using a dictionary containing several members, where three members are most common. The 'command' member is a @@ -636,6 +637,13 @@ possible, the command expression should include the op= tional key 'success-response' with boolean value false. So far, only QGA makes use of this member. =20 +Most of the commands require the Big QEMU Lock (BQL) be held during +execution. However, there is a small subset of the commands that may +not really need BQL at all. To mark out this kind of commands, we can +specify "without-bql" to "true". This parameter is only a hint for +internal QMP implementation to provide possiblility to allow commands +be run in parallel, or reduce the contention of the lock. Users of QMP +should not really be aware of such information. =20 =3D=3D=3D Events =3D=3D=3D =20 diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 20578dc..ec5c620 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -23,6 +23,7 @@ typedef enum QmpCommandOptions { QCO_NO_OPTIONS =3D 0x0, QCO_NO_SUCCESS_RESP =3D 0x1, + QCO_WITHOUT_BQL =3D 0x2, } QmpCommandOptions; =20 typedef struct QmpCommand diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 3b6b224..b7fba5e 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -107,6 +107,17 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, QINCREF(args); } =20 + if (cmd->options & QCO_WITHOUT_BQL) { + /* + * If this command can live without BQL, then we don't take + * it. One thing to mention: we may have already taken the + * BQL before reaching here. If so, we just keep it. So + * generally speaking we are trying our best on reducing the + * contention of BQL. + */ + take_bql =3D false; + } + if (take_bql) { qemu_mutex_lock_iothread(); } diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 974d0a4..155a0a4 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -192,10 +192,17 @@ out: return ret =20 =20 -def gen_register_command(name, success_response): - options =3D 'QCO_NO_OPTIONS' +def gen_register_command(name, success_response, without_bql): + options =3D [] + if not success_response: - options =3D 'QCO_NO_SUCCESS_RESP' + options +=3D ['QCO_NO_SUCCESS_RESP'] + if without_bql: + options +=3D ['QCO_WITHOUT_BQL'] + + if not options: + options =3D ['QCO_NO_OPTIONS'] + options =3D " | ".join(options) =20 ret =3D mcgen(''' qmp_register_command(cmds, "%(name)s", @@ -241,7 +248,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._visited_ret_types =3D None =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): if not gen: return self.decl +=3D gen_command_decl(name, arg_type, boxed, ret_type) @@ -250,7 +257,8 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self.defn +=3D gen_marshal_output(ret_type) self.decl +=3D gen_marshal_decl(name) self.defn +=3D gen_marshal(name, arg_type, boxed, ret_type) - self._regy +=3D gen_register_command(name, success_response) + self._regy +=3D gen_register_command(name, success_response, + without_bql) =20 =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D parse_command_line() diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 032bcea..a523544 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -154,7 +154,7 @@ const char %(c_name)s[] =3D %(c_string)s; for m in variants.variants]}) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type self._gen_json(name, 'command', diff --git a/scripts/qapi.py b/scripts/qapi.py index 8aa2775..3951143 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -920,7 +920,8 @@ def check_exprs(exprs): elif 'command' in expr: meta =3D 'command' check_keys(expr_elem, 'command', [], - ['data', 'returns', 'gen', 'success-response', 'box= ed']) + ['data', 'returns', 'gen', 'success-response', + 'boxed', 'without-bql']) elif 'event' in expr: meta =3D 'event' check_keys(expr_elem, 'event', [], ['data', 'boxed']) @@ -1031,7 +1032,7 @@ class QAPISchemaVisitor(object): pass =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): pass =20 def visit_event(self, name, info, arg_type, boxed): @@ -1398,7 +1399,7 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): QAPISchemaEntity.__init__(self, name, info, doc) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -1408,6 +1409,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.ret_type =3D None self.gen =3D gen self.success_response =3D success_response + self.without_bql =3D without_bql self.boxed =3D boxed =20 def check(self, schema): @@ -1432,7 +1434,8 @@ class QAPISchemaCommand(QAPISchemaEntity): def visit(self, visitor): visitor.visit_command(self.name, self.info, self.arg_type, self.ret_type, - self.gen, self.success_response, self.boxed) + self.gen, self.success_response, + self.boxed, self.without_bql) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): @@ -1639,6 +1642,7 @@ class QAPISchema(object): rets =3D expr.get('returns') gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) + without_bql =3D expr.get('without-bql', False) boxed =3D expr.get('boxed', False) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( @@ -1647,7 +1651,8 @@ class QAPISchema(object): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) self._def_entity(QAPISchemaCommand(name, info, doc, data, rets, - gen, success_response, boxed)) + gen, success_response, + boxed, without_bql)) =20 def _def_event(self, expr, info, doc): name =3D expr['event'] diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index a317526..659bd83 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -236,7 +236,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): body=3Dtexi_entity(doc, 'Members')) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, without_bql): doc =3D self.cur_doc if self.out: self.out +=3D '\n' --=20 2.7.4 From nobody Sat Apr 27 22:48:51 2024 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 1503301581887485.15477893639957; Mon, 21 Aug 2017 00:46:21 -0700 (PDT) Received: from localhost ([::1]:51152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhPg-0002UW-JA for importer@patchew.org; Mon, 21 Aug 2017 03:46:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhOA-0001P6-Tq for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djhOA-0005C6-7n for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50242) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djhOA-0005Bm-1o for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0652CC0587F1; Mon, 21 Aug 2017 07:44:45 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6966D66A01; Mon, 21 Aug 2017 07:44:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0652CC0587F1 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=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 15:44:22 +0800 Message-Id: <1503301464-27886-5-git-send-email-peterx@redhat.com> In-Reply-To: <1503301464-27886-1-git-send-email-peterx@redhat.com> References: <1503301464-27886-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 21 Aug 2017 07:44:45 +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 4/6] migration: qmp: migrate_incoming don't need BQL 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 , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , 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" Let "migrate-incoming" command be run without BQL. Then even if any thread hanged with BQL held, we can still run this command. Signed-off-by: Peter Xu --- qapi-schema.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qapi-schema.json b/qapi-schema.json index 802ea53..b55e73b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3259,7 +3259,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-incoming', 'data': {'uri': 'str' } } +{ 'command': 'migrate-incoming', 'data': {'uri': 'str' }, + 'without-bql': 'true' } =20 ## # @xen-save-devices-state: --=20 2.7.4 From nobody Sat Apr 27 22:48:51 2024 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 1503301741529496.50645940457866; Mon, 21 Aug 2017 00:49:01 -0700 (PDT) Received: from localhost ([::1]:51250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhSG-0004XX-CQ for importer@patchew.org; Mon, 21 Aug 2017 03:49:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhOJ-0001WR-Bx for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djhOE-0005Dn-HU for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djhOE-0005DW-BM for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EF37C0587E0; Mon, 21 Aug 2017 07:44:49 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71F49669F3; Mon, 21 Aug 2017 07:44:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4EF37C0587E0 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=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 15:44:23 +0800 Message-Id: <1503301464-27886-6-git-send-email-peterx@redhat.com> In-Reply-To: <1503301464-27886-1-git-send-email-peterx@redhat.com> References: <1503301464-27886-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 21 Aug 2017 07:44:49 +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 5/6] hmp: support "without_bql" 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 , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , 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" Introducing new option "without_bql" for HMP commands. It works just like QMP "without-bql", but for HMP commands. Signed-off-by: Peter Xu --- monitor.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/monitor.c b/monitor.c index 18504ef..475a3a6 100644 --- a/monitor.c +++ b/monitor.c @@ -124,6 +124,8 @@ typedef struct mon_cmd_t { const char *args_type; const char *params; const char *help; + /* Whether this command can be run without taking BQL? */ + bool without_bql; void (*cmd)(Monitor *mon, const QDict *qdict); /* @sub_table is a list of 2nd level of commands. If it does not exist, * cmd should be used. If it exists, sub_table[?].cmd should be @@ -3146,6 +3148,14 @@ static void handle_hmp_command(Monitor *mon, const c= har *cmdline) return; } =20 + if (cmd->without_bql) { + /* + * This is similar to QMP's "without-bql". See comments in + * do_qmp_dispatch(). + */ + take_bql =3D false; + } + if (take_bql) { qemu_mutex_lock_iothread(); } --=20 2.7.4 From nobody Sat Apr 27 22:48:51 2024 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 1503301705374623.7024889495931; Mon, 21 Aug 2017 00:48:25 -0700 (PDT) Received: from localhost ([::1]:51230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhRg-00045v-86 for importer@patchew.org; Mon, 21 Aug 2017 03:48:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1djhOJ-0001WS-Bz for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1djhOI-0005FB-0s for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50426) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1djhOH-0005En-R9 for qemu-devel@nongnu.org; Mon, 21 Aug 2017 03:44:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6AF2C0587E0; Mon, 21 Aug 2017 07:44:52 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC1005D6A6; Mon, 21 Aug 2017 07:44:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6AF2C0587E0 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=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 21 Aug 2017 15:44:24 +0800 Message-Id: <1503301464-27886-7-git-send-email-peterx@redhat.com> In-Reply-To: <1503301464-27886-1-git-send-email-peterx@redhat.com> References: <1503301464-27886-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 21 Aug 2017 07:44: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] [RFC 6/6] migration: hmp: migrate_incoming don't need BQL 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 , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , 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" Allow this command to run without BQL held. Signed-off-by: Peter Xu --- hmp-commands.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19..e8d8812 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -968,6 +968,7 @@ ETEXI .params =3D "uri", .help =3D "Continue an incoming migration from an -incoming = defer", .cmd =3D hmp_migrate_incoming, + .without_bql =3D true, }, =20 STEXI --=20 2.7.4