Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Feb 2010 14:36:19 GMT
From:      Boris Kochergin <spawk@acm.poly.edu>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/144232: [PATCH] Add debug.cpufreq.highest to cpufreq
Message-ID:  <201002231436.o1NEaJDt079221@www.freebsd.org>
Resent-Message-ID: <201002231440.o1NEe0Ra002633@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         144232
>Category:       kern
>Synopsis:       [PATCH] Add debug.cpufreq.highest to cpufreq
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 23 14:40:00 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Boris Kochergin
>Release:        8.0-RELEASE-p2
>Organization:
Polytechnic Institute of NYU
>Environment:
FreeBSD peer 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #2: Mon Feb 22 23:18:53 EST 2010     root@peer:/usr/obj/usr/src/sys/PEER  i386
>Description:
I request that support for the debug.cpufreq.highest sysctl, which places an upper bound on the frequencies returned to users, be added to cpufreq. I am currently using it in conjunction with the dev.acpi_ibm.0.fan_level sysctl from the acpi_ibm module set to 0 to keep a laptop both cool and quiet while it has a broken fan. Others have also found uses for the functionality (http://forums.freebsd.org/showthread.php?t=172).
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- sys/kern/kern_cpu.c.orig    2010-02-22 22:40:37.000000000 -0500
+++ sys/kern/kern_cpu.c 2010-02-22 23:11:03.000000000 -0500
@@ -131,12 +131,16 @@
 DRIVER_MODULE(cpufreq, cpu, cpufreq_driver, cpufreq_dc, 0, 0);
 
 static int             cf_lowest_freq;
+static int             cf_highest_freq;
 static int             cf_verbose;
 TUNABLE_INT("debug.cpufreq.lowest", &cf_lowest_freq);
+TUNABLE_INT("debug.cpufreq.highest", &cf_highest_freq);
 TUNABLE_INT("debug.cpufreq.verbose", &cf_verbose);
 SYSCTL_NODE(_debug, OID_AUTO, cpufreq, CTLFLAG_RD, NULL, "cpufreq debugging");
 SYSCTL_INT(_debug_cpufreq, OID_AUTO, lowest, CTLFLAG_RW, &cf_lowest_freq, 1,
     "Don't provide levels below this frequency.");
+SYSCTL_INT(_debug_cpufreq, OID_AUTO, highest, CTLFLAG_RW, &cf_highest_freq, 1,
+    "Don't provide levels above this frequency.");
 SYSCTL_INT(_debug_cpufreq, OID_AUTO, verbose, CTLFLAG_RW, &cf_verbose, 1,
     "Print verbose debugging messages");
 
@@ -306,6 +310,14 @@
                goto out;
        }
 
+       /* Reject levels that are above our specified threshold. */
+       if (cf_highest_freq > 0 && level->total_set.freq > cf_highest_freq) {
+               CF_DEBUG("rejecting freq %d, greater than %d limit\n",
+                   level->total_set.freq, cf_highest_freq);
+               error = EINVAL;
+               goto out;
+       }
+
        /* If already at this level, just return. */
        if (CPUFREQ_CMP(sc->curr_level.total_set.freq, level->total_set.freq)) {
                CF_DEBUG("skipping freq %d, same as current level %d\n",
@@ -633,8 +645,13 @@
                        continue;
                }
 
-               /* Skip levels that have a frequency that is too low. */
-               if (lev->total_set.freq < cf_lowest_freq) {
+               /*
+                * Skip levels that have a frequency that is too low or too
+                * high.
+                */
+               if (lev->total_set.freq < cf_lowest_freq ||
+                   (cf_highest_freq > 0 &&
+                    lev->total_set.freq > cf_highest_freq)) {
                        sc->all_count--;
                        continue;
                }

--- share/man/man4/cpufreq.4.orig       2010-02-23 09:24:45.000000000 -0500
+++ share/man/man4/cpufreq.4    2010-02-23 09:25:59.000000000 -0500
@@ -98,6 +98,11 @@
 This setting is also accessible via a tunable with the same name.
 This can be used to disable very low levels that may be unusable on
 some systems.
+.It Va debug.cpufreq.highest
+Highest CPU frequency in MHz to offer to users.
+This setting is also accessible via a tunable with the same name.
+This can be used to disable very high levels that may be unusable on
+some systems.
 .It Va debug.cpufreq.verbose
 Print verbose messages.
 This setting is also accessible via a tunable with the same name.


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002231436.o1NEaJDt079221>