From: Luiz Capitulino <lcapitulino@redhat.com>
To: Lei Li <lilei@linux.vnet.ibm.com>
Cc: aliguori@us.ibm.com, eblake@redhat.com, qemu-devel@nongnu.org,
armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/5] qemu-char: Add new char device CirMemCharDriver
Date: Wed, 19 Sep 2012 14:43:22 -0300 [thread overview]
Message-ID: <20120919144322.7aaf6adb@doriath.home> (raw)
In-Reply-To: <1347451046-5513-2-git-send-email-lilei@linux.vnet.ibm.com>
On Wed, 12 Sep 2012 19:57:22 +0800
Lei Li <lilei@linux.vnet.ibm.com> wrote:
> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
> ---
> qemu-char.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 84 insertions(+), 0 deletions(-)
>
> diff --git a/qemu-char.c b/qemu-char.c
> index 767da93..0470085 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -2591,6 +2591,90 @@ size_t qemu_chr_mem_osize(const CharDriverState *chr)
> return d->outbuf_size;
> }
>
> +/*********************************************************/
> +/*CircularMemory chardev*/
> +
> +typedef struct {
> + size_t cbuf_capacity;
> + size_t cbuf_in;
> + size_t cbuf_out;
> + size_t cbuf_count;
> + uint8_t *cbuf;
> +} CircMemCharDriver;
> +
> +static int cirmem_chr_is_empty(CharDriverState *chr)
> +{
> + CircMemCharDriver *d = chr->opaque;
> +
> + return d->cbuf_count == 0;
> +}
> +
> +static int cirmem_chr_is_full(CharDriverState *chr)
> +{
> + CircMemCharDriver *d = chr->opaque;
> +
> + return d->cbuf_count == d->cbuf_capacity;
> +}
Both argument's from the functions above can be const.
> +
> +static int cirmem_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
> +{
> + CircMemCharDriver *d = chr->opaque;
> + int left;
> +
> + if (d->cbuf_capacity < len) {
> + return -1;
> + }
> +
> + left = d->cbuf_capacity - d->cbuf_count % d->cbuf_capacity;
> +
> + /* Some of cbuf need to be overwrited */
> + if (left < len) {
> + memcpy(d->cbuf + d->cbuf_in, buf, left);
> + memcpy(d->cbuf + d->cbuf_out, buf + left, len - left);
> + d->cbuf_out = (d->cbuf_out + len - left) % d->cbuf_capacity;
> + d->cbuf_count = d->cbuf_count + left;
> + } else {
> + /* Completely overwrite */
> + if (cirmem_chr_is_full(chr)) {
> + d->cbuf_out = (d->cbuf_out + len) % d->cbuf_capacity;
> + } else {
> + /* Enough cbuf to write */
> + d->cbuf_count += len;
> + }
> + memcpy(d->cbuf + d->cbuf_in, buf, len);
> + }
> +
> + d->cbuf_in = (d->cbuf_in + len) % d->cbuf_capacity;
> +
> + return len;
> +}
I remember I made a few comments about using pointers instead
of indexes, did you consider doing that?
Btw, does this patch even build by its own? You're adding static
functions but no users.
> +
> +static void cirmem_chr_read(CharDriverState *chr, uint8_t *buf, int len)
> +{
> + CircMemCharDriver *d = chr->opaque;
> + int left;
> +
> + if (cirmem_chr_is_empty(chr)) {
> + return;
> + }
> +
> + left = d->cbuf_capacity - d->cbuf_count % d->cbuf_capacity;
> +
> + if (d->cbuf_capacity < len) {
> + len = d->cbuf_capacity;
> + }
> +
> + if (left < len) {
> + memcpy(buf, d->cbuf + d->cbuf_out, left);
> + memcpy(buf + left, d->cbuf + d->cbuf_out + left, len - left);
> + } else {
> + memcpy(buf, d->cbuf + d->cbuf_out, len);
> + }
> +
> + d->cbuf_out = (d->cbuf_out + len) % d->cbuf_capacity;
> + d->cbuf_count -= len;
> +}
> +
> QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
> {
> char host[65], port[33], width[8], height[8];
next prev parent reply other threads:[~2012-09-19 17:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-12 11:57 [Qemu-devel] [RFC v3 ATCH 0/5] char: expose CirMemCharDriver and provide QMP interface Lei Li
2012-09-12 11:57 ` [Qemu-devel] [PATCH 1/5] qemu-char: Add new char device CirMemCharDriver Lei Li
2012-09-19 17:43 ` Luiz Capitulino [this message]
2012-09-12 11:57 ` [Qemu-devel] [PATCH 2/5] Expose CirMemCharDriver via command line Lei Li
2012-09-19 17:45 ` Luiz Capitulino
2012-09-12 11:57 ` [Qemu-devel] [PATCH 3/5] QAPI: Introduce memchar-write QMP command Lei Li
2012-09-14 17:18 ` Blue Swirl
2012-09-19 18:05 ` Luiz Capitulino
2012-09-20 7:42 ` Lei Li
2012-09-20 20:05 ` Luiz Capitulino
2012-09-12 11:57 ` [Qemu-devel] [PATCH 4/5] QAPI: Introduce memchar-read " Lei Li
2012-09-12 15:01 ` Eric Blake
2012-09-14 17:29 ` Blue Swirl
2012-09-12 11:57 ` [Qemu-devel] [PATCH 5/5] HMP: Introduce console command Lei Li
2012-09-14 17:15 ` Blue Swirl
2012-09-19 18:11 ` Luiz Capitulino
2012-09-12 15:53 ` [Qemu-devel] [RFC v3 ATCH 0/5] char: expose CirMemCharDriver and provide QMP interface Avi Kivity
2012-09-12 16:12 ` Daniel P. Berrange
2012-09-13 1:58 ` Anthony Liguori
2012-09-19 17:40 ` 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=20120919144322.7aaf6adb@doriath.home \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=lilei@linux.vnet.ibm.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).