chcpu
Manage CPU online/offline status
TLDR
Disable one or more CPUs by their IDs
Enable one or more ranges of CPUs by their IDs
SYNOPSIS
chcpu [options] [cpu_id...]
PARAMETERS
-e, --enable
Enables the specified CPU(s), bringing them online for scheduling.
-d, --disable
Disables the specified CPU(s), taking them offline from scheduling.
-a, --all
Applies the --enable or --disable action to all detected CPUs. Cannot be used alone.
-r, --reboot-cpu
Attempts to reboot the specified CPU(s) or all CPUs if --all is used. This is a highly platform-dependent feature.
-s, --status
Displays the current online/offline status for all detected CPU cores.
-h, --help
Shows a help message and exits.
-V, --version
Prints version information and exits.
cpu_id...
One or more numerical CPU IDs (e.g., 0, 1, 2) to operate on. CPU IDs can be found via lscpu.
DESCRIPTION
chcpu is a command-line utility included in the util-linux package, designed for managing the online and offline states of CPU cores within a Linux system. It provides a convenient way for system administrators to enable or disable specific CPUs dynamically, without requiring a system reboot. This functionality is invaluable for various administrative tasks, including optimizing power consumption, isolating potentially faulty CPU cores, testing system resilience under reduced CPU availability, or fine-tuning resource allocation for particular workloads.
When a CPU is disabled using chcpu, it is taken offline by the kernel and will no longer be considered for task scheduling. Conversely, enabling a CPU brings it back online, making it available for the scheduler. The command leverages the Linux sysfs filesystem, specifically by interacting with the /sys/devices/system/cpu/cpuX/online file for each CPU ID X. Due to its direct interaction with core system hardware, executing chcpu requires root privileges.
CAVEATS
Using chcpu requires root (superuser) privileges. Attempting to disable cpu0 (the primary CPU) is generally disallowed by the kernel and the command itself, as it can lead to system instability or crashes. The --reboot-cpu option is highly dependent on specific kernel and hardware support, and its functionality may vary or be unavailable on many systems. Modifying CPU states can impact overall system performance and resource allocation, so caution is advised.
UNDERLYING MECHANISM
chcpu operates by writing '1' (online) or '0' (offline) to the online file located at /sys/devices/system/cpu/cpuX/online for the specified CPU X. This sysfs interface is the standard and direct method for user-space applications to control the online state of individual CPU cores.
CPU IDENTIFICATION
CPU IDs are typically numerical, starting from '0' and incrementing (e.g., 0, 1, 2...). You can determine the available CPU IDs on your system by using the lscpu command or by examining the directory names within /sys/devices/system/cpu/.
HISTORY
chcpu is an integral part of the widely used util-linux project, which aggregates essential system utilities for Linux. Its development and utility gained prominence as the Linux kernel evolved to support CPU hotplugging capabilities, allowing for dynamic management of CPU resources without requiring a full system reboot. The command's functionality is deeply intertwined with the kernel's sysfs interface, which provides the underlying programmatic access to control CPU states. It serves as a specialized tool primarily for system administrators engaged in advanced power management, performance optimization, or hardware troubleshooting.
SEE ALSO
lscpu(1), numactl(8), cpufreq-info(1), hwinfo(8)