How do you set CPU throttling frequencies?  Topic is solved

Post questions regarding lower-level issues will here.

How do you set CPU throttling frequencies?

Postby Liss » January 16th, 2018, 4:52 am

Hi, I'm new here so please be gentle.

I'm having problems with an HP laptop with a very limited BIOS setup program.

cpu throttling is working fine but I'd like to change the upper and lower limits to prevent overheating.
In Windows it throttles down to something like 2/300MHz and OCs up to about 2.3GHz.
I tried editing the following files but I can't overwrite them even as root.

/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

/sys/devices/system/cpu/cpu1/cpufreq/scaling_available_frequencies

/sys/devices/system/cpu/cpu2/cpufreq/scaling_available_frequencies

/sys/devices/system/cpu/cpu3/cpufreq/scaling_available_frequencies

The contents currently say:
1600000 1400000 1200000 1100000 1000000 900000 800000

I'd like to throttle it back to something like this:
1200000 1100000 1000000 900000 800000 700000 600000 500000 400000
making the minimum 400MHz and the maximum 1.2GHz.

If possible I'd also like to know how to disable cores 1 and 3 but first thing first aye.

Anyone have any idea how to do this?

In case it matters I'm using Debian 9 AMD64 with XFCE.

Alyssa
Liss
 
Posts: 5
Joined: January 16th, 2018, 4:44 am

Re: How do you set CPU throttling frequencies?

Postby Pick2 » January 16th, 2018, 8:17 am

The registers and cache in CPUs use Dynamic memory, which needs to be refreshed , so you can't go below that 800000 or 800 MHz in modern CPUs.
You may be able to set the high frequency lower , But I don't know how.

Good Luck
Just folded space from Arrakis
Fugitive of the fdn re-education camp.
User avatar
Pick2
 
Posts: 171
Joined: February 10th, 2011, 1:22 am
Location: Decatur , Illinois , USA

Re: How do you set CPU throttling frequencies?

Postby Liss » January 16th, 2018, 4:08 pm

How modern is modern? I'd call this legacy hardware; not exactly antique like my G4 iMac but still, it's like 7++ years old (Win7 was brand new and Vista was still on new PCs).
With AMD Catalyst Control Centre and HP's Bundled Win 7 it definitely goes below 800MHz, disables cores and one of the GPUs.
It doesn't do that with default Win7 or Win10 (it can't really handle Win10 tbh), only with the HP Win7, but then drivers directly from AMD never worked, only the ones from HP.
I have no idea what the clock frequency or multipliers or anything else are as the BIOS program is totally locked down HPware.

Anyhoo thanks for the reply; I'll scour Google some more and hope someone turns up with the answer.

:)
Liss
 
Posts: 5
Joined: January 16th, 2018, 4:44 am

Re: How do you set CPU throttling frequencies?  Topic is solved

Postby Liss » January 16th, 2018, 8:02 pm

I don't know how to make this permanent yet but here we go:

First install cpufrequtils from Synaptic or bash.

In bash do:
Code: Select all
sudo cpufreq-info

This tells you useful info about your CPU cores.
The info we want is the available frequencies, and the available governors.

-g allows you to choose which governor to use.
-c selects which core to set. omitting this is the same as selecting the first core (cpu0) and only the first core.
-u sets the maximum frequency.
-d sets the minimum frequency.

With cpufrequtils installed and the relevant info gathered, these 4 lines dropped into bash one at a time, sets the governor of each core to ondemand and limits them to 1GHz:
Code: Select all
sudo cpufreq-set -g ondemand -c 0 -u 1000MHz
sudo cpufreq-set -g ondemand -c 1 -u 1000MHz
sudo cpufreq-set -g ondemand -c 2 -u 1000MHz
sudo cpufreq-set -g ondemand -c 3 -u 1000MHz


You can check it worked with
Code: Select all
cpufreq-info


To undo this I would simply do:
Code: Select all
sudo cpufreq-set -g ondemand -c 0 -u 1.6GHz
sudo cpufreq-set -g ondemand -c 1 -u 1.6GHz
sudo cpufreq-set -g ondemand -c 2 -u 1.6GHz
sudo cpufreq-set -g ondemand -c 3 -u 1.6GHz


So problem partially solved.
Liss
 
Posts: 5
Joined: January 16th, 2018, 4:44 am

Re: How do you set CPU throttling frequencies?

Postby Liss » January 16th, 2018, 10:49 pm

I wrote a script to automate this:

Code: Select all
#!/bin/bash

#   This shell script is to select new maximum cpu speed.
#   Written by Alyssa.
#   There is probably much better sh out there so please feel free to improve it.
#
#   Notes:
#   Originally written for Debian 9 AMD64
#   This script assumes 4 cpus [0-3].
#   This script assumes cpu throttling is already working.
#   This script assumes 7 cpu speeds are available in /sys/devices/system/cpu/cpu[0-3]/cpufreq/scaling_available_frequencies
#   This script does not enable cpu speeds other than those already supported; it is not for over/underclocking or correcting cpu upper or lower limits.
#
#   This script requires cpufrequtils and will install it if missing (Debian).

echo '****************************************************************'
echo '****************************************************************'
echo 'CPU Speed Script'
echo 'Written by Alyssa'
echo ''
#############################################################################################
#   check if cpufrequtils is installed, and if not, install it.
echo 'Checking script dependencies...'
installed=$(dpkg-query -W --showformat='${Status}\n' cpufrequtils|grep "install ok installed")
echo Checking for cpufrequtils: $installed
if [ "" == "$installed" ]; then
  echo "Dependencies missing. Installing now..."
  sudo apt-get --force-yes --yes install cpufrequtils
fi
echo 'Dependencies installed.'
#############################################################################################
#echo 'Current settings:'
#echo '****************************************************************'
#cpufreq-info
#echo '****************************************************************'
#############################################################################################
echo ''
cd /sys/devices/system/cpu
echo 'Checking cpu frequency options in'; pwd
#############################################################################################
#define 7 variables and assign values to them based on the data in /sys/devices/system/cpu/cpu[0-3]/cpufreq/scaling_available_frequencies.
speedOne=`awk '{print $1}' ./cpu0/cpufreq/scaling_available_frequencies`
speedTwo=`awk '{print $2}' ./cpu0/cpufreq/scaling_available_frequencies`
speedThree=`awk '{print $3}' ./cpu0/cpufreq/scaling_available_frequencies`
speedFour=`awk '{print $4}' ./cpu0/cpufreq/scaling_available_frequencies`
speedFive=`awk '{print $5}' ./cpu0/cpufreq/scaling_available_frequencies`
speedSix=`awk '{print $6}' ./cpu0/cpufreq/scaling_available_frequencies`
speedSeven=`awk '{print $7}' ./cpu0/cpufreq/scaling_available_frequencies`
#############################################################################################
#print the seven variables numbered
echo '****************************************************************'
echo '****************************************************************'
echo 'Select new max frequency.'

echo 'Press 1) for' $speedOne kHz
echo 'Press 2) for' $speedTwo kHz
echo 'Press 3) for' $speedThree kHz
echo 'Press 4) for' $speedFour kHz
echo 'Press 5) for' $speedFive kHz
echo 'Press 6) for' $speedSix kHz
echo 'Press 7) for' $speedSeven kHz
echo 'Enter any other value to exit without making changes.'

echo 'Waiting for response...'
#############################################################################################
#define new variable "n" and get user to select a value for it.
read n
   case $n in
      1)    sudo cpufreq-set -g ondemand -c 0 -u $speedOne'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedOne'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedOne'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedOne'kHz'
         echo 'CPU set to' $speedOne'kHz';;
      2)  sudo cpufreq-set -g ondemand -c 0 -u $speedTwo'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedTwo'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedTwo'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedTwo'kHz'
         echo 'CPU set to' $speedTwo'kHz';;
      3)    sudo cpufreq-set -g ondemand -c 0 -u $speedThree'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedThree'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedThree'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedThree'kHz'
         echo 'CPU set to' $speedThree'kHz';;
      4)    sudo cpufreq-set -g ondemand -c 0 -u $speedFour'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedFour'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedFour'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedFour'kHz'
         echo 'CPU set to' $speedFour'kHz';;
      5)    sudo cpufreq-set -g ondemand -c 0 -u $speedFive'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedFive'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedFive'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedFive'kHz'
         echo 'CPU set to' $speedFive'kHz';;
      6)    sudo cpufreq-set -g ondemand -c 0 -u $speedSix'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedSix'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedSix'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedSix'kHz'
         echo 'CPU set to' $speedSix'kHz';;
      7)    sudo cpufreq-set -g ondemand -c 0 -u $speedSeven'kHz'
         sudo cpufreq-set -g ondemand -c 1 -u $speedSeven'kHz'
         sudo cpufreq-set -g ondemand -c 2 -u $speedSeven'kHz'
         sudo cpufreq-set -g ondemand -c 3 -u $speedSeven'kHz'
         echo 'CPU set to' $speedSeven'kHz';;
      *)    echo 'Exiting without making changes';;
   esac

#############################################################################################
cd
#echo '****************************************************************'
#echo 'New settings:'
#echo '****************************************************************'
#cpufreq-info
echo '****************************************************************'
echo '****************************************************************'
Liss
 
Posts: 5
Joined: January 16th, 2018, 4:44 am

Re: How do you set CPU throttling frequencies?

Postby dryden » February 23rd, 2018, 12:44 pm

Liss wrote:I wrote a script to automate this:

Code: Select all
#!/bin/bash

#   Notes:
#   Originally written for Debian 9 AMD64
#   This script assumes 4 cpus [0-3].
#   This script assumes cpu throttling is already working.
#   This script assumes 7 cpu speeds are available in /sys/devices/system/cpu/cpu[0-3]/cpufreq/scaling_available_frequencies
#   This script does not enable cpu speeds other than those already supported; it is not for over/underclocking or correcting cpu upper or lower limits.
#
#   This script requires cpufrequtils and will install it if missing (Debian).

#############################################################################################


You are thorough.

My first thought was "she fell for it" when I read

Code: Select all
if [ "" == "$installed" ]; then


(Some coding styles advocate against placing the variable in front because of the risk of accidentally writing a single =, I consider that bad style, but the curious thing about Bash is that is also has no merit because the single = does the exact same thing).

Well I know you are probably not looking for it, I just find it hard not to comment on the code ;-).

It's a delightful script though.

Should I?

To test for "empty string" one can also write [ -z "$installed" ].

The line of commands that read:

Code: Select all
speedOne=`awk '{print $1}' ./cpu0/cpufreq/scaling_available_frequencies`
speedTwo=`awk '{print $2}' ./cpu0/cpufreq/scaling_available_frequencies`


Can in fact be quite easily replaced by

Code: Select all
read speedOne speedTwo .... speedSeven < ./cpu0/cpufreq/scaling_available_frequencies


In fact since you are using Bash you could use arrays.

But right now the code looks calming, so I better not touch it.

In fact one thing could be easily replaced even without arrays:

Code: Select all
sudo cpufreq-set -g ondemand -c 0 -u $speedOne'kHz'
sudo cpufreq-set -g ondemand -c 1 -u $speedOne'kHz'
sudo cpufreq-set -g ondemand -c 2 -u $speedOne'kHz'
sudo cpufreq-set -g ondemand -c 3 -u $speedOne'kHz'


Is in fact equivalent to:

Code: Select all
for i in 0 1 2 3; do
   sudo cpufreq-set -g ondemand -c $i -u $speedOne'kHz'
done


I will leave it at that.
dryden
 
Posts: 22
Joined: February 23rd, 2018, 12:26 pm


Return to System Issues

Who is online

Users browsing this forum: No registered users and 2 guests

x