qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] monitor: Fix slow reading


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH] monitor: Fix slow reading
Date: Fri, 22 Nov 2019 11:23:03 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1

Cc'ing the chardev maintainers.

On 11/22/19 10:23 AM, Yury Kotov wrote:
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 <address@hidden>
---
  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;
+/*
+ * 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

This looks reasonable.
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>

+
  /* Shared monitor I/O thread */
  IOThread *mon_iothread;
@@ -498,7 +505,7 @@ int monitor_can_read(void *opaque)
  {
      Monitor *mon = opaque;
- return !atomic_mb_read(&mon->suspend_cnt);
+    return atomic_mb_read(&mon->suspend_cnt) ? 0 : MONITOR_READ_LEN_MAX;
  }
void monitor_list_append(Monitor *mon)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]