Skip to contentSkip to conversation

x86/S3: Restore broken vcpu affinity on resume (v4)

PATCH In review Ben Guthro 4 participants 7 messages Mar 27, 2013 – Apr 3, 2013

lore
Share & tools
lore

Ben Guthro

author
#0 lore raw

PATCH 1/1 x86/S3: Restore broken vcpu affinity on resume (v4)

When in SYS_STATE_suspend, and going through the cpu_disable_scheduler path, save a copy of the current cpu affinity, and mark a flag to restore it later.

Later, in the resume process, when enabling nonboot cpus restore these affinities.

v2:
Formatting: Fix hard tabs.
remove early return in cpu_disable_scheduler() path.

v3:
Formatting: Fix remaining errant tab.
Move restore_vcpu_affinity() to thaw_domains(), eliminating the need to promote for_each_cpupool()

v4:
Formatting: Fix if statement spacing.
Eliminate unnecessary if statement in thaw_domains() Suppress affinity related logging to XENLOG_DEBUG to reduce noise.

---
 xen/arch/x86/acpi/power.c |    3 +++
 xen/common/domain.c       |    2 ++
 xen/common/schedule.c     |   45 ++++++++++++++++++++++++++++++++++++++++++---
 xen/include/xen/sched.h   |    6 ++++++
 4 files changed, 53 insertions(+), 3 deletions(-)
xen/arch/x86/acpi/power.c +3 -0
index 3c2585c..f41f0de 100644
@@ -96,7 +96,10 @@ static void thaw_domains(void)
 
     rcu_read_lock(&domlist_read_lock);
     for_each_domain ( d )
+    {
+        restore_vcpu_affinity(d);
         domain_unpause(d);
+    }
     rcu_read_unlock(&domlist_read_lock);
 }
 
xen/common/domain.c +2 -0
index 64ee29d..590548e 100644
@@ -126,6 +126,7 @@ struct vcpu *alloc_vcpu(
 
     if ( !zalloc_cpumask_var(&v->cpu_affinity) ||
          !zalloc_cpumask_var(&v->cpu_affinity_tmp) ||
+         !zalloc_cpumask_var(&v->cpu_affinity_saved) ||
          !zalloc_cpumask_var(&v->vcpu_dirty_cpumask) )
         goto fail_free;
 
@@ -155,6 +156,7 @@ struct vcpu *alloc_vcpu(
  fail_free:
         free_cpumask_var(v->cpu_affinity);
         free_cpumask_var(v->cpu_affinity_tmp);
+        free_cpumask_var(v->cpu_affinity_saved);
         free_cpumask_var(v->vcpu_dirty_cpumask);
         free_vcpu_struct(v);
         return NULL;
xen/common/schedule.c +42 -3

63 lines not on this page · raw message

xen/include/xen/sched.h +6 -0
index cabaf27..d15d567 100644
@@ -153,6 +153,9 @@ struct vcpu
     bool_t           defer_shutdown;
     /* VCPU is paused following shutdown request (d->is_shutting_down)? */
     bool_t           paused_for_shutdown;
+    /* VCPU need affinity restored */
+    bool_t           affinity_broken;
+
 
     /*
      * > 0: a single port is being polled;
@@ -175,6 +178,8 @@ struct vcpu
     cpumask_var_t    cpu_affinity;
     /* Used to change affinity temporarily. */
     cpumask_var_t    cpu_affinity_tmp;
+    /* Used to restore affinity across S3. */
+    cpumask_var_t    cpu_affinity_saved;
 
     /* Bitmask of CPUs which are holding onto this VCPU's state. */
     cpumask_var_t    vcpu_dirty_cpumask;
@@ -697,6 +702,7 @@ int schedule_cpu_switch(unsigned int cpu, struct cpupool *c);
 void vcpu_force_reschedule(struct vcpu *v);
 int cpu_disable_scheduler(unsigned int cpu);
 int vcpu_set_affinity(struct vcpu *v, const cpumask_t *affinity);
+void restore_vcpu_affinity(struct domain *d);
 
 void vcpu_runstate_get(struct vcpu *v, struct vcpu_runstate_info *runstate);
 uint64_t get_cpu_idle_time(unsigned int cpu);
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Ben Guthro

When in SYS_STATE_suspend, and going through the cpu_disable_scheduler path, save a copy of the current cpu affinity, and mark a flag to restore it later.

Later, in the resume process, when enabling nonboot cpus restore these affinities.

v2:
Formatting: Fix hard tabs.
remove early return in cpu_disable_scheduler() path.

v3:
Formatting: Fix remaining errant tab.
Move restore_vcpu_affinity() to thaw_domains(), eliminating the need to promote for_each_cpupool()

Quoted 6 lines

v4:
Formatting: Fix if statement spacing.
Eliminate unnecessary if statement in thaw_domains() Suppress affinity related logging to XENLOG_DEBUG to reduce noise.

Looks good to me now, but needs an ack by Keir (or George, considering the minor change to xen/common/domain.c is perhaps acceptable without formal ack).

Thanks, Jan

Acked-by on v1 1/1
#2 lore raw
In reply to Ben Guthro
Quoted 16 lines · Ben Guthro

When in SYS_STATE_suspend, and going through the cpu_disable_scheduler path, save a copy of the current cpu affinity, and mark a flag to restore it later.

Later, in the resume process, when enabling nonboot cpus restore these affinities.

v2:
Formatting: Fix hard tabs.
remove early return in cpu_disable_scheduler() path.

v3:
Formatting: Fix remaining errant tab.
Move restore_vcpu_affinity() to thaw_domains(), eliminating the need to promote for_each_cpupool()

Quoted 6 lines

v4:
Formatting: Fix if statement spacing.
Eliminate unnecessary if statement in thaw_domains() Suppress affinity related logging to XENLOG_DEBUG to reduce noise.

I'm not super-familiar with the save/restore paths; but it looks like a reasonable change to me:

author
#3 lore raw
Quoted 22 lines · George Dunlap
Quoted 21 lines · Ben Guthro

When in SYS_STATE_suspend, and going through the cpu_disable_scheduler path, save a copy of the current cpu affinity, and mark a flag to restore it later.

Later, in the resume process, when enabling nonboot cpus restore these affinities.

v2:
Formatting: Fix hard tabs.
remove early return in cpu_disable_scheduler() path.

v3:
Formatting: Fix remaining errant tab.
Move restore_vcpu_affinity() to thaw_domains(), eliminating the need to promote for_each_cpupool()

v4:
Formatting: Fix if statement spacing.
Eliminate unnecessary if statement in thaw_domains() Suppress affinity related logging to XENLOG_DEBUG to reduce noise.

Quoted 7 lines
Quoted 1 line

I'm not super-familiar with the save/restore paths; but it looks like a reasonable change to me:

Thanks George.

Jan,

Is this a sufficient Ack, or does Kier need to weigh in as well?

Thanks,

Ben

Acked-by
#4 lore raw
Quoted 10 lines · Ben Guthro
Quoted 10 lines
Quoted 6 lines

v4:
Formatting: Fix if statement spacing.
Eliminate unnecessary if statement in thaw_domains() Suppress affinity related logging to XENLOG_DEBUG to reduce noise.

I'm not super-familiar with the save/restore paths; but it looks like a reasonable change to me:

Quoted 8 lines
Quoted 2 lines

Thanks George.

Jan,

Is this a sufficient Ack, or does Kier need to weigh in as well?

I kind of feel this sort of thing should be done in dom0 userspace but, pragmatically, I know that's not really going to happen!

-- Keir

#5 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 15 lines · Ben Guthro
Quoted 5 lines
Quoted 5 lines

v4:
Formatting: Fix if statement spacing.
Eliminate unnecessary if statement in thaw_domains() Suppress affinity related logging to XENLOG_DEBUG to reduce noise.

Quoted 7 lines
Quoted 1 line

I'm not super-familiar with the save/restore paths; but it looks like a reasonable change to me:

Thanks George.

Quoted 8 lines
Quoted 3 lines

Jan,

Is this a sufficient Ack, or does Kier need to weigh in as well?

I kind of feel this sort of thing should be done in dom0 userspace but, pragmatically, I know that's not really going to happen!

How would that work, considering the Dom0's vCPU affinities are equally affected, and considering that all domains get thawed at once? Minimally you'd have a burst of (overcommit) load on pCPU0 right after resume, and whether the system would survive that is impossible to predict.

Jan

#6 lore raw
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 5 lines

Thanks George.

Jan,

Is this a sufficient Ack, or does Kier need to weigh in as well?

Quoted 8 lines
Quoted 2 lines

I kind of feel this sort of thing should be done in dom0 userspace but, pragmatically, I know that's not really going to happen!

How would that work, considering the Dom0's vCPU affinities are equally affected, and considering that all domains get thawed at once? Minimally you'd have a burst of (overcommit) load on pCPU0 right after resume, and whether the system would survive that is impossible to predict.

Ha, yes, well you'd put freeze/thaw in dom0 too. Well, it wasn't really a serious suggestion on my part, what we have works, this new patch will also work, and I'm happy. :)

-- Keir