From nobody@FreeBSD.org  Sun Dec 25 20:09:58 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B611A16A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Dec 2005 20:09:58 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3CD6643D64
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Dec 2005 20:09:58 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jBPK9v4F090942
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Dec 2005 20:09:57 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jBPK9vuA090941;
	Sun, 25 Dec 2005 20:09:57 GMT
	(envelope-from nobody)
Message-Id: <200512252009.jBPK9vuA090941@www.freebsd.org>
Date: Sun, 25 Dec 2005 20:09:57 GMT
From: Christian Wittenhorst <wiwi@progon.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: cpufreq inconsistency / powerd broken
X-Send-Pr-Version: www-2.3

>Number:         90903
>Category:       bin
>Synopsis:       powerd(8): cpufreq inconsistency / powerd broken
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 25 20:20:10 GMT 2005
>Closed-Date:    Tue Nov 18 16:05:16 UTC 2008
>Last-Modified:  Tue Nov 18 16:05:16 UTC 2008
>Originator:     Christian Wittenhorst
>Release:        6.0p1
>Organization:
progon network engineering
>Environment:
FreeBSD ns-a.kanti-zug.ch 6.0-RELEASE-p1 FreeBSD 6.0-RELEASE-p1 #0: Sun Dec 25 16:55:09 UTC 2005     root@ns-a.kanti-zug.ch:/usr/src/sys/i386/compile/services-a  i386              
>Description:
one some platforms, dev.cpu.0.freq does not match any value from dev.cpu.0.freq_levels. This breaks powerd. 

sysctl -a:
dev.cpu.0.freq: 2798
dev.cpu.0.freq_levels: 2795/-1 2445/-1 2139/-1 2096/-1 1834/-1 1746/-1 1572/-1 1527/-1 1397/-1 1309/-1 1222/-1 1091/-1 1048/-1 917/-1 873/-1 786/-1 698/-1 655/-1 610/-1 523/-1 436/-1 349/-1 305/-1 261/-1 218/-1 174/-1 130/-1 87/-1 43/-1
dev.acpi_throttle.0.freq_settings: 10000/-1 8750/-1 7500/-1 6250/-1 5000/-1 3750/-1 2500/-1 1250/-1
dev.cpufreq.0.%driver: cpufreq
dev.cpufreq.0.%parent: cpu0

The reason why powerd fails is:

src/usr.sbin/powerd/powerd.c:
[...]
if (vflag) {
   for (i = 0; i < numfreqs; i++) {
      if (freqs[i] == curfreq)
         break;
   }
[...]

                        }

>How-To-Repeat:
              
>Fix:
quick and dirty fix:

src/usr.sbin/powerd/powerd.c:

[...]
if (vflag) {
   for (i = 0; i < numfreqs; i++) {
      if (freqs[i] == curfreq)
         break;
   }
***
   if (i==numfreqs) {
      i=0;
   }
***
>Release-Note:
>Audit-Trail:

From: Christian Wittenhorst <wiwi@progon.net>
To: bug-followup@FreeBSD.org, wiwi@progon.net
Cc:  
Subject: Re: kern/90903: cpufreq inconsistency / powerd broken
Date: Mon, 26 Dec 2005 21:29:39 +0100

 There's more fix in powerd (still very quick and dirty...). Fixing the 
 inconsistency in cpufreq would be a far better solution...
 
       /*
 * If we're idle less than the active mark, bump up two levels.
 * If we're idle more than the idle mark, drop down one level.
 */
 	for (i = 0; i < numfreqs; i++) {
                         if (freqs[i] == curfreq)
                                 break;
                 }
                 if (i==numfreqs) {
                          i=0;
                 }
 
                 if (idle < (total * cpu_running_mark) / 100 &&
                     curfreq < freqs[0]) {
                         printf("i: %d\n", i);

From: Craig Manley <cmanley@xs4all.nl>
To: bug-followup@FreeBSD.org, wiwi@progon.net
Cc:  
Subject: Re: bin/90903: [powerd] cpufreq inconsistency / powerd broken
Date: Tue, 14 Mar 2006 15:32:16 +0100

 Hi,
 Could you please also add a sanity check after this block at line 50 in 
 powerd.c where the current frequency is read and then all known 
 frequencies in freqs are tested before entering the for (ever) loop 
 later on. A warning is shown for those frequencies that fail to be set, 
 and if 0 or 1 frequencies are good, then de daemon should croak with an 
 appropriate warning. I've only got limited knowledge of C and don't know 
 how to get this stuff patched or compiled myself otherwise I would, so 
 forgive me on that. The reason why this additional sanity check is 
 useful is because I've noticed that many people like me have more 
 frequencies in the array than that can be set by sysctl.
 
         /* Check if we can read the idle time and supported freqs. */
         if (read_usage_times(NULL, NULL))
                 err(1, "read_usage_times");
         if (read_freqs(&numfreqs, &freqs, &mwatts))
                 err(1, "error reading supported CPU frequencies");
 
         .... sanity check here ....
        
         .... leaving a fresh new numfreqs, freqs, and mwatts here ...
 
 Regards,
 Craig Manley
    
State-Changed-From-To: open->closed 
State-Changed-By: mav 
State-Changed-When: Tue Nov 18 16:02:58 UTC 2008 
State-Changed-Why:  
I believe it is fixed in -CURRENT by r185050. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90903 
>Unformatted:
