[SOLVED] Can't change CPU frequency... no matter what
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Okay, so I've searched far and wide all over the innerwebs and have tried all of the suggestions I've found to no avail. I added intel_pstate=disable to the kernel boot line... and then tried to use cpufreq-set and others to try to set the governor to "performance"... If I try to manually set the frequency to the highest speed it doesn't work. It just continually fluctuates from the lowest frequency all the way up to the highest. It doesn't seem to bother speeding up the CPUs when the system is under load. I tried setting the governor to "userspace" and manually setting the range or the CPU speed... it does not work.
I've tried manually entering values into /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_frequency and scaling_governor.... no dice. I tried disabling "frequency scaling" in the BIOS (as it's supposed to go to the highest speed when you do that) and it still fluctuates all over the place. Anyone had this problem before?
I've got:
Intel(R) Core(TM) i5 CPU 680 @ 3.60GHz
Here are a few scripts I've used to limit and change my cpu. They should work on your system, but if not then you're going to have to research it, check to be sure they match your system /sys path to your cpus, and, or wait for someone else to pop in and give you something else.
This one is command line driven. just tell it what temp you want your cpu and it governs it. I have since modded it then added it to my start up of init scripts, so it is always running to keep my cpus from going into the red no matter what setting I have for them at the time. power saving or performance.
Code:
#!/bin/bash
# Usage: temp_throttle.sh max_temp
# USE CELSIUS TEMPERATURES.
# version 2.20
cat << EOF
Author: Sepero 2016 (sepero 111 @ gmx . com)
URL: http://github.com/Sepero/temp-throttle/
EOF
# Additional Links
# http://seperohacker.blogspot.com/2012/10/linux-keep-your-cpu-cool-with-frequency.html
# Additional Credits
# Wolfgang Ocker <weo AT weo1 DOT de> - Patch for unspecified cpu frequencies.
# License: GNU GPL 2.0
# Generic function for printing an error and exiting.
err_exit () {
echo ""
echo "Error: $@" 1>&2
exit 128
}
if [ $# -ne 1 ]; then
# If temperature wasn't given, then print a message and exit.
echo "Please supply a maximum desired temperature in Celsius." 1>&2
echo "For example: ${0} 60" 1>&2
exit 2
else
#Set the first argument as the maximum desired temperature.
MAX_TEMP=$1
fi
### START Initialize Global variables.
# The frequency will increase when low temperature is reached.
LOW_TEMP=$((MAX_TEMP - 5))
CORES=$(nproc) # Get number of CPU cores.
echo -e "Number of CPU cores detected: $CORES\n"
CORES=$((CORES - 1)) # Subtract 1 from $CORES for easier counting later.
# Temperatures internally are calculated to the thousandth.
MAX_TEMP=${MAX_TEMP}000
LOW_TEMP=${LOW_TEMP}000
FREQ_FILE="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies"
FREQ_MIN="/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"
FREQ_MAX="/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
# Store available cpu frequencies in a space separated string FREQ_LIST.
if [ -f $FREQ_FILE ]; then
# If $FREQ_FILE exists, get frequencies from it.
FREQ_LIST=$(cat $FREQ_FILE) || err_exit "Could not read available cpu frequencies from file $FREQ_FILE"
elif [ -f $FREQ_MIN -a -f $FREQ_MAX ]; then
# Else if $FREQ_MIN and $FREQ_MAX exist, generate a list of frequencies between them.
FREQ_LIST=$(seq $(cat $FREQ_MAX) -100000 $(cat $FREQ_MIN)) || err_exit "Could not compute available cpu frequencies"
else
err_exit "Could not determine available cpu frequencies"
fi
FREQ_LIST_LEN=$(echo $FREQ_LIST | wc -w)
# CURRENT_FREQ will save the index of the currently used frequency in FREQ_LIST.
CURRENT_FREQ=2
# This is a list of possible locations to read the current system temperature.
TEMPERATURE_FILES="
/sys/class/thermal/thermal_zone0/temp
/sys/class/thermal/thermal_zone1/temp
/sys/class/thermal/thermal_zone2/temp
/sys/class/hwmon/hwmon0/temp1_input
/sys/class/hwmon/hwmon1/temp1_input
/sys/class/hwmon/hwmon2/temp1_input
/sys/class/hwmon/hwmon0/device/temp1_input
/sys/class/hwmon/hwmon1/device/temp1_input
/sys/class/hwmon/hwmon2/device/temp1_input
null
"
# Store the first temperature location that exists in the variable TEMP_FILE.
# The location stored in $TEMP_FILE will be used for temperature readings.
for file in $TEMPERATURE_FILES; do
TEMP_FILE=$file
[ -f $TEMP_FILE ] && break
done
[ $TEMP_FILE == "null" ] && err_exit "The location for temperature reading was not found."
### END Initialize Global variables.
### START define script functions.
# Set the maximum frequency for all cpu cores.
set_freq () {
# From the string FREQ_LIST, we choose the item at index CURRENT_FREQ.
FREQ_TO_SET=$(echo $FREQ_LIST | cut -d " " -f $CURRENT_FREQ)
echo $FREQ_TO_SET
for i in $(seq 0 $CORES); do
# Try to set core frequency by writing to /sys/devices.
{ sudo echo $FREQ_TO_SET 2> /dev/null > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; } ||
# Else, try to set core frequency using command cpufreq-set.
{ sudo cpufreq-set -c $i --max $FREQ_TO_SET > /dev/null; } ||
# Else, return error message.
{ err_exit "Failed to set frequency CPU core$i. Run script as Root user. Some systems may require to install the package cpufrequtils."; }
done
}
# Will reduce the frequency of cpus if possible.
throttle () {
if [ $CURRENT_FREQ -lt $FREQ_LIST_LEN ]; then
CURRENT_FREQ=$((CURRENT_FREQ + 1))
echo -n "throttle "
set_freq $CURRENT_FREQ
fi
}
# Will increase the frequency of cpus if possible.
unthrottle () {
if [ $CURRENT_FREQ -ne 1 ]; then
CURRENT_FREQ=$((CURRENT_FREQ - 1))
echo -n "unthrottle "
set_freq $CURRENT_FREQ
fi
}
get_temp () {
# Get the system temperature.
TEMP=$(cat $TEMP_FILE)
}
### END define script functions.
echo "Initialize to max CPU frequency"
unthrottle
# Main loop
while true; do
get_temp # Gets the current temperature and set it to the variable TEMP.
if [ $TEMP -gt $MAX_TEMP ]; then # Throttle if too hot.
throttle
elif [ $TEMP -le $LOW_TEMP ]; then # Unthrottle if cool.
unthrottle
fi
sleep 3 # The amount of time between checking temperatures.
done
this one switches cpu from one to the other.
Code:
#!/bin/bash
whatisit="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)"
if [[ "$whatisit" == 'performance' ]] ;
then
echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
else
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
fi
it too is command line driven.
this one uses cpulimit to limit load on whatever process that is running.
form what I understand most modern cpus are on demand and only top out when needed to keep them from over heating. One should not what to run a cpu at 100% its speed on a constant. That just causes undue wear and tear on them. If a process does not need a freq of 3.6 to get it done. then why use it?
I usually keep mine on power save and I know it will still go as fast as it needs to go when it needs to. So real since in keeping the peddle to the metal going as fast as I can. When it does not need to. But its your CPU.
Thanks for your answer.
For the Red-Hat enterprise Linux, Version 7.4:
1. The paths are OK.
2. There is no file scaling_available_frequencies.
For the UBUNTU 18.10:
1. The paths are OK.
2. The file file scaling_available_frequencies exists.
3. Only /sys/class/thermal/thermal_zone0/temp exists.
4. /sys/class/thermal/thermal_zone1/temp and /sys/class/thermal/thermal_zone2/temp do not exist even it is an Intel 4 cores.
5. /sys/class/hwmon/hwmon0/temp1_input exists.
6. /sys/class/hwmon/hwmon2/temp1_input does not exixt. Instead /sys/class/hwmon/hwmon2/temp1_input2
7. /sys/class/hwmon/hwmon2/temp1_input does not exists.
8. /sys/class/hwmon/hwmon0/device/temp1_input and /sys/class/hwmon/hwmon1/device/temp1_input and /sys/class/hwmon/hwmon2/device/temp1_input do not exist.
What do you advice?
Thanks in advance. Best regards,
Yehuda
I am not that verse on this subject other than my system, I do know that not all cpus have every capability for scaling one may think. Though the internet is littered with information on this very subject. Reading it should help you.
question is, why do you want to do this yourself?
the kernel is probably better at figuring out the right CPU frequency for any given situation.
fwiw, i had the very same itch when i started using linux.
comes with using dated hardware i guess.
but i quickly learned that scratching that itch does not improve anything.
fwiw, there used to be some systray applet that was able to do what you want.
Thank you all for the responses. I don't want the CPU to run at 100% all the time. It seems like it does not speed up and hold a constant higher speed when I'm, for instance, playing a game or something that's CPU intensive. None of the settings I change seem to have any effect. Thank you BW-userx for your suggestions, but those scripts seem to be attempting to do things I was trying to do manually already... they're just automating them. I have tried setting frequency range from roughly 2ghz - 3.6ghz...no luck thus far
if your cpu is running at 100% then it has to run at 100%. that is just the way it is. limitcpu can control that. But will that hinder your gaming experience? that is something only you can answer.
I don't know... I set a min freq and max freq in /etc/default/cpufrequtils and tried all the different governors... according to cpufreq-info my settings are working and it's keeping the speed between x and y. After running glxgears and trying different governors... to see which produces the most FPS... I have come to the conclusion that ondemand will work fine for my purposes.. and with setting a range. Thank you all for your help
the kernel is much better at figuring these things out than you.
if your cpu is at 100% then there's some application that takes too many resources. the cpu governor cannot change that, and you cannot invent new cpu frequencies.
Pleas note:
1. Cache access is around 2 nano seconds.
2. DRAM access is around 4-8 nano seconds.
3. Clock rate is around 0.25 nano seconds.
Conclusions:
1. For each memory access at least two clock cycles are devoted for waiting.
2. Instructions which need multiple clock cycles: Float/double precision arithmetic, and integer division.
If your program has few of these arithmetic instruction, you can change the clock frequency and not loose performance.
the kernel is much better at figuring these things out than you.
if your cpu is at 100% then there's some application that takes too many resources. the cpu governor cannot change that, and you cannot invent new cpu frequencies.
I wouldn't invent new frequencies. I used frequencies listed in /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies
I also decided against forcing it to run at higher frequencies all the time... and just put the lowest available frequency as the min.. and the highest as the max... with ondemand as the governor. It just seemed to me originally that nothing I was doing was changing any settings. That doesn't seem to be the case anymore. Thanks all for your help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.