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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
da261e7fe7
commit
24a89d1cb6
@@ -557,6 +557,19 @@ extern void tty_ldisc_init(struct tty_struct *tty);
|
||||
extern void tty_ldisc_deinit(struct tty_struct *tty);
|
||||
extern void tty_ldisc_begin(void);
|
||||
|
||||
static inline int tty_ldisc_receive_buf(struct tty_ldisc *ld, unsigned char *p,
|
||||
char *f, int count)
|
||||
{
|
||||
if (ld->ops->receive_buf2)
|
||||
count = ld->ops->receive_buf2(ld->tty, p, f, count);
|
||||
else {
|
||||
count = min_t(int, count, ld->tty->receive_room);
|
||||
if (count)
|
||||
ld->ops->receive_buf(ld->tty, p, f, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/* n_tty.c */
|
||||
extern struct tty_ldisc_ops tty_ldisc_N_TTY;
|
||||
|
Reference in New Issue
Block a user