Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Jul 2020 07:14:33 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r363511 - head/sys/kern
Message-ID:  <202007250714.06P7EXHu016497@repo.freebsd.org>

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



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