kernel - Fix very annoying lockup (SMP)
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 11 Jan 2011 22:36:24 +0000 (14:36 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 11 Jan 2011 22:40:30 +0000 (14:40 -0800)
commitcfaeae2ac9bf2ac78367308f7070d4a11c1680d2
tree158d47480b943484af068a0e55f15253b5fc7aa6
parent72d6a027d96b30c52d242ce162021efcecfe2bb9
kernel - Fix very annoying lockup (SMP)

* Fix an extremely annoying lockup that took a week+ to find.  The cpusync
  code is rather fragile and any for (;;) or while (1) style loops in the
  kernel can trip it up and cause a deadlock.  These loops are careful to
  call lwkt_process_ipiq() to ensure that cpusync processing occurs.

  However, there is a race in the LWKT thread migration code where a thread
  deschedules itself on one cpu and schedules itself on another via a remote
  ipi.  The target cpu expects the thread's TDF_RUNNING state to clear and
  will loop until that happens.

  An IPI could sneak itself into the deschedule/lwkt_switch() path and
  deadlock against a cpusync, preventing the thread from leaving the
  TDF_RUNNING state.

  The solution is to ensure that lwkt_process_ipiq() is *NOT* run in
  the lwkt_switch() path if the calling thread has descheduled itself.

* The original bug could be reproduced by running blogbench in one window
  and a while (1) ps axl shell script in another.

* Add DEBUG_PUSH_INFO(msg)/DEBUG_POP_INFO() macros which record (msg)
  in the globaldata structure as a debugging aid.

* Remove unused platform/pc64/x86_64/systimer.c file.  The entire contents
  of this file was #ifdef'd out and its functionality is handled elsewhere
  by the lapic timer code.

* #if 0 out numerous debugging bits but don't remove the code because it
  is extremely useful for finding lockup conditions.
12 files changed:
sys/kern/kern_ktr.c
sys/kern/lwkt_ipiq.c
sys/kern/lwkt_thread.c
sys/platform/pc32/apic/mpapic.c
sys/platform/pc32/i386/pmap.c
sys/platform/pc32/i386/pmap_inval.c
sys/platform/pc64/apic/mpapic.c
sys/platform/pc64/conf/files
sys/platform/pc64/x86_64/pmap.c
sys/platform/pc64/x86_64/pmap_inval.c
sys/platform/pc64/x86_64/systimer.c [deleted file]
sys/sys/globaldata.h