Disable a few cores when you want to save power.

If you have a lot of CPU power and working on battery. If you do not need that much of power and would like to rather save some battery power by disabling some cpus then you can use the below script. This script disables cpus from 4 to 7. You can change the number in the for loop. You would need the sudo to be setup or remove sudo and run the script as root. The script will show you the currently active cpu’s before and after disabling the CPU’s.

If you want to disable to cpus from the grub itself then you can add the below parameter in grub.cfg or grub2.cfg in the vmlinuz line:

1
maxcpus=4

Here is the script:

#!/bin/bash -
#===============================================================================
#
#          FILE: disablecpu.sh
#
#         USAGE: ./disablecpu.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#      REVISION:  ---
#===============================================================================

#set -o nounset                              # Treat unset variables as an error
cat /proc/cpuinfo|grep cores|wc -l
for i in {4..7}
do
    sudo sh -c "echo 0 > /sys/devices/system/cpu/cpu$i/online"
done
cat /proc/cpuinfo|grep cores|wc -l
Enhanced by Zemanta

Linux hardware details.

Here is one of the scripts that I found on the net while searching for something … Note the URL for the script in the Description.

#!/bin/bash -
#===============================================================================
#
#          FILE:  linux_hw.sh
#
#         USAGE:  ./linux_hw.sh
#
#   DESCRIPTION:  http://www.howtogeek.com/howto/solaris/get-the-processor-type-on-solaris/
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), [email protected]
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 09/13/2011 03:57:34 PM IST
# Last modified: Sun Oct 30, 2011  04:59PM
#      REVISION:  ---
#===============================================================================

function linux_hw_CPU {
	typeset num=0
	typeset name=""
	typeset cores=""
	name="$( cat /proc/cpuinfo | awk -F: '
/vendor_id/ { vendor=$2 }
/model name/ { model=$2 }
/cpu MHz/ {
if( model ~ "Hz" ) {speed=""} else { speed=$2? MHz" };
print vendor, model, speed; }
		' | tail -1
	)"

        num=$(if [ -r /proc/vmware/cpuinfo ]; then awk '/pcpu/ { print NF-1 }' /proc/vmware/cpuinfo; else cat /proc/cpuinfo | grep processor| wc -l; fi)

	# ESX: mas info sobre logical/cores/packages
	if [ -r /proc/vmware/sched/ncpus ]
	then
		cores=$( echo $( cat /proc/vmware/sched/ncpus ) )
	fi

	echo $num $( echo "$name ($cores)" | enclose )
}

function enclose {
	tr -s " " | sed -e "s/^/\"/; s/$/\"/; s/\"\ /\"/; s/\ \"/\"/"
}

function linux_hw_CPU {

	typeset num=0
	typeset name=""
	typeset cores=""

	name="$(
		cat /proc/cpuinfo | awk -F: '
/vendor_id/ { vendor=$2 }
/model name/ { model=$2 }
/cpu MHz/ {
if( model ~ "Hz" ) {speed=""} else { speed=$2" MHz" };
print vendor, model, speed; }
		' | tail -1
	)"

	num=$(
		if [ -r /proc/vmware/cpuinfo ]
		then
			awk '/pcpu/ { print NF-1 }' /proc/vmware/cpuinfo
		else
			cat /proc/cpuinfo | grep processor| wc -l
		fi

	)

	if grep -q "physical id" /proc/cpuinfo || grep "siblings" /proc/cpuinfo
	then
		chip_count=$( grep "physical id" /proc/cpuinfo | sort -u | wc -l )
		chip_core=$( grep "siblings" /proc/cpuinfo | tail -1 | cut -d: -f2 )
		cores="($chip_count chips x $chip_core cores)"
	fi

	# Blades HP con
	if [ -x /sbin/hpasmcli ]
	then
		chip_name=$( /sbin/hpasmcli -s "SHOW SERVER" | grep "Name" | head -1 | cut -d: -f2 )
		chip_speed=$( /sbin/hpasmcli -s "SHOW SERVER" | grep "Speed" | head -1 | cut -d: -f2 )
		chip_core=$( /sbin/hpasmcli -s "SHOW SERVER" | grep "Core" | head -1 | cut -d: -f2 )
	fi

	# ESX: mas info sobre logical/cores/packages
	if [ -r /proc/vmware/sched/ncpus ]
	then
		cores="($( echo $( cat /proc/vmware/sched/ncpus ) ))"
	fi

	# Linux Itanium IA64
	if grep -q -i itanium /proc/cpuinfo
	then
		name="$(
		grep "vendor" /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep "arch " /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep "family" /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep "cpu MHz" /proc/cpuinfo | cut -d: -f2- | cut -d. -f1 | tail -1 ) Mhz"

		chip_count=$( grep "physical id" /proc/cpuinfo | sort -u | wc -l )
		chip_core=$( grep "siblings" /proc/cpuinfo | tail -1 | cut -d: -f2 )
		cores="($chip_count chips x $chip_core cores)"
	fi

	echo $num $( echo "$name $cores" | enclose )
}

linux_hw_CPU
Enhanced by Zemanta

Total upload and download on any interface.

Something that I have been searching for a long time, finally some look inside the /proc got me what I wanted. Hope this will save someone’s day. So far, the only option I could think of was to run conky which becomes a little heave on some of the very old laptops I have to use sometimes 🙁

1
 cat /proc/net/dev|grep eth2|awk '{print $2/1024/1024"  "$10/1024/1024}'

Enhanced by Zemanta