svn commit: r363634 - stable/12/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Tue Jul 28 07:05:50 UTC 2020


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


More information about the svn-src-all mailing list