Linux Hotplug a CPU and Disable CPU Cores At Run Time

Hotplugging a CPU involves adding or removing a CPU from a running system without shutting down the system. In Linux, you can hotplug a CPU and disable CPU cores at run time using the following steps:

  1. Check if your system supports CPU hotplugging:
    cat /sys/devices/system/cpu/cpu*/online

    This command will show the current status of all CPUs in the system. If your system supports hotplugging, you should see a file named “hotplug” under each CPU directory.

  2. Disable a CPU core:
    echo 0 > /sys/devices/system/cpu/cpuX/online

    Replace “cpuX” with the CPU core number you want to disable. For example, to disable CPU core 3, use “cpu3”.

  3. Check if the CPU core is disabled:
    cat /sys/devices/system/cpu/cpuX/online

    This command should return “0”, indicating that the CPU core is disabled.

  4. Enable a CPU core:
    echo 1 > /sys/devices/system/cpu/cpuX/online

    This will enable the CPU core that you disabled in step 2.

Note that disabling CPU cores can affect the performance of the system and may cause unexpected behavior. It is recommended to test the system thoroughly after disabling or hotplugging a CPU core. Additionally, hotplugging a CPU may not be supported on all hardware platforms, so it is important to check if your system supports CPU hotplugging before attempting to do so.

Leave a Comment