x86/S3: Restore broken vcpu affinity on resume (v3)
PATCH 1/1 x86/S3: Restore broken vcpu affinity on resume (v3)
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:
Fix formatting problems.
remove early return in cpu_disable_scheduler() path.
v3:
Fix remaining errant tab
Move restore_vcpu_affinity() to thaw_domains(), eliminating the need to promote for_each_cpupool()
--- xen/arch/x86/acpi/power.c | 4 ++++ xen/common/domain.c | 2 ++ xen/common/schedule.c | 41 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/sched.h | 6 ++++++ 4 files changed, 52 insertions(+), 1 deletion(-)
xen/arch/x86/acpi/power.c +4 -0
@@ -96,7 +96,11 @@ static void thaw_domains(void)rcu_read_lock (&domlist_read_lock);for_each_domain ( d ) + { +if (system_state == SYS_STATE_resume) +restore_vcpu_affinity (d);domain_unpause (d); + }rcu_read_unlock (&domlist_read_lock); }
xen/common/domain.c +2 -0
@@ -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 +40 -1
59 lines not on this page · raw message
xen/include/xen/sched.h +6 -0
@@ -153,6 +153,9 @@ struct vcpubool_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 vcpucpumask_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
xen/arch/x86/acpi/power.c static void thaw_domains(void) · line 100
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Ben Guthro
xen/arch/x86/acpi/power.c +2
-0@@ -96,7 +96,11 @@ static void thaw_domains(void)rcu_read_lock (&domlist_read_lock);for_each_domain ( d ) + { +if (system_state == SYS_STATE_resume)
I don't think there's a way to get here with system_state other than SYS_STATE_resume.
Also, should there be a need to re-submit again, there are spaces missing inside the parentheses.
Quoted 11 lines
xen/arch/x86/acpi/power.c +2
-0+restore_vcpu_affinity (d);domain_unpause (d); + }rcu_read_unlock (&domlist_read_lock); }xen/common/schedule.c +0
-0@@ -541,6 +541,38 @@ void vcpu_force_reschedule(struct vcpu *v) } }
xen/common/schedule.c void vcpu_force_reschedule(struct vcpu *v) · line 552
Quoted 10 lines
xen/common/schedule.c +9
-0+void restore_vcpu_affinity (struct domain *d) +{ +struct vcpu *v; + + for_each_vcpu ( d, v ) + { +vcpu_schedule_lock_irq (v); + +if (v->affinity_broken)
And here again.
xen/common/schedule.c void vcpu_force_reschedule(struct vcpu *v) · line 555
Quoted 3 lines
xen/common/schedule.c +3
-0+ { +printk ("Restoring vcpu affinity for domain %d vcpu %d\n" , + v->domain->domain_id, v->vcpu_id);
XENLOG_DEBUG perhaps? Otherwise this can get pretty noisy even without loglvl= override during resume if there are many and/or big domains. To conserve on ring and transmit buffer space, I'd also suggest shortening the text to "Restoring affinity for d%dv%d\n" (and using d->domain_id).
Jan
Quoted 23 lines
xen/common/schedule.c +20
-0+cpumask_copy (v->cpu_affinity, v->cpu_affinity_saved); + v->affinity_broken =0 ; + } + +if ( v->processor ==smp_processor_id () ) + { +set_bit (_VPF_migrating, &v->pause_flags); +vcpu_schedule_unlock_irq (v); +vcpu_sleep_nosync (v); +vcpu_migrate (v); + } +else + { +vcpu_schedule_unlock_irq (v); + } + } + +domain_update_node_affinity (d); +} +/* * This function is used by cpu_hotplug code from stop_machine context * and from cpupools to switch schedulers on a cpu.
Quoted 13 lines · Jan Beulich
xen/arch/x86/acpi/power.c static void thaw_domains(void) · line 100
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Ben Guthro
xen/arch/x86/acpi/power.c +2
-0@@ -96,7 +96,11 @@ static void thaw_domains(void)rcu_read_lock (&domlist_read_lock);for_each_domain ( d ) + { +if (system_state == SYS_STATE_resume)I don't think there's a way to get here with
system_stateother thanSYS_STATE_resume.
Quoted 2 lines
Also, should there be a need to re-submit again, there are spaces missing inside the parentheses.
OK, I'll remove this if entirely
Quoted 13 lines
Quoted 13 lines
xen/arch/x86/acpi/power.c +2
-0+restore_vcpu_affinity (d);domain_unpause (d); + }rcu_read_unlock (&domlist_read_lock); }xen/common/schedule.c +0
-0@@ -541,6 +541,38 @@ void vcpu_force_reschedule(struct vcpu *v) } }
Quoted 11 lines
xen/common/schedule.c void vcpu_force_reschedule(struct vcpu *v) · line 552
Quoted 9 lines
xen/common/schedule.c +9
-0+void restore_vcpu_affinity (struct domain *d) +{ +struct vcpu *v; + + for_each_vcpu ( d, v ) + { +vcpu_schedule_lock_irq (v); + +if (v->affinity_broken)And here again.
ACK. Will resolve in v4
Quoted 5 lines
xen/common/schedule.c void vcpu_force_reschedule(struct vcpu *v) · line 555
Quoted 4 lines
xen/common/schedule.c +3
-0+ { +printk ("Restoring vcpu affinity for domain %d vcpu %d\n" , + v->domain->domain_id, v->vcpu_id);
Quoted 7 lines
XENLOG_DEBUGperhaps? Otherwise this can get pretty noisy even without loglvl= override during resume if there are many and/or big domains. To conserve on ring and transmit buffer space, I'd also suggest shortening the text to "Restoring affinity for d%dv%d\n" (and usingd->domain_id).Jan
I modeled this after the printk where the affinity was broken, so they could be matched up in the log, for anyone looking.
Should I also change that printk to XENLOG_DEBUG?
Ben
Quoted 26 lines
Quoted 24 lines
xen/common/schedule.c +20
-0+cpumask_copy (v->cpu_affinity, v->cpu_affinity_saved); + v->affinity_broken =0 ; + } + +if ( v->processor ==smp_processor_id () ) + { +set_bit (_VPF_migrating, &v->pause_flags); +vcpu_schedule_unlock_irq (v); +vcpu_sleep_nosync (v); +vcpu_migrate (v); + } +else + { +vcpu_schedule_unlock_irq (v); + } + } + +domain_update_node_affinity (d); +} +/* * This function is used by cpu_hotplug code from stop_machine context * and from cpupools to switch schedulers on a cpu.