Get the dev.cpu.0.temperature from sysctl(3)
demelier.david at gmail.com
Tue May 3 20:12:34 UTC 2011
On 03/05/2011 21:40, Roland Smith wrote:
> On Tue, May 03, 2011 at 10:12:33AM +0200, David Demelier wrote:
>> I would like to get the dev.cpu.0.temperature node from sysctlbyname().
>> It seems this node is an opaque type but how to check it and store it to
>> the appropriate variable type ?
> The best way to determine this is to read the source. I did that some time ago
> to fix the temperature display in sysutils/conky.
> The sysctl dev.cpu.0.temperature returns an integer, see
> /sys/dev/coretemp/coretemp.c (look for the string "temperature"), and you'll see:
> * Add the "temperature" MIB to dev.cpu.N.
> sc->sc_oid = SYSCTL_ADD_PROC(device_get_sysctl_ctx(pdev),
> OID_AUTO, "temperature",
> CTLTYPE_INT | CTLFLAG_RD,
> dev, 0, coretemp_get_temp_sysctl, "IK",
> "Current temperature");
> If you look at the definition of coretemp_get_temp_sysctl in the same file:
> device_t dev = (device_t) arg1;
> int temp;
> temp = coretemp_get_temp(dev) * 10 + TZ_ZEROC;
> return (sysctl_handle_int(oidp,&temp, 0, req));
> So the returned value is an 'int'. Note that TZ_ZEROC is #defined as 2732 at
> the beginning of the file. The returned value is therefore the temperature
> in Kelvin times ten.
> On my machine, it gives e.g.:
> sysctl dev.cpu.0.temperature
> dev.cpu.0.temperature: 46.0C
> If we check the 'raw' return value;
> sysctl -b dev.cpu.0.temperature|hd
> 00000000 78 0c 00 00 |x...|
> Running this value with the abovementioned algorithm in reverse through a
> calculator, we get
> (0x0c78-2732)/10 = 46°C
> Hope this helps.
Thanks a lot!
I had a look into the src and I saw the format "IK" used to register the
sysctl node but I was also surprised that "IK" was not defined in man
But I finally understood that K should means Kelvin :)
More information about the freebsd-questions