Skip to content

Commit

Permalink
virtio: console: make get_inbuf() return port->inbuf if present
Browse files Browse the repository at this point in the history
Instead of pulling in a buffer from the vq each time it's called,
get_inbuf() now checks if the current active buffer, in port->inbuf is
valid.  If it is, just returns a pointer to it.  This ends up
simplifying a lot of code calling get_inbuf() since the check for
port->inbuf being valid was done by all the callers.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Amit Shah authored and Rusty Russell committed Nov 2, 2011
1 parent defde66 commit d25a9dd
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,12 @@ static struct port_buffer *alloc_buf(size_t buf_size)
static struct port_buffer *get_inbuf(struct port *port)
{
struct port_buffer *buf;
struct virtqueue *vq;
unsigned int len;

vq = port->in_vq;
buf = virtqueue_get_buf(vq, &len);
if (port->inbuf)
return port->inbuf;

buf = virtqueue_get_buf(port->in_vq, &len);
if (buf) {
buf->len = len;
buf->offset = 0;
Expand Down Expand Up @@ -418,18 +419,12 @@ static bool port_has_data(struct port *port)
unsigned long flags;
bool ret;

ret = false;
spin_lock_irqsave(&port->inbuf_lock, flags);
if (port->inbuf) {
ret = true;
goto out;
}
port->inbuf = get_inbuf(port);
if (port->inbuf) {
if (port->inbuf)
ret = true;
goto out;
}
ret = false;
out:

spin_unlock_irqrestore(&port->inbuf_lock, flags);
return ret;
}
Expand Down Expand Up @@ -1489,8 +1484,7 @@ static void in_intr(struct virtqueue *vq)
return;

spin_lock_irqsave(&port->inbuf_lock, flags);
if (!port->inbuf)
port->inbuf = get_inbuf(port);
port->inbuf = get_inbuf(port);

/*
* Don't queue up data when port is closed. This condition
Expand Down

0 comments on commit d25a9dd

Please sign in to comment.