You are not logged in.
Hi guys! A problem is connected with switching cpu governors. Usually I set it by commands and made alias in .bashrc:
sudo cpufreq-set -c 0 -g performance && sudo cpufreq-set -c 1 -g performance
sudo cpufreq-set -c 0 -g ondemand && sudo cpufreq-set -c 1 -g ondemand
sudo cpufreq-set -c 0 -g powersave && sudo cpufreq-set -c 1 -g powersave
Could you help me with script which can read system information about current cpu governor and switches the next governor
Last edited by noMaster (2012-01-27 06:36:55)
Offline
can i ask why?
here you can read the current governor for cpu0
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
work from there
Offline
Can you please be more specific with what you are trying to accomplish?
Linux ArchLinux 3.2.8-1-ARCH
#1 SMP PREEMPT Mon Feb 27 21:51:46 CET 2012 x86_64 AMD FX(tm)-8120 Eight-Core Processor AuthenticAMD GNU/Linux
8192MB DDR3 1300MHz | Asus m5a97 | GeForce GTX 550 Ti | 120 GB SSD
Offline
Can you please be more specific with what you are trying to accomplish?
I need that script for set it on hotkey and change cpu states. Unfortunately I havent scripting experience
I make one thing but it doesnt work for me
### Toggle Super Hybrid Engine ##################################
she_names=("performance" "ondemand" "powersave")
she_value_performance=( "0" "performance")
she_value_ondemand=( "1" "ondemand")
she_value_powersave=( "2" "powersave")
# Find current
she_current=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
if [[ "${she_current}" == "${she_value_performance[0]}" ]]; then
she_next=${she_value_ondemand[0]}
elif [[ "${she_current}" == "${she_value_ondeman[1]}" ]]; then
she_next=${she_value_powersave[0]}
elif [[ "${she_current}" == "${she_value_powersave[1]}" ]]; then
she_next=${she_value_performance[0]}
fi
function she_toggle() {
if [[ "${she_names[${she_current}]}" != "${she_names[${she_next}]}" ]]; then
cmd="/usr/bin/notify-send -t 5000 SHE changed"
echo ${she_next} > ${she_current}
else
cmd="/usr/bin/notify-send -t 5000 SHE original"
fi
}
#################################################################
case $1 in
# "debug")
# print_debug
# ;;
"powersave")
she_next=2
she_toggle
;;
"normal")
she_next=1
she_toggle
;;
"performance")
she_next=0
she_toggle
;;
*)
she_toggle
;;
esac
### End of file #################################################
Last edited by noMaster (2012-01-26 08:46:30)
Offline
JuseBox wrote:Can you please be more specific with what you are trying to accomplish?
I need that script for set it on hotkey and change cpu states. Unfortunately I havent scripting experience
I make one thing but it doesnt work for me
### Toggle Super Hybrid Engine ################################## she_names=("performance" "ondemand" "powersave") she_value_performance=( "0" "performance") she_value_ondemand=( "1" "ondemand") she_value_powersave=( "2" "powersave") # Find current she_current=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor` if [[ "${she_current}" == "${she_value_performance[0]}" ]]; then she_next=${she_value_ondemand[0]} elif [[ "${she_current}" == "${she_value_ondeman[1]}" ]]; then she_next=${she_value_powersave[0]} elif [[ "${she_current}" == "${she_value_powersave[1]}" ]]; then she_next=${she_value_performance[0]} fi function she_toggle() { if [[ "${she_names[${she_current}]}" != "${she_names[${she_next}]}" ]]; then cmd="/usr/bin/notify-send -t 5000 SHE changed" echo ${she_next} > ${she_current} else cmd="/usr/bin/notify-send -t 5000 SHE original" fi } ################################################################# case $1 in # "debug") # print_debug # ;; "powersave") she_next=2 she_toggle ;; "normal") she_next=1 she_toggle ;; "performance") she_next=0 she_toggle ;; *) she_toggle ;; esac ### End of file #################################################
I am looking over the script. Without it, do you think you could explain what your trying to accomplish? What states and when should they toggle? Something rough to get an idea? I think if I am thinking correctly this could be easier then it seems. I will help ya.
Linux ArchLinux 3.2.8-1-ARCH
#1 SMP PREEMPT Mon Feb 27 21:51:46 CET 2012 x86_64 AMD FX(tm)-8120 Eight-Core Processor AuthenticAMD GNU/Linux
8192MB DDR3 1300MHz | Asus m5a97 | GeForce GTX 550 Ti | 120 GB SSD
Offline
I need that script provides switching cpu governor and that's all I need
Offline
You misspelled ondemand
elif [[ "${she_current}" == "${she_value_ondeman[1]}" ]]; then
You're just jealous because the voices only talk to me.
Offline
#!/bin/bash
governors=(performance ondemand powersave)
performance=0 ondemand=1 powersave=2
gov_get() {
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
}
gov_set() {
<<<"$1" tee | /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
notify-send "governor set to: $1"
}
gov_next() {
local current next
current=$(gov_get)
next=${!current}
printf '%s\n' ${governors[(next + 1) % 3]}
}
case $1 in
performance|ondemand|powersave)
gov_set "$1"
;;
toggle)
gov_set "$(gov_next)"
;;
*)
printf 'usage: %s <performance|ondemand|powersave|toggle>\n' "${0##*/}"
printf '\ncurrent governor is: %s\n' "$(gov_get)"
;;
esac
Untested.
Offline
falconindy, thank you for your script, it seems very good, but it unfortunately doesnt work for me
sudo /home/ku/others/she.sh powersave
/home/ku/others/she.sh: line 11: /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor: Permission denied
I made own and it works, really amazing! My first script
###Governors
p1=("performance")
p2=("ondemand")
p3=("powersave")
### Current cpu governor
she_current=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
if [[ "${she_current}" == "${p1}" ]]; then
cpufreq-set -c 0 -g ondemand && cpufreq-set -c 1 -g ondemand
elif [[ "${she_current}" == "${p2}" ]]; then
cpufreq-set -c 0 -g powersave && cpufreq-set -c 1 -g powersave
elif [[ "${she_current}" == "${p3}" ]]; then
cpufreq-set -c 0 -g performance && cpufreq-set -c 1 -g performance
fi
You misspelled ondemand
elif [[ "${she_current}" == "${she_value_ondeman[1]}" ]]; then
And, moetunes, especially thanks! When I made my script the problem was in that line. I read you post and fixed and it works for me.
Thank you all, guys
Offline