tvtohz() was originally designed for tsleep() and timeout() operations but
authorMatthew Dillon <dillon@dragonflybsd.org>
Wed, 7 Jan 2004 11:07:04 +0000 (11:07 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Wed, 7 Jan 2004 11:07:04 +0000 (11:07 +0000)
commita94976ad1c640675944df907e51150e6a2c779c6
tree4d38c68962b3895b8926e1c03b114099df8ab3d3
parent9a47427ace25a3a72080949635218626b96ba1b0
tvtohz() was originally designed for tsleep() and timeout() operations but
it is also used to time nanosleep() ops.  The problem is that in order to
compensate for the fact that a clock interrupt might occur just after a
thread blocks or registers a timeout, this function effectively added +1
to the returned value plus added another +1 for timeouts that were not
integer multiples if the clock interrupt frequency.

Split tvtohz() into two routines: tvtohz_low() and tvtohz_high().
tvtohz_low() does not do any compensation, tvtohz_high() does.

Add the kern.sleep_hardloop sysctl, which defaults to 0 (off).  If set to
1 this will cause nanosleep() to attempt to time exactly the requested
interval (which could cost more cpu) rather then rounding it off to a
multiple of hz.  If set to 2 nanosleep() will only do the more rigid
timing for requests less then 1 second.   Also change the normal hz-baesd
case to only compensate by +1, not +2, in order to improve accuracy.
16 files changed:
sys/kern/kern_clock.c
sys/kern/kern_event.c
sys/kern/kern_sig.c
sys/kern/kern_synch.c
sys/kern/kern_threads.c
sys/kern/kern_time.c
sys/kern/sys_generic.c
sys/kern/vfs_aio.c
sys/net/bpf.c
sys/netinet/in_rmx.c
sys/netinet6/in6_rmx.c
sys/netproto/ncp/ncp_sock.c
sys/netproto/smb/smb_trantcp.c
sys/sys/signalvar.h
sys/sys/time.h
sys/vfs/smbfs/smbfs_smb.c