qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 2/2] Monitor: Make output buffer dynamic


From: Wenchao Xia
Subject: Re: [Qemu-devel] [PATCH 2/2] Monitor: Make output buffer dynamic
Date: Wed, 27 Mar 2013 14:45:53 +0800
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130307 Thunderbird/17.0.4

Hi, Luiz
  Personally I hope reduce the dynamic allocated buffer which brings
fragments and unexpected memory grow. Instead, how about sacrifice
some time to wait output complete, since monitor is not time critical?
in this case static buffer's size can decide how many work can be
postponded. Following is my suggestion:

--- a/monitor.c
+++ b/monitor.c
@@ -293,17 +293,28 @@ static void monitor_puts(Monitor *mon, const char
*str)
 {
     char c;

+    /* if mux do not put in any thing to buffer */
+    if (mon->mux_out) {
+        return;
+    }
+
     for(;;) {
-        assert(mon->outbuf_index < sizeof(mon->outbuf) - 1);
+        if (mon->outbuf_index >= sizeof(mon->outbuf) - 1) {
+            /* when buffer is full, flush it and retry. If buffer is
bigger, more
+               work can be postponed. */
+            monitor_flush(mon);
+            usleep(1);
+            continue;
+        }
         c = *str++;
         if (c == '\0')
             break;
         if (c == '\n')
             mon->outbuf[mon->outbuf_index++] = '\r';
         mon->outbuf[mon->outbuf_index++] = c;
-        if (mon->outbuf_index >= (sizeof(mon->outbuf) - 1)
-            || c == '\n')
+        if (c == '\n') {
             monitor_flush(mon);
+        }
     }
 }

> Commit f628926bb423fa8a7e0b114511400ea9df38b76a changed monitor_flush()
> to retry on qemu_chr_fe_write() errors. However, the Monitor's output
> buffer can keep growing while the retry is not issued and this can
> cause the buffer to overflow.
> 
> To reproduce this issue, just start qemu and type on the Monitor:
> 
> (qemu) ?
> 
> This will cause the assertion to trig.
> 
> To fix this problem this commit makes the Monitor buffer dynamic,
> which means that it can grow as much as needed.
> 
> Signed-off-by: Luiz Capitulino <address@hidden>
> ---
>   monitor.c | 42 +++++++++++++++++++++++++-----------------
>   1 file changed, 25 insertions(+), 17 deletions(-)
> 




reply via email to

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