From patchwork Fri Nov 27 13:35:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 11936359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 424A4C2D0E4 for ; Fri, 27 Nov 2020 13:41:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A863F22253 for ; Fri, 27 Nov 2020 13:41:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A863F22253 Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=nongnu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kidzh-0002Rs-NB for qemu-devel@archiver.kernel.org; Fri, 27 Nov 2020 08:41:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvR-0005um-Mx; Fri, 27 Nov 2020 08:36:37 -0500 Received: from relay.sw.ru ([185.231.240.75]:52496 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvP-0003BA-MH; Fri, 27 Nov 2020 08:36:37 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidux-00AfjY-5Y; Fri, 27 Nov 2020 16:36:07 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 1/5] monitor: change function obsolete name in comments Date: Fri, 27 Nov 2020 16:35:42 +0300 Message-Id: <1606484146-913540-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich X-Patchwork-Original-From: Andrey Shinkevich via From: Andrey Shinkevich The function name monitor_qmp_bh_dispatcher() has been changed to monitor_qmp_dispatcher_co() since the commit 9ce44e2c. Let's amend the comments. Signed-off-by: Andrey Shinkevich --- monitor/qmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index b42f8c6..7169366 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -80,7 +80,7 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon) qemu_mutex_lock(&mon->qmp_queue_lock); /* - * Same condition as in monitor_qmp_bh_dispatcher(), but before + * Same condition as in monitor_qmp_dispatcher_co(), but before * removing an element from the queue (hence no `- 1`). * Also, the queue should not be empty either, otherwise the * monitor hasn't been suspended yet (or was already resumed). @@ -343,7 +343,7 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err) /* * Suspend the monitor when we can't queue more requests after - * this one. Dequeuing in monitor_qmp_bh_dispatcher() or + * this one. Dequeuing in monitor_qmp_dispatcher_co() or * monitor_qmp_cleanup_queue_and_resume() will resume it. * Note that when OOB is disabled, we queue at most one command, * for backward compatibility. From patchwork Fri Nov 27 13:35:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 11936369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32B81C2D0E4 for ; Fri, 27 Nov 2020 13:42:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84BC32224B for ; Fri, 27 Nov 2020 13:42:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84BC32224B Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=nongnu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie0j-0002xu-Ht for qemu-devel@archiver.kernel.org; Fri, 27 Nov 2020 08:42:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvp-0006LW-25; Fri, 27 Nov 2020 08:37:02 -0500 Received: from relay.sw.ru ([185.231.240.75]:52608 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvm-0003I8-SN; Fri, 27 Nov 2020 08:37:00 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidvK-00AfjY-N5; Fri, 27 Nov 2020 16:36:30 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 2/5] monitor: drain requests queue with 'channel closed' event Date: Fri, 27 Nov 2020 16:35:43 +0300 Message-Id: <1606484146-913540-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich X-Patchwork-Original-From: Andrey Shinkevich via From: Andrey Shinkevich When CHR_EVENT_CLOSED comes, the QMP requests queue may still contain unprocessed commands. It can happen with QMP capability OOB enabled. Let the dispatcher complete handling requests rest in the monitor queue. Signed-off-by: Andrey Shinkevich --- monitor/qmp.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index 7169366..a86ed35 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -75,36 +75,32 @@ static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon) } } -static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon) +/* + * Let unprocessed QMP commands be handled. + */ +static void monitor_qmp_drain_queue(MonitorQMP *mon) { - qemu_mutex_lock(&mon->qmp_queue_lock); + bool q_is_empty = false; - /* - * Same condition as in monitor_qmp_dispatcher_co(), but before - * removing an element from the queue (hence no `- 1`). - * Also, the queue should not be empty either, otherwise the - * monitor hasn't been suspended yet (or was already resumed). - */ - bool need_resume = (!qmp_oob_enabled(mon) || - mon->qmp_requests->length == QMP_REQ_QUEUE_LEN_MAX) - && !g_queue_is_empty(mon->qmp_requests); + while (!q_is_empty) { + qemu_mutex_lock(&mon->qmp_queue_lock); + q_is_empty = g_queue_is_empty(mon->qmp_requests); + qemu_mutex_unlock(&mon->qmp_queue_lock); - monitor_qmp_cleanup_req_queue_locked(mon); + if (!q_is_empty) { + if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) { + /* Kick the dispatcher coroutine */ + aio_co_wake(qmp_dispatcher_co); + } else { + /* Let the dispatcher do its job for a while */ + g_usleep(40); + } + } + } - if (need_resume) { - /* - * handle_qmp_command() suspended the monitor because the - * request queue filled up, to be resumed when the queue has - * space again. We just emptied it; resume the monitor. - * - * Without this, the monitor would remain suspended forever - * when we get here while the monitor is suspended. An - * unfortunately timed CHR_EVENT_CLOSED can do the trick. - */ + if (qatomic_mb_read(&mon->common.suspend_cnt)) { monitor_resume(&mon->common); } - - qemu_mutex_unlock(&mon->qmp_queue_lock); } void qmp_send_response(MonitorQMP *mon, const QDict *rsp) @@ -418,7 +414,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event) * stdio, it's possible that stdout is still open when stdin * is closed. */ - monitor_qmp_cleanup_queue_and_resume(mon); + monitor_qmp_drain_queue(mon); json_message_parser_destroy(&mon->parser); json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); From patchwork Fri Nov 27 13:35:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 11936371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2441C2D0E4 for ; Fri, 27 Nov 2020 13:43:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1AF092224C for ; Fri, 27 Nov 2020 13:43:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1AF092224C Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=nongnu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie1c-0004Tf-0d for qemu-devel@archiver.kernel.org; Fri, 27 Nov 2020 08:43:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwD-00075k-HL; Fri, 27 Nov 2020 08:37:25 -0500 Received: from relay.sw.ru ([185.231.240.75]:52764 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwB-0003RG-BQ; Fri, 27 Nov 2020 08:37:25 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidvi-00AfjY-8I; Fri, 27 Nov 2020 16:36:54 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 3/5] monitor: let QMP monitor track JSON message content Date: Fri, 27 Nov 2020 16:35:44 +0300 Message-Id: <1606484146-913540-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich X-Patchwork-Original-From: Andrey Shinkevich via From: Andrey Shinkevich We are going to allow the QMP monitor reading data from input channel more than one byte at once to increase the performance. With the OOB compatibility disabled, the monitor queues one QMP command at most. It was done for the backward compatibility as stated in the comment before pushing a command into the queue. To keep that concept functional, the monitor should track the end of a single QMP command. It allows the dispatcher handling the command and send a response to client in time. Signed-off-by: Andrey Shinkevich --- include/qapi/qmp/json-parser.h | 5 +++-- monitor/qmp.c | 18 ++++++++++++++++-- qga/main.c | 2 +- qobject/json-lexer.c | 30 +++++++++++++++++++++--------- qobject/json-parser-int.h | 8 +++++--- qobject/json-streamer.c | 15 ++++++++------- qobject/qjson.c | 2 +- tests/qtest/libqtest.c | 2 +- 8 files changed, 56 insertions(+), 26 deletions(-) diff --git a/include/qapi/qmp/json-parser.h b/include/qapi/qmp/json-parser.h index 7345a9b..039addb 100644 --- a/include/qapi/qmp/json-parser.h +++ b/include/qapi/qmp/json-parser.h @@ -36,8 +36,9 @@ void json_message_parser_init(JSONMessageParser *parser, Error *err), void *opaque, va_list *ap); -void json_message_parser_feed(JSONMessageParser *parser, - const char *buffer, size_t size); +size_t json_message_parser_feed(JSONMessageParser *parser, + const char *buffer, size_t size, + bool track_qmp); void json_message_parser_flush(JSONMessageParser *parser); diff --git a/monitor/qmp.c b/monitor/qmp.c index a86ed35..0b39c62 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -367,8 +367,22 @@ static void handle_qmp_command(void *opaque, QObject *req, Error *err) static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { MonitorQMP *mon = opaque; - - json_message_parser_feed(&mon->parser, (const char *) buf, size); + char *cursor = (char *) buf; + size_t len; + + while (size > 0) { + len = json_message_parser_feed(&mon->parser, (const char *) cursor, + size, true); + cursor += len; + size -= len; + + if (size > 0) { + /* Let the dispatcher process the QMP command */ + while (qatomic_mb_read(&mon->common.suspend_cnt)) { + g_usleep(20); + } + } + } } static QDict *qmp_greeting(MonitorQMP *mon) diff --git a/qga/main.c b/qga/main.c index dea6a3a..16de642 100644 --- a/qga/main.c +++ b/qga/main.c @@ -605,7 +605,7 @@ static gboolean channel_event_cb(GIOCondition condition, gpointer data) case G_IO_STATUS_NORMAL: buf[count] = 0; g_debug("read data, count: %d, data: %s", (int)count, buf); - json_message_parser_feed(&s->parser, (char *)buf, (int)count); + json_message_parser_feed(&s->parser, (char *)buf, (int)count, false); break; case G_IO_STATUS_EOF: g_debug("received EOF"); diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index 632320d..1fefbae 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -280,10 +280,11 @@ void json_lexer_init(JSONLexer *lexer, bool enable_interpolation) lexer->x = lexer->y = 0; } -static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush) +static JSONTokenType json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush) { int new_state; bool char_consumed = false; + JSONTokenType ret; lexer->x++; if (ch == '\n') { @@ -310,16 +311,16 @@ static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush) case JSON_FLOAT: case JSON_KEYWORD: case JSON_STRING: - json_message_process_token(lexer, lexer->token, new_state, - lexer->x, lexer->y); + ret = json_message_process_token(lexer, lexer->token, new_state, + lexer->x, lexer->y); /* fall through */ case IN_START: g_string_truncate(lexer->token, 0); new_state = lexer->start_state; break; case JSON_ERROR: - json_message_process_token(lexer, lexer->token, JSON_ERROR, - lexer->x, lexer->y); + ret = json_message_process_token(lexer, lexer->token, JSON_ERROR, + lexer->x, lexer->y); new_state = IN_RECOVERY; /* fall through */ case IN_RECOVERY: @@ -335,20 +336,31 @@ static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush) * this is a security consideration. */ if (lexer->token->len > MAX_TOKEN_SIZE) { - json_message_process_token(lexer, lexer->token, lexer->state, - lexer->x, lexer->y); + ret = json_message_process_token(lexer, lexer->token, lexer->state, + lexer->x, lexer->y); g_string_truncate(lexer->token, 0); lexer->state = lexer->start_state; } + return ret; } -void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size) +/* + * Return the number of characters fed until the end of a QMP command or + * the buffer size if not any or else not tracked. + */ +size_t json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size, + bool track) { size_t i; + JSONTokenType type = JSON_ERROR; for (i = 0; i < size; i++) { - json_lexer_feed_char(lexer, buffer[i], false); + if ((type == JSON_QMP_CMD_END) && track) { + break; + } + type = json_lexer_feed_char(lexer, buffer[i], false); } + return i; } void json_lexer_flush(JSONLexer *lexer) diff --git a/qobject/json-parser-int.h b/qobject/json-parser-int.h index 16a25d0..904555b 100644 --- a/qobject/json-parser-int.h +++ b/qobject/json-parser-int.h @@ -31,6 +31,7 @@ typedef enum json_token_type { JSON_KEYWORD, JSON_STRING, JSON_INTERP, + JSON_QMP_CMD_END, JSON_END_OF_INPUT, JSON_MAX = JSON_END_OF_INPUT } JSONTokenType; @@ -39,13 +40,14 @@ typedef struct JSONToken JSONToken; /* json-lexer.c */ void json_lexer_init(JSONLexer *lexer, bool enable_interpolation); -void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size); +size_t json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size, + bool track); void json_lexer_flush(JSONLexer *lexer); void json_lexer_destroy(JSONLexer *lexer); /* json-streamer.c */ -void json_message_process_token(JSONLexer *lexer, GString *input, - JSONTokenType type, int x, int y); +JSONTokenType json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y); /* json-parser.c */ JSONToken *json_token(JSONTokenType type, int x, int y, GString *tokstr); diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index b93d97b..fe33303 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -28,8 +28,8 @@ static void json_message_free_tokens(JSONMessageParser *parser) } } -void json_message_process_token(JSONLexer *lexer, GString *input, - JSONTokenType type, int x, int y) +JSONTokenType json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y) { JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer); QObject *json = NULL; @@ -54,7 +54,7 @@ void json_message_process_token(JSONLexer *lexer, GString *input, goto out_emit; case JSON_END_OF_INPUT: if (g_queue_is_empty(&parser->tokens)) { - return; + return type; } json = json_parser_parse(&parser->tokens, parser->ap, &err); goto out_emit; @@ -86,7 +86,7 @@ void json_message_process_token(JSONLexer *lexer, GString *input, if ((parser->brace_count > 0 || parser->bracket_count > 0) && parser->brace_count >= 0 && parser->bracket_count >= 0) { - return; + return type; } json = json_parser_parse(&parser->tokens, parser->ap, &err); @@ -97,6 +97,7 @@ out_emit: json_message_free_tokens(parser); parser->token_size = 0; parser->emit(parser->opaque, json, err); + return JSON_QMP_CMD_END; } void json_message_parser_init(JSONMessageParser *parser, @@ -115,10 +116,10 @@ void json_message_parser_init(JSONMessageParser *parser, json_lexer_init(&parser->lexer, !!ap); } -void json_message_parser_feed(JSONMessageParser *parser, - const char *buffer, size_t size) +size_t json_message_parser_feed(JSONMessageParser *parser, + const char *buffer, size_t size, bool track_qmp) { - json_lexer_feed(&parser->lexer, buffer, size); + return json_lexer_feed(&parser->lexer, buffer, size, track_qmp); } void json_message_parser_flush(JSONMessageParser *parser) diff --git a/qobject/qjson.c b/qobject/qjson.c index f1f2c69..f85a1ff 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -66,7 +66,7 @@ static QObject *qobject_from_jsonv(const char *string, va_list *ap, JSONParsingState state = {}; json_message_parser_init(&state.parser, consume_json, &state, ap); - json_message_parser_feed(&state.parser, string, strlen(string)); + json_message_parser_feed(&state.parser, string, strlen(string), false); json_message_parser_flush(&state.parser); json_message_parser_destroy(&state.parser); diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index e49f3a1..7e82d9f 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -611,7 +611,7 @@ QDict *qmp_fd_receive(int fd) if (log) { len = write(2, &c, 1); } - json_message_parser_feed(&qmp.parser, &c, 1); + json_message_parser_feed(&qmp.parser, &c, 1, false); } json_message_parser_destroy(&qmp.parser); From patchwork Fri Nov 27 13:35:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 11936377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFCC0C2D0E4 for ; Fri, 27 Nov 2020 13:45:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3AC8D2224B for ; Fri, 27 Nov 2020 13:45:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AC8D2224B Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=nongnu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie4R-0007O7-46 for qemu-devel@archiver.kernel.org; Fri, 27 Nov 2020 08:45:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwd-0007V3-Et; Fri, 27 Nov 2020 08:37:51 -0500 Received: from relay.sw.ru ([185.231.240.75]:52908 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwa-0003Yg-82; Fri, 27 Nov 2020 08:37:51 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidw5-00AfjY-Pj; Fri, 27 Nov 2020 16:37:17 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 4/5] iotests: 129 don't check backup "busy" Date: Fri, 27 Nov 2020 16:35:45 +0300 Message-Id: <1606484146-913540-5-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich X-Patchwork-Original-From: Andrey Shinkevich via From: Andrey Shinkevich From: Vladimir Sementsov-Ogievskiy Busy is racy, job has it's "pause-points" when it's not busy. Drop this check. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- tests/qemu-iotests/129 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/qemu-iotests/129 b/tests/qemu-iotests/129 index 0e13244..3c22f64 100755 --- a/tests/qemu-iotests/129 +++ b/tests/qemu-iotests/129 @@ -67,7 +67,6 @@ class TestStopWithBlockJob(iotests.QMPTestCase): result = self.vm.qmp("stop") self.assert_qmp(result, 'return', {}) result = self.vm.qmp("query-block-jobs") - self.assert_qmp(result, 'return[0]/busy', True) self.assert_qmp(result, 'return[0]/ready', False) def test_drive_mirror(self): From patchwork Fri Nov 27 13:35:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 11936375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0219FC2D0E4 for ; Fri, 27 Nov 2020 13:45:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E23F2224B for ; Fri, 27 Nov 2020 13:45:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E23F2224B Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=nongnu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie3j-0006ep-4T for qemu-devel@archiver.kernel.org; Fri, 27 Nov 2020 08:45:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwx-0007rb-M0; Fri, 27 Nov 2020 08:38:11 -0500 Received: from relay.sw.ru ([185.231.240.75]:53020 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwv-0003iH-Aj; Fri, 27 Nov 2020 08:38:11 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidwT-00AfjY-Av; Fri, 27 Nov 2020 16:37:41 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 5/5] monitor: increase amount of data for monitor to read Date: Fri, 27 Nov 2020 16:35:46 +0300 Message-Id: <1606484146-913540-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich X-Patchwork-Original-From: Andrey Shinkevich via From: Andrey Shinkevich QMP and HMP monitors read one byte at a time from the socket or stdin, which is very inefficient. With 100+ VMs on the host, this results in multiple extra system calls and CPU overuse. This patch increases the amount of read data up to 4096 bytes that fits the buffer size on the channel level. Suggested-by: Denis V. Lunev Signed-off-by: Andrey Shinkevich --- monitor/monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 84222cd..43d2d3b 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -566,7 +566,7 @@ int monitor_can_read(void *opaque) { Monitor *mon = opaque; - return !qatomic_mb_read(&mon->suspend_cnt); + return !qatomic_mb_read(&mon->suspend_cnt) ? CHR_READ_BUF_LEN : 0; } void monitor_list_append(Monitor *mon)