x86: Px statistic update for cpu idle time.
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 30 Jun 2008 08:59:39 +0000 (09:59 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 30 Jun 2008 08:59:39 +0000 (09:59 +0100)
Update px statistic, subtract cx idle time from px residency time.

Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
xen/arch/x86/acpi/cpufreq/cpufreq_ondemand.c
xen/arch/x86/acpi/cpufreq/utility.c
xen/arch/x86/acpi/pmstat.c
xen/include/acpi/cpufreq/processor_perf.h

index dbd39b5a65a9233f39a3e349f2aa4d394940a101..7398dc960719d74809f267380bbaa947aa8f3777 100644 (file)
@@ -52,7 +52,7 @@ static struct dbs_tuners {
 
 static struct timer dbs_timer[NR_CPUS];
 
-static inline uint64_t get_cpu_idle_time(unsigned int cpu)
+inline uint64_t get_cpu_idle_time(unsigned int cpu)
 {
     uint64_t idle_ns;
     struct vcpu *v;
index 966217828ba10d61c5b9ba9ee515aba0b4e36375..e34586e3b51a919f1a7ff4f9ba9b4ef9076706f0 100644 (file)
@@ -46,8 +46,15 @@ void px_statistic_suspend(void)
 
     for_each_online_cpu(cpu) {
         struct pm_px *pxpt = &px_statistic_data[cpu];
+        uint64_t total_idle_ns;
+        uint64_t tmp_idle_ns;
+
+        total_idle_ns = get_cpu_idle_time(cpu);
+        tmp_idle_ns = total_idle_ns - pxpt->prev_idle_wall;
+
         pxpt->u.pt[pxpt->u.cur].residency +=
                     now - pxpt->prev_state_wall;
+        pxpt->u.pt[pxpt->u.cur].residency -= tmp_idle_ns;
     }
 }
 
@@ -61,6 +68,7 @@ void px_statistic_resume(void)
     for_each_online_cpu(cpu) {
         struct pm_px *pxpt = &px_statistic_data[cpu];
         pxpt->prev_state_wall = now;
+        pxpt->prev_idle_wall = get_cpu_idle_time(cpu);
     }
 }
 
@@ -74,15 +82,22 @@ void px_statistic_update(cpumask_t cpumask, uint8_t from, uint8_t to)
     for_each_cpu_mask(i, cpumask) {
         struct pm_px *pxpt = &px_statistic_data[i];
         uint32_t statnum = processor_pminfo[i].perf.state_count;
+        uint64_t total_idle_ns;
+        uint64_t tmp_idle_ns;
+
+        total_idle_ns = get_cpu_idle_time(i);
+        tmp_idle_ns = total_idle_ns - pxpt->prev_idle_wall;
 
         pxpt->u.last = from;
         pxpt->u.cur = to;
         pxpt->u.pt[to].count++;
         pxpt->u.pt[from].residency += now - pxpt->prev_state_wall;
+        pxpt->u.pt[from].residency -= tmp_idle_ns;
 
         (*(pxpt->u.trans_pt + from*statnum + to))++;
 
         pxpt->prev_state_wall = now;
+        pxpt->prev_idle_wall = total_idle_ns;
     }
 }
 
@@ -114,6 +129,7 @@ int px_statistic_init(int cpuid)
         pxpt->u.pt[i].freq = pmpt->perf.states[i].core_frequency;
 
     pxpt->prev_state_wall = NOW();
+    pxpt->prev_idle_wall = get_cpu_idle_time(cpuid);
 
     return 0;
 }
@@ -134,6 +150,7 @@ void px_statistic_reset(int cpuid)
     }
 
     pxpt->prev_state_wall = NOW();
+    pxpt->prev_idle_wall = get_cpu_idle_time(cpuid);
 }
 
 
index 9aa5a4750a3e64553e58090be0712db51c3ba706..cf14fc9d647f38717a3dca1ea12200b2e9fb3158 100644 (file)
@@ -71,11 +71,18 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op)
     case PMSTAT_get_pxstat:
     {
         uint64_t now, ct;
+        uint64_t total_idle_ns;
+        uint64_t tmp_idle_ns;
+
+        total_idle_ns = get_cpu_idle_time(op->cpuid);
+        tmp_idle_ns = total_idle_ns - pxpt->prev_idle_wall;
 
         now = NOW();
         pxpt->u.usable = pmpt->perf.state_count - pmpt->perf.ppc;
         pxpt->u.pt[pxpt->u.cur].residency += now - pxpt->prev_state_wall;
+        pxpt->u.pt[pxpt->u.cur].residency -= tmp_idle_ns;
         pxpt->prev_state_wall = now;
+        pxpt->prev_idle_wall = total_idle_ns;
 
         ct = pmpt->perf.state_count;
         if ( copy_to_guest(op->u.getpx.trans_pt, pxpt->u.trans_pt, ct*ct) )
index e27869c1ac6b5fc97d45030387bdcc100a391f02..7a71cfaf84d10cfaa17b327a42e4532032250635 100644 (file)
@@ -7,17 +7,21 @@
 int get_cpu_id(u8);
 int acpi_cpufreq_init(void);
 int powernow_cpufreq_init(void);
+
 void px_statistic_update(cpumask_t, uint8_t, uint8_t);
 int  px_statistic_init(int);
 void px_statistic_reset(int);
 void px_statistic_suspend(void);
 void px_statistic_resume(void);
+
 void cpufreq_dom_exit(void);
 int  cpufreq_dom_init(void);
 int  cpufreq_dom_dbs(unsigned int);
 void cpufreq_suspend(void);
 int  cpufreq_resume(void);
 
+inline uint64_t get_cpu_idle_time(unsigned int);
+
 struct processor_performance {
     uint32_t state;
     uint32_t ppc;
@@ -52,6 +56,7 @@ struct px_stat {
 struct pm_px {
     struct px_stat u;
     uint64_t prev_state_wall;
+    uint64_t prev_idle_wall;
 };
 
 extern struct pm_px px_statistic_data[NR_CPUS];