kernel - Separate inherited mplocks from td_mplocks and fix a gettoken bug
authorMatthew Dillon <dillon@apollo.backplane.com>
Mon, 30 Aug 2010 19:29:06 +0000 (12:29 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Mon, 30 Aug 2010 19:29:06 +0000 (12:29 -0700)
commit3933a3ab606b81b57423112e261ca5426deac2e6
tree9520b386351cd4a70446ef9f9133b1ebcb5b26d6
parentcda2599a167e4afae7e1416d138b7eb795656c50
kernel - Separate inherited mplocks from td_mplocks and fix a gettoken bug

* Separate out td_mpcount into td_xpcount and td_mpcount.  td_xpcount
  is an inherited mpcount.  A preempting thread inherits the mpcount
  on the thread being preempted until it switches out to guarantee
  that the mplock remains atomic through the preemption (as expected
  by the poor thread that got preempted).

* Fix a serious but hard to reproduce bug in lwkt_gettoken().  This
  function marks the token reference as being MPSAFE if td_mpcount
  is non-zero even when the token is not a MPSAFE token.

  However, until this patch td_mpcount also included inherited mpcounts
  when one thread preempts another and the inherited mpcounts could
  go away if the thread blocks or switches, leaving the token unprotected.

* Fix a less serious bug where a new token reference was being populated
  prior to td_toks_stop being incremented, and where an existing token
  reference was being depopulated after td_toks_stop is decremented.
  Nothing can race us but switch around the index increment/decrement
  to protect the slot being operated upon.

* Add a ton of assertions in the interrupt, trap, and syscall paths
  To assert that the mplock, number of tokens, and critcount remain
  unchanged across driver and other calls.
sys/kern/kern_intr.c
sys/kern/kern_mplock.c
sys/kern/kern_shutdown.c
sys/kern/lwkt_thread.c
sys/kern/lwkt_token.c
sys/platform/pc32/i386/trap.c
sys/platform/pc64/x86_64/trap.c
sys/platform/vkernel/i386/trap.c
sys/platform/vkernel64/x86_64/trap.c
sys/sys/mplock2.h
sys/sys/thread.h