From: Lei Li <lilei@linux.vnet.ibm.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: blauwirbel@gmail.com, aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/5] qemu-char: Add new char backend CircularMemCharDriver
Date: Tue, 23 Oct 2012 14:36:31 +0800 [thread overview]
Message-ID: <50863AEF.2090804@linux.vnet.ibm.com> (raw)
In-Reply-To: <20121022161429.6fc70b08@doriath.home>
On 10/23/2012 02:14 AM, Luiz Capitulino wrote:
> On Mon, 22 Oct 2012 00:47:57 +0800
> Lei Li <lilei@linux.vnet.ibm.com> wrote:
>
>> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
> 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
next prev parent reply other threads:[~2012-10-23 6:37 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-21 16:47 [Qemu-devel] [PATCH 0/5 V4] char: add CirMemCharDriver and provide QMP interface Lei Li
2012-10-21 16:47 ` [Qemu-devel] [PATCH 1/5] qemu-char: Add new char backend CircularMemCharDriver Lei Li
2012-10-22 14:08 ` Eric Blake
2012-10-23 5:40 ` Lei Li
2012-10-23 12:42 ` Luiz Capitulino
2012-10-22 18:14 ` Luiz Capitulino
2012-10-23 6:36 ` Lei Li [this message]
2012-10-21 16:47 ` [Qemu-devel] [PATCH 2/5] Expose CirMemCharDriver via command line Lei Li
2012-10-22 16:31 ` Luiz Capitulino
2012-10-21 16:47 ` [Qemu-devel] [PATCH 3/5] QAPI: Introduce memchar-write QMP command Lei Li
2012-10-22 18:37 ` Luiz Capitulino
2012-10-23 6:36 ` Lei Li
2012-10-23 12:44 ` Luiz Capitulino
2012-10-21 16:48 ` [Qemu-devel] [PATCH 4/5] QAPI: Introduce memchar-read " Lei Li
2012-10-22 18:43 ` Luiz Capitulino
2012-10-21 16:48 ` [Qemu-devel] [PATCH 5/5] HMP: Introduce console command Lei Li
2012-10-22 18:59 ` Luiz Capitulino
2012-10-24 7:17 ` Lei Li
2012-10-24 12:55 ` Luiz Capitulino
2012-10-25 19:43 ` Lei Li
2012-10-26 13:56 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50863AEF.2090804@linux.vnet.ibm.com \
--to=lilei@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=blauwirbel@gmail.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).