WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Avoid negative runstate pieces.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Avoid negative runstate pieces.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 Dec 2008 22:30:23 -0800
Delivery-date: Tue, 16 Dec 2008 22:30:48 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1228917941 0
# Node ID 6401c9533ef52e9217b39fa7f07df97e757683bc
# Parent  2a349db39496263fb326af12042c8ebdf421b071
Avoid negative runstate pieces.

Also consolidate all places to get cpu idle time.

Signed-off-by: Kevin Tian <kevin.tian@xxxxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 xen/arch/x86/acpi/cpu_idle.c           |    5 ---
 xen/arch/x86/platform_hypercall.c      |   10 -------
 xen/common/schedule.c                  |   46 ++++++++++++++++++++++-----------
 xen/common/sysctl.c                    |    9 ------
 xen/drivers/cpufreq/cpufreq_ondemand.c |   15 ----------
 xen/include/xen/sched.h                |    1 
 6 files changed, 35 insertions(+), 51 deletions(-)

diff -r 2a349db39496 -r 6401c9533ef5 xen/arch/x86/acpi/cpu_idle.c
--- a/xen/arch/x86/acpi/cpu_idle.c      Wed Dec 10 13:41:34 2008 +0000
+++ b/xen/arch/x86/acpi/cpu_idle.c      Wed Dec 10 14:05:41 2008 +0000
@@ -749,7 +749,6 @@ int pmstat_get_cx_stat(uint32_t cpuid, s
 int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat)
 {
     const struct acpi_processor_power *power = processor_powers[cpuid];
-    struct vcpu *v = idle_vcpu[cpuid];
     uint64_t usage;
     int i;
 
@@ -763,9 +762,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, s
 
     stat->last = power->last_state ? power->last_state->idx : 0;
     stat->nr = power->count;
-    stat->idle_time = v->runstate.time[RUNSTATE_running];
-    if ( v->is_running )
-        stat->idle_time += NOW() - v->runstate.state_entry_time;
+    stat->idle_time = get_cpu_idle_time(cpuid);
 
     for ( i = 0; i < power->count; i++ )
     {
diff -r 2a349db39496 -r 6401c9533ef5 xen/arch/x86/platform_hypercall.c
--- a/xen/arch/x86/platform_hypercall.c Wed Dec 10 13:41:34 2008 +0000
+++ b/xen/arch/x86/platform_hypercall.c Wed Dec 10 14:05:41 2008 +0000
@@ -337,16 +337,8 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
         for_each_cpu_mask ( cpu, cpumap )
         {
             if ( (v = idle_vcpu[cpu]) != NULL )
-            {
-                idletime = v->runstate.time[RUNSTATE_running];
-                if ( v->is_running )
-                    idletime += now - v->runstate.state_entry_time;
-            }
-            else
-            {
-                idletime = 0;
                 cpu_clear(cpu, cpumap);
-            }
+            idletime = get_cpu_idle_time(cpu);
 
             ret = -EFAULT;
             if ( copy_to_guest_offset(idletimes, cpu, &idletime, 1) )
diff -r 2a349db39496 -r 6401c9533ef5 xen/common/schedule.c
--- a/xen/common/schedule.c     Wed Dec 10 13:41:34 2008 +0000
+++ b/xen/common/schedule.c     Wed Dec 10 14:05:41 2008 +0000
@@ -84,33 +84,49 @@ static inline void vcpu_runstate_change(
 static inline void vcpu_runstate_change(
     struct vcpu *v, int new_state, s_time_t new_entry_time)
 {
+    s_time_t delta;
+
     ASSERT(v->runstate.state != new_state);
     ASSERT(spin_is_locked(&per_cpu(schedule_data,v->processor).schedule_lock));
 
     trace_runstate_change(v, new_state);
 
-    v->runstate.time[v->runstate.state] +=
-        new_entry_time - v->runstate.state_entry_time;
-    v->runstate.state_entry_time = new_entry_time;
     v->runstate.state = new_state;
+
+    delta = new_entry_time - v->runstate.state_entry_time;
+    if ( delta > 0 )
+    {
+        v->runstate.time[v->runstate.state] += delta;
+        v->runstate.state_entry_time = new_entry_time;
+    }
 }
 
 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate)
 {
-    if ( likely(v == current) )
-    {
-        /* Fast lock-free path. */
-        memcpy(runstate, &v->runstate, sizeof(*runstate));
-        ASSERT(runstate->state == RUNSTATE_running);
-        runstate->time[RUNSTATE_running] += NOW() - runstate->state_entry_time;
-    }
-    else
-    {
+    s_time_t delta;
+
+    if ( unlikely(v != current) )
         vcpu_schedule_lock_irq(v);
-        memcpy(runstate, &v->runstate, sizeof(*runstate));
-        runstate->time[runstate->state] += NOW() - runstate->state_entry_time;
+
+    memcpy(runstate, &v->runstate, sizeof(*runstate));
+    delta = NOW() - runstate->state_entry_time;
+    if ( delta > 0 )
+        runstate->time[runstate->state] += delta;
+
+    if ( unlikely(v != current) )
         vcpu_schedule_unlock_irq(v);
-    }
+}
+
+uint64_t get_cpu_idle_time(unsigned int cpu)
+{
+    struct vcpu_runstate_info state = { .state = RUNSTATE_running };
+    struct vcpu *v;
+
+    if ( (v = idle_vcpu[cpu]) == NULL )
+        return 0;
+
+    vcpu_runstate_get(v, &state);
+    return state.time[RUNSTATE_running];
 }
 
 int sched_init_vcpu(struct vcpu *v, unsigned int processor) 
diff -r 2a349db39496 -r 6401c9533ef5 xen/common/sysctl.c
--- a/xen/common/sysctl.c       Wed Dec 10 13:41:34 2008 +0000
+++ b/xen/common/sysctl.c       Wed Dec 10 14:05:41 2008 +0000
@@ -167,7 +167,6 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
     {
         uint32_t i, nr_cpus;
         struct xen_sysctl_cpuinfo cpuinfo;
-        struct vcpu *v;
 
         nr_cpus = min_t(uint32_t, op->u.getcpuinfo.max_cpus, NR_CPUS);
 
@@ -177,13 +176,7 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
 
         for ( i = 0; i < nr_cpus; i++ )
         {
-            /* Assume no holes in idle-vcpu map. */
-            if ( (v = idle_vcpu[i]) == NULL )
-                break;
-
-            cpuinfo.idletime = v->runstate.time[RUNSTATE_running];
-            if ( v->is_running )
-                cpuinfo.idletime += NOW() - v->runstate.state_entry_time;
+            cpuinfo.idletime = get_cpu_idle_time(i);
 
             ret = -EFAULT;
             if ( copy_to_guest_offset(op->u.getcpuinfo.info, i, &cpuinfo, 1) )
diff -r 2a349db39496 -r 6401c9533ef5 xen/drivers/cpufreq/cpufreq_ondemand.c
--- a/xen/drivers/cpufreq/cpufreq_ondemand.c    Wed Dec 10 13:41:34 2008 +0000
+++ b/xen/drivers/cpufreq/cpufreq_ondemand.c    Wed Dec 10 14:05:41 2008 +0000
@@ -93,21 +93,6 @@ int get_cpufreq_ondemand_para(uint32_t *
     *up_threshold = dbs_tuners_ins.up_threshold;
 
     return 0;
-}
-
-uint64_t get_cpu_idle_time(unsigned int cpu)
-{
-    uint64_t idle_ns;
-    struct vcpu *v;
-
-    if ((v = idle_vcpu[cpu]) == NULL)
-        return 0;
-
-    idle_ns = v->runstate.time[RUNSTATE_running];
-    if (v->is_running)
-        idle_ns += NOW() - v->runstate.state_entry_time;
-
-    return idle_ns;
 }
 
 static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
diff -r 2a349db39496 -r 6401c9533ef5 xen/include/xen/sched.h
--- a/xen/include/xen/sched.h   Wed Dec 10 13:41:34 2008 +0000
+++ b/xen/include/xen/sched.h   Wed Dec 10 14:05:41 2008 +0000
@@ -538,6 +538,7 @@ void vcpu_unlock_affinity(struct vcpu *v
 void vcpu_unlock_affinity(struct vcpu *v, cpumask_t *affinity);
 
 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate);
+uint64_t get_cpu_idle_time(unsigned int cpu);
 
 #define IS_PRIV(_d) ((_d)->is_privileged)
 #define IS_PRIV_FOR(_d, _t) (IS_PRIV(_d) || ((_d)->target && (_d)->target == 
(_t)))

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Avoid negative runstate pieces., Xen patchbot-unstable <=