aboutsummaryrefslogtreecommitdiff
path: root/drivers/tty/tty_buffer.c
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2013-06-15 09:36:06 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-07-23 16:47:08 -0700
commit809850b7a5fcc0a96d023e1171a7944c60fd5a71 (patch)
tree5c6a22458a7d756cbfe948bfb6b7d331af01610f /drivers/tty/tty_buffer.c
parent2cf7b67e87f0d8db025cff12b5d29c0663bbcd87 (diff)
tty: Use lockless flip buffer free list
In preparation for lockless flip buffers, make the flip buffer free list lockless. NB: using llist is not the optimal solution, as the driver and buffer work may contend over the llist head unnecessarily. However, test measurements indicate this contention is low. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/tty_buffer.c')
-rw-r--r--drivers/tty/tty_buffer.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 0259a766b87..069640e5b9c 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -44,16 +44,17 @@ static void tty_buffer_reset(struct tty_buffer *p, size_t size)
void tty_buffer_free_all(struct tty_port *port)
{
struct tty_bufhead *buf = &port->buf;
- struct tty_buffer *p;
+ struct tty_buffer *p, *next;
+ struct llist_node *llist;
while ((p = buf->head) != NULL) {
buf->head = p->next;
kfree(p);
}
- while ((p = buf->free) != NULL) {
- buf->free = p->next;
+ llist = llist_del_all(&buf->free);
+ llist_for_each_entry_safe(p, next, llist, free)
kfree(p);
- }
+
buf->tail = NULL;
buf->memory_used = 0;
}
@@ -68,22 +69,20 @@ void tty_buffer_free_all(struct tty_port *port)
* allocation behaviour.
* Return NULL if out of memory or the allocation would exceed the
* per device queue
- *
- * Locking: Caller must hold tty->buf.lock
*/
static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
{
- struct tty_buffer **tbh = &port->buf.free;
+ struct llist_node *free;
struct tty_buffer *p;
/* Round the buffer size out */
size = __ALIGN_MASK(size, TTYB_ALIGN_MASK);
if (size <= MIN_TTYB_SIZE) {
- if (*tbh) {
- p = *tbh;
- *tbh = p->next;
+ free = llist_del_first(&port->buf.free);
+ if (free) {
+ p = llist_entry(free, struct tty_buffer, free);
goto found;
}
}
@@ -109,8 +108,6 @@ found:
*
* Free a tty buffer, or add it to the free list according to our
* internal strategy
- *
- * Locking: Caller must hold tty->buf.lock
*/
static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b)
@@ -123,10 +120,8 @@ static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b)
if (b->size > MIN_TTYB_SIZE)
kfree(b);
- else {
- b->next = buf->free;
- buf->free = b;
- }
+ else
+ llist_add(&b->free, &buf->free);
}
/**
@@ -542,7 +537,7 @@ void tty_buffer_init(struct tty_port *port)
spin_lock_init(&buf->lock);
buf->head = NULL;
buf->tail = NULL;
- buf->free = NULL;
+ init_llist_head(&buf->free);
buf->memory_used = 0;
INIT_WORK(&buf->work, flush_to_ldisc);
}