Do a lockless check in kthread_suspend_check

Otherwise an idle system running lockstat sleep 10 reports contention on
process lock comming from bufdaemon.

While here fix a style nit.
This commit is contained in:
Mateusz Guzik 2020-07-25 07:14:33 +00:00
parent d873a521ca
commit bf71b96c69

View File

@ -441,12 +441,15 @@ kthread_suspend_check(void)
panic("%s: curthread is not a valid kthread", __func__);
/*
* As long as the double-lock protection is used when accessing the
* TDF_KTH_SUSP flag, synchronizing the read operation via proc mutex
* is fine.
* Setting the TDF_KTH_SUSP flag is protected by process lock.
*
* Do an unlocked read first to avoid serializing with all other threads
* in the common case of not suspending.
*/
if ((td->td_flags & TDF_KTH_SUSP) == 0)
return;
PROC_LOCK(p);
while (td->td_flags & TDF_KTH_SUSP) {
while ((td->td_flags & TDF_KTH_SUSP) != 0) {
wakeup(&td->td_flags);
msleep(&td->td_flags, &p->p_mtx, PPAUSE, "ktsusp", 0);
}