2007-08-15 19:26:03 +00:00
|
|
|
/*-
|
2008-05-11 23:17:57 +00:00
|
|
|
* Copyright (c) 2007, 2008 Rui Paulo <rpaulo@FreeBSD.org>
|
2007-08-15 19:26:03 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device driver for Intel's On Die thermal sensor via MSR.
|
|
|
|
* First introduced in Intel's Core line of processors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
2007-10-15 20:00:24 +00:00
|
|
|
#include <sys/sysctl.h>
|
2007-08-15 19:26:03 +00:00
|
|
|
#include <sys/proc.h> /* for curthread */
|
|
|
|
#include <sys/sched.h>
|
|
|
|
|
|
|
|
#include <machine/specialreg.h>
|
|
|
|
#include <machine/cpufunc.h>
|
2008-11-26 19:25:13 +00:00
|
|
|
#include <machine/cputypes.h>
|
2007-08-15 19:26:03 +00:00
|
|
|
#include <machine/md_var.h>
|
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
#define TZ_ZEROC 2732
|
|
|
|
|
|
|
|
#define THERM_STATUS_LOG 0x02
|
|
|
|
#define THERM_STATUS 0x01
|
|
|
|
#define THERM_STATUS_TEMP_SHIFT 16
|
|
|
|
#define THERM_STATUS_TEMP_MASK 0x7f
|
|
|
|
#define THERM_STATUS_RES_SHIFT 27
|
|
|
|
#define THERM_STATUS_RES_MASK 0x0f
|
|
|
|
#define THERM_STATUS_VALID_SHIFT 31
|
|
|
|
#define THERM_STATUS_VALID_MASK 0x01
|
2009-09-06 12:01:29 +00:00
|
|
|
|
2007-08-15 19:26:03 +00:00
|
|
|
struct coretemp_softc {
|
2007-10-15 20:00:24 +00:00
|
|
|
device_t sc_dev;
|
|
|
|
int sc_tjmax;
|
2011-09-02 17:06:23 +00:00
|
|
|
unsigned int sc_throttle_log;
|
2007-08-15 19:26:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device methods.
|
|
|
|
*/
|
|
|
|
static void coretemp_identify(driver_t *driver, device_t parent);
|
|
|
|
static int coretemp_probe(device_t dev);
|
|
|
|
static int coretemp_attach(device_t dev);
|
|
|
|
static int coretemp_detach(device_t dev);
|
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
static uint64_t coretemp_get_thermal_msr(int cpu);
|
|
|
|
static void coretemp_clear_thermal_msr(int cpu);
|
|
|
|
static int coretemp_get_val_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int coretemp_throttle_log_sysctl(SYSCTL_HANDLER_ARGS);
|
2007-08-15 19:26:03 +00:00
|
|
|
|
|
|
|
static device_method_t coretemp_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_identify, coretemp_identify),
|
|
|
|
DEVMETHOD(device_probe, coretemp_probe),
|
|
|
|
DEVMETHOD(device_attach, coretemp_attach),
|
|
|
|
DEVMETHOD(device_detach, coretemp_detach),
|
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t coretemp_driver = {
|
|
|
|
"coretemp",
|
|
|
|
coretemp_methods,
|
|
|
|
sizeof(struct coretemp_softc),
|
|
|
|
};
|
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
enum therm_info {
|
|
|
|
CORETEMP_TEMP,
|
|
|
|
CORETEMP_DELTA,
|
|
|
|
CORETEMP_RESOLUTION,
|
|
|
|
CORETEMP_TJMAX,
|
|
|
|
};
|
|
|
|
|
2007-08-15 19:26:03 +00:00
|
|
|
static devclass_t coretemp_devclass;
|
2011-09-02 17:06:23 +00:00
|
|
|
DRIVER_MODULE(coretemp, cpu, coretemp_driver, coretemp_devclass, NULL,
|
|
|
|
NULL);
|
2007-08-15 19:26:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
coretemp_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
u_int regs[4];
|
|
|
|
|
|
|
|
/* Make sure we're not being doubly invoked. */
|
|
|
|
if (device_find_child(parent, "coretemp", -1) != NULL)
|
|
|
|
return;
|
2007-08-23 10:53:03 +00:00
|
|
|
|
2008-05-11 23:17:57 +00:00
|
|
|
/* Check that CPUID 0x06 is supported and the vendor is Intel.*/
|
2008-11-26 19:25:13 +00:00
|
|
|
if (cpu_high < 6 || cpu_vendor_id != CPU_VENDOR_INTEL)
|
2007-08-15 19:26:03 +00:00
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* CPUID 0x06 returns 1 if the processor has on-die thermal
|
|
|
|
* sensors. EBX[0:3] contains the number of sensors.
|
|
|
|
*/
|
|
|
|
do_cpuid(0x06, regs);
|
|
|
|
if ((regs[0] & 0x1) != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We add a child for each CPU since settings must be performed
|
|
|
|
* on each CPU in the SMP case.
|
|
|
|
*/
|
|
|
|
child = device_add_child(parent, "coretemp", -1);
|
|
|
|
if (child == NULL)
|
|
|
|
device_printf(parent, "add coretemp child failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
coretemp_probe(device_t dev)
|
|
|
|
{
|
2012-10-22 13:06:09 +00:00
|
|
|
if (resource_disabled("coretemp", 0))
|
|
|
|
return (ENXIO);
|
2007-08-15 19:26:03 +00:00
|
|
|
|
|
|
|
device_set_desc(dev, "CPU On-Die Thermal Sensors");
|
|
|
|
|
|
|
|
return (BUS_PROBE_GENERIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
coretemp_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct coretemp_softc *sc = device_get_softc(dev);
|
|
|
|
device_t pdev;
|
|
|
|
uint64_t msr;
|
2010-07-29 19:08:22 +00:00
|
|
|
int cpu_model, cpu_stepping;
|
|
|
|
int ret, tjtarget;
|
2011-09-02 17:06:23 +00:00
|
|
|
struct sysctl_oid *oid;
|
|
|
|
struct sysctl_ctx_list *ctx;
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2007-08-23 10:53:03 +00:00
|
|
|
sc->sc_dev = dev;
|
2007-08-15 19:26:03 +00:00
|
|
|
pdev = device_get_parent(dev);
|
2010-07-29 19:08:22 +00:00
|
|
|
cpu_model = CPUID_TO_MODEL(cpu_id);
|
|
|
|
cpu_stepping = cpu_id & CPUID_STEPPING;
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2008-02-14 14:14:59 +00:00
|
|
|
/*
|
|
|
|
* Some CPUs, namely the PIII, don't have thermal sensors, but
|
|
|
|
* report them when the CPUID check is performed in
|
|
|
|
* coretemp_identify(). This leads to a later GPF when the sensor
|
|
|
|
* is queried via a MSR, so we stop here.
|
|
|
|
*/
|
|
|
|
if (cpu_model < 0xe)
|
|
|
|
return (ENXIO);
|
2011-09-02 17:06:23 +00:00
|
|
|
|
2008-01-10 16:09:22 +00:00
|
|
|
#if 0 /*
|
|
|
|
* XXXrpaulo: I have this CPU model and when it returns from C3
|
|
|
|
* coretemp continues to function properly.
|
|
|
|
*/
|
|
|
|
|
2007-08-15 19:26:03 +00:00
|
|
|
/*
|
|
|
|
* Check for errata AE18.
|
|
|
|
* "Processor Digital Thermal Sensor (DTS) Readout stops
|
|
|
|
* updating upon returning from C3/C4 state."
|
|
|
|
*
|
|
|
|
* Adapted from the Linux coretemp driver.
|
2007-08-23 10:53:03 +00:00
|
|
|
*/
|
2010-07-29 19:08:22 +00:00
|
|
|
if (cpu_model == 0xe && cpu_stepping < 0xc) {
|
2007-08-15 19:26:03 +00:00
|
|
|
msr = rdmsr(MSR_BIOS_SIGN);
|
|
|
|
msr = msr >> 32;
|
|
|
|
if (msr < 0x39) {
|
2007-08-23 10:53:03 +00:00
|
|
|
device_printf(dev, "not supported (Intel errata "
|
|
|
|
"AE18), try updating your BIOS\n");
|
2007-08-15 19:26:03 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
2008-01-10 16:09:22 +00:00
|
|
|
#endif
|
2010-07-29 19:08:22 +00:00
|
|
|
|
2007-08-15 19:26:03 +00:00
|
|
|
/*
|
2010-07-29 19:08:22 +00:00
|
|
|
* Use 100C as the initial value.
|
2007-08-15 19:26:03 +00:00
|
|
|
*/
|
2007-08-23 10:53:03 +00:00
|
|
|
sc->sc_tjmax = 100;
|
2010-07-29 19:08:22 +00:00
|
|
|
|
|
|
|
if ((cpu_model == 0xf && cpu_stepping >= 2) || cpu_model == 0xe) {
|
|
|
|
/*
|
|
|
|
* On some Core 2 CPUs, there's an undocumented MSR that
|
|
|
|
* can tell us if Tj(max) is 100 or 85.
|
|
|
|
*
|
|
|
|
* The if-clause for CPUs having the MSR_IA32_EXT_CONFIG was adapted
|
|
|
|
* from the Linux coretemp driver.
|
|
|
|
*/
|
2007-08-15 19:26:03 +00:00
|
|
|
msr = rdmsr(MSR_IA32_EXT_CONFIG);
|
2007-08-23 10:53:03 +00:00
|
|
|
if (msr & (1 << 30))
|
2007-08-15 19:26:03 +00:00
|
|
|
sc->sc_tjmax = 85;
|
2010-08-04 00:25:13 +00:00
|
|
|
} else if (cpu_model == 0x17) {
|
|
|
|
switch (cpu_stepping) {
|
|
|
|
case 0x6: /* Mobile Core 2 Duo */
|
2011-05-02 18:41:54 +00:00
|
|
|
sc->sc_tjmax = 105;
|
2010-08-04 00:25:13 +00:00
|
|
|
break;
|
|
|
|
default: /* Unknown stepping */
|
|
|
|
break;
|
|
|
|
}
|
2011-05-05 19:15:15 +00:00
|
|
|
} else if (cpu_model == 0x1c) {
|
|
|
|
switch (cpu_stepping) {
|
|
|
|
case 0xa: /* 45nm Atom D400, N400 and D500 series */
|
|
|
|
sc->sc_tjmax = 100;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sc->sc_tjmax = 90;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-04 00:25:13 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Attempt to get Tj(max) from MSR IA32_TEMPERATURE_TARGET.
|
|
|
|
*
|
|
|
|
* This method is described in Intel white paper "CPU
|
|
|
|
* Monitoring With DTS/PECI". (#322683)
|
|
|
|
*/
|
|
|
|
ret = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &msr);
|
|
|
|
if (ret == 0) {
|
|
|
|
tjtarget = (msr >> 16) & 0xff;
|
2011-09-02 17:06:23 +00:00
|
|
|
|
2010-08-04 00:25:13 +00:00
|
|
|
/*
|
|
|
|
* On earlier generation of processors, the value
|
|
|
|
* obtained from IA32_TEMPERATURE_TARGET register is
|
|
|
|
* an offset that needs to be summed with a model
|
|
|
|
* specific base. It is however not clear what
|
|
|
|
* these numbers are, with the publicly available
|
|
|
|
* documents from Intel.
|
|
|
|
*
|
2011-08-19 13:31:48 +00:00
|
|
|
* For now, we consider [70, 110]C range, as
|
2010-08-04 00:25:13 +00:00
|
|
|
* described in #322683, as "reasonable" and accept
|
|
|
|
* these values whenever the MSR is available for
|
|
|
|
* read, regardless the CPU model.
|
|
|
|
*/
|
2011-08-19 13:31:48 +00:00
|
|
|
if (tjtarget >= 70 && tjtarget <= 110)
|
2010-08-04 00:25:13 +00:00
|
|
|
sc->sc_tjmax = tjtarget;
|
|
|
|
else
|
|
|
|
device_printf(dev, "Tj(target) value %d "
|
|
|
|
"does not seem right.\n", tjtarget);
|
|
|
|
} else
|
|
|
|
device_printf(dev, "Can not get Tj(target) "
|
|
|
|
"from your CPU, using 100C.\n");
|
2007-08-23 10:53:03 +00:00
|
|
|
}
|
|
|
|
|
2010-07-29 19:08:22 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "Setting TjMax=%d\n", sc->sc_tjmax);
|
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
ctx = device_get_sysctl_ctx(dev);
|
|
|
|
|
|
|
|
oid = SYSCTL_ADD_NODE(ctx,
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(pdev)), OID_AUTO,
|
|
|
|
"coretemp", CTLFLAG_RD, NULL, "Per-CPU thermal information");
|
|
|
|
|
2007-08-15 19:26:03 +00:00
|
|
|
/*
|
2011-09-02 17:06:23 +00:00
|
|
|
* Add the MIBs to dev.cpu.N and dev.cpu.N.coretemp.
|
2007-08-15 19:26:03 +00:00
|
|
|
*/
|
2011-09-02 17:06:23 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(pdev)),
|
|
|
|
OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD, dev,
|
|
|
|
CORETEMP_TEMP, coretemp_get_val_sysctl, "IK",
|
2009-09-06 12:01:29 +00:00
|
|
|
"Current temperature");
|
2011-09-02 17:06:23 +00:00
|
|
|
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "delta",
|
|
|
|
CTLTYPE_INT | CTLFLAG_RD, dev, CORETEMP_DELTA,
|
|
|
|
coretemp_get_val_sysctl, "I",
|
|
|
|
"Delta between TCC activation and current temperature");
|
|
|
|
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "resolution",
|
|
|
|
CTLTYPE_INT | CTLFLAG_RD, dev, CORETEMP_RESOLUTION,
|
|
|
|
coretemp_get_val_sysctl, "I",
|
|
|
|
"Resolution of CPU thermal sensor");
|
|
|
|
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "tjmax",
|
|
|
|
CTLTYPE_INT | CTLFLAG_RD, dev, CORETEMP_TJMAX,
|
|
|
|
coretemp_get_val_sysctl, "IK",
|
|
|
|
"TCC activation temperature");
|
|
|
|
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
|
|
|
|
"throttle_log", CTLTYPE_INT | CTLFLAG_RW, dev, 0,
|
|
|
|
coretemp_throttle_log_sysctl, "I",
|
|
|
|
"Set to 1 if the thermal sensor has tripped");
|
2007-08-15 19:26:03 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
coretemp_detach(device_t dev)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
static uint64_t
|
|
|
|
coretemp_get_thermal_msr(int cpu)
|
2007-08-15 19:26:03 +00:00
|
|
|
{
|
2007-08-23 10:53:03 +00:00
|
|
|
uint64_t msr;
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2007-10-15 20:00:24 +00:00
|
|
|
thread_lock(curthread);
|
|
|
|
sched_bind(curthread, cpu);
|
|
|
|
thread_unlock(curthread);
|
|
|
|
|
2007-08-15 19:26:03 +00:00
|
|
|
/*
|
2007-10-15 20:00:24 +00:00
|
|
|
* The digital temperature reading is located at bit 16
|
|
|
|
* of MSR_THERM_STATUS.
|
|
|
|
*
|
|
|
|
* There is a bit on that MSR that indicates whether the
|
|
|
|
* temperature is valid or not.
|
|
|
|
*
|
|
|
|
* The temperature is computed by subtracting the temperature
|
|
|
|
* reading by Tj(max).
|
2007-08-15 19:26:03 +00:00
|
|
|
*/
|
2007-10-15 20:00:24 +00:00
|
|
|
msr = rdmsr(MSR_THERM_STATUS);
|
|
|
|
|
|
|
|
thread_lock(curthread);
|
|
|
|
sched_unbind(curthread);
|
|
|
|
thread_unlock(curthread);
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
return (msr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
coretemp_clear_thermal_msr(int cpu)
|
|
|
|
{
|
|
|
|
thread_lock(curthread);
|
|
|
|
sched_bind(curthread, cpu);
|
|
|
|
thread_unlock(curthread);
|
|
|
|
|
|
|
|
wrmsr(MSR_THERM_STATUS, 0);
|
|
|
|
|
|
|
|
thread_lock(curthread);
|
|
|
|
sched_unbind(curthread);
|
|
|
|
thread_unlock(curthread);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
coretemp_get_val_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
uint64_t msr;
|
|
|
|
int val, tmp;
|
|
|
|
struct coretemp_softc *sc;
|
|
|
|
enum therm_info type;
|
|
|
|
char stemp[16];
|
|
|
|
|
|
|
|
dev = (device_t) arg1;
|
|
|
|
msr = coretemp_get_thermal_msr(device_get_unit(dev));
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
type = arg2;
|
|
|
|
|
|
|
|
if (((msr >> THERM_STATUS_VALID_SHIFT) & THERM_STATUS_VALID_MASK) != 1) {
|
|
|
|
val = -1;
|
|
|
|
} else {
|
|
|
|
switch (type) {
|
|
|
|
case CORETEMP_TEMP:
|
|
|
|
tmp = (msr >> THERM_STATUS_TEMP_SHIFT) &
|
|
|
|
THERM_STATUS_TEMP_MASK;
|
|
|
|
val = (sc->sc_tjmax - tmp) * 10 + TZ_ZEROC;
|
|
|
|
break;
|
|
|
|
case CORETEMP_DELTA:
|
|
|
|
val = (msr >> THERM_STATUS_TEMP_SHIFT) &
|
|
|
|
THERM_STATUS_TEMP_MASK;
|
|
|
|
break;
|
|
|
|
case CORETEMP_RESOLUTION:
|
|
|
|
val = (msr >> THERM_STATUS_RES_SHIFT) &
|
|
|
|
THERM_STATUS_RES_MASK;
|
|
|
|
break;
|
|
|
|
case CORETEMP_TJMAX:
|
|
|
|
val = sc->sc_tjmax * 10 + TZ_ZEROC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msr & THERM_STATUS_LOG) {
|
2011-09-19 10:58:30 +00:00
|
|
|
coretemp_clear_thermal_msr(device_get_unit(dev));
|
2011-09-02 17:06:23 +00:00
|
|
|
sc->sc_throttle_log = 1;
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2007-08-23 10:53:03 +00:00
|
|
|
/*
|
2011-09-02 17:06:23 +00:00
|
|
|
* 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.
|
2007-08-23 10:53:03 +00:00
|
|
|
*/
|
2011-09-02 17:06:23 +00:00
|
|
|
if (msr & THERM_STATUS) {
|
|
|
|
tmp = (msr >> THERM_STATUS_TEMP_SHIFT) &
|
|
|
|
THERM_STATUS_TEMP_MASK;
|
|
|
|
tmp = (sc->sc_tjmax - tmp) * 10 + TZ_ZEROC;
|
|
|
|
device_printf(dev, "critical temperature detected, "
|
|
|
|
"suggest system shutdown\n");
|
|
|
|
snprintf(stemp, sizeof(stemp), "%d", tmp);
|
|
|
|
devctl_notify("coretemp", "Thermal", stemp,
|
|
|
|
"notify=0xcc");
|
|
|
|
}
|
2007-08-15 19:26:03 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
return (sysctl_handle_int(oidp, &val, 0, req));
|
2007-08-15 19:26:03 +00:00
|
|
|
}
|
|
|
|
|
2007-10-15 20:00:24 +00:00
|
|
|
static int
|
2011-09-02 17:06:23 +00:00
|
|
|
coretemp_throttle_log_sysctl(SYSCTL_HANDLER_ARGS)
|
2007-08-15 19:26:03 +00:00
|
|
|
{
|
2011-09-02 17:06:23 +00:00
|
|
|
device_t dev;
|
|
|
|
uint64_t msr;
|
|
|
|
int error, val;
|
|
|
|
struct coretemp_softc *sc;
|
|
|
|
|
|
|
|
dev = (device_t) arg1;
|
|
|
|
msr = coretemp_get_thermal_msr(device_get_unit(dev));
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2011-09-19 10:58:30 +00:00
|
|
|
if (msr & THERM_STATUS_LOG) {
|
|
|
|
coretemp_clear_thermal_msr(device_get_unit(dev));
|
2011-09-02 17:06:23 +00:00
|
|
|
sc->sc_throttle_log = 1;
|
2011-09-19 10:58:30 +00:00
|
|
|
}
|
2011-09-02 17:06:23 +00:00
|
|
|
|
|
|
|
val = sc->sc_throttle_log;
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
2007-08-15 19:26:03 +00:00
|
|
|
|
2011-09-02 17:06:23 +00:00
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
else if (val != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
coretemp_clear_thermal_msr(device_get_unit(dev));
|
|
|
|
sc->sc_throttle_log = 0;
|
|
|
|
|
|
|
|
return (0);
|
2007-08-15 19:26:03 +00:00
|
|
|
}
|