Re: [PATCH] SMP problem in 2.2 n_tty code

From: Alan Modra (alan@SPRI.Levels.UniSA.Edu.Au)
Date: Wed Feb 23 2000 - 06:53:14 EST


On Wed, 23 Feb 2000, Paul Mackerras wrote:

> I have tracked down why my ppp-over-pty-over-socket-over-ethernet test
> setup was clagging up on SMP machines with 2.2.15pre9. The problem is
> actually in drivers/char/n_tty.c.

Congratulations. :-)

> The n_tty.c code has a receive buffer (tty->read_buf) which is used as a
> ring buffer addressed by tty->read_head and tty->read_tail, with
> tty->read_cnt being the number of characters in the buffer. What I was
> seeing was that these three were getting out of sync, so that for example
> at one stage read_head was 225, read_tail was 475 but read_cnt was 0.

Yuck. Having a write pointer, read pointer, and count is just plain
stupid. It's much better to calculate the count from the pointers
whenever needed. (Always leave one location free in the buffer too,
otherwise read_ptr == write_ptr when full, which is of course the same as
empty.) This way, you don't need to update two variables when poking data
into the buffer and also when reading it out. More importantly, there's
no need for locking between the reader and writer.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:33 EST