Tuesday, May 24, 2011

CPU Frequency Scaling

I have written a small shell script to increase or decrease CPU frequency. By default, it shows current CPU Frequency Scaling Governor. This can be changed only by root user. So this script needs to be run as root user or sudo as root, while changing the CPU Frequency Scaling governor.


#!/bin/bash

available_governors=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors \
| head -1 | sed -e 's/ \([a-zA-Z0-9]\)/|\1/g' -e 's/ $//')
if [ $# -ne 1 ]
then

echo "USAGE: $0 [$available_governors]"
fi

echo "Command line to change CPU Scaling."
echo " - By Mitesh Singh Jat"
echo ""

## CPU Governor path
#/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
function current_cpu_governor ()
{
echo -n "Current CPU Scaling Governor is: "
cpu_scaling_governor="NOT SET"
for governor in $(ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor)
do
cpu_scaling_governor=$(cat $governor)
done
echo "$cpu_scaling_governor"
}

current_cpu_governor;

## Exit, if no governor is provided
new_governor=""
if [ $# -eq 0 ]
then
exit 0
else
new_governor="$1"
fi

## Run as root always
user_id=`whoami`
if [[ "$user_id" != "root" ]]
then
echo "$0: please run this script as root user."
exit
fi

if [ -z $(echo $available_governors | sed -e 's/^/|/' -e 's/$/|/' | grep "|$new_governor|") ]
then
echo "Sorry, this mode '$new_governor' is not supported."
exit 1
else
echo "Setting CPU into '$new_governor' Mode..."
fi
## Now set cpu governor to the given mode
for governor in $(ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor)
do
echo "$new_governor" > $governor
done
current_cpu_governor;

exit 0



Sample Run

Getting current CPU Frequency Scaling Governor
$ cd /path/where/cpu_scaling.sh/is/copied/
$ ./cpu_scaling.sh
USAGE: ./cpu_scaling.sh [powersave|conservative|ondemand|userspace|performance]
Command line to change CPU Scaling.
- By Mitesh Singh Jat

Current CPU Scaling Governor is: ondemand


Increasing CPU frequency (Please run as root).
$ ./cpu_scaling.sh performance
Command line to change CPU Scaling.
- By Mitesh Singh Jat

Current CPU Scaling Governor is: ondemand
./cpu_scaling.sh: please run this script as root user.
$ sudo ./cpu_scaling.sh performance
[sudo] password for mitesh:
Command line to change CPU Scaling.
- By Mitesh Singh Jat

Current CPU Scaling Governor is: ondemand
Setting CPU into Performance Mode...
Current CPU Scaling Governor is: performance
$ ./cpu_scaling.sh
USAGE: ./cpu_scaling.sh [powersave|conservative|ondemand|userspace|performance]
Command line to change CPU Scaling.
- By Mitesh Singh Jat

Current CPU Scaling Governor is: performance


Decreasing CPU frequency
$ sudo ./cpu_scaling.sh ondemand
Command line to change CPU Scaling.
- By Mitesh Singh Jat

Current CPU Scaling Governor is: performance
Setting CPU into OnDemand Mode...
Current CPU Scaling Governor is: ondemand

Friday, March 11, 2011

Playing only Audio from a Video File

If you want to play only audio from a video file (say xyz.avi),
please provide -vo null in mplayer, given as:

$ mplayer -vo null xyz.avi

Wednesday, March 9, 2011

Speeding up Disk Performance

We can increase Hard Disk performance by ~40%, and decrease power consumption by Hard Disk, if we provide "noatime,nodiratime" options during partition mounting. Actually what happens is: whenever a file/directory is accessed, its atime "access time" is updated with epoch. These two options prevent these not-so-useful disk accesses. Hence
performance improvement.



The sample mount point (/home) entry in /etc/fstab may look like:


$ cat /etc/fstab | grep home
/dev/sda2 /home ext3 defaults,noatime,nodiratime 0 0

Thursday, February 24, 2011

Windows XP in Grub 2

When I installed Debian 6.0 (Squeeze) on my laptop, I found that Debian Installer had not added Windows XP entry in the GRUB 2. You might also face same issue, then you can add following lines in /boot/grub/grub.cfg



## (1) Windows XP in /dev/sda1
menuentry "Windows XP" {
set root=(hd0,1)
chainloader +1
}




Here are few tips how to set root in the grub.cfg



# DEVICE NAME CONVERSIONS
#
# Linux Grub
# -------------------------
# /dev/fd0 (fd0)
# /dev/sda (hd0)
# /dev/sdb2 (hd1,2)
# /dev/sda3 (hd0,3)
#


Tuesday, February 2, 2010

Cleaning of Temporary Install Files in Ubuntu/Debian

Cleaning of Temporary Install Files in Ubuntu/Debian can be done by giving
following commands:

$ sudo apt-get autoclean; sudo apt-get autoremove

Tuesday, December 15, 2009

How to change boot order in GRUB2?

With Ubuntu 9.10 (Karmic Koala), GRUB2 is the default boot loader.
How to change boot order in GRUB2?

1.
$ cat /etc/grub/grub.cfg
see the order of the wanted kernel. Starts from 0.

2.
$ vi /etc/default/grub
change GRUB_DEFAULT=0 value to wanted kernel

3. run
$ update-grub
to update

4. reboot and check with
$ uname -r
to see if correct kernel selected.

Monday, December 7, 2009

Find Biggest Files/Directories





Since ls does not give correct size on disk, better to
use du command.





$ du /path/to/dir | sort -nr




I hope above
command will give you the proper result you wanted.



Note: The above command may take large time, depending on

number of files in /path/to/dir . You can use depth(say 2) in
that dir.




$ du --max-depth=2 /path/to/dir | sort -nr