From nobody@FreeBSD.org  Sat May 13 12:13:33 2006
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 B4E2616A569
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 13 May 2006 12:13:33 +0000 (UTC)
	(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 1376243D6E
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 13 May 2006 12:13:33 +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 k4DCDWwi009234
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 13 May 2006 12:13:32 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k4DCDWeq009231;
	Sat, 13 May 2006 12:13:32 GMT
	(envelope-from nobody)
Message-Id: <200605131213.k4DCDWeq009231@www.freebsd.org>
Date: Sat, 13 May 2006 12:13:32 GMT
From: Julian Stecklina <der_julian@web.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: powerd unable to reduce CPU frequency
X-Send-Pr-Version: www-2.3

>Number:         97198
>Category:       bin
>Synopsis:       [patch] powerd(8) unable to reduce CPU frequency
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    matteo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 13 12:20:10 GMT 2006
>Closed-Date:    Tue Feb 13 12:53:14 GMT 2007
>Last-Modified:  Tue Feb 13 12:53:14 GMT 2007
>Originator:     Julian Stecklina
>Release:        6.1-RELEASE
>Organization:
>Environment:
FreeBSD dellbeast.localhost 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Tue May  9 12:41:09 CEST 2006     blitz@dellbeast.localhost:/usr/obj/usr/src/sys/DELLBEAST  i386
>Description:
When I run powerd -v I get:

# powerd -v
idle time > 90%, decreasing clock speed from 1400 MHz to 1400 MHz
idle time > 90%, decreasing clock speed from 1400 MHz to 1400 MHz
idle time > 90%, decreasing clock speed from 1400 MHz to 1400 MHz
..

This is caused by:
> sysctl dev.cpu.0.freq_levels
dev.cpu.0.freq_levels: 1400/21000 1400/21000 1400/21000 1400/21000 1225/18375 1200/17500 1050/15312 1000/14000 875/12250 800/10900 700/9537 600/7500 525/6562 450/5625 375/4687 300/3750 225/2812 150/1875 75/937

Here you see that the first frequency level is repeated multiple times. And because of the way powerd handles "downclocking" it will never reach any frequency level below 1400 MHz.

This is on an Dell Inspiron 510m with Pentium-M 1,4GHz.
>How-To-Repeat:
powerd -v
>Fix:
More like a workaround:

--- /usr/src/usr.sbin/powerd/powerd.c   Sun Jan 15 18:50:37 2006
+++ powerd.c    Sat May 13 14:00:06 2006
@@ -483,7 +483,7 @@
                                    freqs[i]);
                } else if (idle > (total * cpu_idle_mark) / 100 &&
                    curfreq > freqs[numfreqs - 1]) {
-                       i++;
+                       while (curfreq == freqs[++i]) {};
                        if (vflag) {
                                printf("idle time > %d%%, decreasing clock"
                                    " speed from %d MHz to %d MHz\n",

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Thu Sep 28 12:47:09 UTC 2006 
Responsible-Changed-Why:  
Take this one. 

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

From: Matteo Riondato <matteo@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/97198
Date: Fri, 29 Sep 2006 18:01:00 +0200

 --JsihDCElWRmQcbOr
 Content-Type: multipart/mixed; boundary="v2/QI0iRXglpx0hK"
 Content-Disposition: inline
 
 
 --v2/QI0iRXglpx0hK
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Could you please try the attached patch?
 I prefer it over yours because it avoids adding a loop.
 Thanks
 Best regards
 --=20
 Matteo Riondato
 FreeBSD Committer (http://www.freebsd.org)
 G.U.F.I. Staff Member (http://www.gufi.org)
 FreeSBIE Developer (http://www.freesbie.org)
 
 --v2/QI0iRXglpx0hK
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="powerd.c.diff"
 Content-Transfer-Encoding: quoted-printable
 
 Index: powerd.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /home/rionda/branch/ncvs/src/usr.sbin/powerd/powerd.c,v
 retrieving revision 1.20
 diff -u -r1.20 powerd.c
 --- powerd.c	19 Feb 2006 00:40:28 -0000	1.20
 +++ powerd.c	29 Sep 2006 15:55:47 -0000
 @@ -182,9 +182,22 @@
  			free(*power);
  			return (-1);
  		}
 +		if (i > 0) {
 +			if ((*freqs)[i] =3D=3D (*freqs)[i-1]) {
 +				i--;
 +				(*numfreqs)--;
 +			}
 +		}
  		p =3D q + 1;
  	}
 =20
 +	if ((*freqs =3D reallocf(*freqs, *numfreqs * sizeof(int))) =3D=3D
 +				NULL) {
 +		free(freqstr);
 +		free(*power);
 +		return (-1);
 +	}
 +
  	free(freqstr);
  	return (0);
  }
 
 --v2/QI0iRXglpx0hK--
 
 --JsihDCElWRmQcbOr
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.5 (FreeBSD)
 
 iD8DBQFFHUM82Mp4pR7Fa+wRAuSlAKCGBjGqFOjB8ZSSYETkZ+JmQI1NPACdGJFW
 +UJlxqCrGRfkS/6G6Cipwo0=
 =3x2+
 -----END PGP SIGNATURE-----
 
 --JsihDCElWRmQcbOr--
State-Changed-From-To: open->feedback 
State-Changed-By: matteo 
State-Changed-When: Sat Sep 30 09:43:18 UTC 2006 
State-Changed-Why:  
I asked for feedback 

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

From: Matteo Riondato <matteo@freebsd.org>
To: bug-followup@freebsd.org, der_julian@web.de
Cc:  
Subject: Re: bin/97198
Date: Sun, 1 Oct 2006 00:21:30 +0200

 --Q8BnQc91gJZX4vDc
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Can you please paste the output of
 sysctl dev.cpu
 ?
 
 Anyway, the issue should already have been fixed by bruno@ with
 revision 1.21.2.3 of sys/dev/acpica/acpi_perf.c
 
 Let me know.
 Best Regards
 --=20
 Matteo Riondato
 FreeBSD Committer (http://www.freebsd.org)
 G.U.F.I. Staff Member (http://www.gufi.org)
 FreeSBIE Developer (http://www.freesbie.org)
 
 --Q8BnQc91gJZX4vDc
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.5 (FreeBSD)
 
 iD8DBQFFHu3q2Mp4pR7Fa+wRAhU2AKDKoK7b04o4+eaBU2I+cAw6BNkHzgCg2Rbx
 4g3VBbqPpG53c27Q58RMby0=
 =ostR
 -----END PGP SIGNATURE-----
 
 --Q8BnQc91gJZX4vDc--
State-Changed-From-To: feedback->closed 
State-Changed-By: matteo 
State-Changed-When: Tue Feb 13 12:52:40 UTC 2007 
State-Changed-Why:  
Feedback timeout 

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