An idea for spin_lock_contested()

看板DFBSD_kernel作者時間14年前 (2011/11/10 10:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
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;
文章代碼(AID): #1EkpUlxx (DFBSD_kernel)
文章代碼(AID): #1EkpUlxx (DFBSD_kernel)