set-cpufreq 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #! /bin/sh
  2. # Set the CPU Frequency Scaling governor to "ondemand"/"powersave" where available
  3. set -eu
  4. FIRSTCPU=`cut -f1 -d- /sys/devices/system/cpu/online`
  5. AVAILABLE="/sys/devices/system/cpu/cpu$FIRSTCPU/cpufreq/scaling_available_governors"
  6. DOWN_FACTOR="/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"
  7. [ -f $AVAILABLE ] || exit 0
  8. read governors < $AVAILABLE
  9. case $governors in
  10. *interactive*)
  11. GOVERNOR="interactive"
  12. break
  13. ;;
  14. *ondemand*)
  15. GOVERNOR="ondemand"
  16. case $(uname -m) in
  17. ppc64*)
  18. SAMPLING=100
  19. ;;
  20. esac
  21. break
  22. ;;
  23. *powersave*)
  24. GOVERNOR="powersave"
  25. break
  26. ;;
  27. *)
  28. exit 0
  29. ;;
  30. esac
  31. [ -n "${GOVERNOR:-}" ] || exit 0
  32. echo "Setting $GOVERNOR scheduler for all CPUs"
  33. for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  34. do
  35. [ -f $CPUFREQ ] || continue
  36. echo -n $GOVERNOR > $CPUFREQ
  37. done
  38. if [ -n "${SAMPLING:-}" ] && [ -f $DOWN_FACTOR ]; then
  39. echo -n $SAMPLING > $DOWN_FACTOR
  40. fi