All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: Amit Shah <amit.shah@redhat.com>
Cc: Paul Brook <paul@codesourcery.com>,
	qemu list <qemu-devel@nongnu.org>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] Re: [PATCH v6 6/6] virtio-console: Throttle virtio-serial-bus if we can't consume any more guest data
Date: Tue, 04 May 2010 22:28:49 +0200	[thread overview]
Message-ID: <m3sk671ke6.fsf@trasno.mitica> (raw)
In-Reply-To: <1272997439-9675-7-git-send-email-amit.shah@redhat.com> (Amit Shah's message of "Tue, 4 May 2010 23:53:59 +0530")

Amit Shah <amit.shah@redhat.com> wrote:
> If the char device we're connected to is overwhelmed with data and it
> can't accept any more, signal to the virtio-serial-bus to stop sending
> us more data till we tell otherwise.
>
> If the current buffer being processed hasn't been completely written out
> to the char device, we have to keep it around and re-try sending it
> since the virtio-serial-bus code assumes we consume the entire buffer.
>
> Allow the chardev backends to return -EAGAIN; we're ready with a
> callback handler that will flush the remainder of the buffer.
>
> Also register with savevm so that we save/restore such a buffer across
> migration.
>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> ---
>  hw/virtio-console.c |  126 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 123 insertions(+), 3 deletions(-)
>
> diff --git a/hw/virtio-console.c b/hw/virtio-console.c
> index 749ed59..7eb6aa1 100644
> --- a/hw/virtio-console.c
> +++ b/hw/virtio-console.c
> @@ -13,18 +13,92 @@
>  #include "qemu-char.h"
>  #include "virtio-serial.h"
>  
> +typedef struct Buffer {
> +    uint8_t *buf;
> +    size_t rem_len;
> +    size_t offset;
> +} Buffer;
> +
>  typedef struct VirtConsole {
>      VirtIOSerialPort port;
>      CharDriverState *chr;
> +    Buffer *unflushed_buf;

This part of teh struct can be static instead of a pointer, and adjust
rest of code accordingly.  for the rest, it looks ok.

For this to work, I think that you will have to change rem_len for
total_len (or whatever) and adjust code around.  This makes trivial to
check for buffer used/no, just see if len = 0.

> +static int buffered_write_to_chardev(VirtConsole *vcon, const uint8_t *buf,
> +                                     size_t len)
> +{
> +    size_t written;
> +    ssize_t ret;
> +
> +    written = 0;
> +    do {
> +        ret = qemu_chr_write_nb(vcon->chr, buf + written, len - written);
> +        if (ret < 0) {
> +            if (vcon->unflushed_buf) {
> +                vcon->unflushed_buf->offset += written;
> +                vcon->unflushed_buf->rem_len -= written;
> +            } else {
> +                virtio_serial_throttle_port(&vcon->port, true);
> +                add_unflushed_buf(vcon, buf + written, len - written);
> +            }
> +
> +            return -EAGAIN;

You can "return ret" instead of "inventing" a new error :)

> +static void virtio_console_port_save(QEMUFile *f, void *opaque)
> +{
> +    VirtConsole *vcon = opaque;
> +    uint32_t have_buffer;
> +
> +    have_buffer = vcon->unflushed_buf ? true : false;

So, here you can just write vcon->unflushed_buf.len if you go with my
proposal, what will make VMState transition easier.


Rest of patch is good.  I also like the series, specially the change of
qemu_chr_add_handlers() to use one struct to pass its arguments.

Later, Juan.

  reply	other threads:[~2010-05-04 20:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04 18:23 [Qemu-devel] [PATCH v6 0/6] char: non-blocking writes, virtio-console flow control Amit Shah
2010-05-04 18:23 ` [Qemu-devel] [PATCH v6 1/6] virtio-console: Factor out common init between console and generic ports Amit Shah
2010-05-04 18:23   ` [Qemu-devel] [PATCH v6 2/6] char: Add a QemuChrHandlers struct to initialise chardev handlers Amit Shah
2010-05-04 18:23     ` [Qemu-devel] [PATCH v6 3/6] char: Let writers know how much data was written in case of errors Amit Shah
2010-05-04 18:23       ` [Qemu-devel] [PATCH v6 4/6] char: Add qemu_chr_write_nb() for nonblocking writes Amit Shah
2010-05-04 18:23         ` [Qemu-devel] [PATCH v6 5/6] char: unix/tcp: Add a non-blocking write handler Amit Shah
2010-05-04 18:23           ` [Qemu-devel] [PATCH v6 6/6] virtio-console: Throttle virtio-serial-bus if we can't consume any more guest data Amit Shah
2010-05-04 20:28             ` Juan Quintela [this message]
2010-05-04 19:54           ` [Qemu-devel] Re: [PATCH v6 5/6] char: unix/tcp: Add a non-blocking write handler Juan Quintela
2010-05-04 19:58             ` Amit Shah
2010-05-04 19:23 ` [Qemu-devel] Re: [PATCH v6 0/6] char: non-blocking writes, virtio-console flow control Gerd Hoffmann

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=m3sk671ke6.fsf@trasno.mitica \
    --to=quintela@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=paul@codesourcery.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.