Measuring the Halted State

Description



The halted state refers to the state in which the CPU is not running. Idle time, as measured by the operating system, will be greater than or equal to halted time. The CPU can be in a lower power state when it is halted. The more the CPU is halted, the more likely it is that the CPU enters deeper power saving states (such as C3 or C6).

Typically the halted state is expressed as the 'percent halted' which is computed as:

%halted = 100 * 'halted cycles' / 'total cycles'
One of the fixed counters, CPU_CLK_UNHALTED.REF, counts the 'reference cycles in the unhalted state'. CPU_CLK_UNHALTED.REF increments at the TSC (Time Stamp Counter) frequency while the CPU is unhalted. The TSC frequency doesn't vary. We can compute

%halted = 100 * (1.0 - (CPU_CLK_UNHALTED.REF / total_cycles))
The 'total cycles' can be computed a couple of ways:

  1. If you have access to the TSC over the same interval as you collected CPU_CLK_UNHALTED.REF then:
    1. Total cycles = TSC_at_interval_end - TSC_at_interval_begin
  2. You can also approximate the total cycles by:
    1. Total cycles = Elapsed_time_in_seconds * TSC_frequency
    2. If you are using Intel® VTune™, it will tell you the elapsed time of the interval and TSC frequency.
    3. If you use this approximation to total cycles, you probably should make sure your % unhalted value is between 0.0 and 100.0.

Measuring the halted state



To use the above method, you need to collect CPU_CLK_UNHALTED.REF. Intel® VTune™ and Intel® Performance Tuning Utility (Intel® PTU) collect the TSC with each sample. Use the approximate 'total cycles = elapsed time * TSC_frequency' method if you can't display the beginning and ending TSC.

If you are using Intel® Performance Tuning Utility (Intel® PTU) data, be clear whether you are looking at 'samples' or 'events'. You need the CPU_CLK_UNHALTED.REF events. You can compute the events = samples *sample_after_value (SAV).
For more complete information about compiler optimizations, see our Optimization Notice.