Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: add throttle/unthrottle helpers

Something Arjan suggested which allows us to clean up the code nicely

Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alan Cox and committed by
Linus Torvalds
39c2e60f 8cd64518

+31 -25
+1 -3
drivers/bluetooth/hci_ldisc.c
··· 370 370 hu->hdev->stat.byte_rx += count; 371 371 spin_unlock(&hu->rx_lock); 372 372 373 - if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 374 - tty->ops->unthrottle) 375 - tty->ops->unthrottle(tty); 373 + tty_unthrottle(tty); 376 374 } 377 375 378 376 static int hci_uart_register_dev(struct hci_uart *hu)
+4 -10
drivers/char/n_tty.c
··· 147 147 148 148 static void check_unthrottle(struct tty_struct *tty) 149 149 { 150 - if (tty->count && 151 - test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 152 - tty->ops->unthrottle) 153 - tty->ops->unthrottle(tty); 150 + if (tty->count) 151 + tty_unthrottle(tty); 154 152 } 155 153 156 154 /** ··· 980 982 * mode. We don't want to throttle the driver if we're in 981 983 * canonical mode and don't have a newline yet! 982 984 */ 983 - if (tty->receive_room < TTY_THRESHOLD_THROTTLE) { 984 - /* check TTY_THROTTLED first so it indicates our state */ 985 - if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && 986 - tty->ops->throttle) 987 - tty->ops->throttle(tty); 988 - } 985 + if (tty->receive_room < TTY_THRESHOLD_THROTTLE) 986 + tty_throttle(tty); 989 987 } 990 988 991 989 int is_ignored(int sig)
+16
drivers/char/tty_ioctl.c
··· 67 67 68 68 EXPORT_SYMBOL(tty_driver_flush_buffer); 69 69 70 + void tty_throttle(struct tty_struct *tty) 71 + { 72 + /* check TTY_THROTTLED first so it indicates our state */ 73 + if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && 74 + tty->ops->throttle) 75 + tty->ops->throttle(tty); 76 + } 77 + EXPORT_SYMBOL(tty_throttle); 78 + 79 + void tty_unthrottle(struct tty_struct *tty) 80 + { 81 + if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 82 + tty->ops->unthrottle) 83 + tty->ops->unthrottle(tty); 84 + } 85 + EXPORT_SYMBOL(tty_unthrottle); 70 86 71 87 /** 72 88 * tty_wait_until_sent - wait for I/O to finish
+1 -3
drivers/net/hamradio/6pack.c
··· 491 491 sixpack_decode(sp, buf, count1); 492 492 493 493 sp_put(sp); 494 - if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 495 - && tty->ops->unthrottle) 496 - tty->ops->unthrottle(tty); 494 + tty_unthrottle(tty); 497 495 } 498 496 499 497 /*
+1 -3
drivers/net/hamradio/mkiss.c
··· 936 936 } 937 937 938 938 mkiss_put(ax); 939 - if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 940 - && tty->ops->unthrottle) 941 - tty->ops->unthrottle(tty); 939 + tty_unthrottle(tty); 942 940 } 943 941 944 942 /*
+1 -3
drivers/net/ppp_async.c
··· 361 361 if (!skb_queue_empty(&ap->rqueue)) 362 362 tasklet_schedule(&ap->tsk); 363 363 ap_put(ap); 364 - if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 365 - && tty->ops->unthrottle) 366 - tty->ops->unthrottle(tty); 364 + tty_unthrottle(tty); 367 365 } 368 366 369 367 static void
+1 -3
drivers/net/ppp_synctty.c
··· 401 401 if (!skb_queue_empty(&ap->rqueue)) 402 402 tasklet_schedule(&ap->tsk); 403 403 sp_put(ap); 404 - if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 405 - && tty->ops->unthrottle) 406 - tty->ops->unthrottle(tty); 404 + tty_unthrottle(tty); 407 405 } 408 406 409 407 static void
+2
include/linux/tty.h
··· 303 303 extern int tty_chars_in_buffer(struct tty_struct *tty); 304 304 extern int tty_write_room(struct tty_struct *tty); 305 305 extern void tty_driver_flush_buffer(struct tty_struct *tty); 306 + extern void tty_throttle(struct tty_struct *tty); 307 + extern void tty_unthrottle(struct tty_struct *tty); 306 308 307 309 extern int is_current_pgrp_orphaned(void); 308 310 extern struct pid *tty_get_pgrp(struct tty_struct *tty);
+4
include/linux/tty_driver.h
··· 100 100 * This routine notifies the tty driver that input buffers for 101 101 * the line discipline are close to full, and it should somehow 102 102 * signal that no more characters should be sent to the tty. 103 + * 104 + * Optional: Always invoke via tty_throttle(); 103 105 * 104 106 * void (*unthrottle)(struct tty_struct * tty); 105 107 * ··· 109 107 * that characters can now be sent to the tty without fear of 110 108 * overrunning the input buffers of the line disciplines. 111 109 * 110 + * Optional: Always invoke via tty_unthrottle(); 111 + * 112 112 * void (*stop)(struct tty_struct *tty); 113 113 * 114 114 * This routine notifies the tty driver that it should stop