Sunday, April 15, 2012

All TTY Drivers to Have tty_port

So the second pile of TTY patches have been accepted…

And now, the most of drivers in the tree was augmented to operate with tty_port structure. The only few remaining will be changed in the next merge window (a month or so). After that, every out-of-tree driver will be broken unless it is fixed right now. You have been warned.

One might ask, why we are doing this change? The answer is simple: The code is broken. Some of the code predates Linux 1.0. Yes, it is no argument, but you know what? It is full of ancient broken code designed originally for uniprocessor, no preemption and such. Thus there are many race conditions without any real chance to fix them in the state the code stands now.

And yet, Big-Kernel-Lock (BKL). You heard that it is gone from the kernel for some time already, right? No, it is not. It is still there. Some parts of the kernel still have left-overs from this ancient coarse-grained crap. In TTY, it is called Big-TTY-Mutex. And nobody really knows what is protected by the lock (and what is not). And as a reader may suggest, I volunteered to find out.

The plan is to centralize common code which is repeated over and over. This is done by using tty_port helpers. Next, we will move TTY I/O buffers from tty_struct to tty_port and revamp locking a bit. The move will also ensure that we will not need to care about tty_struct in a prevalent count of interrupt service routines, timers etc. They really need TTY buffers, not a structure which randomly comes and goes with every open and close the way tty_struct does. And since tty_port is in the memory intact as long as the device stays in the machine (and its interrupt service routine installed in the kernel), it is a perfect place to put the buffers in. And this is exactly what is happening here right now.

Stay tuned and report bugs!

No comments: