Date: Wed, 1 Aug 2007 16:07:13 GMT From: Rui Paulo <rpaulo@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 124473 for review Message-ID: <200708011607.l71G7DFj039606@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708011607.l71G7DFj039606>