Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:07:47 -0000
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r346643 - head/sys/x86/x86
Message-ID:  <201904241824.x3OIONL2007617@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Wed Apr 24 18:24:22 2019
New Revision: 346643
URL: https://svnweb.freebsd.org/changeset/base/346643

Log:
  x86: Halt non-BSP CPUs on panic IPI_STOP
  
  We may need the BSP to reboot, but we don't need any AP CPU that isn't the
  panic thread.  Any CPU landing in this routine during panic isn't the panic
  thread, so we can just detect !BSP && panic and shut down the logical core.
  
  The savings can be demonstrated in a bhyve guest with multiple cores; before
  this change, N guest threads would spin at 100% CPU.  After this change,
  only one or two threads spin (depending on if the panicing CPU was the BSP
  or not).
  
  Konstantin points out that this may break any future patches which allow
  switching ddb(4) CPUs after panic and examining CPU-local state that cannot
  be inspected remotely.  In the event that such a mechanism is incorporated,
  this behavior could be made configurable by tunable/sysctl.
  
  Reviewed by:	kib
  Sponsored by:	Dell EMC Isilon
  Differential Revision:	https://reviews.freebsd.org/D20019

Modified:
  head/sys/x86/x86/mp_x86.c

Modified: head/sys/x86/x86/mp_x86.c
==============================================================================
--- head/sys/x86/x86/mp_x86.c	Wed Apr 24 17:30:50 2019	(r346642)
+++ head/sys/x86/x86/mp_x86.c	Wed Apr 24 18:24:22 2019	(r346643)
@@ -1406,8 +1406,17 @@ cpustop_handler(void)
 	CPU_SET_ATOMIC(cpu, &stopped_cpus);
 
 	/* Wait for restart */
-	while (!CPU_ISSET(cpu, &started_cpus))
-	    ia32_pause();
+	while (!CPU_ISSET(cpu, &started_cpus)) {
+		ia32_pause();
+
+		/*
+		 * Halt non-BSP CPUs on panic -- we're never going to need them
+		 * again, and might as well save power / release resources
+		 * (e.g., overprovisioned VM infrastructure).
+		 */
+		while (__predict_false(!IS_BSP() && panicstr != NULL))
+			halt();
+	}
 
 	cpustop_handler_post(cpu);
 }





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