From owner-p4-projects@FreeBSD.ORG Wed Aug 1 16:07:14 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id F21C416A41F; Wed, 1 Aug 2007 16:07:13 +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 B5E0B16A419 for ; Wed, 1 Aug 2007 16:07:13 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A6BF613C46A for ; Wed, 1 Aug 2007 16:07:13 +0000 (UTC) (envelope-from rpaulo@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 l71G7DYW039609 for ; Wed, 1 Aug 2007 16:07:13 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l71G7DFj039606 for perforce@freebsd.org; Wed, 1 Aug 2007 16:07:13 GMT (envelope-from rpaulo@FreeBSD.org) Date: Wed, 1 Aug 2007 16:07:13 GMT Message-Id: <200708011607.l71G7DFj039606@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rpaulo@FreeBSD.org using -f From: Rui Paulo To: Perforce Change Reviews Cc: Subject: PERFORCE change 124473 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: Wed, 01 Aug 2007 16:07:14 -0000 http://perforce.freebsd.org/chv.cgi?CH=124473 Change 124473 by rpaulo@rpaulo_epsilon on 2007/08/01 16:06:30 Try to guess some CPUs that have Tj(max) == 85. Obtained from: OpenBSD, Linux Affected files ... .. //depot/projects/soc2007/rpaulo-macbook/dev/msrtemp/msrtemp.c#10 edit Differences ... ==== //depot/projects/soc2007/rpaulo-macbook/dev/msrtemp/msrtemp.c#10 (text+ko) ==== @@ -23,7 +23,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/msrtemp/msrtemp.c#9 $ + * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/msrtemp/msrtemp.c#10 $ * */ @@ -52,6 +52,7 @@ struct msrtemp_softc { device_t sc_dev; + int sc_tjmax; struct sysctl_oid *sc_oid; }; @@ -63,7 +64,7 @@ static int msrtemp_attach(device_t dev); static int msrtemp_detach(device_t dev); -static int msrtemp_get_temp(int cpu); +static int msrtemp_get_temp(device_t dev); static int msrtemp_get_temp_sysctl(SYSCTL_HANDLER_ARGS); static device_method_t msrtemp_methods[] = { @@ -131,10 +132,24 @@ { struct msrtemp_softc *sc = device_get_softc(dev); device_t pdev; + uint64_t msr; pdev = device_get_parent(dev); + /* + * On some Core 2 CPUs, there's an undocumented MSR that + * can tell us if Tj(max) is 100 or 85. + * + * This is only valid for some steppings. + */ + msr = rdmsr(MSR_EXT_CONFIG); + if ((msr >> 30) & 0x1) + sc->sc_tjmax = 85; + else + sc->sc_tjmax = 100; + + /* * Add the "temperature" MIB to dev.cpu.N. */ sc->sc_oid = SYSCTL_ADD_PROC(device_get_sysctl_ctx(pdev), @@ -159,9 +174,11 @@ static int -msrtemp_get_temp(int cpu) +msrtemp_get_temp(device_t dev) { uint64_t temp; + int cpu = device_get_unit(dev); + struct msrtemp_softc *sc = device_get_softc(dev); thread_lock(curthread); sched_bind(curthread, cpu); @@ -176,10 +193,6 @@ * * The temperature is computed by subtracting the temperature * reading by Tj(max). - * - * 100 is Tj(max). On some CPUs it should be 85, but Intel - * doesn't supply that info, so right now, we are using - * 100 degC for everyone. */ temp = rdmsr(MSR_THERM_STATUS); @@ -191,7 +204,7 @@ * Starting on bit 16 and ending on bit 22. * We use 0x7f to ignore the minus signal. */ - temp = 100 - ((temp >> 16) & 0x7f); + temp = sc->sc_tjmax - ((temp >> 16) & 0x7f); return (int) temp; } @@ -204,7 +217,7 @@ device_t dev = (device_t) arg1; int temp; - temp = msrtemp_get_temp(device_get_unit(dev)); + temp = msrtemp_get_temp(dev); return sysctl_handle_int(oidp, &temp, 0, req); }