WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Cpu frequency scaling basics  (Read 31289 times)

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Cpu frequency scaling basics
« on: July 07, 2009, 01:32:54 AM »
CPU FREQUENCY SCALING BASICS

To reduce power consumption is essential for portable computers but there are no reason not to use on desktop machines. You can save power turning off not needed hardware components like WiFi, Bluetooth, turning off or reduce monitor backlight, spinning down HDD and to control CPU frequency.

CPU frequency scaling is built into 2.6 kernel and available with Tiny Core also, but you need few additional tools and you have to setup it yourself. Most of the modern CPU's and chipsets support frequency scaling, there is a high chance that you can use it.

It is a short introductory article how to enable and use it. There are plenty of additional recources on the net.


TOOLS REQUIRED

You need the cpufreq.tczl extension and its dependencies from the repository.


CPU DRIVER

Next you have to load the proper CPU kernel driver matching your CPU. To identify the CPU type in a terminal window:

cat /proc/cpuinfo

Depending on the CPU, load one of the following modules with the 'modprobe' command:

p4-clockmod (Intel)
powernow-k6 (AMD K6)
powernow-k7 (AMD K7)
powernow-k8 (AMD K8)

If you choose a wrong driver you will get an error message and module is not loaded, nothing goes wrong.

Alternatively you can try

acpi-cpufreq

It is not so efficient as CPU specific modules, but better than nothing.

There are drivers for certain chipsets not only for CPU's but it is out of the scope of this introduction.


VIEW CPU FREQUENCY INFORMATION

Now you can check actual CPU frequency and other information. Type in a terminal window:

cpufreq-info

and you will get a similar screen:




GOVERNORS

Governors are kernel modules changing the CPU frequency. There are different governors implementing different rules:

powersave - sets the lowest possible frequency constantly
performance - sets the possible highest frequency constantly
ondemand - changes frequency automatically based upon actual demand of programs
conservative - same as ondemand but with a different algorithm, better for notebook battery
use
userspace - allows userspace programs (or any process running as root) to set the frequency

Above governors are modules, loaded automatically when needed, but you can modprobe them before using. Default is performance.

For most systems, the Ondemand governor can provide the best compromise between heat emission, power consumption, performance, and manageability. When the system is only busy at specific times of the day, the Ondemand governor will automatically switch between maximum and minimum frequency depending on the load without any further intervention.


SELECT GOVERNOR

At this point everything is prepared but no active governor selected and no running third party daemon installed, so no any power saving yet.

Use the 'cpufreq-set' command to activate one of the governors mentioned above, for example:

cpufreq-set -g ondemand

Please note, if you have a dual-core or multiple-core CPU, you must specify explicitely the CPU. There are CPU's where each core can run with different setting! Example for a dual-core CPU:

cpufreq-set -c 0 -g conservative
cpufreq-set -c 1 -g conservative

You can explicitely specify the frequency also.


MAN PAGES

You can read man pages here:

http://linux.die.net/man/1/cpufreq-info
http://linux.die.net/man/1/cpufreq-set


USER SPACE PROGRAMS

There are user space programs to manage not only cpu frequency but other components also. One of those, cpufreqd is part of the cpufreq.tcel/tcpufreq.tczl extension installed.

For the curious there are many good articles on the net.

Hope it helps a bit to understand and use frequency scaling.
« Last Edit: December 14, 2009, 09:47:42 AM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Cpu frequency scaling basics
« Reply #1 on: July 07, 2009, 03:53:01 AM »
Thanks for the info

Alternatively you can try

acpi-cpufreq

It is not so efficient as CPU specific modules, but better than nothing.

I thought acpi-cpufreq had taken over from the speedstep module to be the module usually required for Intel cpu's, but I may be mistaken

Quote
Now you can check actual CPU frequency and other information.

If you load the cpufreq_stats and freq_table modules, you can also see a whole bunch of data
« Last Edit: July 07, 2009, 04:01:34 AM by Juanito »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Cpu frequency scaling basics
« Reply #2 on: July 07, 2009, 04:34:36 AM »
Thanks for the info

Alternatively you can try

acpi-cpufreq

It is not so efficient as CPU specific modules, but better than nothing.

I thought acpi-cpufreq had taken over from the speedstep module to be the module usually required for Intel cpu's, but I may be mistaken


As far as I know acpi-cpufreq is not Intel specific. There are many contrversary info found on the net. For example REDHAT is advising to use it over p4-clockmode as it reduce not only CPU speed but voltage. On forums there are user reports that acpi-cpufreq doesn't work with certain machines even if equipped with Intel dual-core, can't recognize all possible CPU frequency therefore less efficient, ...

Regarding speedstep I have no experience, I have never used. However there are some info in Wikipedia:

http://en.wikipedia.org/wiki/SpeedStep

For sure one has to play around on the specific machine and fine tune frequency scaling. The good point that if module doesn't match hardware will not load so it is safe to play with different modules.

« Last Edit: July 07, 2009, 04:48:57 AM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Cpu frequency scaling basics
« Reply #3 on: July 07, 2009, 04:53:34 AM »
Just found an interesting IBM document released in June 2009 on the topic:

http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/topic/liaai/cpufreq/liaai-cpufreq_pdf.pdf
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline pema

  • Newbie
  • *
  • Posts: 48
Re: Cpu frequency scaling basics
« Reply #4 on: July 12, 2009, 12:45:00 PM »
I would recommend powernowd, solves everything in a zap, why bother with the crapy cpufreq ?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Cpu frequency scaling basics
« Reply #5 on: July 12, 2009, 01:12:05 PM »
I would recommend powernowd, solves everything in a zap, why bother with the crapy cpufreq ?

Please read the article carefully. cpufreq is a 2.6 kernel stuff and the low level part of frequency scaling, far away being crapy. However you are free to use whatever userspace program as you want.

Regarding your advice, it is written on the author's WEB as the latest news:

Quote
What's New (1/27/2008)
Took me long enough, but this is the final release of powernowd. The ondemand kernel governor seems to be the wave of the future, and "good enough for me". I do still use it on older kernels, and it's been rock steady for years. v1.00 is just a couple of small cleanups, and running it through valgrind to clean a couple of pedantic memory issues. PowerNowd does everything it set out to do, and is small, efficient, and complete. Barring any brown-paper-bag style bugs, this will be the final release.

http://www.deater.net/john/powernowd.html

Regards...
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: Cpu frequency scaling basics
« Reply #6 on: August 12, 2009, 05:11:36 PM »
Code: [Select]
[quote author=bmarkus link=topic=2259.msg11856#msg11856 date=1246955574]
[center][b][size=12pt]CPU FREQUENCY SCALING BASICS[/size][/b][/center]

To reduce power consumption is essential for portable computers but there are no reason not to use on desktop machines. You can save power turning off not needed hardware components like WiFi, Bluetooth, turning off or reduce monitor backlight, spinning down HDD and to control CPU frequency.

CPU frequency scaling is built into 2.6 kernel and available with Tiny Core also, but you need few additional tools and you have to setup it yourself. Most of the modern CPU's and chipsets support frequency scaling, there is a high chance that you can use it.

It is a short introductory article how to enable and use it. There are plenty of additional recources on the net.


[b]TOOLS REQUIRED[/b]

You need the [b]cpufreq.tcel[/b] or [b]cpufreq.tczl[/b] extension and its dependencies from the repository.


[b]CPU DRIVER[/b]

Next you have to load the proper CPU kernel driver matching your CPU. To identify the CPU type in a terminal window:

cat /proc/cpuinfo

Depending on the CPU, load one of the following modules with the 'modprobe' command:

p4-clockmod (Intel)
powernow-k6 (AMD K6)
powernow-k7 (AMD K7)
powernow-k8 (AMD K8)

If you choose a wrong driver you will get an error message and module is not loaded, nothing goes wrong.

Alternatively you can try

acpi-cpufreq

It is not so efficient as CPU specific modules, but better than nothing.

There are drivers for certain chipsets not only for CPU's but it is out of the scope of this introduction.


[b]VIEW CPU FREQUENCY INFORMATION[/b]

Now you can check actual CPU frequency and other information. Type in a terminal window:

cpufreq-info

and you will get a similar screen:

[img]http://tc.hasix.org/scrcap/cpufreqinfo1.png[/img]


[b]GOVERNORS[/b]

Governors are kernel modules changing the CPU frequency. There are different governors implementing different rules:

powersave - sets the lowest possible frequency constantly
performance - sets the possible highest frequency constantly
ondemand - changes frequency automatically based upon actual demand of programs
conservative - same as ondemand but with a different algorithm, better for notebook battery
use
userspace - allows userspace programs (or any process running as root) to set the frequency

Above governors are modules, loaded automatically when needed, but you can modprobe them before using. Default is performance.

For most systems, the Ondemand governor can provide the best compromise between heat emission, power consumption, performance, and manageability. When the system is only busy at specific times of the day, the Ondemand governor will automatically switch between maximum and minimum frequency depending on the load without any further intervention.


[b]SELECT GOVERNOR[/b]

At this point everything is prepared but no active governor selected and no running third party daemon installed, so no any power saving yet.

Use the 'cpufreq-set' command to activate one of the governors mentioned above, for example:

cpufreq-set -g ondemand

Please note, if you have a dual-core or multiple-core CPU, you must specify explicitely the CPU. There are CPU's where each core can run with different setting! Example for a dual-core CPU:

cpufreq-set -c 0 -g conservative
cpufreq-set -c 1 -g conservative

You can explicitely specify the frequency also.


[b]MAN PAGES[/b]

You can read man pages here:

http://linux.die.net/man/1/cpufreq-info
http://linux.die.net/man/1/cpufreq-set


[b]USER SPACE PROGRAMS[/b]

There are user space programs to manage not only cpu frequency but other components also. One of those, cpufreqd is part of the cpufreq.tcel/tcpufreq.tczl extension installed.

For the curious there are many good articles on the net.

Hope it helps a bit to understand and use frequency scaling.

[/quote]
What is the modprobe for the intel atom processor kernel driver?

I don't think it's any of these:
p4-clockmod (Intel)
powernow-k6 (AMD K6)
powernow-k7 (AMD K7)
powernow-k8 (AMD K8)
« Last Edit: August 12, 2009, 07:03:46 PM by bigpcman »
big pc man

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Cpu frequency scaling basics
« Reply #7 on: August 12, 2009, 10:01:32 PM »
Did you try acpi_cpufreq ? You can try speedstep also, depending on CPU model.
« Last Edit: August 12, 2009, 10:07:57 PM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: Cpu frequency scaling basics
« Reply #8 on: August 13, 2009, 06:31:01 AM »
Did you try acpi_cpufreq ? You can try speedstep also, depending on CPU model.
Yes, I tried acpi_cpufreq. cpufreq-info responded with "hardware limits: 1.6Ghz - 1.6Ghz". No speed steps present.
big pc man

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Cpu frequency scaling basics
« Reply #9 on: August 13, 2009, 07:25:28 AM »
What is the CPU model?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: Cpu frequency scaling basics
« Reply #10 on: August 13, 2009, 07:34:16 AM »
I rebooted and started over and this time I made some progress. I performed the "info steps":
tc@box:~$ sudo modprobe acpi-cpufreq
tc@box:~$ sudo modprobe cpufreq_conservative
tc@box:~$ sudo modprobe cpufreq_ondemand
tc@box:~$ sudo modprobe cpufreq_powersave
tc@box:~$ sudo modprobe cpufreq_userspace
tc@box:~$ sudo acpid
tc@box:~$ sudo cpufreqd

Then ran the cpufreq-info command with the following successful results:
Code: [Select]
tc@box:~$ cpufreq-info
cpufrequtils 005: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which need to switch frequency at the same time: 0
  hardware limits: 800 MHz - 1.60 GHz
  available frequency steps: 1.60 GHz, 1.33 GHz, 1.07 GHz, 800 MHz
  available cpufreq governors: userspace, powersave, ondemand, conservative, performance
  current policy: frequency should be within 1.60 GHz and 1.60 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 1.60 GHz.
analyzing CPU 1:
  driver: acpi-cpufreq
  CPUs which need to switch frequency at the same time: 1
  hardware limits: 800 MHz - 1.60 GHz
  available frequency steps: 1.60 GHz, 1.33 GHz, 1.07 GHz, 800 MHz
  available cpufreq governors: userspace, powersave, ondemand, conservative, performance
  current policy: frequency should be within 1.60 GHz and 1.60 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 1.60 GHz.
It's interesting that cpufreq does not know about the HD super performance mode (1.8Ghz) that Zandros supports.
Now I will try out the governor.

edit: pulled the ac plug and sure enough the speed dropped down to 800Mhz.

edit2: Looks like cpufreq is not working after all. I performed several cpufreq-set commands and none of them change the speed from 1.6Ghz. For instance:
 sudo cpufreq-set -c 0 -f 800000
 sudo cpufreq-set -c 0 -g powersave

I also tried adding commands for processor 1. Still no dice.

It looks like my initial suspicion that  acpi-cpufreq does not support the atom n270 processor might be correct.
« Last Edit: August 13, 2009, 11:18:06 AM by bigpcman »
big pc man

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Cpu frequency scaling basics
« Reply #11 on: August 13, 2009, 10:51:28 AM »

It's interesting that cpufreq does not know about the HD super performance mode (1.8Ghz) that Zandros supports.


Most likely because it is not an official CPU frequency, it is overclocking. You may read this:

http://www.liliputing.com/2009/03/intel-atom-n280-cpu-can-hit-175ghz-with-ease.html
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: Cpu frequency scaling basics
« Reply #12 on: August 13, 2009, 11:15:58 AM »

It's interesting that cpufreq does not know about the HD super performance mode (1.8Ghz) that Zandros supports.


Most likely because it is not an official CPU frequency, it is overclocking. You may read this:

http://www.liliputing.com/2009/03/intel-atom-n280-cpu-can-hit-175ghz-with-ease.html

Thanks for the link. Please see the additions to my previous post for more problems.

Perhaps this has something to do with it:

Code: [Select]
tc@box:~$ sudo cpufreqd-get -l
No cpufreqd socket found

edit: I got rid of the above error by enabling the "enable_remote=1" line in the "general" section of the cpufreqd.conf file. But this did not fix the inability to set the cpu speed.
« Last Edit: August 13, 2009, 11:37:16 AM by bigpcman »
big pc man

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Cpu frequency scaling basics
« Reply #13 on: August 13, 2009, 01:40:43 PM »
If all else fails, read the info file, eh  ;)

It could be that the cpufreq daemon overrides your terminal commands?

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: Cpu frequency scaling basics
« Reply #14 on: August 13, 2009, 05:04:54 PM »
If all else fails, read the info file, eh  ;)

It could be that the cpufreq daemon overrides your terminal commands?
I'm confused... what do you mean? What are you referring to in the info?

edit 1: Ok, I see what you mean about the daemon. It will once activated at each interval period do whatever the conf file specifies. So since Basic  AC calls for high performance and high performance specifies 100% cpu, the cpu freq stays at 1.6Ghz. I thought the terminal commands were sent to the daemon to execute and would override the conf file settings.

So I changed the Basic AC  setting to set max and min at 800000 and restarted cpufreq. Sure enough the cpu freq is now at 800Mhz.

edit 2: I guess you are suggesting that I didn't execute the sudo "command set" in the info file and that was what was causing my problems.  Well I did but I also did other things that must have messed up the system. A reboot and more exact approach got cpufreq to do what it is suppose to do.

Anyway, thanks for the daemon tip that was what I was missing.

edit 3: As the worm turns... I changed my "Basic AC on" governor setting to "ON Demand High" which has min freq=40% and max freq=100% and then restarted cpufreqd. At idle the cpu is running at 800Mhz using the "ondemand" governor. However, with the cpu running at >85% cpu, cpufreq-info reports the cpu is running at 1.3Ghz (not 1.6Ghz as it should) using the "performance" governor. Now I really am confused.

edit 4: Enjoy your vacation Juanito.   :)

By the way here are some usefull commands:

Code: [Select]
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors - shows all gov's
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor - shows current gov
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq - shows current freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq - shows min freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq - shows max freq

Code: [Select]
Title:          cpufreq.tcel info file
Description:    cpufreq for tc_2.X
Version:        2.3.4
Author:         see list of sites below
Original-site:  see list of sites below
Copying-policy: see list of sites below
Size: 65KB
Extension_by:   juanito
Comments:       cpufreqd and cpufrequtils for tinycore_2.x
                requires acpid.tce, cpufreq-2.6.29.1-tinycore.tcem
                ----------
                Example howto:
                $ sudo modprobe acpi-cpufreq [beware - choose the correct module for your cpu]
                $ sudo modprobe cpufreq_conservative
                $ sudo modprobe cpufreq_ondemand
                $ sudo modprobe cpufreq_powersave
                $ sudo modprobe cpufreq_userspace
                $ sudo acpid
                $ sudo cpufreqd
                ----------
                config file at:
                /usr/local/etc/cpufreqd.conf
                ----------
                This extension contains:
                cpufrequtils-005 - GPLv2 - http://www.kernel.org/pub/linux/utils/kernel/cpufreq/cpufrequtils-005.tar.bz2
                cpufreqd-2.3.4 - GPLv2 - http://garr.dl.sourceforge.net/sourceforge/cpufreqd/cpufreqd-2.3.4.tar.bz2
                ----------
Change-log:     First version
Current:        2009/04/28

« Last Edit: August 13, 2009, 08:00:01 PM by bigpcman »
big pc man