Posts Tagged ‘linux’

Find out number of cores / CPUs for a linux system

Tuesday, September 7th, 2010

If you need to find out the number of CPUs or CPU cores or cores per CPU of your system, you could look it up in /proc/cpuinfo but it’s quite hard to figure out the right parameters. A good overview on the parameters for different system configurations can be found here. If you want to put the actual numbers in variables, here is a nice way to do it:

export CORES_PER_CPU=`grep -c "physical id.*: 0" /proc/cpuinfo`
export CPU_TOTAL=`grep -c "core id.*: 0" /proc/cpuinfo`
export CORE_TOTAL=`grep -c processor /proc/cpuinfo`

/proc/cpuinfo shows an entry for each CPU core. The physical id is incremented for each physical CPU. If the entry has the same physical id as another core, the core belongs to the same CPU. Therefore counting the number of entries with physical id set to 0 results in the number of cores per CPU. The core id is incremented for each core on a physical CPU. Therefore counting the number of entries with core id set to 0 results in the number of physical CPUs. The total number of cores can be retrieved quite easily by counting the number of processor entries.

Unfortunately the above method does not work on all systems. I noticed on some systems with single core processors, that the values core id and physical id are not present.

I searched for official documentation on the proc filesystem, but only found the following document which doesn’t describe the cpuinfo values:

If someone happens to know a better documentation I would be glad if he/she would share it with me!

Manually create linux user password hashs

Friday, August 1st, 2008

Manually creating a password under linux for e.g. /etc/shadow or kickstart isn’t really easy. I searched for a while until I found the userdbpw utility. On Debian Systems (including Ubuntu) it can be installed with

apt-get install courier-authlib-userdb

For most distributions the md5 algorithm is used to create passwords. The userdbpw command for md5 passwords is:

userdbpw -md5

More information on userdbpw can be found in its manpage.

CPU scaling SLC4 on an Esprimo

Monday, July 28th, 2008

So Summer is getting hot and fans are starting to roar. So if you appreciate some silence in the office and just happen to have a Fujitsu Siemens ESPRIMO with P4 on your desk this is for you.

This works for SLC 4 on Fujitsu Siemens ESPRIMO with P4

Install sysutils:

yum install sysfsutils

load module p4_clockmod:
modprobe p4_clockmod

check available schedulers and frequencies:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

if needed load “ondemand” scheduler:
modprobe cpufreq_ondemand;

check current frequency and scheduler:
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

make “ondemand” the active scheduler:
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

make changes permanent:
echo “modprobe p4_clockmod” >> /etc/rc.modules
echo “modprobe cpufreq_ondemand” >> /etc/rc.modules
chomod u+x /etc/rc.modules
echo “devices/system/cpu/cpu0/cpufreq/scaling_governor=ondemand >> /etc/sysfs.conf

I stole some of this from this german Howto on CPU scaling.