Skip to contentSkip to conversation

xenpm, x86: Fix reporting of idle state average residency times

PATCH New Boris Ostrovsky 1 participant 1 message Jun 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xenpm, x86: Fix reporting of idle state average residency times

# HG changeset patch
# User Boris Ostrovsky <[email protected]>
# Date 1338831484 -7200
# Node ID 390346181927d0350f83c4046470a0b9b28c1686
# Parent 6bea63e6c780de6303361e5f190d6925996cd2a2 xenpm, x86: Fix reporting of idle state average residency times

If CPU stays in the same idle state for the full duration of xenpm sample then average residency may not be reported correctly since usage counter will not be incremented.

In addition, in order to calculate averages correctly residence time and usage counter should be read and written atomically.

tools/misc/xenpm.c +8 -1
diff -r 6bea63e6c780 -r 390346181927 tools/misc/xenpm.c
@@ -389,7 +389,14 @@ static void signal_int_handler(int signo
                 res = ( diff >= 0 ) ? diff : 0;
                 triggers = cxstat_end[i].triggers[j] -
                     cxstat_start[i].triggers[j];
-                avg_res = (triggers==0) ? 0: (double)res/triggers/1000000.0;
+                /* 
+                 * triggers may be zero if the CPU has been in this state for
+                 * the whole sample or if it never entered the state
+                 */
+                if ( triggers == 0 && cxstat_end[i].last == j )
+                    avg_res =  (double)sum_cx[i]/1000000.0;
+                else
+                    avg_res = (triggers==0) ? 0: (double)res/triggers/1000000.0;
                 printf("  C%d\t%"PRIu64"\t(%5.2f%%)\t%.2f\n", j, res/1000000UL,
                         100 * res / (double)sum_cx[i], avg_res );
             }
xen/arch/x86/acpi/cpu_idle.c +61 -36

190 lines not on this page · raw message

xen/include/xen/cpuidle.h +2 -0
diff -r 6bea63e6c780 -r 390346181927 xen/include/xen/cpuidle.h
@@ -28,6 +28,7 @@
 #define _XEN_CPUIDLE_H
 
 #include <xen/cpumask.h>
+#include <xen/spinlock.h>
 
 #define ACPI_PROCESSOR_MAX_POWER        8
 #define CPUIDLE_NAME_LEN                16
@@ -69,6 +70,7 @@ struct acpi_processor_power
     void *gdata; /* governor specific data */
     u32 last_residency;
     u32 count;
+    spinlock_t stat_lock;
     struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
 };