Make tsleep/wakeup() MP SAFE for kernel threads and get us closer to
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 14 Nov 2005 18:50:18 +0000 (18:50 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 14 Nov 2005 18:50:18 +0000 (18:50 +0000)
commit344ad853388ea34261cc85d903fa9e4cb0ef2198
tree77a4400fd6e03a26439ff62d6351693b94ab948e
parent8c0bb9813a6cc65dc1835a4cf45af73603bed765
Make tsleep/wakeup() MP SAFE for kernel threads and get us closer to
making it MP SAFE for user processes.  Currently the code is operating
under the rule that access to a thread structure requires cpu locality of
reference, and access to a proc structure requires the Big Giant Lock.  The
two are not mutually exclusive so, for example, tsleep/wakeup on a proc
needs both cpu locality of reference *AND* the BGL.  This was true with the
old tsleep/wakeup and has now been documented.

The new tsleep/wakeup algorithm is quite simple in concept.  Each cpu has its
own ident based hash table and each hash slot has a cpu mask which tells
wakeup() which cpu's might have the ident.  A wakeup iterates through all
candidate cpus simply by chaining the IPI message through them until either
all candidate cpus have been serviced, or (with wakeup_one()) the requested
number of threads have been woken up.

Other changes made in this patch set:

* The sense of P_INMEM has been reversed.  It is now P_SWAPPEDOUT.  Also,
  P_SWAPPING, P_SWAPINREQ are not longer relevant and have been removed.

* The swapping code has been cleaned up and seriously revamped.  The new
  swapin code staggers swapins to give the VM system a chance to respond
  to new conditions.  Also some lwp-related fixes were made (more
  p_rtprio vs lwp_rtprio confusion).

* As mentioned above, tsleep/wakeup have been rewritten.  The process
  p_stat no longer does crazy transitions from SSLEEP to SSTOP.  There is
  now only SSLEEP and SSTOP is synthesized from P_SWAPPEDOUT for userland
  consumpion.  Additionally, tsleep() with PCATCH will NO LONGER STOP THE
  PROCESS IN THE TSLEEP CALL.  Instead, the actual stop is deferred until
  the process tries to return to userland.  This removes all remaining cases
  where a stopped process can hold a locked kernel resource.

* A P_BREAKTSLEEP flag has been added.  This flag indicates when an event
  occurs that is allowed to break a tsleep with PCATCH.  All the weird
  undocumented setrunnable() rules have been removed and replaced with a
  very simple algorithm based on this flag.

* Since the UAREA is no longer swapped, we no longer faultin() on PHOLD().
  This also incidently fixes the 'ps' command's tendancy to try to swap
  all processes back into memory.

* speedup_syncer() no longer does hackish checks on proc0's tsleep channel
  (td_wchan).

* Userland scheduler acquisition and release has now been tightened up and
  KKASSERT's have been added (one of the bugs Stefan found was related
  to an improper lwkt_schedule() that was found by one of the new assertions).
  We also have added other assertions related to expected conditions.

* A serious race in pmap_release_free_page() has been corrected.  We
  no longer couple the object generation check with a failed
  pmap_release_free_page() call.  Instead the two conditions are checked
  independantly.  We no longer loop when pmap_release_free_page() succeeds
  (it is unclear how that could ever have worked properly).

Major testing by: Stefan Krueger <skrueger@meinberlikomm.de>
46 files changed:
bin/ps/print.c
bin/ps/ps.1
bin/ps/ps.c
sys/dev/raid/vinum/vinumdaemon.c
sys/emulation/linux/i386/linux_ptrace.c
sys/emulation/posix4/ksched.c
sys/emulation/svr4/svr4_misc.c
sys/i386/i386/db_trace.c
sys/i386/i386/pmap.c
sys/i386/i386/procfs_machdep.c
sys/i386/i386/trap.c
sys/kern/init_main.c
sys/kern/kern_exit.c
sys/kern/kern_fork.c
sys/kern/kern_proc.c
sys/kern/kern_resource.c
sys/kern/kern_sched.c
sys/kern/kern_sig.c
sys/kern/kern_synch.c
sys/kern/lwkt_thread.c
sys/kern/sys_generic.c
sys/kern/sys_process.c
sys/kern/tty.c
sys/kern/usched_bsd4.c
sys/kern/vfs_sync.c
sys/netproto/smb/smb_subr.c
sys/platform/pc32/i386/db_trace.c
sys/platform/pc32/i386/pmap.c
sys/platform/pc32/i386/procfs_machdep.c
sys/platform/pc32/i386/trap.c
sys/sys/kernel.h
sys/sys/proc.h
sys/sys/systm.h
sys/sys/thread.h
sys/vfs/procfs/procfs_ctl.c
sys/vfs/procfs/procfs_dbregs.c
sys/vfs/procfs/procfs_fpregs.c
sys/vfs/procfs/procfs_regs.c
sys/vfs/procfs/procfs_status.c
sys/vm/pmap.h
sys/vm/vm_fault.c
sys/vm/vm_glue.c
sys/vm/vm_meter.c
sys/vm/vm_pageout.c
usr.bin/systat/pigs.c
usr.bin/top/machine.c