From nobody Mon May 6 12:35:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1574414735; cv=none; d=zoho.com; s=zohoarc; b=O1aXNiuqtvh9DsEAHXvJ7fkVJN3Ao0aQ69sxxW/xjI9S8Im9AH0euPntN/qYSxyt1mm70QD1bn7jli6HaciLDazgkAy9hE88gfg4XtuovX2GVkk53V6vuNKRc3cGLrkZ4Esi6t0nYGFrggUw7Hrf+D1V1+nh01xNcx6HK+fCAlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574414735; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=UgCQNxylzk2/QXWWfCKI/3zxCide36Xb5Q7WD5QS/a8=; b=jBsLpSK6K3FRlx6s7RPnE/NHqdA6fYn12MSiJYE+Cqy8fuhLTchaHyO+RHZPutdGCrKlQFvyCOTetMyELUuztv2Xuhykr50xxMGiNWKP8dIwr2zszWxj7orYEtg18vQyK3yFxB1P4P++jEFsV1ZT9lvYS4rRkLq/MJLA0HbJMQQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574414735085254.77102565321263; Fri, 22 Nov 2019 01:25:35 -0800 (PST) Received: from localhost ([::1]:48802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY5Bw-00048j-14 for importer@patchew.org; Fri, 22 Nov 2019 04:25:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52131) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY5B4-0003fH-8W for qemu-devel@nongnu.org; Fri, 22 Nov 2019 04:24:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY5B1-0007vd-35 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 04:24:32 -0500 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:52294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY5B0-0007ur-Hf for qemu-devel@nongnu.org; Fri, 22 Nov 2019 04:24:31 -0500 Received: from mxbackcorp1j.mail.yandex.net (mxbackcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::162]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 7C8092E1547; Fri, 22 Nov 2019 12:24:26 +0300 (MSK) Received: from myt5-6212ef07a9ec.qloud-c.yandex.net (myt5-6212ef07a9ec.qloud-c.yandex.net [2a02:6b8:c12:3b2d:0:640:6212:ef07]) by mxbackcorp1j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id 1nHpQYuaPq-OQTutWFe; Fri, 22 Nov 2019 12:24:26 +0300 Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:408:1460:716c:11e2:7064]) by myt5-6212ef07a9ec.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id IIDretiYZ4-OQVah5Yc; Fri, 22 Nov 2019 12:24:26 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1574414666; bh=insK5ULVBnraPS+Iwhi0j+3xaw3LrkQmybXW3buT7bc=; h=Message-Id:Date:Subject:To:From:Cc; b=pxaMR8FFDlNWp77cJ6UtgZwkath4ZQ4MHx8jz9LtZCQ2DanldT0mbzNZf4SPt9Twa Whj+MVqhilOnByVLcKpy2TtAhPM6hO+r50GmkcydfFmis31xeEz70V9ZKHeWW8hmq3 EVu3IFXw+lHXMEA2KeW5LBKgn7hEhEWdVpTTEvfc= Authentication-Results: mxbackcorp1j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Yury Kotov To: qemu-devel@nongnu.org Subject: [PATCH] monitor: Fix slow reading Date: Fri, 22 Nov 2019 12:23:47 +0300 Message-Id: <20191122092347.28309-1-yury-kotov@yandex-team.ru> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 77.88.29.217 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , yc-core@yandex-team.ru, "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The monitor_can_read (as a callback of qemu_chr_fe_set_handlers) should return size of buffer which monitor_qmp_read or monitor_read can process. Currently, monitor_can_read returns 1 as a result of logical not. Thus, for each QMP command, len(QMD) iterations of the main loop are required to handle a command. In fact, these both functions can process any buffer size. So, return 1024 as a reasonable size which is enough to process the most QMP commands, but not too big to block the main loop for a long time. Signed-off-by: Yury Kotov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- monitor/monitor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 12898b6448..cac3f39727 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -50,6 +50,13 @@ typedef struct { int64_t rate; /* Minimum time (in ns) between two events */ } MonitorQAPIEventConf; =20 +/* + * The maximum buffer size which the monitor can process in one iteration + * of the main loop. We don't want to block the loop for a long time + * because of JSON parser, so use a reasonable value. + */ +#define MONITOR_READ_LEN_MAX 1024 + /* Shared monitor I/O thread */ IOThread *mon_iothread; =20 @@ -498,7 +505,7 @@ int monitor_can_read(void *opaque) { Monitor *mon =3D opaque; =20 - return !atomic_mb_read(&mon->suspend_cnt); + return atomic_mb_read(&mon->suspend_cnt) ? 0 : MONITOR_READ_LEN_MAX; } =20 void monitor_list_append(Monitor *mon) --=20 2.24.0