freebsd-dev/sys
Ian Lepore f64342e354 Rework tty_drain() to poll the hardware for completion, and restore
drain timeout handling to historical freebsd behavior.

The primary reason for these changes is the need to have tty_drain() call
ttydevsw_busy() at some reasonable sub-second rate, to poll hardware that
doesn't signal an interrupt when the transmit shift register becomes empty
(which includes virtually all USB serial hardware).  Such hardware hangs
in a ttyout wait, because it never gets an opportunity to trigger a wakeup
from the sleep in tty_drain() by calling ttydisc_getc() again, after
handing the last of the buffered data to the hardware.

While researching the history of changes to tty_drain() I stumbled across
some email describing the historical BSD behavior of tcdrain() and close()
on serial ports, and the ability of comcontrol(1) to control timeout
behavior.  Using that and some advice from Bruce Evans as a guide, I've
put together these changes to implement the hardware polling and restore
the historical timeout behaviors...

 - tty_drain() now calls ttydevsw_busy() in a loop at 10 Hz to accomodate
   hardware that requires polling for busy state.

 - The "new historical" behavior for draining during close(2) is retained:
   the drain timeout is "1 second without making any progress".  When the
   1-second timeout expires, if the count of bytes remaining in the tty
   layer buffer is smaller than last time, the timeout is extended for
   another second.  Unfortunately, the same logic cannot be extended all
   the way down to the hardware, because the interface to that layer is a
   simple busy/not-busy indication.

 - Due to the previous point, an application that needs a guarantee that
   all data has been transmitted must use TIOCDRAIN/tcdrain(3) before
   calling close(2).

 - The historical behavior of honoring the drainwait setting for TIOCDRAIN
   (used by tcdrain(3)) is restored.

 - The historical kern.drainwait sysctl to control the global default
   drainwait time is restored, but is now named kern.tty_drainwait.

 - The historical default drainwait timeout of 300 seconds is restored.

 - Handling of TIOCGDRAINWAIT and TIOCSDRAINWAIT ioctls is restored
   (this also makes the comcontrol(1) drainwait verb work again).

 - Manpages are updated to document these behaviors.

Reviewed by:	bde (prior version)
2017-01-12 00:48:06 +00:00
..
amd64 Coalesce TLB shootdowns of global PTEs in pmap_advise() on x86. 2017-01-10 21:52:48 +00:00
arm Use the new sdhci_fdt_gpio helper functions to add full support for FDT 2017-01-09 01:57:51 +00:00
arm64 Migrate e1000 to the IFLIB framework: 2017-01-10 03:23:22 +00:00
boot Use proper prototypes in struct boot_module_t 2017-01-11 20:00:24 +00:00
bsm
cam Do not wait for HA thread shutdown if scheduler is stopped. 2017-01-10 20:16:16 +00:00
cddl Have DTrace handle faults when dereferencing a lock object pointer. 2017-01-11 01:18:06 +00:00
compat Use getsock_cap() instead of fgetsock(). 2017-01-06 04:38:38 +00:00
conf [sdhci] Add ACPI platform support for SDHCI driver 2017-01-11 01:53:54 +00:00
contrib Get rid of a compiler warning which I saw too often. 2017-01-12 00:01:02 +00:00
crypto libmd: add noexec stack annotation in skein_block_asm.s 2017-01-07 19:26:25 +00:00
ddb Enable the use of ^C and ^S/^Q in DDB. 2017-01-12 00:22:36 +00:00
dev Include sys/systm.h for use of bootverbose. Fixes powerpc MPC85XXSPE build. 2017-01-12 00:09:31 +00:00
fs cd9660: fix up compilation on sparc after r311665 2017-01-10 04:17:53 +00:00
gdb
geom Fix logic error in gvinum's gv_set_sd_state() 2017-01-08 17:56:54 +00:00
gnu Add Ingenic X1000 DTS files (unofficial). 2016-11-19 15:03:49 +00:00
i386 Coalesce TLB shootdowns of global PTEs in pmap_advise() on x86. 2017-01-10 21:52:48 +00:00
isa
kern Rework tty_drain() to poll the hardware for completion, and restore 2017-01-12 00:48:06 +00:00
kgssapi
libkern Update r309143 to prevent false sharing. 2016-11-25 17:20:23 +00:00
mips Migrate e1000 to the IFLIB framework: 2017-01-10 03:23:22 +00:00
modules Add acpi_if.h and opt_acpi.h to Makefile to unbreak "make depend" with 2017-01-11 08:43:58 +00:00
net Remove unused mtx_held() macro. 2017-01-09 23:41:10 +00:00
net80211 Fix build without IEEE80211_DEBUG. 2017-01-10 19:28:40 +00:00
netgraph Changes to allow the patching of packets with an offset (and other changes.. see man page) 2016-12-02 10:47:10 +00:00
netinet sysctl net.inet.tcp.hostcache.list in a jail can see connections from other 2017-01-05 17:22:09 +00:00
netinet6 Release the ND6 list lock before making a prefix off-link in nd6_timer(). 2017-01-08 18:46:00 +00:00
netipsec Add direction argument to ipsec_setspidx_inpcb() function. 2017-01-08 12:40:07 +00:00
netnatm
netpfil In dummynet(4), random chunks of memory are casted to struct dn_*, 2017-01-09 20:51:51 +00:00
netsmb
nfs
nfsclient
nfsserver
nlm
ofed
opencrypto Add support for the fpu_kern(9) KPI on arm64. It hooks into the existing 2016-10-20 09:22:10 +00:00
pc98 Add a COMPAT_FREEBSD11 kernel option. 2016-12-09 18:54:12 +00:00
powerpc Force all TOC references in asm to include '@toc' 2017-01-11 02:21:34 +00:00
riscv Disable superpages reservations as we don't have implemented them yet. 2016-11-21 12:00:31 +00:00
rpc
security Audit 'fd' and 'cmd' arguments to fcntl(2), and when generating BSM, 2016-11-22 00:41:24 +00:00
sparc64 sparc64: add atomic_fcmpset 2017-01-10 21:10:20 +00:00
sys Rework tty_drain() to poll the hardware for completion, and restore 2017-01-12 00:48:06 +00:00
teken
tests
tools Replace using of objdump with elfdump 2017-01-10 18:46:40 +00:00
ufs Use type-independent formats for printing nlink_t and ino_t. 2017-01-06 16:59:33 +00:00
vm Remove a redundant use of min(). 2017-01-05 03:13:45 +00:00
x86 xen: fix IPI setup with EARLY_AP_STARTUP 2016-12-22 16:09:44 +00:00
xdr
xen xen: fix IPI setup with EARLY_AP_STARTUP 2016-12-22 16:09:44 +00:00
Makefile