Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Aug 2007 17:49:59 GMT
From:      "Constantine A. Murenin" <cnst@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 125633 for review
Message-ID:  <200708241749.l7OHnxV5017878@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125633

Change 125633 by cnst@dale on 2007/08/24 17:49:52

	integrate coretemp changes by des, rpaulo and cnst from CVS
	
	
	Screenshot from `systat -sensors` for my Intel Core 2 Duo E4300:
	
	Sensor                            Value      Status       Description
	cpu0.temp0                   29.00 degC
	cpu1.temp0                   30.00 degC

Affected files ...

.. //depot/projects/soc2007/cnst-sensors/sys.dev.coretemp/coretemp.c#5 integrate

Differences ...

==== //depot/projects/soc2007/cnst-sensors/sys.dev.coretemp/coretemp.c#5 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/coretemp/coretemp.c,v 1.1 2007/08/15 19:26:02 des Exp $
+ * $FreeBSD: src/sys/dev/coretemp/coretemp.c,v 1.2 2007/08/23 10:53:03 des Exp $
  *
  */
 
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/coretemp/coretemp.c,v 1.1 2007/08/15 19:26:02 des Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/coretemp/coretemp.c,v 1.2 2007/08/23 10:53:03 des Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -98,7 +98,7 @@
 	/* Make sure we're not being doubly invoked. */
 	if (device_find_child(parent, "coretemp", -1) != NULL)
 		return;
-	
+
 	/* Check that CPUID is supported and the vendor is Intel.*/
 	if (cpu_high == 0 || strcmp(cpu_vendor, "GenuineIntel"))
 		return;
@@ -140,13 +140,11 @@
 	int cpu_mask;
 
 	sc->sc_dev = dev;
-
 	pdev = device_get_parent(dev);
-
-	cpu_model  = (cpu_id >> 4) & 15;
+	cpu_model = (cpu_id >> 4) & 15;
 	/* extended model */
 	cpu_model += ((cpu_id >> 16) & 0xf) << 4;
-	cpu_mask   = cpu_id & 15;
+	cpu_mask = cpu_id & 15;
 
 	/*
 	 * Check for errata AE18.
@@ -154,15 +152,13 @@
 	 *  updating upon returning from C3/C4 state."
 	 *
 	 * Adapted from the Linux coretemp driver.
- 	 */
+	 */
 	if (cpu_model == 0xe && cpu_mask < 0xc) {
 		msr = rdmsr(MSR_BIOS_SIGN);
 		msr = msr >> 32;
 		if (msr < 0x39) {
-			device_printf(dev, "This processor behaves "
-			    "erronously regarding to Intel errata "
-			    "AE18.\nPlease update your BIOS or the "
-			    "CPU microcode.\n");
+			device_printf(dev, "not supported (Intel errata "
+			    "AE18), try updating your BIOS\n");
 			return (ENXIO);
 		}
 	}
@@ -173,13 +169,13 @@
 	 * The if-clause for CPUs having the MSR_IA32_EXT_CONFIG was adapted
 	 * from the Linux coretemp driver.
 	 */
-	if ((cpu_model == 0xf && cpu_mask > 3) || cpu_model == 0xe) {
+	sc->sc_tjmax = 100;
+	if ((cpu_model == 0xf && cpu_mask >= 2) || cpu_model == 0xe) {
 		msr = rdmsr(MSR_IA32_EXT_CONFIG);
-		if ((msr >> 30) & 0x1)
+		if (msr & (1 << 30))
 			sc->sc_tjmax = 85;
-	} else
-		sc->sc_tjmax = 100;
-		
+	}
+
 	/*
 	 * Add hw.sensors.cpuN.temp0 MIB.
 	 */
@@ -211,9 +207,11 @@
 static int
 coretemp_get_temp(device_t dev)
 {
-	uint64_t temp;
+	uint64_t msr;
+	int temp;
 	int cpu = device_get_unit(dev);
 	struct coretemp_softc *sc = device_get_softc(dev);
+	char stemp[16];
 
 	/*
 	 * Bind to specific CPU to read the correct temperature.
@@ -237,40 +235,48 @@
 	 * The temperature is computed by subtracting the temperature
 	 * reading by Tj(max).
 	 */
-	temp = rdmsr(MSR_THERM_STATUS);
+	msr = rdmsr(MSR_THERM_STATUS);
+
+	thread_lock(curthread);
+	sched_unbind(curthread);
+	thread_unlock(curthread);
 
 	/*
 	 * Check for Thermal Status and Thermal Status Log.
 	 */
-	if ((temp & 0x3) == 0x3) 
+	if ((msr & 0x3) == 0x3)
 		device_printf(dev, "PROCHOT asserted\n");
 
 	/*
+	 * Bit 31 contains "Reading valid"
+	 */
+	if (((msr >> 31) & 0x1) == 1) {
+		/*
+		 * Starting on bit 16 and ending on bit 22.
+		 */
+		temp = sc->sc_tjmax - ((msr >> 16) & 0x7f);
+	} else
+		temp = -1;
+
+	/*
 	 * Check for Critical Temperature Status and Critical
 	 * Temperature Log.
+	 * It doesn't really matter if the current temperature is
+	 * invalid because the "Critical Temperature Log" bit will
+	 * tell us if the Critical Temperature has been reached in
+	 * past. It's not directly related to the current temperature.
 	 *
 	 * If we reach a critical level, allow devctl(4) to catch this
 	 * and shutdown the system.
 	 */
-	if (((temp >> 4) & 0x3) == 0x3) {
-		device_printf(dev, "Critical Temperature detected.\n"
-		    "Advising system shutdown.\n");
-		devctl_notify("CPU", "coretemp", "temperature",
-		    "notify=0x1");
+	if (((msr >> 4) & 0x3) == 0x3) {
+		device_printf(dev, "critical temperature detected, "
+		    "suggest system shutdown\n");
+		snprintf(stemp, sizeof(stemp), "%d", temp);
+		devctl_notify("coretemp", "Thermal", stemp, "notify=0xcc");
 	}
 
-	/*
-	 * Bit 31 contains "Reading valid"
-	 */
-	if (((temp >> 31) & 0x1) == 1) {
-		/*
-		 * Starting on bit 16 and ending on bit 22.
-		 */
-		temp = sc->sc_tjmax - ((temp >> 16) & 0x7f);
-		return ((int) temp);
-	}
-
-	return (-1);
+	return (temp);
 }
 
 static void



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