LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 04-10-2019, 01:42 PM   #1
anomalyLuna
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Rep: Reputation: Disabled
Can't change CPU frequency... no matter what


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
 
Old 04-10-2019, 05:44 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.
Code:
#!/bin/bash

# requires cpulimit


[[ -z $1 ]] || [[ $# -ne '2' ]] && { echo "Usage bash limitcpu command limit #" ; exit 1 ; }

echo $1
echo $2
count=0

    pidd=$(pidof $1)
    pidd=${pidd%% *}
	echo "pid $pidd"
	cpulimit  -p $pidd -l $2 -z -i
while sleep 3;
do
	
	pidd=$(pidof $1)
	pidd=${pidd%% *} 
	cpulimit  -p $pidd -l $2 -z -i
	
	if [[ $count -eq '1' ]] && [[ -z "$pidd" ]] ; then
		{
		echo "Ran dry...
			exiting .....
			
			"
		exit
		}
		else
		{
		((count++))
		}
		fi
		[[ -n "$pidd" ]] && count=0
done
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.

Last edited by BW-userx; 04-10-2019 at 05:57 PM.
 
Old 04-11-2019, 02:23 AM   #3
YehudaSinger
Member
 
Registered: Jun 2013
Posts: 30

Rep: Reputation: Disabled
Dear BW-userx

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
 
Old 04-11-2019, 07:19 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.

1. https://wiki.archlinux.org/index.php...quency_scaling
2. https://wiki.debian.org/HowTo/CpuFrequencyScaling
3. https://www.kernel.org/doc/html/v4.1...m/cpufreq.html

there is a little to get you started.
 
1 members found this post helpful.
Old 04-11-2019, 02:58 PM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
Old 04-11-2019, 03:43 PM   #6
anomalyLuna
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-11-2019, 03:57 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.
 
Old 04-11-2019, 04:13 PM   #8
anomalyLuna
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-12-2019, 12:37 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ don't do this, full stop.

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.
 
Old 04-12-2019, 03:46 AM   #10
YehudaSinger
Member
 
Registered: Jun 2013
Posts: 30

Rep: Reputation: Disabled
Dear Ondoho

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.
 
Old 04-13-2019, 07:44 PM   #11
anomalyLuna
LQ Newbie
 
Registered: Apr 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
^ don't do this, full stop.

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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is my true maximum RAM capacity. Motherboard appears to support 16GB but CPU is 2 core - does it matter? OExcret Linux - Hardware 15 07-19-2017 12:31 AM
Set Clock Frequency on a Frequency Scaling Disabled Kernel mobin.seven Linux - Kernel 3 02-18-2017 10:33 PM
[SOLVED] KPowerSave can't set CPU frequency policy killy9999 Linux - Laptop and Netbook 1 04-19-2011 11:03 AM
cpu frequency scaling with Pentium(R) Dual-Core CPU E5200 @ 2.50GHz tramni1980 Slackware 5 08-16-2009 08:29 AM
How to re-calibrate clocks after I change CPU frequency? cracauer Linux - Kernel 4 11-09-2006 11:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration