Tuesday, March 10, 2009

How to enable and disable a cpu on a live Linux system?

For squeezing out a bit of extra battery time, I usually disables one of cpus of my laptop.

This option is only available from RHEL5.

I do have two cores in my system.

# grep processor /proc/cpuinfo
processor : 0
processor : 1

/sys/devices/system/cpu/cpuX/online decides if a cpu is enabled or disabled.

# cat /sys/devices/system/cpu/cpu1/online
1


To disable the cpu1:

# echo 0 > /sys/devices/system/cpu/cpu1/online


Now only one cpu is up.

# grep processor /proc/cpuinfo
processor : 0


To re-enable the cpu:

# echo 1 > /sys/devices/system/cpu/cpu1/online


I will not be able to disable cpu0. Even online file is not availabe.

# ll /sys/devices/system/cpu/cpu0/
total 0
drwxr-xr-x 5 root root 0 2009-03-10 16:50 cache
drwxr-xr-x 3 root root 0 2009-03-10 16:38 cpufreq
drwxr-xr-x 5 root root 0 2009-03-10 16:50 cpuidle
-r-------- 1 root root 4096 2009-03-10 16:50 crash_notes
drwxr-xr-x 2 root root 0 2009-03-10 16:50 topology


Some architectures (i386, X86_64) does have some special dependency on a certain CPU. I have not tested it in any other architectures.

1 comment: