Don't place threads on the run queue after waking up other CPUs.
authorjhb <jhb@FreeBSD.org>
Sat, 12 Nov 2016 00:14:13 +0000 (00:14 +0000)
committerjhb <jhb@FreeBSD.org>
Sat, 12 Nov 2016 00:14:13 +0000 (00:14 +0000)
commit2fd562f38da05d945d5297f9b87caedc1c97f4c4
tree4d0364a275fa2cc875aa3035dd1ab4495741867e
parentc090f6f0c6aceecac4e8d3b19aa9d65f9f8b913f
Don't place threads on the run queue after waking up other CPUs.

The other CPU might resume and see a still-empty runq and go back to
sleep before sched_add() adds the thread to the runq.  This results
in a lost wakeup and a potential hang if the system is otherwise
completely idle.

The race originated due to a micro-optimization (my fault) in 4BSD in
that it avoided putting a thread on the run queue if the scheduler was
going to preempt to the new thread.  To avoid complexity while fixing
this race, just drop this optimization.  4BSD now always sets the
"owepreempt" flag when a preemption is warranted and defers the actual
preemption to the thread_unlock of the caller the same as ULE.

MFC after: 2 weeks
Sponsored by: Netflix
sys/kern/sched_4bsd.c