From owner-p4-projects@FreeBSD.ORG Fri Aug 24 17:50:00 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E2C0916A41B; Fri, 24 Aug 2007 17:49:59 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8F44D16A418 for ; Fri, 24 Aug 2007 17:49:59 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 8022513C458 for ; Fri, 24 Aug 2007 17:49:59 +0000 (UTC) (envelope-from cnst@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l7OHnxw4017881 for ; Fri, 24 Aug 2007 17:49:59 GMT (envelope-from cnst@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l7OHnxV5017878 for perforce@freebsd.org; Fri, 24 Aug 2007 17:49:59 GMT (envelope-from cnst@FreeBSD.org) Date: Fri, 24 Aug 2007 17:49:59 GMT Message-Id: <200708241749.l7OHnxV5017878@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to cnst@FreeBSD.org using -f From: "Constantine A. Murenin" To: Perforce Change Reviews Cc: Subject: PERFORCE change 125633 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Aug 2007 17:50:00 -0000 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 -__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 #include @@ -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