An alternative TTY layer
The kernel's terminal (TTY) layer supports a long list of hardware and no
end of features. It is a complex subsystem that must support decades of
Unix and Linux history; core-kernel developer Ingo Molnar once confessed that the TTY code is "one of
the very few pieces of kernel code that scares the hell out of me
".
It is also quite large, weighing in at about 46KB of compiled code without
the low-level hardware drivers. 46KB is not a lot of memory on a typical
desktop system, or even on a mobile handset but, in situations where every
byte counts, it hurts.
When Pitre set out to find a way to slim down the TTY subsystem for small systems, he ran into some problems. The TTY code has a multi-layer design to give it the maximum amount of flexibility; each layer adds overhead. Line disciplines — modules that manage the low-level protocols used on serial lines — can be plugged in and out, and the kernel supports about two dozen of them. The line disciplines themselves are easy to leave out, but the infrastructure that allows them to be modular is not optional. The TTY layer is designed to support pseudoterminals, and it is able to support dozens of ports running at full speed — an important feature in the early days of Linux. Pitre concluded that there is no way to make this infrastructure optional without worsening performance or functionality for those who need it.
So, instead, he went and wrote an entirely new TTY subsystem called "minitty". About the only thing it can do is move data over a hardware serial port. There are no pseudoterminals, no choice of line disciplines, no job control, and not much of anything else. What it does provide is the ability to get debugging information out of the system via a serial port or to run simple login sessions. Minitty shares the TTY layer's low-level hardware drivers, though, and it provides a standard (if limited) interface to user space. And, importantly, it does that in 8KB of memory — about 1/6 of what is required by the standard TTY layer.
Minitty seems like a clear win for extremely small Linux deployments, but it quickly ran into trouble on the mailing list. Kernel developers have a strong aversion to duplicated subsystems, and for a number of good reasons. This kind of duplication forces choices onto distributors and users that they may not be in a position to make. It can split development effort between multiple competing implementations, bugs present in both subsystems are often only fixed in one, and maintenance can be complicated if changes to one subsystem can break the other. So it is not entirely surprising that minitty has drawn some unfavorable responses.
Greg Kroah-Hartman, the current maintainer of the TTY layer, described it as "a horrid thing to
do
" and advised Pitre to work with the existing code instead:
Other developers also made their opposition to a separate TTY layer known. Pitre is not so easily discouraged, though. He reiterated that the TTY layer simply cannot be shrunk to the same degree:
Most of his message (which is worth reading in its entirety) was devoted to explaining why he thinks a tiny TTY layer is so important. Linux is simply not a viable kernel for the smallest systems without the ability to make it as small as possible. But there is a great advantage to using Linux in such settings. Linux is well maintained and well debugged; security issues are fixed (relatively) quickly there. If a target system is running Linux, developers can write and debug their code on an ordinary desktop Linux system and, with a bit of care, expect it to work unmodified on the target system. All of the existing Linux-based development tools will be available, and existing Linux developers already know how to develop for such targets.
The ability to shrink the kernel in this way is, according to Pitre, a crucial part of making Linux successful in the smallest Internet-of-things settings. A smaller TTY layer is only the beginning; he would eventually like to come up with miniaturized versions of many other kernel subsystems as well. Accommodating these mini-subsystems will require a bit of a change to the normal kernel development model, he said, but the rewards will be more than worth the cost.
At least part of this message seems to have gotten through; Kroah-Hartman
responded to the most recent posting by
saying: "I agree with your goal of getting Linux running on these
very tiny chips, I want that to happen too
". If minitty can find
its way to acceptance, that may eventually open the door to other
tinification efforts; one should remember that this is the kernel community
we're talking about, though, so expect a lengthy discussion for each proposal.
Getting this kind of work merged will never be easy but, just
maybe, the community will be able to accept enough of it to help ensure
that the kernel is competitive in the smallest of deployments.
Index entries for this article | |
---|---|
Kernel | Embedded systems |
Kernel | TTY layer |
Posted Apr 27, 2017 20:06 UTC (Thu)
by post-factum (subscriber, #53836)
[Link] (6 responses)
But since current TTY subsystem is a huge mess, it worth throwing it out, replacing with something equivalent but properly architected.
If such an effort is started already, why stopping with minimal implementation? If designed properly, optional layers might be disabled if necessary.
Posted Apr 27, 2017 22:52 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link] (4 responses)
Posted Apr 28, 2017 6:49 UTC (Fri)
by josh (subscriber, #17465)
[Link] (3 responses)
The last time someone tried to significantly overhaul the TTY layer, they ran into obscure issues with bits of the interface that only emacs used, and almost nothing else.
Posted Apr 28, 2017 6:51 UTC (Fri)
by Cyberax (✭ supporter ✭, #52523)
[Link] (1 responses)
Posted Apr 28, 2017 22:06 UTC (Fri)
by nix (subscriber, #2304)
[Link]
(A better API without all the horror shows of the existing one around job control, signal handling, ioctls etc would be nice too, but it sounds like minitty just throws most of that out since none of it is needed for its use case -- and for any other use case, the better API would have to coexist with the horrible existing one that everything uses in any case, and because that API is so ancient and widely used there really could never be a sunset period for it -- like it or not, we're stuck with SIOC* forever.)
Posted May 11, 2017 1:45 UTC (Thu)
by geek (guest, #45074)
[Link]
Posted Apr 29, 2017 1:58 UTC (Sat)
by flussence (guest, #85566)
[Link]
Posted Apr 27, 2017 21:13 UTC (Thu)
by mm7323 (subscriber, #87386)
[Link] (5 responses)
Isn't the logical conclusion of such work essentially a _new_ kernel with some interfaces compatible with the Linux kernel (syscall, drivers, netlink etc...).
Wouldn't it be better to take an existing hardened RTOS or small kernel and add Linux interface compatibility? Doesn't this just point to the unsuitability of the Linux kernel to tiny IoT devices?
Posted Apr 27, 2017 22:19 UTC (Thu)
by jkingweb (subscriber, #113039)
[Link] (1 responses)
That's certainly what it sounds like to me. I don't see how you you benefit from active maintenance of the kernel if you throw huge chunks of it away.
Posted Apr 27, 2017 22:54 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Posted Apr 28, 2017 11:41 UTC (Fri)
by roblucid (guest, #48964)
[Link] (1 responses)
In the long run, who knows what parts of the kernel will become irrelevant in some deployments?
Many people may not see tinification effort benefits, but making software more adaptable opens up new possibilities and can drive growth as it's deployed more widely, as well as enhancing survival characteristics.
Posted Apr 29, 2017 17:26 UTC (Sat)
by flussence (guest, #85566)
[Link]
Posted Apr 30, 2017 9:04 UTC (Sun)
by linusw (subscriber, #40300)
[Link]
Of course it is possible to fork, or maintain a separate kernel, but history tell us it is not a good idea.
Posted Jun 27, 2017 22:49 UTC (Tue)
by gavinsmith (guest, #117044)
[Link] (1 responses)
If it is really so vital that these low-memory systems are supported, then I expect that someone will do the work to implement the new functionality in a way that works well with the existing code, not increasing the total complexity as much as a completely new and separate subsystem would.
Posted Jun 28, 2017 17:30 UTC (Wed)
by corbet (editor, #1)
[Link]
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
An alternative TTY layer
Intel's hardware spyware runs on it, supposedly: https://mail.coreboot.org/pipermail/coreboot/2017-April/0...
An alternative TTY layer
An alternative TTY layer
That is not a correct impression and I apologize if the article suggested that. Nico understands the tty subsystem very well, but does not believe it can be made small without impacting other use cases.
An alternative TTY layer