Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Feb 2017 16:46:57 +0000 (UTC)
From:      "Jonathan T. Looney" <jtl@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r313447 - in head/sys: dev/acpica x86/x86
Message-ID:  <201702081646.v18Gkvfr056123@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jtl
Date: Wed Feb  8 16:46:57 2017
New Revision: 313447
URL: https://svnweb.freebsd.org/changeset/base/313447

Log:
  Ensure the idle thread's loop services interrupts in a timely way when
  using the ACPI C1/mwait sleep method.
  
  Previously, the mwait instruction would return when an interrupt was
  pending; however, the idle loop did not actually enable interrupts when
  this occurred. This led to a situation where the idle loop could quickly
  spin through the C1/mwait sleep method a number of times when an interrupt
  was pending. (Eventually, the situation corrected itself when something
  other than an interrupt triggered the idle loop to either enable interrupts
  or schedule another thread.)
  
  Reviewed by:	kib, imp (earlier version)
  Input from:	jhb
  MFC after:	1 week
  Sponsored by:	Netflix

Modified:
  head/sys/dev/acpica/acpi_cpu.c
  head/sys/x86/x86/cpu_machdep.c

Modified: head/sys/dev/acpica/acpi_cpu.c
==============================================================================
--- head/sys/dev/acpica/acpi_cpu.c	Wed Feb  8 16:07:59 2017	(r313446)
+++ head/sys/dev/acpica/acpi_cpu.c	Wed Feb  8 16:46:57 2017	(r313447)
@@ -1158,6 +1158,9 @@ acpi_cpu_idle(sbintime_t sbt)
 	end_time = ((cpu_ticks() - cputicks) << 20) / cpu_tickrate();
 	if (curthread->td_critnest == 0)
 		end_time = min(end_time, 500000 / hz);
+	/* acpi_cpu_c1() returns with interrupts enabled. */
+	if (cx_next->do_mwait)
+	    ACPI_ENABLE_IRQS();
 	sc->cpu_prev_sleep = (sc->cpu_prev_sleep * 3 + end_time) / 4;
 	return;
     }

Modified: head/sys/x86/x86/cpu_machdep.c
==============================================================================
--- head/sys/x86/x86/cpu_machdep.c	Wed Feb  8 16:07:59 2017	(r313446)
+++ head/sys/x86/x86/cpu_machdep.c	Wed Feb  8 16:46:57 2017	(r313447)
@@ -129,6 +129,14 @@ acpi_cpu_c1(void)
 	__asm __volatile("sti; hlt");
 }
 
+/*
+ * Use mwait to pause execution while waiting for an interrupt or
+ * another thread to signal that there is more work.
+ *
+ * NOTE: Interrupts will cause a wakeup; however, this function does
+ * not enable interrupt handling. The caller is responsible to enable
+ * interrupts.
+ */
 void
 acpi_cpu_idle_mwait(uint32_t mwait_hint)
 {



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