Skip to content

Instantly share code, notes, and snippets.

@tchn
Last active August 8, 2023 11:53
Show Gist options
  • Save tchn/15a9caf0755e8d657b06 to your computer and use it in GitHub Desktop.
Save tchn/15a9caf0755e8d657b06 to your computer and use it in GitHub Desktop.
[Linux] CPUコアの有効化/無効化

制御の仕方

カーネル起動時のパラメータ( maxcpus=number_of_core )で指定

SMPでも起動時はシングルコアにする (起動が早くなる?)

$ cat grub.cfg
linux /vmlinuz-3.13-1-amd64 root=/dev/mapper/vg-lv ro quiet elevator=noop maxcpus=1

sysfs

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

起動したらマルチコアに戻す

$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
for i in /sys/devices/system/cpu/cpu*/online; do
    echo 1 > "$i"
done

exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment