提交 2c5dc464 编写于 作者: P Peter Hurley 提交者: Greg Kroah-Hartman

n_tty: Eliminate receive_room() from consumer/exclusive paths

The input worker never reschedules itself; it only processes input until
either there is no more input or the read buffer is full. So the reader
is responsible for restarting the input worker only if the read buffer
was previously full (no_room == 1) _and_ space is now available to process
more input because the reader has consumed data from the read buffer.

However, computing the actual space available is not required to determine
if the reader has consumed data from the read buffer. This condition is
evaluated in 5 situations, each of which the space avail is already known:
1. n_tty_flush_buffer() - the read buffer is empty; kick the worker
2. n_tty_set_termios() - no data has been consumed; do not kick the worker
       (although it may have kicked the reader so data _will be_ consumed)
3. n_tty_check_unthrottle - avail space > 3968; kick the worker
4. n_tty_read, before leaving - only kick the worker if the reader has
       moved the tail. This prevents unnecessarily kicking the worker
       when timeout-style reading is used.
5. n_tty_read, before sleeping - although it is possible for the read
       buffer to be full and input_available_p() to be false, this can
       only happen when the input worker is racing the reader, in which
       case the reader will have been woken and won't sleep.

Rename n_tty_set_room() to n_tty_kick_worker() to reflect what the
function actually does.
Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 62d38099
...@@ -187,10 +187,10 @@ static int receive_room(struct tty_struct *tty) ...@@ -187,10 +187,10 @@ static int receive_room(struct tty_struct *tty)
} }
/** /**
* n_tty_set_room - receive space * n_tty_kick_worker - start input worker (if required)
* @tty: terminal * @tty: terminal
* *
* Re-schedules the flip buffer work if space just became available. * Re-schedules the flip buffer work if it may have stopped
* *
* Caller holds exclusive termios_rwsem * Caller holds exclusive termios_rwsem
* or * or
...@@ -198,12 +198,12 @@ static int receive_room(struct tty_struct *tty) ...@@ -198,12 +198,12 @@ static int receive_room(struct tty_struct *tty)
* holds non-exclusive termios_rwsem * holds non-exclusive termios_rwsem
*/ */
static void n_tty_set_room(struct tty_struct *tty) static void n_tty_kick_worker(struct tty_struct *tty)
{ {
struct n_tty_data *ldata = tty->disc_data; struct n_tty_data *ldata = tty->disc_data;
/* Did this open up the receive buffer? We may need to flip */ /* Did the input worker stop? Restart it */
if (unlikely(ldata->no_room) && receive_room(tty)) { if (unlikely(ldata->no_room)) {
ldata->no_room = 0; ldata->no_room = 0;
WARN_RATELIMIT(tty->port->itty == NULL, WARN_RATELIMIT(tty->port->itty == NULL,
...@@ -274,7 +274,7 @@ static void n_tty_check_unthrottle(struct tty_struct *tty) ...@@ -274,7 +274,7 @@ static void n_tty_check_unthrottle(struct tty_struct *tty)
return; return;
if (!tty->count) if (!tty->count)
return; return;
n_tty_set_room(tty); n_tty_kick_worker(tty);
n_tty_write_wakeup(tty->link); n_tty_write_wakeup(tty->link);
if (waitqueue_active(&tty->link->write_wait)) if (waitqueue_active(&tty->link->write_wait))
wake_up_interruptible_poll(&tty->link->write_wait, POLLOUT); wake_up_interruptible_poll(&tty->link->write_wait, POLLOUT);
...@@ -296,7 +296,7 @@ static void n_tty_check_unthrottle(struct tty_struct *tty) ...@@ -296,7 +296,7 @@ static void n_tty_check_unthrottle(struct tty_struct *tty)
break; break;
if (!tty->count) if (!tty->count)
break; break;
n_tty_set_room(tty); n_tty_kick_worker(tty);
unthrottled = tty_unthrottle_safe(tty); unthrottled = tty_unthrottle_safe(tty);
if (!unthrottled) if (!unthrottled)
break; break;
...@@ -379,7 +379,7 @@ static void n_tty_flush_buffer(struct tty_struct *tty) ...@@ -379,7 +379,7 @@ static void n_tty_flush_buffer(struct tty_struct *tty)
{ {
down_write(&tty->termios_rwsem); down_write(&tty->termios_rwsem);
reset_buffer_flags(tty->disc_data); reset_buffer_flags(tty->disc_data);
n_tty_set_room(tty); n_tty_kick_worker(tty);
if (tty->link) if (tty->link)
n_tty_packet_mode_flush(tty); n_tty_packet_mode_flush(tty);
...@@ -1817,7 +1817,6 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) ...@@ -1817,7 +1817,6 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
else else
ldata->real_raw = 0; ldata->real_raw = 0;
} }
n_tty_set_room(tty);
/* /*
* Fix tty hang when I_IXON(tty) is cleared, but the tty * Fix tty hang when I_IXON(tty) is cleared, but the tty
* been stopped by STOP_CHAR(tty) before it. * been stopped by STOP_CHAR(tty) before it.
...@@ -2130,6 +2129,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2130,6 +2129,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
ssize_t retval = 0; ssize_t retval = 0;
long timeout; long timeout;
int packet; int packet;
size_t tail;
c = job_control(tty, file); c = job_control(tty, file);
if (c < 0) if (c < 0)
...@@ -2166,6 +2166,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2166,6 +2166,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
} }
packet = tty->packet; packet = tty->packet;
tail = ldata->read_tail;
add_wait_queue(&tty->read_wait, &wait); add_wait_queue(&tty->read_wait, &wait);
while (nr) { while (nr) {
...@@ -2208,7 +2209,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2208,7 +2209,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
retval = -ERESTARTSYS; retval = -ERESTARTSYS;
break; break;
} }
n_tty_set_room(tty);
up_read(&tty->termios_rwsem); up_read(&tty->termios_rwsem);
timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, timeout = wait_woken(&wait, TASK_INTERRUPTIBLE,
...@@ -2253,7 +2253,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2253,7 +2253,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
if (time) if (time)
timeout = time; timeout = time;
} }
n_tty_set_room(tty); if (tail != ldata->read_tail)
n_tty_kick_worker(tty);
up_read(&tty->termios_rwsem); up_read(&tty->termios_rwsem);
remove_wait_queue(&tty->read_wait, &wait); remove_wait_queue(&tty->read_wait, &wait);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册