Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jul 2020 07:05:49 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r363634 - stable/12/sys/kern
Message-ID:  <202007280705.06S75nUG094370@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007280705.06S75nUG094370>