From owner-svn-src-head@FreeBSD.ORG Sat Mar 10 18:56:17 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 20B85106564A; Sat, 10 Mar 2012 18:56:17 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0167A8FC20; Sat, 10 Mar 2012 18:56:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2AIuGXk072787; Sat, 10 Mar 2012 18:56:16 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2AIuGt4072785; Sat, 10 Mar 2012 18:56:16 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201203101856.q2AIuGt4072785@svn.freebsd.org> From: Alexander Motin Date: Sat, 10 Mar 2012 18:56:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232793 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Mar 2012 18:56:17 -0000 Author: mav Date: Sat Mar 10 18:56:16 2012 New Revision: 232793 URL: http://svn.freebsd.org/changeset/base/232793 Log: Revert r175376 and tune cpufreq(4) frequency comparison logic instead. Instead of using 25MHz equality threshold, look for the nearest value when handling dev.cpu.0.freq sysctl and for exact match when it is expected. ACPI may report extra level with frequency 1MHz above the nominal to control Intel Turbo Boost operation. It is not a bug, but feature: dev.cpu.0.freq_levels: 2934/106000 2933/95000 2800/82000 ... In this case value 2933 means 2.93GHz, but 2934 means 3.2-3.6GHz. I've found that my Core i7-870 based system has Intel Turbo Boost disabled by default and without this change it was absolutely invisible and hard to control. MFC after: 2 weeks Modified: head/sys/kern/kern_cpu.c Modified: head/sys/kern/kern_cpu.c ============================================================================== --- head/sys/kern/kern_cpu.c Sat Mar 10 18:37:01 2012 (r232792) +++ head/sys/kern/kern_cpu.c Sat Mar 10 18:56:16 2012 (r232793) @@ -312,7 +312,7 @@ cf_set_method(device_t dev, const struct } /* If already at this level, just return. */ - if (CPUFREQ_CMP(sc->curr_level.total_set.freq, level->total_set.freq)) { + if (sc->curr_level.total_set.freq == level->total_set.freq) { CF_DEBUG("skipping freq %d, same as current level %d\n", level->total_set.freq, sc->curr_level.total_set.freq); goto skip; @@ -471,7 +471,7 @@ cf_get_method(device_t dev, struct cf_le if (CPUFREQ_DRV_GET(devs[n], &set) != 0) continue; for (i = 0; i < count; i++) { - if (CPUFREQ_CMP(set.freq, levels[i].total_set.freq)) { + if (set.freq == levels[i].total_set.freq) { sc->curr_level = levels[i]; break; } @@ -627,16 +627,6 @@ cf_levels_method(device_t dev, struct cf /* Finally, output the list of levels. */ i = 0; TAILQ_FOREACH(lev, &sc->all_levels, link) { - /* - * Skip levels that are too close in frequency to the - * previous levels. Some systems report bogus duplicate - * settings (i.e., for acpi_perf). - */ - if (i > 0 && CPUFREQ_CMP(lev->total_set.freq, - levels[i - 1].total_set.freq)) { - sc->all_count--; - continue; - } /* Skip levels that have a frequency that is too low. */ if (lev->total_set.freq < cf_lowest_freq) { @@ -870,7 +860,7 @@ cpufreq_curr_sysctl(SYSCTL_HANDLER_ARGS) { struct cpufreq_softc *sc; struct cf_level *levels; - int count, devcount, error, freq, i, n; + int best, count, diff, bdiff, devcount, error, freq, i, n; device_t *devs; devs = NULL; @@ -902,17 +892,16 @@ cpufreq_curr_sysctl(SYSCTL_HANDLER_ARGS) "cpufreq: need to increase CF_MAX_LEVELS\n"); break; } + best = 0; + bdiff = 1 << 30; for (i = 0; i < count; i++) { - if (CPUFREQ_CMP(levels[i].total_set.freq, freq)) { - error = CPUFREQ_SET(devs[n], &levels[i], - CPUFREQ_PRIO_USER); - break; + diff = abs(levels[i].total_set.freq - freq); + if (diff < bdiff) { + bdiff = diff; + best = i; } } - if (i == count) { - error = EINVAL; - break; - } + error = CPUFREQ_SET(devs[n], &levels[best], CPUFREQ_PRIO_USER); } out: