How to Enable, Disable, and Hotplug CPU Cores Using chcpu in Linux

Modern Linux servers and high-performance computing clusters frequently run on multi-socket architectures with dozens or hundreds of logical CPU threads. In enterprise cloud virtualization, power-sensitive embedded deployments, and performance profiling environments, having all processor cores active at all times is not always desirable. Disabling idle cores can dramatically reduce thermal generation, prevent context switching overhead for latency-critical single-threaded workloads, and isolate CPU cores for real-time applications. While interacting directly with kernel sysfs interfaces at /sys/devices/system/cpu/ is possible, the chcpu (Change CPU) command provides a robust, purpose-built command-line utility to hotplug and configure processor core states dynamically.

Auditing Active and Offline Cores with lscpu

Before modifying core availability, inspect the current CPU topology and hotplug capabilities using lscpu:

lscpu

Pay close attention to key metrics reported in the output:

  • CPU(s): The total count of logical processors recognised by the system.
  • On-line CPU(s) mask / list: Lists all cores currently participating in OS task scheduling (e.g., 0-15).
  • Off-line CPU(s) list: Displays any cores that are currently powered down or parked. If all cores are active, this line will not appear.

You can also query online status directly across all cores:

lscpu -e=CPU,NODE,SOCKET,CORE,ONLINE

This table view provides an individual breakdown of each CPU identifier alongside a boolean yes or no indicating online status.

Disabling Specific CPU Cores with chcpu -d

To take specific logical cores offline, execute chcpu with the -d (disable) flag under elevated privileges:

sudo chcpu -d 2,3

The command halts scheduling on CPU 2 and CPU 3 immediately. The Linux kernel migrates any active threads assigned to those cores onto remaining online processors, unregisters their hardware interrupts, and places the cores into a low-power sleep state.

You can also disable contiguous ranges of cores using hyphens:

sudo chcpu -d 8-15

This command disables logical processors 8 through 15 simultaneously.

Re-Enabling Cores with chcpu -e

When workload demands increase and additional compute capacity is required, re-enable parked cores using the -e (enable) flag:

sudo chcpu -e 2,3

To bring an entire range of disabled cores back online:

sudo chcpu -e 8-15

The kernel wakes the physical hardware threads, re-initialises APIC timers, and restores them into the Completely Fair Scheduler (CFS) load balancing pool immediately without requiring a system reboot.

Important System Constraints: Protecting CPU 0

When managing CPU cores, observe the following architectural constraints:

  • Boot Core (CPU 0): On many x86_64 architectures and older Linux kernels, logical CPU 0 handles low-level ACPI interrupts, non-maskable interrupts (NMIs), and bootstrap initialisation routines. While modern Linux kernels support hotplugging CPU 0 on compliant hardware, attempting to disable CPU 0 may return “Operation not permitted” or cause system instability if the platform firmware does not support CPU 0 hotplugging. In general, avoid taking CPU 0 offline.
  • Hyper-Threading Pairs: Modern processors feature simultaneous multithreading (SMT). For example, physical Core 1 may host logical processors 1 and 9. If your goal is reducing power or testing performance without hyper-threading, ensure you disable the secondary sibling threads across all physical cores.

Configuring Virtual Machine CPU Hotplugging

In cloud and virtualised environments (such as KVM, QEMU, or VMware ESXi), virtual machines can be configured with CPU hotplug support. When a hypervisor administrator dynamically adds vCPUs to a running Linux guest, the guest OS detects new hardware in an offline state. Running sudo chcpu -e <id> allows the running guest to consume the newly provisioned virtual compute resources instantly without downtime.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.