From root@death.ispvds.com  Sun Oct 22 22:07:52 2006
Return-Path: <root@death.ispvds.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D74C616A403
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 22 Oct 2006 22:07:52 +0000 (UTC)
	(envelope-from root@death.ispvds.com)
Received: from death.ispvds.com (death.ispvds.com [82.146.33.163])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 81F0343D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 22 Oct 2006 22:07:51 +0000 (GMT)
	(envelope-from root@death.ispvds.com)
Received: by death.ispvds.com (Postfix, from userid 0)
	id 2C7612E0C07; Sun, 22 Oct 2006 22:07:57 +0000 (UTC)
Message-Id: <20061022220757.2C7612E0C07@death.ispvds.com>
Date: Sun, 22 Oct 2006 22:07:57 +0000 (UTC)
From: redchrom@gmail.com
Reply-To: redchrom@gmail.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: add support for limiting cpu frequency on adaptive mode
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         104689
>Category:       bin
>Synopsis:       [patch] [request] powerd(8): add support for limiting cpu frequency on adaptive mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    matteo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 22 22:10:14 GMT 2006
>Closed-Date:    Sat Jun 19 04:44:37 UTC 2010
>Last-Modified:  Sat Jun 19 04:44:37 UTC 2010
>Originator:     Stepan Zastupov (RedChrom)
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
ISPSystem
>Environment:
System: FreeBSD stepan.ispsystem.net 7.0-CURRENT FreeBSD 7.0-CURRENT #5: Fri Oct 20 11:51:51 IRKST 2006 root@stepan.ispsystem.net:/usr/obj/usr/src/sys/LILITH i386


	
>Description:
	Adaptive mode really helps to prolong life of battery but with low idle it sets maximum frequency. I think limit maximum frequency on adaptive mode it's good idea. I know patch is very dirty but I hope you'll like my idea.
>How-To-Repeat:
	
	Apply the patch and run powerd:
	powerd -a maximum -b adaptive -m 558
	Where 558 is maximum frequency on adaptive mode
>Fix:

	

--- powerd.c.diff begins here ---
--- powerd.c.orig	Mon Oct 23 06:08:17 2006
+++ powerd.c	Mon Oct 23 06:54:31 2006
@@ -370,7 +370,7 @@
 	struct pidfh *pfh = NULL;
 	const char *pidfile = NULL;
 	long idle, total;
-	int curfreq, *freqs, i, *mwatts, numfreqs;
+	int curfreq, *freqs, i, *mwatts, numfreqs, maxfreq;
 	int ch, mode, mode_ac, mode_battery, mode_none;
 	uint64_t mjoules_used;
 	size_t len;
@@ -382,12 +382,13 @@
 	poll_ival = DEFAULT_POLL_INTERVAL;
 	mjoules_used = 0;
 	vflag = 0;
+	maxfreq = 0;
 
 	/* User must be root to control frequencies. */
 	if (geteuid() != 0)
 		errx(1, "must be root to run");
 
-	while ((ch = getopt(argc, argv, "a:b:i:n:p:P:r:v")) != EOF)
+	while ((ch = getopt(argc, argv, "a:b:i:n:p:P:r:m:v")) != EOF)
 		switch (ch) {
 		case 'a':
 			parse_mode(optarg, &mode_ac, ch);
@@ -424,6 +425,9 @@
 				usage();
 			}
 			break;
+		case 'm':
+			maxfreq = atoi(optarg);
+			break;
 		case 'v':
 			vflag = 1;
 			break;
@@ -592,9 +596,19 @@
 			if (freqs[i] == curfreq)
 				break;
 		}
+
+		if (maxfreq == 0)
+			maxfreq = freqs[0];
+
 		if (idle < (total * cpu_running_mark) / 100 &&
-		    curfreq < freqs[0]) {
-			i -= 2;
+			curfreq < maxfreq) {
+			/*
+			 * I know, next three lines is dirty
+			 */
+			i -= 1;
+			if (freqs[i] < maxfreq)
+				i -= 1;
+
 			if (i < 0)
 				i = 0;
 			if (vflag) {
--- powerd.c.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Sat Feb 17 11:13:51 UTC 2007 
Responsible-Changed-Why:  
I'll take care of this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=104689 
State-Changed-From-To: open->suspended 
State-Changed-By: matteo 
State-Changed-When: Sat Feb 17 18:53:16 UTC 2007 
State-Changed-Why:  
A patche based on this idea is available at 
http://people.freebsd.org/~matteo/powerd-minmaxfreq.patch 
but Nate (njl@) said that powerd(8) is going under a major overhaul 
and we don't want to add additional features now. 

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

From: Bruce Cran <bruce@cran.org.uk>
To: bug-followup@freebsd.org,
 redchrom@gmail.com
Cc:  
Subject: Re: bin/104689: [patch] [request] powerd(8): add support for limiting cpu frequency on adaptive mode
Date: Thu, 25 Mar 2010 08:36:35 +0000

 The patch that was linked to appears to have been removed from the freebsd 
 server.
 
 kern/144232 also contains a patch to limit the maximum frequency.
 
 -- 
 Bruce Cran
State-Changed-From-To: suspended->closed 
State-Changed-By: linimon 
State-Changed-When: Sat Jun 19 04:43:30 UTC 2010 
State-Changed-Why:  
This PR is by now quite old.  See kern/144232 for a more modern patch 
addressing the same problem. 

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