Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Mar 2012 16:17:47 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r233368 - stable/9/sys/kern
Message-ID:  <201203231617.q2NGHlKG083738@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Fri Mar 23 16:17:46 2012
New Revision: 233368
URL: http://svn.freebsd.org/changeset/base/233368

Log:
  MFC r232793:
  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 based systems have Intel Turbo Boost not used
  by default and without this change it was absolutely invisible and hard
  to control.

Modified:
  stable/9/sys/kern/kern_cpu.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/kern_cpu.c
==============================================================================
--- stable/9/sys/kern/kern_cpu.c	Fri Mar 23 16:12:52 2012	(r233367)
+++ stable/9/sys/kern/kern_cpu.c	Fri Mar 23 16:17:46 2012	(r233368)
@@ -311,7 +311,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;
@@ -470,7 +470,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;
 			}
@@ -626,16 +626,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) {
@@ -869,7 +859,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;
@@ -901,17 +891,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:



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