Skip to content

Instantly share code, notes, and snippets.

@wmealing
Last active March 29, 2024 22:51
Show Gist options
  • Save wmealing/2dd2b543c4d3cff6cab7 to your computer and use it in GitHub Desktop.
Save wmealing/2dd2b543c4d3cff6cab7 to your computer and use it in GitHub Desktop.
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
@h1ght
Copy link

h1ght commented Apr 14, 2023

i tried your command for the named idle states. looks like some are missing on my system. ive read that for some cpu's they are disabled.
/sys/devices/system/cpu/cpu1/cpuidle/state0/name:POLL /sys/devices/system/cpu/cpu1/cpuidle/state1/name:C1E /sys/devices/system/cpu/cpu1/cpuidle/state2/name:C6 /sys/devices/system/cpu/cpu1/cpuidle/state3/name:C8 /sys/devices/system/cpu/cpu1/cpuidle/state4/name:C10
my system doenst want to go further as c3. now ive do trial and error for bios settings. im a bit confused by this.

also rc6pp is disabled for all system what ive read.

@ksingh7
Copy link

ksingh7 commented May 14, 2023

So i have tried to install this deb file and next i am going to monitor my system and report back back. Hopefully this should fix this problem, fingers crossed.

@ksingh7
Copy link

ksingh7 commented May 14, 2023

And also tried this

cpupower idle-set --disable-by-latency 0
# make systemd run it at startup:
cat >/etc/systemd/system/disable_cpu_idle_states.service <<'EOT'
[Unit]
Description=Disable idle CPU states
After=cpufrequtils.service
[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower idle-set --disable-by-latency 0
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
systemctl enable disable_cpu_idle_states
# if everything went well, reboot

@its0ka
Copy link

its0ka commented Jan 17, 2024

on my system with intel core 2 T5500 only "cpupower idle-set --disable-by-latency 0" or echo 1 to "/sys/devices/system/cpu/cpu*/cpuidle/state*/disable" works. kernel parameters from the first post don't change which c-states are enabled.

@wujtt
Copy link

wujtt commented Jan 31, 2024

Hello, may I ask where the bottom table was obtained from? Do you have any relevant documents or references? Thank you very much!

@wmealing
Copy link
Author

wmealing commented Feb 2, 2024

I think it was the intel hardware reference manuals, and source code.. the doc was written a long.. long time ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment