Author: mjg
Date: Tue Jul 28 07:05:49 2020
New Revision: 363634
URL: https://svnweb.freebsd.org/changeset/base/363634

Log:
  MFC r363511:
  
      Do a lockless check in kthread_suspend_check

Modified:
  stable/12/sys/kern/kern_kthread.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/kern_kthread.c
==============================================================================
--- stable/12/sys/kern/kern_kthread.c   Tue Jul 28 07:04:46 2020        
(r363633)
+++ stable/12/sys/kern/kern_kthread.c   Tue Jul 28 07:05:49 2020        
(r363634)
@@ -444,12 +444,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);
        }
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to