Re: [REGRESSION] 2.6.39-rc1: f23eb2b breaks console output

From: Linus Torvalds
Date: Mon Apr 04 2011 - 16:05:48 EST


On Mon, Apr 4, 2011 at 12:42 PM, Sitsofe Wheeler <sitsofe@xxxxxxxxx> wrote:
> On Mon, Apr 04, 2011 at 11:15:10PM +0400, Alexander Beregalov wrote:
>>
>> commit f23eb2b2b28547fc70df82dd5049eb39bec5ba12 tty: stop using
>> "delayed_work" in the tty layer
>> breaks console output for me.
>
> Same here - doing a dmesg in an xterm makes the machine hang for about
> 10 seconds and latencytop whinges that a raw SCSI command took 4000ms to
> complete (uniprocessor x86 EeePC 900).
>
> Additionally, you won't see this problem if you have CONFIG_PREEMPT set
> but as my config has CONFIG_PREEMPT_VOLUNTARY=y I do see this problem.
> Reverting f23eb2b2b28547fc70df82dd5049eb39bec5ba12 fixed the problem for
> me too.

Does this patch make a difference?

The tty ldisc flushing code had this crazy "reflush if we're full"
logic, which was apparently hiding a problem in N_TTY handling where
it wouldn't wake things up when the receive-room was opened up again.

When I made it not do timers, the "reflush" logic basically made for
an infinite loop (before, it used to instead basically poll for the
event on each timer tick instead).

The attached patch removes the reflush logic, and makes N_TTY instead
wake up the work when opening up the receive buffer again.

Linus
drivers/tty/n_tty.c | 6 ++++++
drivers/tty/tty_buffer.c | 4 +---
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 428f4fe..0ad3288 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -95,6 +95,7 @@ static void n_tty_set_room(struct tty_struct *tty)
{
/* tty->read_cnt is not read locked ? */
int left = N_TTY_BUF_SIZE - tty->read_cnt - 1;
+ int old_left;

/*
* If we are doing input canonicalization, and there are no
@@ -104,7 +105,12 @@ static void n_tty_set_room(struct tty_struct *tty)
*/
if (left <= 0)
left = tty->icanon && !tty->canon_data;
+ old_left = tty->receive_room;
tty->receive_room = left;
+
+ /* Did this open up the receive buffer? We may need to flip */
+ if (left && !old_left)
+ schedule_work(&tty->buf.work);
}

static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index b945121..f1a7918 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -442,10 +442,8 @@ static void flush_to_ldisc(struct work_struct *work)
line discipline as we want to empty the queue */
if (test_bit(TTY_FLUSHPENDING, &tty->flags))
break;
- if (!tty->receive_room || seen_tail) {
- schedule_work(&tty->buf.work);
+ if (!tty->receive_room || seen_tail)
break;
- }
if (count > tty->receive_room)
count = tty->receive_room;
char_buf = head->char_buf_ptr + head->read;