4

Even if no user process is running, don't the kernel processes keep the CPU active enough so as to prevent it from entering a deeper C state like C1 or C2 ?

3
  • 1
    this is a good question, but I'm not so sure it's really a sysadmin question. It's really a question for kernel programmers with hardware experience.. Jan 27, 2012 at 0:03
  • 3
    @JeffAtwood: The mechanics of how to implement this functionality in an OS kernel are probably off-topic, but I'd say that a sysadmin needs to know how the hardware power management functionality in their systems works (serverfault.com/q/196301/7200). Jan 27, 2012 at 1:44
  • This is named the waterfall misconception. You should imagine C-states as a complex neverending game of forecasting activity at a millisecond scale, not as an absolute long-lasting thing. E.g. on my idle laptop right now, in a given second I might have scored 2% of C0 time, together with 90% of C7 residency (which was enough to reach package C3 for 71% of the period).
    – mirh
    Dec 15, 2022 at 16:48

1 Answer 1

8

CPUs (or individual cores) can be put into "deep" C-states by an OS kernel.

You're thinking that the processor "puts itself to sleep" when it "detects" inactivity. This isn't how it works. The OS scheduler determines system idle percentage based on the amount of time spent in the system idle loop to detect system inactivity. The CPU itself (in x86 land, at least) doesn't know "what" it's executing and doesn't have context to "detect" idle cycles on its own.

The system firmware contains ACPI tables that define the power management capabilities of the hardware. These tables are read by the OS when it starts up. The OS kernel processor driver (or whatever the analog is to that for a given operating system) is responsible for monitoring the CPU workload and instructing the hardware to put the CPU into a power management state selected from the firmware ACPI tables.

Microsoft has an article describing power management in Windows 7 and Server 2008 R2. IBM has an article (likely dated, however) about the CPUfreq system in Linux.

Edit:

It's worth pointing out that many server computers have an onboard hardware-based mechanism to monitor and manage CPU states. This isn't being done "in the CPU" either, but rather is taking the place of the OS power and performance management functionality. It's been my experience that this often yields power savings but at the expense of system performance.

1
  • At least since Sandy Bridge, Intel has added a Package Control Unit to their processors. And at least in certain conditions, Linux will not respect the MSR and _CST attributes that the BIOS set. Last but not least, MWAIT or HLT are the instructions to signal idle.
    – mirh
    Dec 15, 2022 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .