svn commit: r186154 - head/sys/kern

Alexander Motin mav at FreeBSD.org
Tue Dec 16 01:24:06 UTC 2008


Author: mav
Date: Tue Dec 16 01:24:05 2008
New Revision: 186154
URL: http://svn.freebsd.org/changeset/base/186154

Log:
  If possible, try to obtain max_mhz on cpufreq attach instead of first request.
  
  On HyperThreading CPUs logical cores have same frequency, so setting it
  on any core will change the other's one. In most cases first request
  to the second core will be the "set" request, done after setting frequency
  of the first core. In such case second CPU will obtain throttled frequency
  of the first core as it's max_mhz making cpufreq broken due to different
  frequency sets.

Modified:
  head/sys/kern/kern_cpu.c

Modified: head/sys/kern/kern_cpu.c
==============================================================================
--- head/sys/kern/kern_cpu.c	Tue Dec 16 01:21:19 2008	(r186153)
+++ head/sys/kern/kern_cpu.c	Tue Dec 16 01:24:05 2008	(r186154)
@@ -144,7 +144,9 @@ static int
 cpufreq_attach(device_t dev)
 {
 	struct cpufreq_softc *sc;
+	struct pcpu *pc;
 	device_t parent;
+	uint64_t rate;
 	int numdevs;
 
 	CF_DEBUG("initializing %s\n", device_get_nameunit(dev));
@@ -156,7 +158,12 @@ cpufreq_attach(device_t dev)
 	CF_MTX_INIT(&sc->lock);
 	sc->curr_level.total_set.freq = CPUFREQ_VAL_UNKNOWN;
 	SLIST_INIT(&sc->saved_freq);
-	sc->max_mhz = CPUFREQ_VAL_UNKNOWN;
+	/* Try to get current CPU freq to use it as maximum later if needed */
+	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;
 
 	/*
 	 * Only initialize one set of sysctls for all CPUs.  In the future,


More information about the svn-src-all mailing list