Saturday, October 1, 2011

CPU frequency scaling in Linux

Real-time monitor of CPU clock
==============================
$ watch grep \"cpu MHz\" /proc/cpuinfo


CPU Frequency Info
==================
$ sudo apt-get install cpufrequtils

$ cpufreq-info
cpufrequtils 007: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: powernow-k8
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 1000 ns.
  hardware limits: 825 MHz - 1.65 GHz
  available frequency steps: 1.65 GHz, 1.32 GHz, 825 MHz
  available cpufreq governors: powersave, conservative, userspace, ondemand, performance
  current policy: frequency should be within 825 MHz and 1.65 GHz.
                  The governor "conservative" may decide which speed to use
                  within this range.
  current CPU frequency is 825 MHz.
  cpufreq stats: 1.65 GHz:15.25%, 1.32 GHz:8.89%, 825 MHz:75.86%  (7)
analyzing CPU 1:
  driver: powernow-k8
  CPUs which run at the same hardware frequency: 1
  CPUs which need to have their frequency coordinated by software: 1
  maximum transition latency: 1000 ns.
  hardware limits: 825 MHz - 1.65 GHz
  available frequency steps: 1.65 GHz, 1.32 GHz, 825 MHz
  available cpufreq governors: powersave, conservative, userspace, ondemand, performance
  current policy: frequency should be within 825 MHz and 1.65 GHz.
                  The governor "conservative" may decide which speed to use
                  within this range.
  current CPU frequency is 825 MHz.
  cpufreq stats: 1.65 GHz:21.09%, 1.32 GHz:11.68%, 825 MHz:67.22%  (9)


Change the scaling governor
============================

Ondemand governor
- sets the CPU frequency depending on the current usage.
This would be good for systems that do a lot of work (high load) for a short periods of time
and then don't do much (low load) the rest of the time.

Conservative governor
- CPU frequency is scaled based on current load of the system. It is similar to ondemand.
The difference is that it gracefully increases and decreases the CPU speed
rather than jumping to max speed the moment there is any load on the CPU.
This would be best used in a battery powered environment.

Powersave governor
- CPU runs at min frequency regardless of load.

Performance governor
- CPU runs at max frequency regardless of load.


$ sudo sh -c "echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"


to set the desired scaling governor at boot-time.
==================================================
sudo vi /etc/init.d/cpufrequtils


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


scaling_available_frequencies
=======================
$ cat /sys/devices/system/cpu/*/cpufreq/scaling_available_frequencies
1650000 1320000 825000
1650000 1320000 825000


Show the current frequency of your CPU(s)
================================
$ sudo cat /sys/devices/system/cpu/*/cpufreq/cpuinfo_cur_freq
1650000
1650000

You can also find this out by doing a "cat /proc/cpuinfo".


scaling_available_governors
===========================
$ cat /sys/devices/system/cpu/*/cpufreq/scaling_available_governors
powersave conservative userspace ondemand performance
powersave conservative userspace ondemand performance


Show the current scaling governor
==========================
$ cat /sys/devices/system/cpu/*/cpufreq/scaling_governor
ondemand
ondemand


Show the cpufreq driver the CPU(s) are using.
==================================
$ cat /sys/devices/system/cpu/*/cpufreq/scaling_driver
powernow-k8
powernow-k8


Note
====
# lsmod - show the status of modules in the Linux Kernel

$ lsmod | grep cpu
cpufreq_stats 12862 0
cpufreq_powersave 12454 0
cpufreq_conservative 13147 1
cpufreq_userspace 12576 0

*Some modules might not be listed in the running modules but is still available.




Ref:
http://idebian.wordpress.com/2008/06/22/cpu-frequency-scaling-in-linux/
http://www.pantz.org/software/cpufreq/usingcpufreqonlinux.html
https://wiki.archlinux.org/index.php/CPU_Frequency_Scaling

No comments:

Post a Comment