From patchwork Wed Mar 27 06:45:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 231600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E0F072C00A2 for ; Wed, 27 Mar 2013 17:48:01 +1100 (EST) Received: from localhost ([::1]:56776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKk9O-0003zo-TP for incoming@patchwork.ozlabs.org; Wed, 27 Mar 2013 02:47:58 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKk97-0003zT-Hl for qemu-devel@nongnu.org; Wed, 27 Mar 2013 02:47:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKk95-0002cj-8r for qemu-devel@nongnu.org; Wed, 27 Mar 2013 02:47:41 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:46663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKk94-0002c0-Nm for qemu-devel@nongnu.org; Wed, 27 Mar 2013 02:47:39 -0400 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Mar 2013 16:42:13 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 27 Mar 2013 16:42:11 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 090CD2CE804D for ; Wed, 27 Mar 2013 17:47:28 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2R6YQcM4587794 for ; Wed, 27 Mar 2013 17:34:26 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2R6lR7n028821 for ; Wed, 27 Mar 2013 17:47:27 +1100 Received: from [127.0.0.1] (wenchaox.cn.ibm.com [9.115.122.87]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2R6jquw025928; Wed, 27 Mar 2013 17:47:26 +1100 Message-ID: <515295A1.8030705@linux.vnet.ibm.com> Date: Wed, 27 Mar 2013 14:45:53 +0800 From: Wenchao Xia User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: Luiz Capitulino References: <1364240439-23450-1-git-send-email-lcapitulino@redhat.com> <1364240439-23450-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1364240439-23450-3-git-send-email-lcapitulino@redhat.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13032706-7014-0000-0000-000002C6F864 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.148 Cc: fred.konrad@greensocs.com, qemu-devel@nongnu.org, kraxel@redhat.com Subject: Re: [Qemu-devel] [PATCH 2/2] Monitor: Make output buffer dynamic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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: } > 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 > --- > monitor.c | 42 +++++++++++++++++++++++++----------------- > 1 file changed, 25 insertions(+), 17 deletions(-) > --- 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); + } }