From nobody@FreeBSD.org  Wed Feb  2 23:57:39 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 5A60B106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  2 Feb 2011 23:57:39 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 2F96F8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  2 Feb 2011 23:57:39 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p12NvcsQ044882
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 2 Feb 2011 23:57:38 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p12Nvc2x044881;
	Wed, 2 Feb 2011 23:57:38 GMT
	(envelope-from nobody)
Message-Id: <201102022357.p12Nvc2x044881@red.freebsd.org>
Date: Wed, 2 Feb 2011 23:57:38 GMT
From: Thomas Bach <bachth@uni-mainz.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] cpupowerd cannot calculate FIDs from dev.cpu.x.freq_levels
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154474
>Category:       ports
>Synopsis:       [PATCH] sysutils/cpupowerd cannot calculate FIDs from dev.cpu.x.freq_levels
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    decke
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 03 00:00:26 UTC 2011
>Closed-Date:    Tue Mar 08 20:57:50 UTC 2011
>Last-Modified:  Tue Mar  8 21:00:28 UTC 2011
>Originator:     Thomas Bach
>Release:        8.2-PRERELEASE
>Organization:
>Environment:
# uname -a
FreeBSD taris.fritz.box 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #0: Sun Jan 30 14:50:11 CET 2011     root@taris.fritz.box:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
cpupword tries to determine FIDs from the frequencies from dev.cpu.x.freq_levels
which reports wrong levels:

# sysctl dev.cpu.0.freq_levels
dev.cpu.0.freq_levels: 2500/50000 2400/46099 2200/38878 2000/32400 1800/26625 1575/23296 1350/19968 1125/16640 1000/12800 875/11200 750/9600 625/8000 500/6400 375/4800 250/3200 125/1600

to calculate the actual fid it executes:
# grep '\-\ 8' *
msr_amd.c:	*fid = (frequency/100) - 8;

Returning '-7' when coming to the frequency 125:
# /usr/local/sbin/cpupowerd -s
cpupowerd 0.2.1 written by Markus Strobl.
WARNING: This program could cause damage to your Hardware!
FID (-7) out of range!
Initialisation failed!


>How-To-Repeat:
Running 'cpupowerd -s' on an amd64

# cat /usr/compat/linux/proc/cpuinfo 
processor	: 0
vendor_id	: AuthenticAMD
cpu family	: 15
model		: 1
model name	: AMD Athlon(tm) Dual Core Processor 4850e
stepping	: 2
processor	: 1
vendor_id	: AuthenticAMD
cpu family	: 15
model		: 1
model name	: AMD Athlon(tm) Dual Core Processor 4850e
stepping	: 2
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 b19 mmx fxsr xmm sse2
cpu MHz		: 2506.52
bogomips	: 2506.52

(Yet I don't know how to extract the information with freebsd commands :P)
>Fix:
dev.powernow.0.freq_settings gives the right possible frequencies on my system/cpu.

So the quick fix is to change the line
snprintf(levels_sysctl, sizeof(levels_sysctl), "dev.cpu.%d.freq_levels", mastercpuid);

to
snprintf(levels_sysctl, sizeof(levels_sysctl), "dev.powernow.%d.freq_settings", mastercpuid);

# diff /tmp/cpu_bsd.c cpu_bsd.c
426c426
< 	snprintf(levels_sysctl, sizeof(levels_sysctl), "dev.powernow.%d.freq_settings", mastercpuid);
---
> 	snprintf(levels_sysctl, sizeof(levels_sysctl), "dev.cpu.%d.freq_levels", mastercpuid);

Anyway, having dev.cpu.0.freq_levels reporting the right frequencies would be much cleaner.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->decke 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Feb 3 02:35:00 UTC 2011 
Responsible-Changed-Why:  
Fix synopsis and assign. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154474 

From: Bernhard Froehlich <decke@FreeBSD.org>
To: <bachth@uni-mainz.de>
Cc: <bug-followup@FreeBSD.org>
Subject: Re: ports/154474: [PATCH] sysutils/cpupowerd cannot calculate FIDs
 from =?UTF-8?Q?dev=2Ecpu=2Ex=2Efreq=5Flevels?=
Date: Mon, 21 Feb 2011 15:09:01 +0100

 Please try to disable throttling.
 
 Add that to /boot/loader.conf and reboot:
 hint.acpi_throttle.0.disabled="1"
 
 -- 
 Bernhard Froehlich
 http://www.bluelife.at/
State-Changed-From-To: open->closed 
State-Changed-By: decke 
State-Changed-When: Tue Mar 8 20:57:48 UTC 2011 
State-Changed-Why:  
Works with described settings now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154474 

From: Bernhard Froehlich <decke@FreeBSD.org>
To: Thomas Bach <bachth@uni-mainz.de>
Cc: <bug-followup@FreeBSD.org>
Subject: Re: ports/154474: [PATCH] sysutils/cpupowerd cannot calculate FIDs
 from =?UTF-8?Q?dev=2Ecpu=2Ex=2Efreq=5Flevels?=
Date: Tue, 08 Mar 2011 21:56:33 +0100

 On Tue, 22 Feb 2011 06:07:20 +0100, Thomas Bach wrote:
 > Bernhard Froehlich <decke@FreeBSD.org> writes:
 > 
 >> Please try to disable throttling.
 >>
 >> Add that to /boot/loader.conf and reboot:
 >> hint.acpi_throttle.0.disabled="1"
 > 
 > Thanks for the reply.
 > 
 > cpupowerd works now with this setting. 
 > 
 > Regards,
 > Thomas Bach.
 
 Thanks for testing!
 
 -- 
 Bernhard Froehlich
 http://www.bluelife.at/
>Unformatted:
