virtio: console: make get_inbuf() return port->inbuf if present

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>
This commit is contained in:
Amit Shah
2011-09-14 13:06:43 +05:30
committed by Rusty Russell
parent defde66996
commit d25a9ddae9

View File

@@ -351,11 +351,12 @@ fail:
static struct port_buffer *get_inbuf(struct port *port) static struct port_buffer *get_inbuf(struct port *port)
{ {
struct port_buffer *buf; struct port_buffer *buf;
struct virtqueue *vq;
unsigned int len; unsigned int len;
vq = port->in_vq; if (port->inbuf)
buf = virtqueue_get_buf(vq, &len); return port->inbuf;
buf = virtqueue_get_buf(port->in_vq, &len);
if (buf) { if (buf) {
buf->len = len; buf->len = len;
buf->offset = 0; buf->offset = 0;
@@ -418,18 +419,12 @@ static bool port_has_data(struct port *port)
unsigned long flags; unsigned long flags;
bool ret; bool ret;
spin_lock_irqsave(&port->inbuf_lock, flags);
if (port->inbuf) {
ret = true;
goto out;
}
port->inbuf = get_inbuf(port);
if (port->inbuf) {
ret = true;
goto out;
}
ret = false; ret = false;
out: spin_lock_irqsave(&port->inbuf_lock, flags);
port->inbuf = get_inbuf(port);
if (port->inbuf)
ret = true;
spin_unlock_irqrestore(&port->inbuf_lock, flags); spin_unlock_irqrestore(&port->inbuf_lock, flags);
return ret; return ret;
} }
@@ -1489,7 +1484,6 @@ static void in_intr(struct virtqueue *vq)
return; return;
spin_lock_irqsave(&port->inbuf_lock, flags); spin_lock_irqsave(&port->inbuf_lock, flags);
if (!port->inbuf)
port->inbuf = get_inbuf(port); port->inbuf = get_inbuf(port);
/* /*