LINUX Jannat

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 1 April 2013

Linux Kernel CPUFreq framework

Posted on 11:52 by Unknown

Most of the processor have mechanism to save power by scaling the frequency & voltage. Now, the question arise, why these two?

Existing CMOS technology consumes power in mostly three major areas :-
1. Leakage current - It is basically due to the underlying circuitry in the schematics.
                                P(lc) = I,load * Vc = squr(Vc)/RL
2. Recharging Current - It is mainly the parasitic capacitance inducing current.
                                P(rc) = squr(Vc)/Rp = squr(Vc) * Cp * F
3. Shoot through  current - Sometimes when the transistor in the circuit is opening up and the opposite  to it is just started to close, there is some amount of current.
                                P(sc) = squr(Vc) * F / Rs

So, the total power equals to P(lc) + P(rc) + P(sc)

Therefore, the power is directly proportional to the square of Voltage and the constant or the linear function of the Frequency.

So, here we are with the answer to our basic question of why scaling only freq & volt.

How does Linux Kernel provide support for this? Answer lies in the CPU-Freq framework provided by the kernel.
It is the linux subsystem to set cpu frequency. The details of this can be read from "Documentation/cpu-freq/".
Lets see how to use this framework from the User-Space.

The cpufreq framework is mostly divided in three parts -
1. cpufreq module 
2. cpu-specific drivers
3. in-kernel governors

Linux kernel provide three kinds of governor which can be used for any kind of CPU. They are
1. performance governor
2. powersave governor
3. userspace governor

apart from these, there are two new governors namely,
1. Ondemand governor
2. conservative governor

On the lowest level of this architecture, there lies ACPI processor driver. This is used by the CPU specific drivers like powernow-k8 etc. These provide various /sys/ and /proc/ interfaces. above it lies in-kernel governors.  User-level governors uses userspace governor to modify cpu frequencies.

To understand how we use these sys attributes, go to /sys/devices/system/cpu/. This lists the available cpus and cpu-freq governor details.

arya@maya:/$ ls /sys/devices/system/cpu/

cpu0  cpu1  cpufreq  cpuidle  kernel_max  microcode  modalias  offline  online  possible  power  present  probe  release  uevent


To check the governor,


arya@maya:/sys/devices/system/cpu$ ls cpufreq/
boost  ondemand


Ok. Now lets go inside one of the cpus.


root@maya:/sys/devices/system/cpu/cpu0# ll cpufreq/
total 0
drwxr-xr-x 3 root root    0 Apr  1 22:53 ./
drwxr-xr-x 8 root root    0 Apr  2  2013 ../
-r--r--r-- 1 root root 4096 Apr  1 23:02 affected_cpus
-r--r--r-- 1 root root 4096 Apr  1 23:02 bios_limit
-rw-r--r-- 1 root root 4096 Apr  1 23:02 cpb
-r-------- 1 root root 4096 Apr  1 23:02 cpuinfo_cur_freq
-r--r--r-- 1 root root 4096 Apr  1 23:02 cpuinfo_max_freq
-r--r--r-- 1 root root 4096 Apr  1 23:02 cpuinfo_min_freq
-r--r--r-- 1 root root 4096 Apr  1 23:02 cpuinfo_transition_latency
-r--r--r-- 1 root root 4096 Apr  1 23:02 related_cpus
-r--r--r-- 1 root root 4096 Apr  1 22:53 scaling_available_frequencies
-r--r--r-- 1 root root 4096 Apr  1 22:53 scaling_available_governors
-r--r--r-- 1 root root 4096 Apr  1 22:53 scaling_cur_freq
-r--r--r-- 1 root root 4096 Apr  1 23:02 scaling_driver
-rw-r--r-- 1 root root 4096 Apr  1 22:53 scaling_governor
-rw-r--r-- 1 root root 4096 Apr  1 23:02 scaling_max_freq
-rw-r--r-- 1 root root 4096 Apr  1 23:02 scaling_min_freq
-rw-r--r-- 1 root root 4096 Apr  1 22:53 scaling_setspeed
drwxr-xr-x 2 root root    0 Apr  1 23:02 stats/

1. current cpu frequency


root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/cpuinfo_cur_freq 
800000
2. max supported cpu frequency
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/cpuinfo_max_freq
1600000
3. min supported cpu frequency
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/cpuinfo_min_freq
800000
4. list all available cpu frequency
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/scaling_available_frequencies 
1600000 1280000 800000 
5. list all available governors
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/scaling_available_governors 
conservative ondemand userspace powersave performance 
6. return cached value of cpu frequency from cpu-freq driver
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/scaling_cur_freq 
800000
7. return cpu specific driver
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/scaling_driver 
acpi-cpufreq
8. user controlled lower cpu frequency
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/scaling_min_freq 
800000

9. user controlled higher cpu frequency
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/scaling_max_freq 
1600000



The interfaces under the stats/ directory provide the statistics about the usage of frequency changes on any particular CPU.

1. details of cpu frequency transitions

root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/stats/trans_table 
   From :To :   1600000   1280000    800000 
  1600000    :               0         1582        2938 
  1280000    :           384               0        1198 
   800000     :         4135               0              0 
2. details of total time spent in a particular state.
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/stats/time_in_state 
1600000    46780
1280000      4558
800000    421491
3. details of total number of transition by cpu.
root@maya:/sys/devices/system/cpu/cpu0# cat cpufreq/stats/total_trans 
10237



This is the basic of all kind of governors today exists. One of the most common governor used in Linux is OnDemand Governor. 
But, this does not stop one to write their own. Infact, there are as many as 28 governors I am aware of in android. This is explained in one of my previous blogs.

More to come on the governors. leave comment to improve the knowledge base.

happy blogging !


Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Android CPU Governors explained
    ( Credit - xda forum ) It always fascinated me how the cpufreq-ondemand driver works in Linux. While browsing, I got a very interesting disc...
  • Mobile signal boost in 2 mins
    Tired of network not available when inside your room? Now, the home made signal booster at your service. Required Material You would require...
  • do we really need sysfs?
    I and my colleague were discussing sometime back about the kernel and how the data flow occurs from user to the hardware. How is the kernel ...
  • Project cpuboard upgrade
    Hi guys Just created my first GIT repo on github. Soon it will have Liunx-3.8.2 to start with a new upgrade project for ARM9 based system. D...
  • __init call in linux kernel..How are they called?
    I always had this doubt about how the Linux drivers and internal core gets loaded in kernel. How do we decide which drive to load first as t...
  • Linux support for ARM big.LITTLE
    By Nicolas Pitre ARM Ltd recently announced the  big.LITTLE architecture  consisting of a twist on the SMP systems that we've all gotten...
  • Context Switch..An initial investigtion on ARM processor
    Modern operating system offer multitasking and multiprocessing. Even we have multiprocessor based systems. All of these require a Scheduler ...
  • Welcome Note
    Friends, I have seen my friends, my colleagues, my seniors and juniors almost everyone near me struggling one or other day with some problem...
  • touch screen technology
    Capacitive touch screen: The capacitive touch screen is made up of a glass panel that is coated with a material. The property of this mater...
  • Linux Kernel CPUFreq framework
    Most of the processor have mechanism to save power by scaling the frequency & voltage. Now, the question arise, why these two? Existing ...

Categories

  • android
  • Context-Switch
  • cpu governor
  • git
  • Linux cpuboard upgrade

Blog Archive

  • ▼  2013 (6)
    • ▼  April (2)
      • Mobile signal boost in 2 mins
      • Linux Kernel CPUFreq framework
    • ►  March (4)
  • ►  2012 (4)
    • ►  October (1)
    • ►  April (3)
Powered by Blogger.

About Me

Unknown
View my complete profile