From maxlor@maxlor.mine.nu  Sun Oct 21 15:32:26 2007
Return-Path: <maxlor@maxlor.mine.nu>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A602416A41B
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 21 Oct 2007 15:32:26 +0000 (UTC)
	(envelope-from maxlor@maxlor.mine.nu)
Received: from popeye1.ggamaur.net (popeye1.ggamaur.net [213.160.40.50])
	by mx1.freebsd.org (Postfix) with ESMTP id E563C13C4A6
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 21 Oct 2007 15:32:00 +0000 (UTC)
	(envelope-from maxlor@maxlor.mine.nu)
Received: from maxlor.mine.nu (c-82-192-240-247.customer.ggaweb.ch [82.192.240.247])
	by popeye1.ggamaur.net (8.13.7/8.13.7/Submit) with ESMTP id l9LEY0c6075299
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 21 Oct 2007 16:34:01 +0200 (CEST)
	(envelope-from maxlor@maxlor.mine.nu)
Received: from localhost (unknown [127.0.0.1])
	by maxlor.mine.nu (Postfix) with ESMTP id 0D0FE2E2C1
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 21 Oct 2007 16:33:55 +0200 (CEST)
Received: from maxlor.mine.nu ([127.0.0.1])
	by localhost (atlantis.intranet [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id bZdnkMgxd9-G for <FreeBSD-gnats-submit@freebsd.org>;
	Sun, 21 Oct 2007 16:33:54 +0200 (CEST)
Received: by maxlor.mine.nu (Postfix, from userid 1000)
	id DAB3F2E2C0; Sun, 21 Oct 2007 16:33:54 +0200 (CEST)
Message-Id: <20071021143354.DAB3F2E2C0@maxlor.mine.nu>
Date: Sun, 21 Oct 2007 16:33:54 +0200 (CEST)
From: Benjamin Lutz <mail@maxlor.com>
Reply-To: Benjamin Lutz <mail@maxlor.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: powerd doesn't work if freq_levels contains same frequency twice
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         117375
>Category:       bin
>Synopsis:       powerd(8) doesn't work if freq_levels contains same frequency twice
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 21 15:40:01 UTC 2007
>Closed-Date:    Tue Nov 18 16:00:55 UTC 2008
>Last-Modified:  Tue Nov 18 16:00:55 UTC 2008
>Originator:     Benjamin Lutz
>Release:        FreeBSD 6.2-RELEASE-p8 i386
>Organization:
>Environment:
System: FreeBSD atlantis.intranet 6.2-RELEASE-p8 FreeBSD 6.2-RELEASE-p8 #13: Wed Oct 17 20:13:26 CEST 2007 maxlor@atlantis.intranet:/usr/obj/usr/src/sys/ATLANTIS i386

CPU: AMD Athlon(tm) X2 Dual Core Processor BE-2350 (2109.61-MHz 686-class CPU)
  Origin = "AuthenticAMD"  Id = 0x60fb1  Stepping = 1
  Features=0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT>
  Features2=0x2001<SSE3,CX16>
  AMD Features=0xea500800<SYSCALL,NX,MMX+,FFXSR,RDTSCP,LM,3DNow+,3DNow>
  AMD Features2=0x11f<LAHF,CMP,<b2>,<b3>,CR8,<b8>>
  Cores per package: 2

dev.cpu.0.freq_levels: 2100/15000 2100/13720 1890/11360 1050/5531

>Description:

I bought a new CPU recently, an Athlon X2 BE-2350, and unfortunately
powerd, the utility to throttle the CPU down when it's not in use,
doesn't work on it.

The problem is this:
  $ sysctl dev.cpu.0.freq_levels
  dev.cpu.0.freq_levels: 2100/15000 2100/13720 1890/11360 1050/5531

So there's two entries with the same frequency. Powerd now essentially
does the following: 

- The CPU is not in use, so lower the frequency.
- Get the current frequency, which is 2100Mhz.
- Find that frequency in the freq_levels list, then pick the one after
  that, which also happens to be 2100MHz.
- The CPU is not in use, so lower the frequency.
- Get the current frequency, which is 2100Mhz.
- Find that frequency in the freq_levels list (and here it picks the
  first 2100 entry, not the second one!), then pick the one after
  that, which is again 2100MHz.

So basically, since the same frequency appears twice in the available
frequency list, powerd *never* lowers the frequency.

>How-To-Repeat:

- Buy an Athlon X2 BE-2350
- Observe:
  $ powerd -v
  idle time > 90%, decreasing clock speed from 2100 MHz to 2100 MHz
  idle time > 90%, decreasing clock speed from 2100 MHz to 2100 MHz
  idle time > 90%, decreasing clock speed from 2100 MHz to 2100 MHz
  idle time > 90%, decreasing clock speed from 2100 MHz to 2100 MHz
  idle time > 90%, decreasing clock speed from 2100 MHz to 2100 MHz
  idle time > 90%, decreasing clock speed from 2100 MHz to 2100 MHz
- grok code in /usr/src/usr.sbin/powerd/powerd.c, around lines 404 and
  492

>Fix:

A possible fix is the following: when picking the next lower frequency,
skip frequencies that equal the current frequency. Another one would be
changing the freq_levels sysctl to never report the same frequency
twice.


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mav 
State-Changed-When: Tue Nov 18 16:00:29 UTC 2008 
State-Changed-Why:  
Fixed in -CURRENT by r185050. 

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