DragonFly kernel List (threaded) for 2011-10
[
Date Prev][Date Next]
[
Thread Prev][Thread Next]
[
Date Index][
Thread Index]
An idea for spin_lock_contested()
Hi,
Currently spin_lock_quick() bumps td->td_critcount on entry, disabling
preemption throughout an entire spinlocked cycle. This makes sense --
the preempting thread might try to take a spinlock the preempted
thread held, which would lead to deadlock. It might be nice to allow
preemption while waiting for a spinlock, however.
Something like:
--gd->gd_curthread->td_critcount;
for (;;) {
if (spin->counta == 1)
continue;
++gd->gd_curthread->td_critcount;
cpu_ccfence();
if (atomic_swap_int(&spin->counta, 1) == 0)
break;
--gd->gd_curthread->td_critcount;
if((++i & 0x7F) == 0x7F) {
++spin->countb;
if (spin_indefinite_check(spin, &info))
break;
}
}
for spin_lock_contested() would allow preemption while waiting for a spinlock.
Preemption would still not happen if you held another spinlock, as
that lock bumped td_critcount for its entire held section, so
deadlocks against the preempted thread wouldn't happen.
Thoughts?
--vs;
[
Date Prev][Date Next]
[
Thread Prev][Thread Next]
[
Date Index][
Thread Index]