Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time each CPU core spends in C0 power state

Any help figuring out how to do this would be great: How much time each CPU core spent in the C0 power state over the past second.

This is for a mac app so Objective-C, cocoa and c are needed.

like image 227
Eric Brotto Avatar asked Aug 18 '10 13:08

Eric Brotto


People also ask

What is CPU C States?

C-states are states when the CPU has reduced or turned off selected functions. Different processors support different numbers of C-states in which various parts of the CPU are turned off. To better understand the C-states that are supported and exposed, contact the CPU vendor.

How do you monitor C states?

How to check and monitor the CPU c-state usage in Linux per CPU and core? You can use "turbostat" tool for this purpose which will give you runtime value for the CPU c-state usage for all the available CPU and cores.


1 Answers

OS X doesn't have any APIs that expose the c-state of the CPU. However, it seems like you can do this using the MWAIT/MONITOR instructions on intel CPUs. Intel mentions that you can track C-state residency using this technique in section 14.4 of the reference manual:

Software should use CPUID to discover if a target processor supports the enumeration of MWAIT extensions. If CPUID.05H.ECX[Bit 0] = 1, the target processor supports MWAIT extensions and their enumeration (see Chapter 3, “Instruction Set Reference, A-M,” of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A).

If CPUID.05H.ECX[Bit 1] = 1, the target processor supports using interrupts as break-events for MWAIT, even when interrupts are disabled. Use this feature to measure C-state residency as follows:

  • Software can write to bit 0 in the MWAIT Extensions register (ECX) when issuing an MWAIT to enter into a processor-specific C-state or sub C-state.
  • When a processor comes out of an inactive C-state or sub C-state, software can read a timestamp before an interrupt service routine (ISR) is potentially executed.
  • You can find more info about the MWAIT instruction in the same manual. Good luck!

    Intel's Reference Manual

    like image 184
    Mahmoud Avatar answered Sep 28 '22 18:09

    Mahmoud