Last active
December 16, 2015 05:49
-
-
Save seidler2547/5387267 to your computer and use it in GitHub Desktop.
Plagued by the wrong CPU frequency scaling on AMD FX processors (e.g. on 3.2.0 kernel), I wrote this simple userspace governor script which will always set the two Bulldozer/Piledriver cores in the same module to the same frequency based on the current CPU usage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in $(grep -Eo "cpu[0-9]+" /proc/stat); do cpufreq-set -c ${i/cpu/} -g userspace ; done | |
bash -c 'while :;do grep -E "cpu[0-9]+" /proc/stat;sleep 0.2;done|gawk '"'"'BEGIN{getline MINF<"/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" ;getline MAXF<"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"}{cn=$1;sub(/cpu/,"",cn);if(cn==0)for(i in cu){ocu[i]=cu[i];cu[i]=0;oci[i]=ci[i];ci[i]=0}pg=rshift(cn,1);for(i=2;i<=NF;i++){if(i!=5)cu[pg]+=$i;ci[pg]+=$i}if(pg*2!=cn){tf=200*(cu[pg]-ocu[pg])/(ci[pg]-oci[pg]);if(tf>100)tf=100;if(tf<0)tf=0;sc=tf*(MAXF-MINF)/100+MINF-300000;sc-=sc%100000;for(j=0;j<2;j++)print sc|"cat>/sys/devices/system/cpu/cpu"(pg*2+j)"/cpufreq/scaling_setspeed"}}'"'&" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Customizing
sleep 0.2
determines the polling frequency[...]+MINF-300000
). Set to approx. 1/2 the distance between the maximum frequency step and the one just below, it's a basic bias towards powersave or performance&&i!=3
afterif(i!=5
&&i!=6
afterif(i!=5
(can be combined)