]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
opensolaris cyclic: fix deadlock and make a little bit closer to upstream
authorAndriy Gapon <avg@FreeBSD.org>
Tue, 7 Dec 2010 12:25:26 +0000 (12:25 +0000)
committerAndriy Gapon <avg@FreeBSD.org>
Tue, 7 Dec 2010 12:25:26 +0000 (12:25 +0000)
commit58f61ce4eb96992afa1473654f6e2c6d9d1d10cd
tree958ede8a91a8a157a38b71d77c46580a6b2415a5
parent0f0170e66aa5137d949705375c22c85b0e6192ba
opensolaris cyclic: fix deadlock and make a little bit closer to upstream

The dealock was caused in the following way:
- thread T1 on CPU C1 holds a spin mutex, IPIs CPU C2 and waits for the
  IPI to be handled
- C2 executes timer interrupt filter, thus has interrupts disabled, and
  gets blocked on the spin mutex held by T1
The problem seems to have been introduced by simplifications made to
OpenSolaris code during porting.
The problem is fixed by reorganizing the code to more closely resemble
the upstream version.  Interrupt filter (cyclic_fire) now doesn't
acquire any locks, all per-CPU data accesses are performed on a
target CPU with preemption and interrupts disabled thus precluding
concurrent access to the data.
cyp_mtx spin mutex is used to disable preemtion and interrupts; it's not
used for classical mutual exclusion, because xcall already serializes
calls to a CPU.  It's an emulation of OpenSolaris
cyb_set_level(CY_HIGH_LEVEL) call, the spin mutexes could probably be
reduced to just a spinlock_enter()/_exit() pair.

Diff with upstream version is now reduced by ~500 lines, however it still
remains quite large - many things that are not needed (at the moment) or
are irrelevant on FreeBSD were simply ripped out during porting.
Examples of such things:
- support for CPU onlining/offlining
- support for suspend/resume
- support for running callouts at soft interrupt levels
- support for callout rebinding from CPU to CPU
- support for CPU partitions

Tested by: Artem Belevich <fbsdlist@src.cx>
MFC after: 3 weeks
X-MFC with: r216252
sys/cddl/compat/opensolaris/sys/cyclic_impl.h
sys/cddl/dev/cyclic/cyclic.c