Programmatically disable CPU core Programmatically disable CPU core linux linux

Programmatically disable CPU core


When you do echo 0 > /sys/devices/system/cpu/cpu<number>/online, what happens next depends on the particular CPU. On ARM embedded systems the kernel will typically disable the clock that drives the particular core PLL so effectively you get what you want.

On Intel X86 systems, you can only disable the interrupts and call the hlt instruction (which Linux Kernel does). This effectively puts CPU to the power-saving state until it is woken up by another CPU at user request. If you have a laptop, you can verify that power draw indeed goes down when you disable the core by reading the power from /sys/class/power_supply/BAT{0,1}/current_now (or uevent for all values such as voltage) or using the "powertop" utility.

For example, here's the call chain for disabling the CPU core in Linux Kernel for Intel CPUs.https://github.com/torvalds/linux/blob/master/drivers/cpufreq/intel_pstate.c

arch/x86/kernel/smp.c: smp_ops.play_dead = native_play_dead,

arch/x86/kernel/smpboot.c : native_play_dead() -> play_dead_common() -> local_irq_disable()

Before that, CPUFREQ also sets the CPU to the lowest power consumption level before disabling it though this does not seem to be strictly necessary.

intel_pstate_stop_cpu -> intel_cpufreq_stop_cpu -> intel_pstate_set_min_pstate -> intel_pstate_set_pstate -> wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate));

On Intel X86 there does not seem to be an official way to disable the actual clocks and voltage regulators. Even if there was, it would be specific to the motherboard and thus your closest bet might be looking into BIOS such as coreboot.Hmm, I realized I have no idea about Intel except looking into kernel sources.


You can get closest to this by using governors like cpufreq. Make Linux exclude the CPU and power saving mode will ensure that the core runs at minimal frequency.


You can also isolate cpus from the scheduler at kernel boot time.

Add isolcpus=0,1,2 to the kernel boot parameters.

https://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/re46.html