Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 May 2011 21:40:10 +0200
From:      Roland Smith <rsmith@xs4all.nl>
To:        David Demelier <demelier.david@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Get the dev.cpu.0.temperature from sysctl(3)
Message-ID:  <20110503194009.GA63997@slackbox.erewhon.net>
In-Reply-To: <4DBFB8F1.4050504@gmail.com>
References:  <4DBFB8F1.4050504@gmail.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help

--1yeeQ81UyVL57Vl7
Content-Type: text/plain; charset=iso-8859-15
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, May 03, 2011 at 10:12:33AM +0200, David Demelier wrote:
> Hello,
>=20
> I would like to get the dev.cpu.0.temperature node from sysctlbyname().=
=20
> It seems this node is an opaque type but how to check it and store it to=
=20
> 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.=20

The sysctl dev.cpu.0.temperature returns an integer, see
/sys/dev/coretemp/coretemp.c (look for the string "temperature"), and you'l=
l see:

        /*
         * Add the "temperature" MIB to dev.cpu.N.
         */
        sc->sc_oid =3D SYSCTL_ADD_PROC(device_get_sysctl_ctx(pdev),
            SYSCTL_CHILDREN(device_get_sysctl_tree(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:

coretemp_get_temp_sysctl(SYSCTL_HANDLER_ARGS)
{
        device_t dev =3D (device_t) arg1;
        int temp;

        temp =3D 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...|
    00000004

Running this value with the abovementioned algorithm in reverse through a
calculator, we get

   (0x0c78-2732)/10 =3D 46=B0C

Hope this helps.


Roland
--=20
R.F.Smith                                   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)

--1yeeQ81UyVL57Vl7
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (FreeBSD)

iEYEARECAAYFAk3AWhkACgkQEnfvsMMhpyXBXwCfXnJvgc2pCSB7jcWcdQeL1e3b
A28An0As50e65UllnA4L7kahWzBpzwYb
=0TmN
-----END PGP SIGNATURE-----

--1yeeQ81UyVL57Vl7--



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20110503194009.GA63997>