]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
fix a thread preemption regression in schedulers introduced in r270423
authorAndriy Gapon <avg@FreeBSD.org>
Thu, 19 Jan 2017 18:46:41 +0000 (18:46 +0000)
committerAndriy Gapon <avg@FreeBSD.org>
Thu, 19 Jan 2017 18:46:41 +0000 (18:46 +0000)
commitad9dadc437ff470f794ce2fd0cd1714d69d725d3
treef7bc2af646648bba4dd9de30d47ac88d537c4783
parent1c07d69bc22d7176d38cdb71201f282578fc7391
fix a thread preemption regression in schedulers introduced in r270423

Commit r270423 fixed a regression in sched_yield() that was introduced
in earlier changes.  Unfortunately, at the same time it introduced an
new regression.  The problem is that SWT_RELINQUISH (6), like all other
SWT_* constants and unlike SW_* flags, is not a bit flag.  So, (flags &
SWT_RELINQUISH) is true in cases where that was not really indended,
for example, with SWT_OWEPREEMPT (2) and SWT_REMOTEPREEMPT (11).

A straight forward fix would be to use (flags & SW_TYPE_MASK) ==
SWT_RELINQUISH, but my impression is that the switch types are designed
mostly for gathering statistics, not for influencing scheduling
decisions.

So, I decided that it would be better to check for SW_PREEMPT flag
instead.  That's also the same flag that was checked before r239157.
I double-checked how that flag is used and I am confident that the flag
is set only in the places where we really have the preemption:
- critical_exit + td_owepreempt
- sched_preempt in the ULE scheduler
- sched_preempt in the 4BSD scheduler

Reviewed by: kib, mav
MFC after: 4 days
Sponsored by: Panzura
Differential Revision: https://reviews.freebsd.org/D9230
sys/kern/sched_4bsd.c
sys/kern/sched_ule.c