View Issue Details

IDProjectCategoryView StatusLast Update
00019161003.1(2024)/Issue8System Interfacespublic2025-03-27 15:58
Reporterhpa Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status ResolvedResolutionAccepted As Marked 
NameH. Peter Anvin
OrganizationLinux
User Reference
Section<termios.h>, cf[gs]et[io]speed()
Page Number441f
Line Number15334ff
Interp Status---
Final Accepted Textsee 0001916:0007135
Summary0001916: termios: the speed_t interfaces are inadequate
DescriptionIt should be more than clear at this point that the speed_t interfaces in termios, cf[sg]et[io]speed(), are insufficient for any reasonable serial user. Perhaps the thought at one point was that TIA232 (RS232) would go away, but it lives on (more frequently with logic level than the original PHY) as well as its cousins RS422 and RS485.

The portable list of baud rates is woefully inadequate; in fact, the most common baud rate in use today, 115200, is not on the list.

The problems are:
1. There is no portable way to discover at compile time what additional B... constants are on a certain platform.
2. There is no portable way to indicate that a platform supports arbitrary baud rates. Clearly having individual B constants for every possible integer is not feasible.
3. On a single platform, multiple kinds of hardware may be supported, each of which have their own granularity requirements for the baud rate. In general a system call is required to establish the closest available baud rate; it is not something that can be directly done in user space.

It is worth noting that the statement of baud (modulation symbols per second) versus bits per second is not necessarily the best way to describe the issue. For a modem, the baud rate may indeed be substantially different from the bit rate, but if one takes the point of view that the tty interface implements or emulates a TIA232 connection, then arguably "baud" more correct than "bits per second", as TIA232 uses between n+2 and n+4 symbols to encode n bits of information. For that reason, I believe there is no fundamental reason not to use the term "baud", and I have done so below.
Desired ActionI brought this up in the context of glibc, but the glibc maintainers noted that since this is fundamentally a portability issue, that it would be better dealt with in this group.

I see a few options for addressing this, in more or less my personal order of preference:

1. The simplest option: add a test macro to <termios.h> e.g. _POSIX_TERMIOS_SPEED_IS_BAUD which, if defined and set to 1, means that software can ignore the B... constants and treat speed_t as a numeric type, i.e. Bxxx == xxx for all xxx. The case of B constants being arbitrary is deprecated.

2. New get/set interfaces which take a numeric type, and optionally an associated numeric type, suggested to be cf[gs]et[io]baud() and baud_t, but still operate "offline" on a struct termios using tcgetattr/tcsetattr.

3. New interfaces that convert between speed_t and a numeric type (e.g. cfbaudtospeed(), cfspeedtobaud()). This means that the number of baud rates than can be supported is still limited to (1 << sizeof(speed_t))-1; for some existing implementations that will be a 16-bit number.

All of these of these options means that an application can only find the true baud rate after setting it (tcsetattr, tcgetattr).

An online (system call) interface to convert between a desired and resulting baud rate for a particular interface (file descriptor) could be provided, of course, and could be combined with either of the above. This is a relatively heavy implementation burden, though, as it typically will touch individual device drivers. As such, there must realistically be a way for such an interface to gracefully fail and require that software falls back to the set-get method.

Note that it is already the case that "not all baud rates need to be supported by the underlying hardware", and so this is not a new problem.
Tagstc1-2024

Activities

nick

2025-03-27 15:56

manager   bugnote:0007135

On page 444 line 15426 section <termios.h>, change FUTURE DIRECTIONS from:
None.

to:
A future version of this standard is expected to add at least the following symbolic constants for use as values of objects of type speed_t: B57600, B115200, B230400, B460800, and B921600.

Implementations are encouraged to propose additional interfaces which will make it possible to set and query a wider range of speeds than just those enumerated by the constants beginning with B. If a set of common interfaces emerges between several implementations, a future version of this standard will likely add those interfaces.

Issue History

Date Modified Username Field Change
2025-03-21 22:44 hpa New Issue
2025-03-27 15:56 nick Note Added: 0007135
2025-03-27 15:57 nick Status New => Resolved
2025-03-27 15:57 nick Resolution Open => Accepted As Marked
2025-03-27 15:57 nick Interp Status => ---
2025-03-27 15:57 nick Final Accepted Text => see 0001916:0007135
2025-03-27 15:58 nick Tag Attached: tc1-2024