virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Amit Shah <amit.shah@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 13/28] virtio: console: Create a buffer pool for sending data to host
Date: Wed, 2 Dec 2009 19:00:35 +1030	[thread overview]
Message-ID: <200912021900.35219.rusty@rustcorp.com.au> (raw)
In-Reply-To: <1259391051-7752-14-git-send-email-amit.shah@redhat.com>

On Sat, 28 Nov 2009 05:20:36 pm Amit Shah wrote:
> The old way of sending data to the host was to populate one buffer and
> then wait till the host consumed it before sending the next chunk of
> data.
> 
> Also, there was no support to send large chunks of data.
> 
> We now maintain a per-device list of buffers that are ready to be
> passed on to the host.
> 
> This patch adds support to send big chunks in multiple buffers of
> PAGE_SIZE each to the host.
> 
> When the host consumes the data and signals to us via an interrupt, we
> add the consumed buffer back to our unconsumed list.
> 
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> ---
>  drivers/char/virtio_console.c |  159 +++++++++++++++++++++++++++++++++-------
>  1 files changed, 131 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index e8dabae..3111e4c 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -67,9 +67,13 @@ struct ports_device {
>  	struct work_struct rx_work;
>  
>  	struct list_head unused_read_head;
> +	struct list_head unused_write_head;
>  
>  	/* To protect the list of unused read buffers and the in_vq */
>  	spinlock_t read_list_lock;
> +
> +	/* To protect the list of unused write buffers and the out_vq */
> +	spinlock_t write_list_lock;
>  };

Let's simplify this a little with a single "buffer_lock" or such in the
previous patch.

> +	if (!in_count)
>  		return 0;

Not necessary: if it happens all we'll do is gratuitously kick the host.

> +	in_offset = 0; /* offset in the user buffer */
> +	spin_lock_irqsave(&port->portdev->write_list_lock, irqf);
> +	while (in_count - in_offset) {

while (in_offset < in_count) seems clearer to me here.

> +		copy_size = min(in_count - in_offset, PAGE_SIZE);

Shouldn't you be using buf->size here?

> +		spin_unlock_irqrestore(&port->portdev->write_list_lock, irqf);
> +
> +		/*
> +		 * Since we're not sure when the host will actually
> +		 * consume the data and tell us about it, we have
> +		 * to copy the data here in case the caller
> +		 * frees the in_buf
> +		 */
> +		memcpy(buf->buf, in_buf + in_offset, copy_size);
> +
> +		buf->len = copy_size;
> +		sg_init_one(sg, buf->buf, buf->len);
> +
> +		spin_lock_irqsave(&port->portdev->write_list_lock, irqf);

Dropping the lock here seems gratuitous.

> +/*
> + * This function is only called from the init routine so the spinlock
> + * for the unused_write_head list isn't taken
> + */
> +static void alloc_write_bufs(struct ports_device *portdev)
> +{
> +	struct port_buffer *buf;
> +	int i;
> +
> +	for (i = 0; i < 30; i++) {

30?  And why aren't we allocating these somehow as they're
consumed?

>  	fill_receive_queue(portdev);
> +	alloc_write_bufs(portdev);

What happens if this fails?

Rusty.

  parent reply	other threads:[~2009-12-02  8:30 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-28  6:50 [PATCH 00/28] virtio: console: Fixes, support for generic ports Amit Shah
2009-11-28  6:50 ` [PATCH 01/28] virtio: console: comment cleanup Amit Shah
2009-11-28  6:50   ` [PATCH 02/28] virtio: console: statically initialize virtio_cons Amit Shah
2009-11-28  6:50     ` [PATCH 03/28] hvc_console: make the ops pointer const Amit Shah
     [not found]     ` <1259391051-7752-4-git-send-email-amit.shah@redhat.com>
2009-11-28  6:50       ` [PATCH 04/28] virtio: console: We support only one device at a time Amit Shah
2009-11-28  6:50         ` [PATCH 05/28] virtio: console: port encapsulation Amit Shah
2009-11-28  6:50           ` [PATCH 06/28] virtio: console: use vdev->priv to avoid accessing global var Amit Shah
2009-11-28  6:50             ` [PATCH 07/28] virtio: console: don't assume a single console port Amit Shah
2009-11-28  6:50               ` [PATCH 08/28] virtio: console: remove global var Amit Shah
2009-11-28  6:50                 ` [PATCH 09/28] virtio: console: struct ports for multiple ports per device Amit Shah
2009-11-28  6:50                   ` [PATCH 10/28] virtio: console: ensure console size is updated on hvc open Amit Shah
2009-11-28  6:50                     ` [PATCH 11/28] virtio: console: Introduce a workqueue for handling host->guest notifications Amit Shah
2009-11-28  6:50                       ` [PATCH 12/28] virtio: console: Buffer data that comes in from the host Amit Shah
2009-11-28  6:50                         ` [PATCH 13/28] virtio: console: Create a buffer pool for sending data to host Amit Shah
2009-11-28  6:50                           ` [PATCH 14/28] virtio: console: Separate out console-specific data into a separate struct Amit Shah
2009-11-28  6:50                             ` [PATCH 15/28] virtio: console: Separate out console init into a new function Amit Shah
2009-11-28  6:50                               ` [PATCH 16/28] virtio: console: Introduce a 'header' for each buffer towards supporting multiport Amit Shah
2009-11-28  6:50                                 ` [PATCH 17/28] virtio: console: Add a new MULTIPORT feature, support for generic ports Amit Shah
2009-11-28  6:50                                   ` [PATCH 18/28] virtio: console: Associate each port with a char device Amit Shah
2009-11-28  6:50                                     ` [PATCH 19/28] virtio: console: Prepare for writing to / reading from userspace buffers Amit Shah
2009-11-28  6:50                                       ` [PATCH 20/28] virtio: console: Add file operations to ports for open/read/write/poll Amit Shah
2009-11-28  6:50                                         ` [PATCH 21/28] virtio: console: Ensure only one process can have a port open at a time Amit Shah
2009-11-28  6:50                                           ` [PATCH 22/28] virtio: console: Register with sysfs and create a 'name' attribute for ports Amit Shah
2009-11-28  6:50                                             ` [PATCH 23/28] virtio: console: Add throttling support to prevent flooding ports Amit Shah
2009-11-28  6:50                                               ` [PATCH 24/28] virtio: console: Add option to remove cached buffers on port close Amit Shah
2009-11-28  6:50                                                 ` [PATCH 25/28] virtio: console: Handle port hot-plug Amit Shah
2009-11-28  6:50                                                   ` [PATCH 26/28] hvc_console: Export (GPL'ed) hvc_remove Amit Shah
     [not found]                                                   ` <1259391051-7752-27-git-send-email-amit.shah@redhat.com>
2009-11-28  6:50                                                     ` [PATCH 27/28] virtio: console: Add ability to hot-unplug ports Amit Shah
2009-11-28  6:50                                                       ` [PATCH 28/28] virtio: console: Add debugfs files for each port to expose debug info Amit Shah
2009-12-02  8:30                           ` Rusty Russell [this message]
2009-12-02  9:19                             ` [PATCH 13/28] virtio: console: Create a buffer pool for sending data to host Amit Shah
2009-12-02  3:44                         ` [PATCH 12/28] virtio: console: Buffer data that comes in from the host Rusty Russell
2009-12-02  9:24                           ` Amit Shah
2009-12-02 22:54                             ` Rusty Russell
2009-12-03  3:43                               ` Amit Shah
2009-12-04 11:02                                 ` Amit Shah
2009-12-08  1:16                                   ` Rusty Russell
2009-12-15 10:45                                     ` Amit Shah
2009-12-15 22:55                                       ` Rusty Russell
2009-11-30  2:09                   ` [PATCH 09/28] virtio: console: struct ports for multiple ports per device Rusty Russell
2009-11-30  5:50                     ` Amit Shah
2009-11-30  1:57                 ` [PATCH 08/28] virtio: console: remove global var Rusty Russell
2009-11-30  5:45                   ` Amit Shah
2009-11-30  1:50               ` [PATCH 07/28] virtio: console: don't assume a single console port Rusty Russell
2009-11-30  5:42                 ` Amit Shah

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=200912021900.35219.rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=amit.shah@redhat.com \
    --cc=virtualization@lists.linux-foundation.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).