powernow regression in 8-STABLE

Jung-uk Kim jkim at FreeBSD.org
Thu Jul 21 21:53:56 UTC 2011


On Thursday 21 July 2011 04:56 pm, Callum Gibson wrote:
> On 21Jul11 12:07, Jung-uk Kim wrote:
> }Can you please do "set debug.cpufreq.verbose=1" from loader prompt
> and }show me the dmesg output?  I want to see intial settings.  You
> can }reset it from command line with "sysctl
> debug.cpufreq.verbose=0" }later.
>
> http://members.optusnet.com.au/callumgibson/boot_verboser.out
>
> Also, as suggested by jhb@, with legacy usb disabled:
> http://members.optusnet.com.au/callumgibson/boot_verboser_nousb.out
> and dev.cpu.0.freq reappears! Spooky. Is that a solution or a
> workaround? I noticed this disables usb keyboard support at the
> boot menus.

It is a workaround.  Please try the attached patch.

Jung-uk Kim
-------------- next part --------------
Index: sys/kern/kern_cpu.c
===================================================================
--- sys/kern/kern_cpu.c	(revision 224245)
+++ sys/kern/kern_cpu.c	(working copy)
@@ -157,17 +157,18 @@ cpufreq_attach(device_t dev)
 	sysctl_ctx_init(&sc->sysctl_ctx);
 	TAILQ_INIT(&sc->all_levels);
 	CF_MTX_INIT(&sc->lock);
-	sc->curr_level.total_set.freq = CPUFREQ_VAL_UNKNOWN;
 	SLIST_INIT(&sc->saved_freq);
 	/* Try to get nominal CPU freq to use it as maximum later if needed */
-	sc->max_mhz = cpu_get_nominal_mhz(dev);
-	/* If that fails, try to measure the current rate */
-	if (sc->max_mhz <= 0) {
-		pc = cpu_get_pcpu(dev);
-		if (cpu_est_clockrate(pc->pc_cpuid, &rate) == 0)
-			sc->max_mhz = rate / 1000000;
-		else
-			sc->max_mhz = CPUFREQ_VAL_UNKNOWN;
+	if (sc->max_mhz == CPUFREQ_VAL_UNKNOWN) {
+		sc->max_mhz = cpu_get_nominal_mhz(dev);
+		/* If that fails, try to measure the current rate */
+		if (sc->max_mhz <= 0) {
+			pc = cpu_get_pcpu(dev);
+			if (cpu_est_clockrate(pc->pc_cpuid, &rate) == 0)
+				sc->max_mhz = rate / 1000000;
+			else
+				sc->max_mhz = CPUFREQ_VAL_UNKNOWN;
+		}
 	}
 
 	/*
@@ -1000,8 +1001,11 @@ out:
 int
 cpufreq_register(device_t dev)
 {
+	struct cf_setting set;
+	struct cf_setting *sets;
 	struct cpufreq_softc *sc;
 	device_t cf_dev, cpu_dev;
+	int error, freq, max, set_count, type;
 
 	/* Add a sysctl to get each driver's settings separately. */
 	SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
@@ -1009,14 +1013,34 @@ cpufreq_register(device_t dev)
 	    OID_AUTO, "freq_settings", CTLTYPE_STRING | CTLFLAG_RD, dev, 0,
 	    cpufreq_settings_sysctl, "A", "CPU frequency driver settings");
 
+	/* Get settings from the device and find current and maximum frequencies */
+	freq = max = CPUFREQ_VAL_UNKNOWN;
+	if (CPUFREQ_DRV_TYPE(dev, &type) == 0 &&
+	    (type & CPUFREQ_TYPE_MASK) == CPUFREQ_TYPE_ABSOLUTE) {
+		if (CPUFREQ_DRV_GET(dev, &set) == 0)
+			freq = set.freq;
+		set_count = MAX_SETTINGS;
+		sets = malloc(set_count * sizeof(*sets), M_TEMP, M_NOWAIT);
+		if (sets != NULL) {
+			if (CPUFREQ_DRV_SETTINGS(dev, sets, &set_count) == 0 &&
+			    set_count > 0)
+				max = sets[0].freq;
+			free(sets, M_TEMP);
+		}
+	}
+
 	/*
 	 * Add only one cpufreq device to each CPU.  Currently, all CPUs
 	 * must offer the same levels and be switched at the same time.
 	 */
 	cpu_dev = device_get_parent(dev);
-	if ((cf_dev = device_find_child(cpu_dev, "cpufreq", -1))) {
+	cf_dev = device_find_child(cpu_dev, "cpufreq", -1);
+	if (cf_dev != NULL) {
 		sc = device_get_softc(cf_dev);
-		sc->max_mhz = CPUFREQ_VAL_UNKNOWN;
+		if (sc->curr_level.total_set.freq == CPUFREQ_VAL_UNKNOWN)
+			sc->curr_level.total_set.freq = freq;
+		if (sc->max_mhz == CPUFREQ_VAL_UNKNOWN)
+			sc->max_mhz = max;
 		return (0);
 	}
 
@@ -1025,8 +1049,13 @@ cpufreq_register(device_t dev)
 	if (cf_dev == NULL)
 		return (ENOMEM);
 	device_quiet(cf_dev);
-
-	return (device_probe_and_attach(cf_dev));
+	error = device_probe(cf_dev);
+	if (error != 0)
+		return (error);
+	sc = device_get_softc(cf_dev);
+	sc->curr_level.total_set.freq = freq;
+	sc->max_mhz = max;
+	return (device_attach(cf_dev));
 }
 
 int


More information about the freebsd-stable mailing list