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
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363511

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);
}