From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 15 21:12:21 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07F6B106564A for ; Sat, 15 Jan 2011 21:12:21 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id C25BE8FC16 for ; Sat, 15 Jan 2011 21:12:20 +0000 (UTC) Received: by iyb26 with SMTP id 26so3632935iyb.13 for ; Sat, 15 Jan 2011 13:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Ew9GJhUDgJ503DaEshirZ0Ap/bsr0W5qm4MOwhIfTZA=; b=LDoibZZ7JjzR0Gyvw530OpsZCHy6ztf0IBCoJi4YdroplAXElyAP0JGo1Mlj6CKRWE TL2K1HmtsPcFTEAE2QLUfR2gI0HGeTcaSiCLeqsVV3FIKQBeXlxDduC5/7WYNLER8O7A 3ZrDma7dFy2LQ/A5BSitaAtS99FAa7Y5tp5R8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=KIBVHFlCNOjM1r8T9u2FoP/RNC8Xt6BB0BFDrWxj/UY1Ge5rEfrbW2o9hdwhkue8h7 FnnzETFrImgCx4up3/6R5T/UiSX3ZKqxCZCmPq9YHnYXetgn2AvObe8nrJztKuDyx9oO TF1k0Xo28j6+VpaWUdqm+74CdPCg0iCdRo9Ro= MIME-Version: 1.0 Received: by 10.231.171.197 with SMTP id i5mr2297016ibz.54.1295124610549; Sat, 15 Jan 2011 12:50:10 -0800 (PST) Received: by 10.231.160.147 with HTTP; Sat, 15 Jan 2011 12:50:10 -0800 (PST) In-Reply-To: References: Date: Sat, 15 Jan 2011 12:50:10 -0800 Message-ID: From: Matthew Fleming To: Harald Servat Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: Question about sysctl-ing coretemp module values X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Jan 2011 21:12:21 -0000 On Sat, Jan 15, 2011 at 12:09 PM, Harald Servat wrote: > Hello, > > =A0First of all, forgive if this is not the appropiate list to ask this. > Could you point me the correct list if so? > > =A0I'm writing a small program to capture the temperature reported by the > coretemp kernel module. I'm doing this by using the sysctl API. However, = I'm > facing a problem when reading that value (dev.cpu.0.temperature, for > example). > > =A0man 3 sysctl has an example (labeled as "To retrieve the standard sear= ch > path for the system utilities:") which seems great to me to know the leng= th > of the OID it wants to read before running the "real" sysctl. I wrote a > similar example (attached) based on that, but it does not work appropiate= ly. > The 1st call tells me that len =3D 4 (whereas the value for > dev.cpu.0.temperature is "37.0C" which should be 5 if \0 is not counted). > > =A0Can anyone shed some light on what I'm doing wrong? The list ate your attachment but I think I know what you're misinterpreting= . The coretemp sysctl is, if I'm reading the code correctly, returning the temperature as an int (hence len=3D4) in 10ths of a degree K. Then sysctl(8) is printing this as %.1fC, which is where the 37.0C comes from. So the sysctl returns an int with some value and then printf does the conversion. The coretemp sysctl uses the unconventional "IK" format, meaning that it's a signed int that should be interpreted as Kelvin. Cheers, matthew