Commit 6e94dbc7 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman
Browse files

tty: cumulate and document tty_struct::flow* members



Group the flow flags under a single struct called flow. The new struct
contains 'stopped' and 'tco_stopped' bools which used to be bits in a
bitfield. The struct also contains the lock protecting them to
potentially share the same cache line.

Note that commit c545b66c (tty: Serialize tcflow() with other tty
flow control changes) added a padding to the original bitfield. It was
for the bitfield to occupy a whole 64b word to avoid interferring stores
on Alpha (cannot we evaporate this arch with weird implications to C
code yet?). But it doesn't work as expected as the padding
(tty_struct::unused) is aligned to a 8B boundary too and occupies some
bytes from the next word.

So make it reliable by:
1) setting __aligned of the struct -- that aligns the start, and
2) making 'unsigned long unused[0]' as the last member of the struct --
   pads the end.

This is also the perfect time to start the documentation of tty_struct
where all this lives. So we start by documenting what these bools
actually serve for. And why we do all the alignment dances. Only the few
up-to-date information from the Theodore's comment made it into this new
Kerneldoc comment.

Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>
Link: https://lore.kernel.org/r/20210505091928.22010-13-jslaby@suse.cz


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0f3dcf3b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -69,9 +69,9 @@ There are debugfs parameters provided for serial communication.

  - 0x01 - tty->warned is on.
  - 0x04 - tty->packed is on.
  - 0x08 - tty->flow_stopped is on.
  - 0x08 - tty->flow.tco_stopped is on.
  - 0x10 - tty->hw_stopped is on.
  - 0x20 - tty->stopped is on.
  - 0x20 - tty->flow.stopped is on.

* last_tx_msg: Binary blob Prints the last transmitted frame.

+4 −4
Original line number Diff line number Diff line
@@ -985,7 +985,7 @@ static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty)
	else
#endif
	{
		if (tty && (tty->stopped || tty->hw_stopped)) {
		if (tty && (tty->flow.stopped || tty->hw_stopped)) {
			tx_stop(info);
			return;
		}
@@ -1005,7 +1005,7 @@ static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty)
		if (!info->tx_active)
			return;
	} else {
		if (tty && (tty->stopped || tty->hw_stopped)) {
		if (tty && (tty->flow.stopped || tty->hw_stopped)) {
			tx_stop(info);
			return;
		}
@@ -1525,7 +1525,7 @@ static void mgslpc_flush_chars(struct tty_struct *tty)
	if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_chars"))
		return;

	if (info->tx_count <= 0 || tty->stopped ||
	if (info->tx_count <= 0 || tty->flow.stopped ||
	    tty->hw_stopped || !info->tx_buf)
		return;

@@ -1594,7 +1594,7 @@ static int mgslpc_write(struct tty_struct * tty,
		ret += c;
	}
start:
	if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
	if (info->tx_count && !tty->flow.stopped && !tty->hw_stopped) {
		spin_lock_irqsave(&info->lock, flags);
		if (!info->tx_active)
			tx_start(info, tty);
+1 −1
Original line number Diff line number Diff line
@@ -439,7 +439,7 @@ static void sdio_uart_transmit_chars(struct sdio_uart_port *port)
	tty = tty_port_tty_get(&port->port);

	if (tty == NULL || !kfifo_len(xmit) ||
				tty->stopped || tty->hw_stopped) {
				tty->flow.stopped || tty->hw_stopped) {
		sdio_uart_stop_tx(port);
		tty_kref_put(tty);
		return;
+2 −2
Original line number Diff line number Diff line
@@ -87,8 +87,8 @@ static void ldisc_tx_wakeup(struct tty_struct *tty);
static inline void update_tty_status(struct ser_device *ser)
{
	ser->tty_status =
		ser->tty->stopped << 5 |
		ser->tty->flow_stopped << 3 |
		ser->tty->flow.stopped << 5 |
		ser->tty->flow.tco_stopped << 3 |
		ser->tty->packet << 2;
}
static inline void debugfs_init(struct ser_device *ser, struct tty_struct *tty)
+1 −1
Original line number Diff line number Diff line
@@ -1640,7 +1640,7 @@ tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
	int i_msg, i;

	spin_lock_bh(&tp->view.lock);
	for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) {
	for (i_msg = 0; !tty->flow.stopped && i_msg < count; i_msg++) {
		if (tp->esc_state != 0) {
			/* Continue escape sequence. */
			tty3270_escape_sequence(tp, buf[i_msg]);
Loading