From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQY7E-0002G1-0n for qemu-devel@nongnu.org; Tue, 23 Oct 2012 02:37:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TQY78-0005lm-TV for qemu-devel@nongnu.org; Tue, 23 Oct 2012 02:37:27 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:41740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQY78-0005li-CL for qemu-devel@nongnu.org; Tue, 23 Oct 2012 02:37:22 -0400 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 23 Oct 2012 16:34:49 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9N6RF2M45547566 for ; Tue, 23 Oct 2012 17:27:15 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9N6bAAP015444 for ; Tue, 23 Oct 2012 17:37:10 +1100 Message-ID: <50863AEF.2090804@linux.vnet.ibm.com> Date: Tue, 23 Oct 2012 14:36:31 +0800 From: Lei Li MIME-Version: 1.0 References: <1350838081-6351-1-git-send-email-lilei@linux.vnet.ibm.com> <1350838081-6351-2-git-send-email-lilei@linux.vnet.ibm.com> <20121022161429.6fc70b08@doriath.home> In-Reply-To: <20121022161429.6fc70b08@doriath.home> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/5] qemu-char: Add new char backend CircularMemCharDriver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: blauwirbel@gmail.com, aliguori@us.ibm.com, qemu-devel@nongnu.org On 10/23/2012 02:14 AM, Luiz Capitulino wrote: > On Mon, 22 Oct 2012 00:47:57 +0800 > Lei Li wrote: > >> Signed-off-by: Lei Li > This patch should be squashed in the next one. More comments below. > >> --- >> qemu-char.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 files changed, 72 insertions(+), 0 deletions(-) >> >> diff --git a/qemu-char.c b/qemu-char.c >> index b082bae..b174da1 100644 >> --- a/qemu-char.c >> +++ b/qemu-char.c >> @@ -2588,6 +2588,78 @@ size_t qemu_chr_mem_osize(const CharDriverState *chr) >> return d->outbuf_size; >> } >> >> +/*********************************************************/ >> +/*CircularMemoryr chardev*/ > s/Memoryr/Memory > >> + >> +typedef struct { >> + size_t size; >> + size_t producer; >> + size_t consumer; >> + uint8_t *cbuf; >> +} CirMemCharDriver; >> + >> +static bool cirmem_chr_is_empty(const CharDriverState *chr) >> +{ >> + const CirMemCharDriver *d = chr->opaque; >> + >> + return d->producer == d->consumer; >> +} >> + >> +static bool cirmem_chr_is_full(const CharDriverState *chr) >> +{ >> + const CirMemCharDriver *d = chr->opaque; >> + >> + return (d->producer - d->consumer) >= d->size; >> +} >> + >> +static int cirmem_chr_write(CharDriverState *chr, const uint8_t *buf, int len) >> +{ >> + CirMemCharDriver *d = chr->opaque; >> + int i; >> + >> + if (len < 0) { >> + return -1; >> + } >> + >> + /* The size should be a power of 2. */ >> + for (i = 0; i < len; i++ ) { >> + d->cbuf[d->producer % d->size] = buf[i]; >> + d->producer++; >> + } >> + >> + return 0; >> +} >> + >> +static int cirmem_chr_read(CharDriverState *chr, uint8_t *buf, int len) >> +{ >> + CirMemCharDriver *d = chr->opaque; >> + int i; >> + >> + if (cirmem_chr_is_empty(chr) || len < 0) { >> + return -1; >> + } >> + >> + if (len > d->size) { >> + len = d->size; >> + } >> + >> + for (i = 0; i < len; i++) { >> + buf[i] = d->cbuf[d->consumer % d->size]; >> + d->consumer++; >> + } >> + >> + return 0; >> +} > You don't seem to reset producer/consumer anywhere, I wonder if it's possible > for a long running VM to trigger the limit here. Yes, it make sense. -- Lei