cpufreq utility

January 21, 2010

cpufrequtils is package which has two nice tools very useful for laptop users.

cpufreq-info is a nice command, which will give information about the cpu.
Here is what I get on my laptop

——————————————————————————————————
rhlaptop:/home/ram#cpufreq-info
cpufrequtils 004: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to cpufreq@lists.linux.org.uk, please.
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which need to switch frequency at the same time: 0 1
hardware limits: 1000 MHz – 2.00 GHz
available frequency steps: 2.00 GHz, 1.67 GHz, 1.33 GHz, 1000 MHz
available cpufreq governors: conservative, powersave, ondemand, userspace, performance
current policy: frequency should be within 1000 MHz and 2.00 GHz.
The governor “performance” may decide which speed to use
within this range.
current CPU frequency is 2.00 GHz (asserted by call to hardware).
cpufreq stats: 2.00 GHz:100.00%, 1.67 GHz:0.00%, 1.33 GHz:0.00%, 1000 MHz:0.00%analyzing CPU 1:
driver: acpi-cpufreq
CPUs which need to switch frequency at the same time: 0 1
hardware limits: 1000 MHz – 2.00 GHz
available frequency steps: 2.00 GHz, 1.67 GHz, 1.33 GHz, 1000 MHz
available cpufreq governors: conservative, powersave, ondemand, userspace, performance
current policy: frequency should be within 1000 MHz and 2.00 GHz.
The governor “performance” may decide which speed to use
within this range.
current CPU frequency is 2.00 GHz (asserted by call to hardware).
cpufreq stats: 2.00 GHz:100.00%, 1.67 GHz:0.00%, 1.33 GHz:0.00%, 1000 MHz:0.00%
——————————————————————————————————————-

This is a detailed output. There are specific options like -f to give frequency, -p for policy etc.
Of importance to us is the policy.
rhlaptop:/home/ram# cpufreq-info -p
1000000 2000000 performance
This means my cpu is tuned for high performance which may mean more power consumption. When on battery it is better to trade off performance with battery life. Different governors are available to help us. They are
——————————————————————————————————————
rhlaptop:/home/ram# cpufreq-info -g
conservative powersave ondemand userspace performance
——————————————————————————————————————
As you can see above we can choose what is appropriate to us.
This tool has another command called cpufreq-set. Using this we can set various cpu options. e.g
cpufreq-set -p powersave
will set cpu to powersave mode reducing frequency of CPU.
I did a small test to understand the significance of cpu frequency. I used acpi command to give batterlife
I ran this script in a terminal
(it is a quick shell script – not perfect or very efficient)
freq=’performance’
while true
do
sleep 60
cpufreq-info -p
acpi
if [ $freq = "performance" ]
then
cpufreq-set -g powersave
freq=’powersave’
else
cpufreq-set -g performance
freq=’performance’
fi
done

Then I continued with my normal usage, including running some youtube videos.
Here is the output

1000000 2000000 performance
Battery 0: Discharging, 92%, 02:24:31 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 92%, 03:02:38 remaining, design capacity 4353 mAh
1000000 2000000 performance
Battery 0: Discharging, 91%, 02:52:27 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 91%, 03:08:29 remaining, design capacity 4353 mAh
1000000 2000000 performance
Battery 0: Discharging, 90%, 03:06:58 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 90%, 03:06:58 remaining, design capacity 4353 mAh
1000000 2000000 performance
Battery 0: Discharging, 89%, 03:03:17 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 89%, 03:03:17 remaining, design capacity 4353 mAh
1000000 2000000 performance
Battery 0: Discharging, 88%, 03:02:04 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 88%, 03:02:04 remaining, design capacity 4353 mAh
1000000 2000000 performance
Battery 0: Discharging, 87%, 02:44:15 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 87%, 02:56:33 remaining, design capacity 4353 mAh
1000000 2000000 performance
Battery 0: Discharging, 86%, 02:33:21 remaining, design capacity 4353 mAh
1000000 2000000 powersave
Battery 0: Discharging, 86%, 03:00:57 remaining, design capacity 4353 mAh
————————————————————————-
Notice that the difference in battery life is marginal when load is small.

Running cpu at lower speed didn’t have any perceptible change in my normal working environment.


வீட்டில் புதினா வளர்த்த அனுபவம்

January 16, 2010

புதினா வீட்டில் வளர்ப்பது எளிது. கடையில் இருந்து வாங்கி வரும் புதினா கட்டிலிருந்து இலையை எடுத்தபின் உள்ள குச்சிகளே போதும்.

இந்த குச்சிகளில் முதிர்ந்தவற்றை தேர்ந்தெடுத்தேன்.

(படம்எடுத்த நாள் 18/11/2009)

தேர்ந்தெடுத்த குச்சிகளை சுமார் 3 அல்லது 4 செ.மீ ஆழத்தில் நட்டேன்.

பிற செடிகள் போலவே இவற்றையும் பராமரித்தேன்.

சுமார் 3 வாரங்கள் கழித்து நன்கு வளர்ந்த பின் எடுத்த படம்

சுமார் 25வது நாளில் முதல் முறையாக கீரை கிள்ளினேன். ஆனால் படம் எடுக்க மறந்தேன்.

சுமார் 45வது நாளில் எடுத்த படம் இதோ

பிறகு கிள்ளிய கீரை இதோ

ஆக என் அனுபவத்தில் புதினா வளர்ப்பதின் நன்மைகள்
மிக எளியது
பூச்சி தொல்லைகள் இல்லாதது
கடையில் வாங்குவதைக்காட்டிலும் சுவையானது
கடையில் வாங்குவதைக்காட்டிலும் நறுமணம் அதிகமானது


Lesser known linux commands – csplit

January 13, 2010

csplit - context split – is a command to split a text file into smaller files based on some context. Let me explain with an example. I have a file  csplit.txt, like this

ram@rhlaptop:~/blog$ cat csplit.txt
Chapter 1
This is chapter one
Chapter 2
This is chapter two
Chapter 3
This is chapter three

I want this file to be broken into three pieces – chapter wise. I can use csplit like this

ram@rhlaptop:~/blog$ csplit -z csplit.txt  /Chapter/ {*}
31
31
32

Let me explain the command. -

csplit.txt – name of the input file

-z remove any empty output file

/Chapter/ : Indicate the match string

{*} : indicates number of times. If star means any number of times. You can give any integer to  limit number of splits.

Upon running the above command it creates three files named xx00,xx01,xx02.  whose contents are

ram@rhlaptop:~/blog$ cat xx00
Chapter 1
This is chapter one

ram@rhlaptop:~/blog$ cat xx01
Chapter 2
This is chapter two

ram@rhlaptop:~/blog$ cat xx02
Chapter 3
This is chapter three

csplit is thus very simple and yet very poweful. It will be very useful when we want to split a large file like a book into chapters.

csplit has options for specifying output file name, regular expression for pattern or simply number of lines. csplit is an improvement over split command.


Follow

Get every new post delivered to your Inbox.

Join 38 other followers