problems with Athlon64 X2 (dual core)
PATCH 1/1 problems with Athlon64 X2 (dual core)
[already posted as bug report on the sourceforge page]
Hi,
As far as I can tell, cpufreq/powersaved (of 0.10.15.1, as in SuSE 10.0) seems to have a severe problem with the Athlon64 X2 dual core chips. If I load just one core, the CPU frequency boost is unreliable (toggles between 1GHz and 2GHz). Loading the second core, too, sort-of-fixes that problem.
The reason is obvious: The Athlon X2 has a *single* CPU frequency setting which affects *both* cores. So you can't simply use a SMP setting, treating the two CPUs as two processors with two speed settings, you have to know that it's a dual-core CPU, and that you can't independently set the CPU frequency. If one core is loaded, both must run at double frequency.
Note that the kernel does know about this fact:
/sys/devices/system/cpu/cpu0/cpufreq> cat affected_cpus 0 1/sys/devices/system/cpu/cpu1/cpufreq> cat affected_cpus 0 1
Setting powersaved to be more verbose confirms the confusion (the following is with one core loaded by an endless loop, the other core loaded lightly):
-------------------------------------------------
Nov 10 13:24:48 linux [powersave]: Info (setSpeed:90) Speed set to: 1800000KHz in file /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed Nov 10 13:24:48 linux [powersave]: Info (setSpeed:90) Speed set to: 2000000KHz in file /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed Nov 10 13:24:48 linux [powersave]: Info (adjustSpeed:196) Speed directly set to max (2000000) MHz Nov 10 13:24:48 linux [powersave]: Info (decreaseSpeed:138) current speed: 2000000KHz new speed: 1800000KHz Nov 10 13:24:48 linux [powersave]: Info (setSpeed:90) Speed set to: 1800000KHz in file /sys/devices/system/cpu/cpu1/cpufreq/scaling_setspeed Nov 10 13:24:48 linux [powersave]: Info (adjustSpeed:207) Speed decreased to (1800000) MHz Nov 10 13:24:48 linux [powersave]: Info (decreaseSpeed:138) current speed: 2000000KHz new speed: 1800000KHz Nov 10 13:24:48 linux [powersave]: Info (setSpeed:90) Speed set to: 1800000KHz in file /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed Nov 10 13:24:48 linux [powersave]: Info (adjustSpeed:207) Speed decreased to (1800000) MHz Nov 10 13:24:48 linux [powersave]: Info (setSpeed:90) Speed set to: 2000000KHz in file /sys/devices/system/cpu/cpu1/cpufreq/scaling_setspeed Nov 10 13:24:48 linux [powersave]: Info (adjustSpeed:196) Speed directly set to max (2000000) MHz Nov 10 13:24:48 linux [powersave]: Info (decreaseSpeed:138) current speed: 1800000KHz new speed: 1000000KHz Nov 10 13:24:48 linux [powersave]: Info (setSpeed:90) Speed set to: 1000000KHz in file /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed Nov 10 13:24:48 linux [powersave]: Info (adjustSpeed:207)
Speed decreased to (1000000) MHz
-------------------------------------------------
This seems to be a pretty severe bug, rendering
cpufreq unreliable on a dual-core Athlon64.
Looking into the source confirms the problem. I suggest to do the following:
Look at cpufreq/affected_cpus, and store this as bitmask or list instead of the number stored in the variable cpu now. There should be only one object per chip (= set of affected processors). For setSpeed, walk through all the processors defined in the mask, get their load, and set the speed to the highest frequency found.
I wrote a small "proof of the concept"-patch that takes the affected_cpus data, and creates a bit-mask (implemented only for the userspace part, since that's what I use). It doesn't eliminate the second scanned CPU out of the list, but it works for me.
What do you think?
Signature · 3 lines
Bernd Paysan "If you want it done right, you have to do it yourself" http://www.jwdt.com/~paysan/
daemon/cpufreq.cpp +3 -0
@@ -128,6 +128,9 @@ strstr << SYSFS_FILES << "cpu" << cpu << "/cpufreq/scaling_available_frequencies"; AVAILABLE_FREQS_FILE = strstr.str(); strstr.str(""); + strstr << SYSFS_FILES << "cpu" << cpu << "/cpufreq/affected_cpus"; + AFFECTED_CPUS = strstr.str(); + strstr.str(""); } // supported speeds
daemon/cpufreq.h +2 -0
@@ -89,6 +89,7 @@*/ string MIN_SPEED_FILE ;string MAX_SPEED_FILE ; +string AFFECTED_CPUS ;string AVAILABLE_FREQS_FILE ;/** @brief configuration variables
@@ -183,6 +184,7 @@/** @brief Stores to which CPU this object corresponds * This is the same as the maps are accessed object_cpus_xxx[cpu] */ int cpu; +long long cpumask;/** @brief This can be called outside after calling createCPUFreqObject() *
daemon/cpufreq_userspace.cpp +36 -2
@@ -24,6 +24,30 @@ #include "cpufreq.h" +/** @brief read values from a file, convert to bit mask */ +inline long long read_mask(const char *filename) +{ + char line[MAX_LINE_SIZE]; + int offset = 0; + long long mask = 0; + char * tmp; + if (read_line(filename, line, sizeof line) < 0) { + // we already throw an error in read_line() + return 0; + } else { + pDebug(DBG_INFO, "Value '%s' read from %s", line, filename); + do { + mask |= (((long long)1) << atoi(line+offset)); + tmp = strstr(line+offset, " "); + if(tmp) + offset = tmp - line; + else + break; + } while(line[offset] != '\0'); + return mask; + } +} + CPUFreq_Userspace::CPUFreq_Userspace(int sysfs, int cpu):CPUFreq_Interface(sysfs, cpu) {
@@ -66,6 +90,7 @@ current_speed = 0; last_cpu_load = 50; new_speed = 0; + cpumask = read_mask(AFFECTED_CPUS.c_str()); #ifdef CPUFREQ_MEASURE for (int x = 0; x <= MAX_SPEEDS; x++)
@@ -162,16 +187,25 @@ return 1; } -int CPUFreq_Userspace::setMode(CPUFREQ_MODE mode) +inline double min(double a, double b) { + return (a < b) ? a : b; +} +int CPUFreq_Userspace::setMode(CPUFREQ_MODE mode) +{ + int i; double maxload=100.0; /* throw these two lines out to force governor to be set */ if (mode == CPUFreq_Interface::mode) return 0; CPUFreq_Interface::mode = mode; - adjustSpeed(getCPULoad(cpu)); + for(i=cpu; i < cpus; i++) { + if((((long long)1)<<i) & cpumask) + maxload=min(getCPULoad(i),maxload); + } + adjustSpeed(maxload); return 0; }
scripts/rcpowersaved +1 -1
@@ -64,7 +64,7 @@ test -x $powersaved_BIN || exit 5 # Check for existence of needed config file and read it -CONFIG=/usr/local/etc/powersave +CONFIG=/etc/powersave test -r $CONFIG || exit 6 . $CONFIG/common
_______________________________________________
Cpufreq mailing list
[email protected]
http://lists.linux.org.uk/mailman/listinfo/cpufreq
12.11.2005 18:33, Bernd Paysan wrote/a écrit:
Quoted 6 lines
[already posted as bug report on the sourceforge page]
Hi,
As far as I can tell, cpufreq/powersaved (of 0.10.15.1, as in SuSE 10.0) seems to have a severe problem with the Athlon64 X2 dual core chips. If I load just one core, the CPU frequency boost is unreliable (toggles between 1GHz and 2GHz). Loading the second core, too, sort-of-fixes that problem.
Quoted 8 lines
The reason is obvious: The Athlon X2 has a *single* CPU frequency setting which affects *both* cores. So you can't simply use a SMP setting, treating the two CPUs as two processors with two speed settings, you have to know that it's a dual-core CPU, and that you can't independently set the CPU frequency. If one core is loaded, both must run at double frequency.
Note that the kernel does know about this fact:
/sys/devices/system/cpu/cpu0/cpufreq> cataffected_cpus0 1/sys/devices/system/cpu/cpu1/cpufreq> cataffected_cpus0 1Setting powersaved to be more verbose confirms the confusion (the following is with one core loaded by an endless loop, the other core loaded lightly):
Hey,
You've probably mistook with the list, it's only about the kernel implementation of cpufreq.
cheers,
Eric