summaryrefslogtreecommitdiff
path: root/drivers/tty/tty_buffer.c
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2013-06-15 09:14:15 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-07-23 16:42:59 -0700
commit24a89d1cb69b6c488cf16d98dd02e7820f62b40c (patch)
treee09745de8a63d9d8039495ed8b9bb79fbb334702 /drivers/tty/tty_buffer.c
parentda261e7fe7b0e23a0d4d46039d20dc60fa197b49 (diff)
tty: Make ldisc input flow control concurrency-friendly
Although line discipline receiving is single-producer/single-consumer, using tty->receive_room to manage flow control creates unnecessary critical regions requiring additional lock use. Instead, introduce the optional .receive_buf2() ldisc method which returns the # of bytes actually received. Serialization is guaranteed by the caller. In turn, the line discipline should schedule the buffer work item whenever space becomes available; ie., when there is room to receive data and receive_room() previously returned 0 (the buffer work item stops processing if receive_buf2() returns 0). Note the 'no room' state need not be atomic despite concurrent use by two threads because only the buffer work thread can set the state and only the read() thread can clear the state. Add n_tty_receive_buf2() as the receive_buf2() method for N_TTY. Provide a public helper function, tty_ldisc_receive_buf(), to use when directly accessing the receive_buf() methods. Line disciplines not using input flow control can continue to set tty->receive_room to a fixed value and only provide the receive_buf() method. 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.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 6c7a1d043c76..ff1b2e37c3ca 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -407,11 +407,16 @@ static int
receive_buf(struct tty_struct *tty, struct tty_buffer *head, int count)
{
struct tty_ldisc *disc = tty->ldisc;
+ char *p = head->char_buf_ptr + head->read;
+ unsigned char *f = head->flag_buf_ptr + head->read;
- count = min_t(int, count, tty->receive_room);
- if (count)
- disc->ops->receive_buf(tty, head->char_buf_ptr + head->read,
- head->flag_buf_ptr + head->read, count);
+ if (disc->ops->receive_buf2)
+ count = disc->ops->receive_buf2(tty, p, f, count);
+ else {
+ count = min_t(int, count, tty->receive_room);
+ if (count)
+ disc->ops->receive_buf(tty, p, f, count);
+ }
head->read += count;
return count;
}