From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzAST-0005Qj-6u for qemu-devel@nongnu.org; Tue, 16 Jul 2013 14:58:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzASR-0007Jc-De for qemu-devel@nongnu.org; Tue, 16 Jul 2013 14:58:45 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:52859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzASR-0007Iu-9R for qemu-devel@nongnu.org; Tue, 16 Jul 2013 14:58:43 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jul 2013 14:58:40 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 05FC06E8028 for ; Tue, 16 Jul 2013 14:58:34 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r6GIwcWH173922 for ; Tue, 16 Jul 2013 14:58:38 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r6GIwc1u015457 for ; Tue, 16 Jul 2013 15:58:38 -0300 From: Anthony Liguori In-Reply-To: <1373998781-29561-3-git-send-email-lersek@redhat.com> References: <1373998781-29561-1-git-send-email-lersek@redhat.com> <1373998781-29561-3-git-send-email-lersek@redhat.com> Date: Tue, 16 Jul 2013 13:58:35 -0500 Message-ID: <87bo62miw4.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 2/2] monitor: maintain at most one G_IO_OUT watch List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek , Luiz Capitulino , qemu-devel@nongnu.org Laszlo Ersek writes: > When monitor_flush() is invoked repeatedly outside the monitor_unblocked() > callback, for example from tlb_info() -> ... -> print_pte(), several > watches may be added for the same event. > > This is no problem per se because the extra monitor_unblocked() callbacks > are harmless if mon->outbuf is empty, the watches will be removed > gradually. However a big number of watches can grow "gpollfds" without > limit in glib_pollfds_fill(), triggering a -1/EINVAL condition in > g_poll(). > > Keep at most one such watch, by following the pattern observable in eg. > commits c874ea97 and c3d6b96e. The change has no effect when > monitor_unblocked() calls monitor_flush() (when the watch can either be > removed or renewed 1-for-1), but non-callback contexts won't create an > additional watch when the monitor already has one. > > Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=970047 > > Signed-off-by: Laszlo Ersek Reviewed-by: Anthony Liguori Regards, Anthony Liguori > --- > monitor.c | 11 +++++++++-- > 1 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/monitor.c b/monitor.c > index 2ba7876..de24b2c 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -189,6 +189,7 @@ struct Monitor { > int suspend_cnt; > bool skip_flush; > QString *outbuf; > + guint watch; > ReadLineState *rs; > MonitorControl *mc; > CPUState *mon_cpu; > @@ -263,7 +264,10 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, > static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond, > void *opaque) > { > - monitor_flush(opaque); > + Monitor *mon = opaque; > + > + mon->watch = 0; > + monitor_flush(mon); > return FALSE; > } > > @@ -294,7 +298,10 @@ void monitor_flush(Monitor *mon) > QDECREF(mon->outbuf); > mon->outbuf = tmp; > } > - qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon); > + if (mon->watch == 0) { > + mon->watch = qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, > + monitor_unblocked, mon); > + } > } > } > > -- > 1.7.1