Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically disable CPU core

It is known the way to disable logical CPUs in Linux, basically with echo 0 > /sys/devices/system/cpu/cpu<number>/online. This way, you are only telling to the OS to ignore that given (<number>) CPU.

My question goes further, is it possible not only to ignore it but to turn it off physically programmatically? I want that CPU to not receive any power, in order to make its energy consumption zero.

I know that it is possible disable cores from the BIOS (not always), but I want to know whether is possible to do it within a certain program or not.

like image 533
horro Avatar asked Jul 04 '17 13:07

horro


People also ask

How do I disable my CPU cores?

From the System Utilities screen, select System Configuration > BIOS/Platform Configuration (RBSU) > System Options > Processor Options > Processor Core Disable and press Enter.

How do I disable CPU cores in Ubuntu?

Execute Linux command "echo 0 > /sys/devices/system/cpu/cpu3/online" to disable CPU core.

How do I limit CPU cores in Linux?

Limiting actual usage is done by using the –limit or -l switch option to set the CPU percentage for a process. Please note that total CPU percentage available is usually (100 x number of CPU Cores). Use top, or even better, install htop and use this to find the offending program.

How do I isolate CPU cores in Linux?

above command loads kernel image there we are manually passing “isolcpus=2” parameter to isolate CPU number 2. after this change we can boot the kernel by pressing F10 or as mentioned in grub note. After this once system boots cpu2 will be isolated and no user/kernel process is loaded.

How do I disable a core in Linux?

In Windows systems, it is possible to disable a core through the system configuration window. Choose the number of processors that should be enabled or disabled and restart the computer for the settings to take effect. Disabling a core in Linux can be done through the grub menu and add parameters to the kernel entry.

How does disabling the core of a CPU reduce power draw?

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.

How do I turn off all cores on my CPU?

Depending on your need, there are actually 3 ways to accomplish it. The first method disables cores for the whole system. The second turns them off for a specific program. Finally, you may just want to shut off those fake Hyperthreading cores.

How do I enable or disable the processor in Linux?

In the System Configuration window click on the Atart sub menu and the on Advanced Options button In the second window that appears, you should be provided with an option for enabling and disabling the processors as you wish What is the procedure when using Linux? When using Linux the procedure is quite different.


2 Answers

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.

like image 168
alexst Avatar answered Oct 19 '22 19:10

alexst


In Windows 10 it became possible with new power management commands CPMINCORES CPMAXCORES.

Powercfg -setacvalueindex scheme_current sub_processor CPMAXCORES 50
Powercfg -setacvalueindex scheme_current sub_processor CPMINCORES 25
Powercfg -setactive scheme_current

Here 50% of cores are assigned for desired deep sleep, and 25% are forbidden to be parked. Very good in numeric simulations requiring increased clock rate (15% boost on Intel)

You can not choose which cores to park, but Windows 10 kernel checks Intel's Comet Lake and newer "prefered" (more power efficient) cores, and starts parking those not preferred. It is not a strict parking, so at high load the kernel can use these cores with very low load.

just in case if you are looking for alternatives

like image 35
Asdf Avatar answered Oct 19 '22 21:10

Asdf