Author: mjg
Date: Sat Jul 25 07:14:33 2020
New Revision: 363511
URL: https://svnweb.freebsd.org/changeset/base/363511

Log:
  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.

Modified:
  head/sys/kern/kern_kthread.c

Modified: head/sys/kern/kern_kthread.c
==============================================================================
--- head/sys/kern/kern_kthread.c        Sat Jul 25 06:32:23 2020        
(r363510)
+++ head/sys/kern/kern_kthread.c        Sat Jul 25 07:14:33 2020        
(r363511)
@@ -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);
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to