From owner-freebsd-questions@FreeBSD.ORG Tue May 3 20:12:34 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A921D106564A for ; Tue, 3 May 2011 20:12:34 +0000 (UTC) (envelope-from demelier.david@gmail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 343BB8FC17 for ; Tue, 3 May 2011 20:12:33 +0000 (UTC) Received: by wyf23 with SMTP id 23so465294wyf.13 for ; Tue, 03 May 2011 13:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=xp8m0dGe70zS7znAvD1n1EQzoB7jUHgQv5y9n1qLXr8=; b=lA/kccrh0csh1MJwxFh8VAljaq86jvgb3ns9+7Tgtt0ZI1tBzbPYYxs0RBUvL+EQ8W keUAiDL47VhxK1GgZQY4BaJCyFKYPrBdHbGtvnrmAiubeuCArYkTSKP3ewwvcd+XvH57 K5uV9iDE4HCsibcghVXb0/Q8mCC5TMfYkljOI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=TIL5rO1nH9cCenjWsG9IWxhmnNQk1702cMl/HXIE56GYjEODpmEyT0vVGD5B9MI/ne fVgpy3/VNJhIK/PI47dS6+9GOHunb5rDuLKGtuN3epqrAfIV4fKMPLLHZXo2TFP8HQS8 6WyPRfUoAxy3PrhkiVr2JXWplQNCFJHskXtqQ= Received: by 10.227.110.37 with SMTP id l37mr221143wbp.114.1304453553019; Tue, 03 May 2011 13:12:33 -0700 (PDT) Received: from Melon.malikania.fr (65.21.102-84.rev.gaoland.net [84.102.21.65]) by mx.google.com with ESMTPS id bd8sm273059wbb.14.2011.05.03.13.12.31 (version=SSLv3 cipher=OTHER); Tue, 03 May 2011 13:12:31 -0700 (PDT) Message-ID: <4DC06181.1070500@gmail.com> Date: Tue, 03 May 2011 22:11:45 +0200 From: David Demelier User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.17) Gecko/20110429 Thunderbird/3.1.10 MIME-Version: 1.0 To: Roland Smith References: <4DBFB8F1.4050504@gmail.com> <20110503194009.GA63997@slackbox.erewhon.net> In-Reply-To: <20110503194009.GA63997@slackbox.erewhon.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: freebsd-questions@freebsd.org Subject: Re: Get the dev.cpu.0.temperature from sysctl(3) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2011 20:12:34 -0000 On 03/05/2011 21:40, Roland Smith wrote: > On Tue, May 03, 2011 at 10:12:33AM +0200, David Demelier wrote: >> Hello, >> >> 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), > 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 = (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...| > 00000004 > > Running this value with the abovementioned algorithm in reverse through a > calculator, we get > > (0x0c78-2732)/10 = 46°C > > Hope this helps. > > > Roland 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 sysctl(9) But I finally understood that K should means Kelvin :) Cheers, -- David Demelier