Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What are CPU "C-states" and how to disable them if needed?

To limit a CPU to a certain C-state, you can pass the processor.max_cstate=X option in the kernel line of /boot/grub/grub.conf.

Here we limit the system to only C-State 1:

    kernel /vmlinuz-2.6.18-371.1.2.el5 ... processor.max_cstate=1

On some systems, the kernel can override the BIOS setting, and the parameter intel_idle.max_cstate=0 may be required to ensure sleep states are not entered:

	kernel /vmlinuz-2.6.32-431.el6.x86_64 ... processor.max_cstate=1 intel_idle.max_cstate=0

You can confirm the maximum allowed CPU C-State with:

# cat /sys/module/intel_idle/parameters/max_cstate
0

In order to save energy when the CPU is idle, the CPU can be commanded to enter a low-power mode. Each CPU has several power modes and they are collectively called “C-states” or “C-modes.”.

The lower-power mode was first introduced with the 486DX4 processor. To the present, more power modes has been introduced and enhancements has been made to each mode for the CPU to consume less power in these low-power modes. The idea of these modes is to cut the clock signal and power from idle units inside the CPU. As many units you stop (by cutting the clock) as you reduce the voltage or even completely shut down to save energy. On the other hand, you have to take into account that more time is required for the CPU to “wake up” and be again 100% operational. These modes are known as C-states. They are usually starting in C0, which is the normal CPU operating mode, i.e., the CPU is 100% turned on. With increasing C number, the CPU sleep mode is deeper, i.e., more circuits and signals are turned off and more time the CPU will require to return to C0 mode, i.e., to wake-up. Each mode is also known by a name and several of them have sub-modes with different power saving – and thus wake-up time – levels.

mode Name What id does CPUs
C0 Operating State CPU fully turned on, currently executing instructions. All CPUs
C1 Operating State CPU fully turned on, awaiting instructions All CPUs
C1E Halt Stops CPU main internal clocks via software; bus interface unit and APIC are kept running at full speed 486DX4 and above
C1E Enhanced Halt Stops CPU main internal clocks via software and reduces CPU voltage; bus interface unit and APIC are kept running at full speed All socket 775 CPUs
C1E -- Stops all CPU internal clocks Turion 64, 65-nm Athlon X2 and Phenom CPUs
C2 Stop Grant Stops CPU main internal clocks via hardware; bus interface unit and APIC are kept running at full speed 486DX4 and above
C2 Stop Clock Stops CPU internal and external clocks via hardware Only 486DX4, Pentium, Pentium MMX, K5, K6, K6-2, K6-III
C2E Extended Stop Grant Stops CPU main internal clocks via hardware and reduces CPU voltage; bus interface unit and APIC are kept running at full speed Core 2 Duo and above (Intel only)
C3 Sleep Stops all CPU internal clocks Pentium II, Athlon and above, but not on Core 2 Duo E4000 and E6000
C3 Deep Sleep Stops all CPU internal and external clocks Pentium II and above, but not on Core 2 Duo E4000 and E6000; Turion 64
C3 AltVID Stops all CPU internal clocks and reduces CPU voltage AMD Turion 64
C4 Deeper Sleep Reduces CPU voltage Pentium M and above, but not on Core 2 Duo E4000 and E6000 series; AMD Turion 64
C4E/C5 Enhanced Deeper Sleep Reduces CPU voltage even more and turns off the memory cache Core Solo, Core Duo and 45-nm mobile Core 2 Duo only
C6 Deep Power Down Reduces the CPU internal voltage to any value, including 0 V 45-nm mobile Core 2 Duo only
@Hi-Angel

This comment has been minimized.

Copy link

@Hi-Angel Hi-Angel commented Jan 21, 2018

# cat /sys/module/intel_idle/parameters/max_cstate
0

What about AMD? And how does one list available c-states?

@steveeJ

This comment has been minimized.

Copy link

@steveeJ steveeJ commented Feb 28, 2018

@Hi-Angel you could try sudo find /sys -name max_cstate and see if you're lucky.

@devurandom

This comment has been minimized.

Copy link

@devurandom devurandom commented Mar 28, 2018

It appears that the intel_idle kernel module is also loaded on AMD CPUs (on the AMD Ryzen 5 2400G at least). The default setting on my system was 9 -- does power state Cn correspond directly to kernel module parameter n?

@wmealing

This comment has been minimized.

Copy link
Owner Author

@wmealing wmealing commented Aug 6, 2018

Oddly, I had forgotten that I had written this gist, and got no notification that it had changed. Maybe I should spend some time updating it for AMD.

@llamafilm

This comment has been minimized.

Copy link

@llamafilm llamafilm commented Feb 26, 2020

What's the difference between C0 and C1? The chart here says C1 means "fully turned on" so C0 somehow even more on than that?

@wmealing

This comment has been minimized.

Copy link
Owner Author

@wmealing wmealing commented Feb 27, 2020

C0 is the operating state (ie, currently executing instructions)

C1 (often known as Halt) is a state where the processor is not executing instructions, but can ready to start executing instructions immediately with no wakeup.

@llamafilm

This comment has been minimized.

Copy link

@llamafilm llamafilm commented Feb 27, 2020

Okay, thanks. So is there a reason you use two different values like this?
processor.max_cstate=1 intel_idle.max_cstate=0

@wmealing

This comment has been minimized.

Copy link
Owner Author

@wmealing wmealing commented Feb 27, 2020

To be honest, it was 5 years ago that I wrote this, I remember that some systems needed it. I don't remember the logic behind it. If you do any additional research on the newer c-states I'd be happy to include it.

@AndrejKorshikov

This comment has been minimized.

Copy link

@AndrejKorshikov AndrejKorshikov commented May 4, 2020

It appears that the intel_idle kernel module is also loaded on AMD CPUs (on the AMD Ryzen 5 2400G at least). The default setting on my system was 9 -- does power state Cn correspond directly to kernel module parameter n?

Kernel intel_idle module parameter n is a state number. Cn is a state name. They do correspond to each other, but state numbers are CPU-specific. So the same n means different Cns on different platforms. You can find out the correspondence between intel_idle driver state numbers and state names using, for example, the following command:

grep . /sys/devices/system/cpu/cpu0/cpuidle/state*/name

And here is the output on my laptop (with Intel Core i3-7100U CPU):

/sys/devices/system/cpu/cpu0/cpuidle/state0/name:POLL
/sys/devices/system/cpu/cpu0/cpuidle/state1/name:C1
/sys/devices/system/cpu/cpu0/cpuidle/state2/name:C1E
/sys/devices/system/cpu/cpu0/cpuidle/state3/name:C3
/sys/devices/system/cpu/cpu0/cpuidle/state4/name:C6
/sys/devices/system/cpu/cpu0/cpuidle/state5/name:C7s
/sys/devices/system/cpu/cpu0/cpuidle/state6/name:C8
/sys/devices/system/cpu/cpu0/cpuidle/state7/name:C9
/sys/devices/system/cpu/cpu0/cpuidle/state8/name:C10

So, as an example, on my platform intel_idle.max_cstate=4 means "Deepest allowed state is C6".

@AndrejKorshikov

This comment has been minimized.

Copy link

@AndrejKorshikov AndrejKorshikov commented May 4, 2020

Okay, thanks. So is there a reason you use two different values like this?
processor.max_cstate=1 intel_idle.max_cstate=0

There are two CPU idle drivers: intel_idle (the default one for nowadays) and acpi_idle (the old school).
With intel_idle driver C-state numbers are processor-specific (see my comment above), and the driver ignores BIOS C-states settings.
With acpi_idle driver C-states are defined by ACPI standard and exported by BIOS, and the driver follows BIOS settings.

intel_idle.max_cstate=0 means "Disable intel_idle driver and use acpi_idle instead". So processor.max_cstate=1 is a command to acpi_idle driver, but I'm not sure about its very meaning. I've read that processor.max_cstate=1 and processor.max_cstate=0 are equal, and both disable C-states completely when using acpi_idle driver. And idle=poll is usually added to kernel parameters when processor.max_cstate=1 is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.