Skip to contentSkip to conversation

xen: simplify suspend/resume handling

PATCH Superseded Juergen Gross 5 participants 43 messages Mar 18, 2019 – Apr 11, 2019 9 messages not in the archive

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover xen: simplify suspend/resume handling

Especially in the scheduler area (schedule.c, cpupool.c) there is a rather complex handling involved when doing suspend and resume.

This can be simplified a lot by not performing a complete cpu down and up cycle for the non-boot cpus, but keeping the pure software related state and freeing it only in case a cpu didn't come up again during resume.

In summary not only the complexity can be reduced, but the failure tolerance will be even better with this series: With a dedicated hook for failing cpus when resuming it is now possible to survive e.g. a cpupool being left without any cpu after resume by moving its domains to cpupool0.

Juergen Gross (6):
xen/sched: call cpu_disable_scheduler() via cpu notifier
xen: add helper for calling notifier_call_chain() to common/cpu.c
xen: add new cpu notifier action CPU_RESUME_FAILED
xen: don't free percpu areas during suspend xen/cpupool: simplify suspend/resume handling xen/sched: don't disable scheduler on cpus during suspend

 xen/arch/x86/percpu.c      |   3 +-
 xen/arch/x86/smpboot.c     |   3 -
 xen/common/cpu.c           |  55 +++++++-------
 xen/common/cpupool.c       | 130 +++++++++++++---------------------
 xen/common/schedule.c      | 173 +++++++++++++++------------------------------
 xen/include/xen/cpu.h      |  20 +++---
 xen/include/xen/sched-if.h |   1 -
 7 files changed, 147 insertions(+), 238 deletions(-)
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/6 xen/sched: call cpu_disable_scheduler() via cpu notifier

cpu_disable_scheduler() is being called from __cpu_disable() today. There is no need to call it on the cpu just being disabled, so use the CPU_DEAD case of the cpu notifier chain.

---
 xen/arch/x86/smpboot.c |  3 ---
 xen/common/schedule.c  | 12 +++++-------
 2 files changed, 5 insertions(+), 10 deletions(-)
xen/arch/x86/smpboot.c +0 -3
index 7d1226d7bc..b7a0a4a419 100644
@@ -1221,9 +1221,6 @@ void __cpu_disable(void)
     cpumask_clear_cpu(cpu, &cpu_online_map);
     fixup_irqs(&cpu_online_map, 1);
     fixup_eoi();
-
-    if ( cpu_disable_scheduler(cpu) )
-        BUG();
 }
 
 void __cpu_die(unsigned int cpu)
xen/common/schedule.c +5 -7
index 60755a631e..665747f247 100644
@@ -773,8 +773,9 @@ void restore_vcpu_affinity(struct domain *d)
 }
 
 /*
- * This function is used by cpu_hotplug code from stop_machine context
+ * This function is used by cpu_hotplug code via cpu notifier chain
  * and from cpupools to switch schedulers on a cpu.
+ * Caller must get domlist_read_lock.
  */
 int cpu_disable_scheduler(unsigned int cpu)
 {
@@ -789,12 +790,6 @@ int cpu_disable_scheduler(unsigned int cpu)
     if ( c == NULL )
         return ret;
 
-    /*
-     * We'd need the domain RCU lock, but:
-     *  - when we are called from cpupool code, it's acquired there already;
-     *  - when we are called for CPU teardown, we're in stop-machine context,
-     *    so that's not be a problem.
-     */
     for_each_domain_in_cpupool ( d, c )
     {
         for_each_vcpu ( d, v )
@@ -1738,6 +1733,9 @@ static int cpu_schedule_callback(
         rc = cpu_schedule_up(cpu);
         break;
     case CPU_DEAD:
+        rcu_read_lock(&domlist_read_lock);
+        cpu_disable_scheduler(cpu);
+        rcu_read_unlock(&domlist_read_lock);
         SCHED_OP(sched, deinit_pdata, sd->sched_priv, cpu);
         /* Fallthrough */
     case CPU_UP_CANCELED:
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

Quoted 5 lines · Juergen Gross

cpu_disable_scheduler() is being called from __cpu_disable() today. There is no need to call it on the cpu just being disabled, so use the CPU_DEAD case of the cpu notifier chain.

Scheduler change:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

In reply to Juergen Gross
Quoted 15 lines · Juergen Gross

cpu_disable_scheduler() is being called from __cpu_disable() today. There is no need to call it on the cpu just being disabled, so use the CPU_DEAD case of the cpu notifier chain.

---
 xen/arch/x86/smpboot.c |  3 ---
 xen/common/schedule.c  | 12 +++++-------
 2 files changed, 5 insertions(+), 10 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 7d1226d7bc..b7a0a4a419 100644

xen/arch/x86/smpboot.c void __cpu_disable(void) · line 1224

Quoted 7 lines
xen/arch/x86/smpboot.c +0 -3
@@ -1221,9 +1221,6 @@ void __cpu_disable(void)
     cpumask_clear_cpu(cpu, &cpu_online_map);
     fixup_irqs(&cpu_online_map, 1);
     fixup_eoi();
-
-    if ( cpu_disable_scheduler(cpu) )
-        BUG();
 }

It looks like ARM needs an equivalent adjustment.

Quoted 7 lines
xen/arch/x86/smpboot.c +0 -0
 void __cpu_die(unsigned int cpu)
xen/common/schedule.c +0 -0
index 60755a631e..665747f247 100644

xen/common/schedule.c void restore_vcpu_affinity(struct domain *d) · line 778

Quoted 7 lines
xen/common/schedule.c +2 -1
@@ -773,8 +773,9 @@ void restore_vcpu_affinity(struct domain *d)
 }
 
 /*
- * This function is used by cpu_hotplug code from stop_machine context
+ * This function is used by cpu_hotplug code via cpu notifier chain
  * and from cpupools to switch schedulers on a cpu.
+ * Caller must get domlist_read_lock.

s/get/hold/ ?

With at least the ARM side adjusted, Reviewed-by: Andrew Cooper <[email protected]>

Quoted 17 lines
xen/common/schedule.c +0 -6
  */
 int cpu_disable_scheduler(unsigned int cpu)
 {
@@ -789,12 +790,6 @@ int cpu_disable_scheduler(unsigned int cpu)
     if ( c == NULL )
         return ret;
 
-    /*
-     * We'd need the domain RCU lock, but:
-     *  - when we are called from cpupool code, it's acquired there already;
-     *  - when we are called for CPU teardown, we're in stop-machine context,
-     *    so that's not be a problem.
-     */
     for_each_domain_in_cpupool ( d, c )
     {
         for_each_vcpu ( d, v )

xen/common/schedule.c static int cpu_schedule_callback( · line 1741

Quoted 9 lines
xen/common/schedule.c +3 -0
@@ -1738,6 +1733,9 @@ static int cpu_schedule_callback(
         rc = cpu_schedule_up(cpu);
         break;
     case CPU_DEAD:
+        rcu_read_lock(&domlist_read_lock);
+        cpu_disable_scheduler(cpu);
+        rcu_read_unlock(&domlist_read_lock);
         SCHED_OP(sched, deinit_pdata, sd->sched_priv, cpu);
         /* Fallthrough */
     case CPU_UP_CANCELED:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

In reply to Juergen Gross

xen/common/schedule.c static int cpu_schedule_callback( · line 1741

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:
xen/common/schedule.c +3 -0
@@ -1738,6 +1733,9 @@ static int cpu_schedule_callback(
         rc = cpu_schedule_up(cpu);
         break;
     case CPU_DEAD:
+        rcu_read_lock(&domlist_read_lock);
+        cpu_disable_scheduler(cpu);
+        rcu_read_unlock(&domlist_read_lock);
         SCHED_OP(sched, deinit_pdata, sd->sched_priv, cpu);
         /* Fallthrough */
     case CPU_UP_CANCELED:

cpu_disable_scheduler() has a return value (and hence means to fail) - is ignoring this here really appropriate?

Also while indeed (as the description says) there's no need to run the function on the CPU itself, it's not obvious to me that it's safe to run it outside of stop_machine() context. Or to be more precise, it's not clear to me that leaving stop_machine() context with the adjustments not done yet is not going to lead to problems (due to the gap between leaving that context and acquiring the RCU lock). Could you clarify this in the description, please (if it indeed is fine this way)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

In reply to Juergen Gross
Quoted 4 lines · Juergen Gross

cpu_disable_scheduler() is being called from __cpu_disable() today. There is no need to call it on the cpu just being disabled, so use the CPU_DEAD case of the cpu notifier chain.

So, what do you mean with "There is no need to call it on the cpu just being disabled"?

Because we still (even after this patch, I mean) call cpu_disable_scheduler() on all non-boot CPUs, aren't we? It's just that right now we call it from __cpu_disable(), with the patch we call it slightly later.

And another difference looks to me to be that right now we call cpu_disable_scheduler() from stop-machine context, which I think is no longer true with this patch. Perhaps the changelog could tell why that is ok?

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

Quoted 5 lines · Dario Faggioli
Quoted 4 lines · Juergen Gross

cpu_disable_scheduler() is being called from __cpu_disable() today. There is no need to call it on the cpu just being disabled, so use the CPU_DEAD case of the cpu notifier chain.

Quoted 7 lines

So, what do you mean with "There is no need to call it on the cpu just being disabled"?

Because we still (even after this patch, I mean) call cpu_disable_scheduler() on all non-boot CPUs, aren't we? It's just that right now we call it from __cpu_disable(), with the patch we call it slightly later.

The CPU_DEAD notifier chain is called on the CPU requesting the other one to go down (so on the boot CPU in suspend case). So we call it _for_ all non-boot CPUs in the boot CPU.

Quoted 4 lines

And another difference looks to me to be that right now we call cpu_disable_scheduler() from stop-machine context, which I think is no longer true with this patch. Perhaps the changelog could tell why that is ok?

Okay, I'll add something.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

Quoted 19 lines · Juergen Gross
Quoted 11 lines · Dario Faggioli
Quoted 6 lines · Juergen Gross

cpu_disable_scheduler() is being called from __cpu_disable() today.
There is no need to call it on the cpu just being disabled, so use
the CPU_DEAD case of the cpu notifier chain.

So, what do you mean with "There is no need to call it on the cpu just
being disabled"?

Quoted 6 lines

Because we still (even after this patch, I mean) call cpu_disable_scheduler() on all non-boot CPUs, aren't we? It's just that
right now we call it from __cpu_disable(), with the patch we call it
slightly later.

Quoted 5 lines

The CPU_DEAD notifier chain is called on the CPU requesting the other one to go down (so on the boot CPU in suspend case). So we call it _for_
all non-boot CPUs in the boot CPU.

Mmm... ok, I see what you mean now.

I guess part of "the problem" is that "call func on cpu A" reads, at least to me, as both 1) call func so that it acts on and change the state of cpu A, and 2) call func in such a way that it executes on cpu A.

But I'm no native speaker, so it may very well be that the confusion is all and only mine.

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

Quoted 25 lines · Dario Faggioli
Quoted 19 lines · Juergen Gross
Quoted 11 lines · Dario Faggioli
Quoted 6 lines · Juergen Gross

cpu_disable_scheduler() is being called from __cpu_disable() today.
There is no need to call it on the cpu just being disabled, so use
the CPU_DEAD case of the cpu notifier chain.

So, what do you mean with "There is no need to call it on the cpu just
being disabled"?

Quoted 6 lines

Because we still (even after this patch, I mean) call cpu_disable_scheduler() on all non-boot CPUs, aren't we? It's just that
right now we call it from __cpu_disable(), with the patch we call it
slightly later.

Quoted 5 lines

The CPU_DEAD notifier chain is called on the CPU requesting the other one to go down (so on the boot CPU in suspend case). So we call it _for_
all non-boot CPUs in the boot CPU.

Quoted 6 lines

Mmm... ok, I see what you mean now.

I guess part of "the problem" is that "call func on cpu A" reads, at least to me, as both 1) call func so that it acts on and change the state of cpu A, and 2) call func in such a way that it executes on cpu A.

I'll rephrase to "execute func on cpu...".

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

Quoted 14 lines · Jan Beulich

xen/common/schedule.c static int cpu_schedule_callback( · line 1741

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:
xen/common/schedule.c +3 -0
@@ -1738,6 +1733,9 @@ static int cpu_schedule_callback(
         rc = cpu_schedule_up(cpu);
         break;
     case CPU_DEAD:
+        rcu_read_lock(&domlist_read_lock);
+        cpu_disable_scheduler(cpu);
+        rcu_read_unlock(&domlist_read_lock);
         SCHED_OP(sched, deinit_pdata, sd->sched_priv, cpu);
         /* Fallthrough */
     case CPU_UP_CANCELED:

cpu_disable_scheduler() has a return value (and hence means to fail) - is ignoring this here really appropriate?

You are right, I should handle those cases in cpu_disable_scheduler(). Without the complete series committed this will result in a case not handled correctly: dom0 trying to pin a vcpu to a physical cpu other than cpu 0 via SCHEDOP_pin_override and suspending in that state. I'm not aware of any dom0 trying to do that.

Quoted 8 lines

Also while indeed (as the description says) there's no need to run the function on the CPU itself, it's not obvious to me that it's safe to run it outside of stop_machine() context. Or to be more precise, it's not clear to me that leaving stop_machine() context with the adjustments not done yet is not going to lead to problems (due to the gap between leaving that context and acquiring the RCU lock). Could you clarify this in the description, please (if it indeed is fine this way)?

It is fine, as the chances are zero that any code will run on the cpu just taken down and that cpu is not holding any locks we might need.

I'll add that to the commit message.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw

Re: [PATCH 1/6] xen/sched: call cpu_disable_scheduler() via cpu notifier

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:45, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

Also while indeed (as the description says) there's no need to run the function on the CPU itself, it's not obvious to me that it's safe to run it outside of stop_machine() context. Or to be more precise, it's not clear to me that leaving stop_machine() context with the adjustments not done yet is not going to lead to problems (due to the gap between leaving that context and acquiring the RCU lock). Could you clarify this in the description, please (if it indeed is fine this way)?

Quoted 2 lines

It is fine, as the chances are zero that any code will run on the cpu just taken down and that cpu is not holding any locks we might need.

Well, of course nothing's going to run on that CPU anymore. But vCPU-s may still have associations with it, so what I'm worried about is e.g. something finding v->processor pointing at an offline CPU and getting confused. Another, more exotic (or should I say contrived) scenario might be a soft-online request coming very quickly after a prior soft-offline one, with this function not having got around to run yet. Or basically anything else that accesses the same state the function means to update (or use).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw

PATCH 2/6 xen: add helper for calling notifier_call_chain() to common/cpu.c

In reply to Juergen Gross

Add a helper cpu_notifier_call_chain() to call notifier_call_chain() for a cpu with a specified action, returning an errno value.

This avoids coding the same pattern multiple times.

---
 xen/common/cpu.c | 50 +++++++++++++++++++++-----------------------------
 1 file changed, 21 insertions(+), 29 deletions(-)
xen/common/cpu.c +21 -29
index 836c62f97f..c436c0de7f 100644
@@ -71,11 +71,18 @@ void __init register_cpu_notifier(struct notifier_block *nb)
     spin_unlock(&cpu_add_remove_lock);
 }
 
+static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action,
+                                   struct notifier_block **nb)
+{
+    void *hcpu = (void *)(long)cpu;
+    int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb);
+
+    return (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);
+}
+
 static void _take_cpu_down(void *unused)
 {
-    void *hcpu = (void *)(long)smp_processor_id();
-    int notifier_rc = notifier_call_chain(&cpu_chain, CPU_DYING, hcpu, NULL);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL));
     __cpu_disable();
 }
 
@@ -87,8 +94,7 @@ static int take_cpu_down(void *arg)
 
 int cpu_down(unsigned int cpu)
 {
-    int err, notifier_rc;
-    void *hcpu = (void *)(long)cpu;
+    int err;
     struct notifier_block *nb = NULL;
 
     if ( !cpu_hotplug_begin() )
@@ -100,12 +106,9 @@ int cpu_down(unsigned int cpu)
         return -EINVAL;
     }
 
-    notifier_rc = notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE, hcpu, &nb);
-    if ( notifier_rc != NOTIFY_DONE )
-    {
-        err = notifier_to_errno(notifier_rc);
+    err = cpu_notifier_call_chain(cpu, CPU_DOWN_PREPARE, &nb);
+    if ( err )
         goto fail;
-    }
 
     if ( unlikely(system_state < SYS_STATE_active) )
         on_selected_cpus(cpumask_of(cpu), _take_cpu_down, NULL, true);
@@ -115,24 +118,21 @@ int cpu_down(unsigned int cpu)
     __cpu_die(cpu);
     BUG_ON(cpu_online(cpu));
 
-    notifier_rc = notifier_call_chain(&cpu_chain, CPU_DEAD, hcpu, NULL);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(cpu, CPU_DEAD, NULL));
 
     send_global_virq(VIRQ_PCPU_STATE);
     cpu_hotplug_done();
     return 0;
 
  fail:
-    notifier_rc = notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED, hcpu, &nb);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(cpu, CPU_DOWN_FAILED, &nb));
     cpu_hotplug_done();
     return err;
 }
 
 int cpu_up(unsigned int cpu)
 {
-    int notifier_rc, err = 0;
-    void *hcpu = (void *)(long)cpu;
+    int err;
     struct notifier_block *nb = NULL;
 
     if ( !cpu_hotplug_begin() )
@@ -144,19 +144,15 @@ int cpu_up(unsigned int cpu)
         return -EINVAL;
     }
 
-    notifier_rc = notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu, &nb);
-    if ( notifier_rc != NOTIFY_DONE )
-    {
-        err = notifier_to_errno(notifier_rc);
+    err = cpu_notifier_call_chain(cpu, CPU_UP_PREPARE, &nb);
+    if ( err )
         goto fail;
-    }
 
     err = __cpu_up(cpu);
     if ( err < 0 )
         goto fail;
 
-    notifier_rc = notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu, NULL);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(cpu, CPU_ONLINE, NULL));
 
     send_global_virq(VIRQ_PCPU_STATE);
 
@@ -164,18 +160,14 @@ int cpu_up(unsigned int cpu)
     return 0;
 
  fail:
-    notifier_rc = notifier_call_chain(&cpu_chain, CPU_UP_CANCELED, hcpu, &nb);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(cpu, CPU_UP_CANCELED, &nb));
     cpu_hotplug_done();
     return err;
 }
 
 void notify_cpu_starting(unsigned int cpu)
 {
-    void *hcpu = (void *)(long)cpu;
-    int notifier_rc = notifier_call_chain(
-        &cpu_chain, CPU_STARTING, hcpu, NULL);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(cpu, CPU_STARTING, NULL));
 }
 
 static cpumask_t frozen_cpus;
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 2/6
#13 lore raw

Re: [PATCH 2/6] xen: add helper for calling notifier_call_chain() to common/cpu.c

Quoted 7 lines · Juergen Gross

Add a helper cpu_notifier_call_chain() to call notifier_call_chain() for a cpu with a specified action, returning an errno value.

This avoids coding the same pattern multiple times.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 2/6
#14 lore raw

Re: [PATCH 2/6] xen: add helper for calling notifier_call_chain() to common/cpu.c

In reply to Juergen Gross
Quoted 6 lines · Juergen Gross

Add a helper cpu_notifier_call_chain() to call notifier_call_chain() for a cpu with a specified action, returning an errno value.

This avoids coding the same pattern multiple times.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw

Re: [PATCH 2/6] xen: add helper for calling notifier_call_chain() to common/cpu.c

In reply to Juergen Gross
Quoted 23 lines · Juergen Gross

Add a helper cpu_notifier_call_chain() to call notifier_call_chain() for a cpu with a specified action, returning an errno value.

This avoids coding the same pattern multiple times.

---
 xen/common/cpu.c | 50 +++++++++++++++++++++-----------------------------
 1 file changed, 21 insertions(+), 29 deletions(-)
xen/common/cpu.c +5 -0
index 836c62f97f..c436c0de7f 100644
@@ -71,11 +71,18 @@ void __init register_cpu_notifier(struct notifier_block *nb)
     spin_unlock(&cpu_add_remove_lock);
 }
 
+static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action,
+                                   struct notifier_block **nb)
+{
+    void *hcpu = (void *)(long)cpu;
+    int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb);

xen/common/cpu.c void __init register_cpu_notifier(struct notifier_block *nb) · line 85

Quoted 10 lines
xen/common/cpu.c +5 -3
+
+    return (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);
+}
+
 static void _take_cpu_down(void *unused)
 {
-    void *hcpu = (void *)(long)smp_processor_id();
-    int notifier_rc = notifier_call_chain(&cpu_chain, CPU_DYING, hcpu, NULL);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL));

Where possible, we're trying to remove side effects from macros.

Could I please talk you into writing this as:

int rc = cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL);

BUG_ON(rc);

An alternative might be to have a:

static void cpu_notifier_call_chain_nofail(...)

wrapper as this seems to be a common pattern.  (Ideally longterm, it might be better to pass the nofail intention into the notifier chain itself so we can identify which callback had a problem, but thats definitely not something for here.)

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

Re: [PATCH 2/6] xen: add helper for calling notifier_call_chain() to common/cpu.c

Quoted 37 lines · Andrew Cooper
Quoted 23 lines · Juergen Gross

Add a helper cpu_notifier_call_chain() to call notifier_call_chain() for a cpu with a specified action, returning an errno value.

This avoids coding the same pattern multiple times.

---
 xen/common/cpu.c | 50 +++++++++++++++++++++-----------------------------
 1 file changed, 21 insertions(+), 29 deletions(-)
xen/common/cpu.c +5 -0
index 836c62f97f..c436c0de7f 100644
@@ -71,11 +71,18 @@ void __init register_cpu_notifier(struct notifier_block *nb)
     spin_unlock(&cpu_add_remove_lock);
 }
 
+static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action,
+                                   struct notifier_block **nb)
+{
+    void *hcpu = (void *)(long)cpu;
+    int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb);

xen/common/cpu.c void __init register_cpu_notifier(struct notifier_block *nb) · line 85

Quoted 10 lines
xen/common/cpu.c +5 -3
+
+    return (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc);
+}
+
 static void _take_cpu_down(void *unused)
 {
-    void *hcpu = (void *)(long)smp_processor_id();
-    int notifier_rc = notifier_call_chain(&cpu_chain, CPU_DYING, hcpu, NULL);
-    BUG_ON(notifier_rc != NOTIFY_DONE);
+    BUG_ON(cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL));

Where possible, we're trying to remove side effects from macros.

Quoted 5 lines

Could I please talk you into writing this as:

int rc = cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL);

BUG_ON(rc);

Fine with me.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

PATCH 3/6 xen: add new cpu notifier action CPU_RESUME_FAILED

In reply to Juergen Gross

Add a new cpu notifier action CPU_RESUME_FAILED which is called for all cpus which failed to come up at resume. The calls will be done after all other cpus are already up.

---
 xen/common/cpu.c      |  5 +++++
 xen/include/xen/cpu.h | 20 +++++++++++---------
 2 files changed, 16 insertions(+), 9 deletions(-)
xen/common/cpu.c +5 -0
index c436c0de7f..f3cf9463b4 100644
@@ -214,7 +214,12 @@ void enable_nonboot_cpus(void)
             printk("Error bringing CPU%d up: %d\n", cpu, error);
             BUG_ON(error == -EBUSY);
         }
+        else
+            __cpumask_clear_cpu(cpu, &frozen_cpus);
     }
 
+    for_each_cpu ( cpu, &frozen_cpus )
+        BUG_ON(cpu_notifier_call_chain(cpu, CPU_RESUME_FAILED, NULL));
+
     cpumask_clear(&frozen_cpus);
 }
xen/include/xen/cpu.h +11 -9
index 2fe3ec05d8..2fc0cb1bb5 100644
@@ -32,23 +32,25 @@ void register_cpu_notifier(struct notifier_block *nb);
  *  (a) A CPU is going down; or (b) CPU_UP_CANCELED
  */
 /* CPU_UP_PREPARE: Preparing to bring CPU online. */
-#define CPU_UP_PREPARE   (0x0001 | NOTIFY_FORWARD)
+#define CPU_UP_PREPARE    (0x0001 | NOTIFY_FORWARD)
 /* CPU_UP_CANCELED: CPU is no longer being brought online. */
-#define CPU_UP_CANCELED  (0x0002 | NOTIFY_REVERSE)
+#define CPU_UP_CANCELED   (0x0002 | NOTIFY_REVERSE)
 /* CPU_STARTING: CPU nearly online. Runs on new CPU, irqs still disabled. */
-#define CPU_STARTING     (0x0003 | NOTIFY_FORWARD)
+#define CPU_STARTING      (0x0003 | NOTIFY_FORWARD)
 /* CPU_ONLINE: CPU is up. */
-#define CPU_ONLINE       (0x0004 | NOTIFY_FORWARD)
+#define CPU_ONLINE        (0x0004 | NOTIFY_FORWARD)
 /* CPU_DOWN_PREPARE: CPU is going down. */
-#define CPU_DOWN_PREPARE (0x0005 | NOTIFY_REVERSE)
+#define CPU_DOWN_PREPARE  (0x0005 | NOTIFY_REVERSE)
 /* CPU_DOWN_FAILED: CPU is no longer going down. */
-#define CPU_DOWN_FAILED  (0x0006 | NOTIFY_FORWARD)
+#define CPU_DOWN_FAILED   (0x0006 | NOTIFY_FORWARD)
 /* CPU_DYING: CPU is nearly dead (in stop_machine context). */
-#define CPU_DYING        (0x0007 | NOTIFY_REVERSE)
+#define CPU_DYING         (0x0007 | NOTIFY_REVERSE)
 /* CPU_DEAD: CPU is dead. */
-#define CPU_DEAD         (0x0008 | NOTIFY_REVERSE)
+#define CPU_DEAD          (0x0008 | NOTIFY_REVERSE)
 /* CPU_REMOVE: CPU was removed. */
-#define CPU_REMOVE       (0x0009 | NOTIFY_REVERSE)
+#define CPU_REMOVE        (0x0009 | NOTIFY_REVERSE)
+/* CPU_RESUME_FAILED: CPU failed to come up in resume, all other CPUs up. */
+#define CPU_RESUME_FAILED (0x000a | NOTIFY_REVERSE)
 
 /* Perform CPU hotplug. May return -EAGAIN. */
 int cpu_down(unsigned int cpu);
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 3/6
#18 lore raw

Re: [PATCH 3/6] xen: add new cpu notifier action CPU_RESUME_FAILED

xen/include/xen/cpu.h void register_cpu_notifier(struct notifier_block · line 37

Quoted 10 lines · Juergen Gross
xen/include/xen/cpu.h +1 -1
@@ -32,23 +32,25 @@ void register_cpu_notifier(struct notifier_block
 *nb);
  *  (a) A CPU is going down; or (b) CPU_UP_CANCELED
  */
 /* CPU_UP_PREPARE: Preparing to bring CPU online. */
-#define CPU_UP_PREPARE   (0x0001 | NOTIFY_FORWARD)
+#define CPU_UP_PREPARE    (0x0001 | NOTIFY_FORWARD)
 

In the comment block before these definitions, there's this:

* Possible event sequences for a given CPU:

 *  CPU_UP_PREPARE -> CPU_UP_CANCELLED           -- failed CPU up
 *  CPU_UP_PREPARE -> CPU_STARTING -> CPU_ONLINE -- successful CPU up
 *  CPU_DOWN_PREPARE -> CPU_DOWN_FAILED          -- failed CPU down
 *  CPU_DOWN_PREPARE -> CPU_DYING -> CPU_DEAD    -- successful CPU down

Shouldn't we add a line for this new hook? Something, IIUIC, like:

CPU_UP_PREPARE -> CPU_UP_CANCELLED -> CPU_RESUME_FAILED --CPU not resuming

With this, FWIW,

One more (minor) thing...

xen/include/xen/cpu.h void register_cpu_notifier(struct notifier_block *nb); · line 54

Quoted 6 lines
xen/include/xen/cpu.h +3 -1
 /* CPU_REMOVE: CPU was removed. */
-#define CPU_REMOVE       (0x0009 | NOTIFY_REVERSE)
+#define CPU_REMOVE        (0x0009 | NOTIFY_REVERSE)
+/* CPU_RESUME_FAILED: CPU failed to come up in resume, all other CPUs up. */
+#define CPU_RESUME_FAILED (0x000a | NOTIFY_REVERSE)
 

... technically, when we're dealing with CPU_RESUME_FAILED on one CPU, we don't know if _all_ others really went up, so I think I'd remove what follows the ','.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

Re: [PATCH 3/6] xen: add new cpu notifier action CPU_RESUME_FAILED

Quoted 14 lines · Dario Faggioli

xen/include/xen/cpu.h void register_cpu_notifier(struct notifier_block · line 37

Quoted 10 lines · Juergen Gross
xen/include/xen/cpu.h +1 -1
@@ -32,23 +32,25 @@ void register_cpu_notifier(struct notifier_block
 *nb);
  *  (a) A CPU is going down; or (b) CPU_UP_CANCELED
  */
 /* CPU_UP_PREPARE: Preparing to bring CPU online. */
-#define CPU_UP_PREPARE   (0x0001 | NOTIFY_FORWARD)
+#define CPU_UP_PREPARE    (0x0001 | NOTIFY_FORWARD)
 

In the comment block before these definitions, there's this:

* Possible event sequences for a given CPU:

Quoted 8 lines
 *  CPU_UP_PREPARE -> CPU_UP_CANCELLED           -- failed CPU up
 *  CPU_UP_PREPARE -> CPU_STARTING -> CPU_ONLINE -- successful CPU up
 *  CPU_DOWN_PREPARE -> CPU_DOWN_FAILED          -- failed CPU down
 *  CPU_DOWN_PREPARE -> CPU_DYING -> CPU_DEAD    -- successful CPU down

Shouldn't we add a line for this new hook? Something, IIUIC, like:

CPU_UP_PREPARE -> CPU_UP_CANCELLED -> CPU_RESUME_FAILED --CPU not resuming

Fine with me.

Quoted 7 lines

With this, FWIW,

One more (minor) thing...

Quoted 9 lines

xen/include/xen/cpu.h void register_cpu_notifier(struct notifier_block *nb); · line 54

Quoted 6 lines
xen/include/xen/cpu.h +3 -1
 /* CPU_REMOVE: CPU was removed. */
-#define CPU_REMOVE       (0x0009 | NOTIFY_REVERSE)
+#define CPU_REMOVE        (0x0009 | NOTIFY_REVERSE)
+/* CPU_RESUME_FAILED: CPU failed to come up in resume, all other CPUs up. */
+#define CPU_RESUME_FAILED (0x000a | NOTIFY_REVERSE)
 

... technically, when we're dealing with CPU_RESUME_FAILED on one CPU, we don't know if _all_ others really went up, so I think I'd remove what follows the ','.

The point is that for the CPU_RESUME_FAILED case we can be sure that no cpu will come up due to resume just a little bit later. So we can test for e.g. a cpupool suddenly having no more cpus available. This is in contrast to CPU_UP_CANCELLED being signalled just after the one cpu failing to come up, but before the next cpu is triggered to come up.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw

Re: [PATCH 3/6] xen: add new cpu notifier action CPU_RESUME_FAILED

Quoted 18 lines · Juergen Gross
Quoted 4 lines · Dario Faggioli

One more (minor) thing...

Quoted 11 lines
Quoted 7 lines

/* CPU_REMOVE: CPU was removed. */

xen/include/xen/cpu.h +2 -1
-#define CPU_REMOVE       (0x0009 | NOTIFY_REVERSE)
+#define CPU_REMOVE        (0x0009 | NOTIFY_REVERSE)
+/* CPU_RESUME_FAILED: CPU failed to come up in resume, all other

CPUs up. */
+#define CPU_RESUME_FAILED (0x000a | NOTIFY_REVERSE)

... technically, when we're dealing with CPU_RESUME_FAILED on one CPU,
we don't know if _all_ others really went up, so I think I'd remove what follows the ','.

Quoted 4 lines

The point is that for the CPU_RESUME_FAILED case we can be sure that no
cpu will come up due to resume just a little bit later.

Ah, I see what you mean... that's the fact that this notifier is invoked from another loop, and although we don't know which CPU did manage to come up and which don't, we do know that all the ones that could come up, are up already.

Quoted 5 lines

So we can test
for e.g. a cpupool suddenly having no more cpus available. This is in contrast to CPU_UP_CANCELLED being signalled just after the one cpu failing to come up, but before the next cpu is triggered to come up.

Right.

Well, it still looks to me that "all other CPUs up" is not entirely accurate. But I can't propose a better alternative (unless we write something very long, which is probably not worth it).

Perhaps you can explain this a little in another comment, like in enable_nonboot_cpus(), before the for_each_cpu() loop itself.

But I don't feel too strong about that, and the RoB stands, whatever you decide to do.

Regards,
Dario

Signature · 10 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 3/6
#21 lore raw

Re: [PATCH 3/6] xen: add new cpu notifier action CPU_RESUME_FAILED

In reply to Juergen Gross
Quoted 5 lines · Juergen Gross

Add a new cpu notifier action CPU_RESUME_FAILED which is called for all cpus which failed to come up at resume. The calls will be done after all other cpus are already up.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

Re: [PATCH 3/6] xen: add new cpu notifier action CPU_RESUME_FAILED

In reply to Juergen Gross
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:
xen/common/cpu.c +0 -0
@@ -214,7 +214,12 @@ void enable_nonboot_cpus(void)
             printk("Error bringing CPU%d up: %d\n", cpu, error);
             BUG_ON(error == -EBUSY);

xen/common/cpu.c void enable_nonboot_cpus(void) · line 225

Quoted 10 lines
xen/common/cpu.c +5 -0
         }
+        else
+            __cpumask_clear_cpu(cpu, &frozen_cpus);
     }
 
+    for_each_cpu ( cpu, &frozen_cpus )
+        BUG_ON(cpu_notifier_call_chain(cpu, CPU_RESUME_FAILED, NULL));
+
     cpumask_clear(&frozen_cpus);
 }

Is there a particular reason you add a second loop here?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#24 lore raw

Re: [PATCH 3/6] xen: add new cpu notifier action CPU_RESUME_FAILED

Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:
xen/common/cpu.c +2 -0
@@ -214,7 +214,12 @@ void enable_nonboot_cpus(void)
             printk("Error bringing CPU%d up: %d\n", cpu, error);
             BUG_ON(error == -EBUSY);
         }
+        else
+            __cpumask_clear_cpu(cpu, &frozen_cpus);
     }
 
Quoted 7 lines

xen/common/cpu.c void enable_nonboot_cpus(void) · line 225

Quoted 5 lines
xen/common/cpu.c +3 -0
+    for_each_cpu ( cpu, &frozen_cpus )
+        BUG_ON(cpu_notifier_call_chain(cpu, CPU_RESUME_FAILED, NULL));
+
     cpumask_clear(&frozen_cpus);
 }

Is there a particular reason you add a second loop here?

Yes, I want to know which cpus did come up again.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#25 lore raw

PATCH 4/6 xen: don't free percpu areas during suspend

In reply to Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

---
 xen/arch/x86/percpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/percpu.c +2 -1
index 8be4ebddf4..5ea14b6ec3 100644
@@ -76,7 +76,8 @@ static int cpu_percpu_callback(
         break;
     case CPU_UP_CANCELED:
     case CPU_DEAD:
-        if ( !park_offline_cpus )
+    case CPU_RESUME_FAILED:
+        if ( !park_offline_cpus && system_state != SYS_STATE_suspend )
             free_percpu_area(cpu);
         break;
     case CPU_REMOVE:
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 4/6
#26 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 6 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#27 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

In reply to Juergen Gross
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Quoted 8 lines

Hmm - this is slightly problematic, given the dual nature of this code.

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Did you look into the patch? I did this by testing system_state.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#29 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:18, <[email protected]> wrote:
Quoted 9 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

Quoted 8 lines
Quoted 6 lines

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Did you look into the patch? I did this by testing system_state.

I think there's a wider problem here: enable_nonboot_cpus() only brings back up the CPUs that were previously online. Parked ones would be left alone, yet after resume they'd need to be put back into parked state.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#30 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

In reply to Juergen Gross
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

There's another aspect here which needs at least mentioning:
Right now, CPUs coming back up have their per-CPU data cleared. Not doing so may indeed be an improvement in some cases (like statistics collected), but may also get in the way in other cases.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#32 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 10 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

There's another aspect here which needs at least mentioning:
Right now, CPUs coming back up have their per-CPU data cleared. Not doing so may indeed be an improvement in some cases (like statistics collected), but may also get in the way in other cases.

I have checked the respective cpu notifier hooks and I think this is no problem. I hope I didn't overlook something.

I'll add a note to the commit message.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#33 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.03.19 at 08:53, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:11, <[email protected]> wrote:

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Quoted 8 lines
Quoted 5 lines

There's another aspect here which needs at least mentioning:
Right now, CPUs coming back up have their per-CPU data cleared. Not doing so may indeed be an improvement in some cases (like statistics collected), but may also get in the way in other cases.

I have checked the respective cpu notifier hooks and I think this is no problem. I hope I didn't overlook something.

Is checking the hooks sufficient? I'd rather expect we need to check all per-CPU data objects.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#34 lore raw

PATCH 5/6 xen/cpupool: simplify suspend/resume handling

In reply to Juergen Gross

Instead of removing cpus temporarily from cpupools during suspend/resume only remove cpus finally which didn't come up when resuming.

---
 xen/common/cpupool.c       | 130 ++++++++++++++++++---------------------------
 xen/include/xen/sched-if.h |   1 -
 2 files changed, 51 insertions(+), 80 deletions(-)
xen/common/cpupool.c +51 -79
index e89bb67e71..ed689fd290 100644
@@ -47,12 +47,6 @@ static struct cpupool *alloc_cpupool_struct(void)
         xfree(c);
         c = NULL;
     }
-    else if ( !zalloc_cpumask_var(&c->cpu_suspended) )
-    {
-        free_cpumask_var(c->cpu_valid);
-        xfree(c);
-        c = NULL;
-    }
 
     return c;
 }
@@ -60,10 +54,7 @@ static struct cpupool *alloc_cpupool_struct(void)
 static void free_cpupool_struct(struct cpupool *c)
 {
     if ( c )
-    {
-        free_cpumask_var(c->cpu_suspended);
         free_cpumask_var(c->cpu_valid);
-    }
     xfree(c);
 }
 
@@ -477,10 +468,6 @@ void cpupool_rm_domain(struct domain *d)
 /*
  * Called to add a cpu to a pool. CPUs being hot-plugged are added to pool0,
  * as they must have been in there when unplugged.
- *
- * If, on the other hand, we are adding CPUs because we are resuming (e.g.,
- * after ACPI S3) we put the cpu back in the pool where it was in prior when
- * we suspended.
  */
 static int cpupool_cpu_add(unsigned int cpu)
 {
@@ -490,42 +477,15 @@ static int cpupool_cpu_add(unsigned int cpu)
     cpumask_clear_cpu(cpu, &cpupool_locked_cpus);
     cpumask_set_cpu(cpu, &cpupool_free_cpus);
 
-    if ( system_state == SYS_STATE_suspend || system_state == SYS_STATE_resume )
-    {
-        struct cpupool **c;
-
-        for_each_cpupool(c)
-        {
-            if ( cpumask_test_cpu(cpu, (*c)->cpu_suspended ) )
-            {
-                ret = cpupool_assign_cpu_locked(*c, cpu);
-                if ( ret )
-                    goto out;
-                cpumask_clear_cpu(cpu, (*c)->cpu_suspended);
-                break;
-            }
-        }
+    /*
+     * If we are not resuming, we are hot-plugging cpu, and in which case
+     * we add it to pool0, as it certainly was there when hot-unplagged
+     * (or unplugging would have failed) and that is the default behavior
+     * anyway.
+     */
+    per_cpu(cpupool, cpu) = NULL;
+    ret = cpupool_assign_cpu_locked(cpupool0, cpu);
 
-        /*
-         * Either cpu has been found as suspended in a pool, and added back
-         * there, or it stayed free (if it did not belong to any pool when
-         * suspending), and we don't want to do anything.
-         */
-        ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus) ||
-               cpumask_test_cpu(cpu, (*c)->cpu_valid));
-    }
-    else
-    {
-        /*
-         * If we are not resuming, we are hot-plugging cpu, and in which case
-         * we add it to pool0, as it certainly was there when hot-unplagged
-         * (or unplugging would have failed) and that is the default behavior
-         * anyway.
-         */
-        per_cpu(cpupool, cpu) = NULL;
-        ret = cpupool_assign_cpu_locked(cpupool0, cpu);
-    }
- out:
     spin_unlock(&cpupool_lock);
 
     return ret;
@@ -535,42 +495,14 @@ static int cpupool_cpu_add(unsigned int cpu)
  * Called to remove a CPU from a pool. The CPU is locked, to forbid removing
  * it from pool0. In fact, if we want to hot-unplug a CPU, it must belong to
  * pool0, or we fail.
- *
- * However, if we are suspending (e.g., to ACPI S3), we mark the CPU in such
- * a way that it can be put back in its pool when resuming.
  */
 static int cpupool_cpu_remove(unsigned int cpu)
 {
     int ret = -ENODEV;
 
     spin_lock(&cpupool_lock);
-    if ( system_state == SYS_STATE_suspend )
-    {
-        struct cpupool **c;
-
-        for_each_cpupool(c)
-        {
-            if ( cpumask_test_cpu(cpu, (*c)->cpu_valid ) )
-            {
-                cpumask_set_cpu(cpu, (*c)->cpu_suspended);
-                cpumask_clear_cpu(cpu, (*c)->cpu_valid);
-                break;
-            }
-        }
 
-        /*
-         * Either we found cpu in a pool, or it must be free (if it has been
-         * hot-unplagged, then we must have found it in pool0). It is, of
-         * course, fine to suspend or shutdown with CPUs not assigned to a
-         * pool, and (in case of suspend) they will stay free when resuming.
-         */
-        ASSERT(cpumask_test_cpu(cpu, &cpupool_free_cpus) ||
-               cpumask_test_cpu(cpu, (*c)->cpu_suspended));
-        ASSERT(cpumask_test_cpu(cpu, &cpu_online_map) ||
-               cpumask_test_cpu(cpu, cpupool0->cpu_suspended));
-        ret = 0;
-    }
-    else if ( cpumask_test_cpu(cpu, cpupool0->cpu_valid) )
+    if ( cpumask_test_cpu(cpu, cpupool0->cpu_valid) )
     {
         /*
          * If we are not suspending, we are hot-unplugging cpu, and that is
@@ -587,6 +519,41 @@ static int cpupool_cpu_remove(unsigned int cpu)
     return ret;
 }
 
+/*
+ * Called during resume for all cpus which didn't come up again. The cpu must
+ * be removed from the cpupool it is assigned to. In case a cpupool will be
+ * left without cpu we move all domains of that cpupool to cpupool0.
+ */
+static void cpupool_cpu_remove_forced(unsigned int cpu)
+{
+    struct cpupool **c;
+    struct domain *d;
+
+    spin_lock(&cpupool_lock);
+
+    if ( cpumask_test_cpu(cpu, &cpupool_free_cpus) )
+        cpumask_clear_cpu(cpu, &cpupool_free_cpus);
+    else
+    {
+        for_each_cpupool(c)
+        {
+            if ( cpumask_test_cpu(cpu, (*c)->cpu_valid) )
+            {
+                cpumask_clear_cpu(cpu, (*c)->cpu_valid);
+                if ( cpumask_weight((*c)->cpu_valid) == 0 )
+                {
+                    if ( *c == cpupool0 )
+                        panic("No cpu left in cpupool0\n");
+                    for_each_domain_in_cpupool(d, *c)
+                        cpupool_move_domain_locked(d, cpupool0);
+                }
+            }
+        }
+    }
+
+    spin_unlock(&cpupool_lock);
+}
+
 /*
  * do cpupool related sysctl operations
  */
@@ -774,10 +741,15 @@ static int cpu_callback(
     {
     case CPU_DOWN_FAILED:
     case CPU_ONLINE:
-        rc = cpupool_cpu_add(cpu);
+        if ( system_state <= SYS_STATE_active )
+            rc = cpupool_cpu_add(cpu);
         break;
     case CPU_DOWN_PREPARE:
-        rc = cpupool_cpu_remove(cpu);
+        if ( system_state <= SYS_STATE_active )
+            rc = cpupool_cpu_remove(cpu);
+        break;
+    case CPU_RESUME_FAILED:
+        cpupool_cpu_remove_forced(cpu);
         break;
     default:
         break;
xen/include/xen/sched-if.h +0 -1
index 9596eae1e2..92bc7a0365 100644
@@ -214,7 +214,6 @@ struct cpupool
 {
     int              cpupool_id;
     cpumask_var_t    cpu_valid;      /* all cpus assigned to pool */
-    cpumask_var_t    cpu_suspended;  /* cpus in S3 that should be in this pool */
     struct cpupool   *next;
     unsigned int     n_dom;
     struct scheduler *sched;
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 5/6
#35 lore raw

Re: [PATCH 5/6] xen/cpupool: simplify suspend/resume handling

Quoted 5 lines · Juergen Gross

Instead of removing cpus temporarily from cpupools during suspend/resume only remove cpus finally which didn't come up when resuming.

Looks good overall -- one comment...

Quoted 7 lines
xen/common/cpupool.c +2 -1
@@ -774,10 +741,15 @@ static int cpu_callback(
     {
     case CPU_DOWN_FAILED:
     case CPU_ONLINE:
-        rc = cpupool_cpu_add(cpu);
+        if ( system_state <= SYS_STATE_active )
+            rc = cpupool_cpu_add(cpu);

xen/common/cpupool.c static int cpu_callback( · line 754

Quoted 10 lines
xen/common/cpupool.c +5 -1
         break;
     case CPU_DOWN_PREPARE:
-        rc = cpupool_cpu_remove(cpu);
+        if ( system_state <= SYS_STATE_active )
+            rc = cpupool_cpu_remove(cpu);
+        break;
+    case CPU_RESUME_FAILED:
+        cpupool_cpu_remove_forced(cpu);
         break;
     default:

It would be good to have some comments here just explaining this; maybe just to the effect of, "Suspend/resume operations don't affect cpupool placement".

With that:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 5/6
#36 lore raw

Re: [PATCH 5/6] xen/cpupool: simplify suspend/resume handling

In reply to Juergen Gross
Quoted 11 lines · Juergen Gross

Instead of removing cpus temporarily from cpupools during suspend/resume only remove cpus finally which didn't come up when resuming.

---
 xen/common/cpupool.c       | 130 ++++++++++++++++++-----------------
----------
 xen/include/xen/sched-if.h |   1 -
 2 files changed, 51 insertions(+), 80 deletions(-)

Cool diffstat! :-)

And I'm particularly happy to see 'c->cpu_suspended' go away. ;-D

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#37 lore raw

PATCH 6/6 xen/sched: don't disable scheduler on cpus during suspend

In reply to Juergen Gross

Today there is special handling in cpu_disable_scheduler() for suspend by forcing all vcpus to the boot cpu. In fact there is no need for that as during resume the vcpus are put on the correct cpus again.

So we can just omit the call of cpu_disable_scheduler() when offlining a cpu due to suspend and on resuming we can omit taking the schedule lock for selecting the new processor.

In restore_vcpu_affinity() we should be careful when applying affinity as the cpu might not have come back to life. This in turn enables us to even support affinity_broken across suspend/resume.

Avoid all other scheduler dealloc - alloc dance when doing suspend and resume, too. It is enough to react on cpus failing to come up on resume again.

---
 xen/common/schedule.c | 161 ++++++++++++++++----------------------------------
 1 file changed, 52 insertions(+), 109 deletions(-)
xen/common/schedule.c +52 -109
index 665747f247..8a8598c7ad 100644
@@ -560,33 +560,6 @@ static void vcpu_move_locked(struct vcpu *v, unsigned int new_cpu)
         v->processor = new_cpu;
 }
 
-/*
- * Move a vcpu from its current processor to a target new processor,
- * without asking the scheduler to do any placement. This is intended
- * for being called from special contexts, where things are quiet
- * enough that no contention is supposed to happen (i.e., during
- * shutdown or software suspend, like ACPI S3).
- */
-static void vcpu_move_nosched(struct vcpu *v, unsigned int new_cpu)
-{
-    unsigned long flags;
-    spinlock_t *lock, *new_lock;
-
-    ASSERT(system_state == SYS_STATE_suspend);
-    ASSERT(!vcpu_runnable(v) && (atomic_read(&v->pause_count) ||
-                                 atomic_read(&v->domain->pause_count)));
-
-    lock = per_cpu(schedule_data, v->processor).schedule_lock;
-    new_lock = per_cpu(schedule_data, new_cpu).schedule_lock;
-
-    sched_spin_lock_double(lock, new_lock, &flags);
-    ASSERT(new_cpu != v->processor);
-    vcpu_move_locked(v, new_cpu);
-    sched_spin_unlock_double(lock, new_lock, flags);
-
-    sched_move_irqs(v);
-}
-
 /*
  * Initiating migration
  *
@@ -735,31 +708,36 @@ void restore_vcpu_affinity(struct domain *d)
 
         ASSERT(!vcpu_runnable(v));
 
-        lock = vcpu_schedule_lock_irq(v);
-
-        if ( v->affinity_broken )
-        {
-            sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL);
-            v->affinity_broken = 0;
-
-        }
-
         /*
-         * During suspend (in cpu_disable_scheduler()), we moved every vCPU
-         * to BSP (which, as of now, is pCPU 0), as a temporary measure to
-         * allow the nonboot processors to have their data structure freed
-         * and go to sleep. But nothing guardantees that the BSP is a valid
-         * pCPU for a particular domain.
+         * Re-assign the initial processor as after resume we have no
+         * guarantee the old processor has come back to life again.
          *
          * Therefore, here, before actually unpausing the domains, we should
          * set v->processor of each of their vCPUs to something that will
          * make sense for the scheduler of the cpupool in which they are in.
          */
         cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity,
-                    cpupool_domain_cpumask(v->domain));
-        v->processor = cpumask_any(cpumask_scratch_cpu(cpu));
+                    cpupool_domain_cpumask(d));
+        if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
+        {
+            if ( v->affinity_broken )
+            {
+                sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL);
+                v->affinity_broken = 0;
+                cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity,
+                            cpupool_domain_cpumask(d));
+            }
 
-        spin_unlock_irq(lock);
+            if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
+            {
+                printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v);
+                sched_set_affinity(v, &cpumask_all, NULL);
+                cpumask_and(cpumask_scratch_cpu(cpu), v->cpu_hard_affinity,
+                            cpupool_domain_cpumask(d));
+            }
+        }
+
+        v->processor = cpumask_any(cpumask_scratch_cpu(cpu));
 
         lock = vcpu_schedule_lock_irq(v);
         v->processor = SCHED_OP(vcpu_scheduler(v), pick_cpu, v);
@@ -783,7 +761,6 @@ int cpu_disable_scheduler(unsigned int cpu)
     struct vcpu *v;
     struct cpupool *c;
     cpumask_t online_affinity;
-    unsigned int new_cpu;
     int ret = 0;
 
     c = per_cpu(cpupool, cpu);
@@ -809,14 +786,7 @@ int cpu_disable_scheduler(unsigned int cpu)
                     break;
                 }
 
-                if (system_state == SYS_STATE_suspend)
-                {
-                    cpumask_copy(v->cpu_hard_affinity_saved,
-                                 v->cpu_hard_affinity);
-                    v->affinity_broken = 1;
-                }
-                else
-                    printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v);
+                printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v);
 
                 sched_set_affinity(v, &cpumask_all, NULL);
             }
@@ -828,60 +798,26 @@ int cpu_disable_scheduler(unsigned int cpu)
                 continue;
             }
 
-            /* If it is on this cpu, we must send it away. */
-            if ( unlikely(system_state == SYS_STATE_suspend) )
-            {
-                vcpu_schedule_unlock_irqrestore(lock, flags, v);
-
-                /*
-                 * If we are doing a shutdown/suspend, it is not necessary to
-                 * ask the scheduler to chime in. In fact:
-                 *  * there is no reason for it: the end result we are after
-                 *    is just 'all the vcpus on the boot pcpu, and no vcpu
-                 *    anywhere else', so let's just go for it;
-                 *  * it's wrong, for cpupools with only non-boot pcpus, as
-                 *    the scheduler would always fail to send the vcpus away
-                 *    from the last online (non boot) pcpu!
-                 *
-                 * Therefore, in the shutdown/suspend case, we just pick up
-                 * one (still) online pcpu. Note that, at this stage, all
-                 * domains (including dom0) have been paused already, so we
-                 * do not expect any vcpu activity at all.
-                 */
-                cpumask_andnot(&online_affinity, &cpu_online_map,
-                               cpumask_of(cpu));
-                BUG_ON(cpumask_empty(&online_affinity));
-                /*
-                 * As boot cpu is, usually, pcpu #0, using cpumask_first()
-                 * will make us converge quicker.
-                 */
-                new_cpu = cpumask_first(&online_affinity);
-                vcpu_move_nosched(v, new_cpu);
-            }
-            else
-            {
-                /*
-                 * OTOH, if the system is still live, and we are here because
-                 * we are doing some cpupool manipulations:
-                 *  * we want to call the scheduler, and let it re-evaluation
-                 *    the placement of the vcpu, taking into account the new
-                 *    cpupool configuration;
-                 *  * the scheduler will always fine a suitable solution, or
-                 *    things would have failed before getting in here.
-                 */
-                vcpu_migrate_start(v);
-                vcpu_schedule_unlock_irqrestore(lock, flags, v);
+            /* If it is on this cpu, we must send it away.
+             * We are doing some cpupool manipulations:
+             *  * we want to call the scheduler, and let it re-evaluation
+             *    the placement of the vcpu, taking into account the new
+             *    cpupool configuration;
+             *  * the scheduler will always find a suitable solution, or
+             *    things would have failed before getting in here.
+             */
+            vcpu_migrate_start(v);
+            vcpu_schedule_unlock_irqrestore(lock, flags, v);
 
-                vcpu_migrate_finish(v);
+            vcpu_migrate_finish(v);
 
-                /*
-                 * The only caveat, in this case, is that if a vcpu active in
-                 * the hypervisor isn't migratable. In this case, the caller
-                 * should try again after releasing and reaquiring all locks.
-                 */
-                if ( v->processor == cpu )
-                    ret = -EAGAIN;
-            }
+            /*
+             * The only caveat, in this case, is that if a vcpu active in
+             * the hypervisor isn't migratable. In this case, the caller
+             * should try again after releasing and reaquiring all locks.
+             */
+            if ( v->processor == cpu )
+                ret = -EAGAIN;
         }
     }
 
@@ -1727,20 +1663,27 @@ static int cpu_schedule_callback(
     switch ( action )
     {
     case CPU_STARTING:
-        SCHED_OP(sched, init_pdata, sd->sched_priv, cpu);
+        if ( system_state != SYS_STATE_resume )
+            SCHED_OP(sched, init_pdata, sd->sched_priv, cpu);
         break;
     case CPU_UP_PREPARE:
-        rc = cpu_schedule_up(cpu);
+        if ( system_state != SYS_STATE_resume )
+            rc = cpu_schedule_up(cpu);
         break;
+    case CPU_RESUME_FAILED:
     case CPU_DEAD:
+        if ( system_state == SYS_STATE_suspend )
+            break;
         rcu_read_lock(&domlist_read_lock);
         cpu_disable_scheduler(cpu);
         rcu_read_unlock(&domlist_read_lock);
         SCHED_OP(sched, deinit_pdata, sd->sched_priv, cpu);
-        /* Fallthrough */
-    case CPU_UP_CANCELED:
         cpu_schedule_down(cpu);
         break;
+    case CPU_UP_CANCELED:
+        if ( system_state != SYS_STATE_resume )
+            cpu_schedule_down(cpu);
+        break;
     default:
         break;
     }
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 6/6
#38 lore raw

Re: [PATCH 6/6] xen/sched: don't disable scheduler on cpus during suspend

Quoted 16 lines · Juergen Gross

Today there is special handling in cpu_disable_scheduler() for suspend
by forcing all vcpus to the boot cpu. In fact there is no need for that
as during resume the vcpus are put on the correct cpus again.

So we can just omit the call of cpu_disable_scheduler() when offlining
a cpu due to suspend and on resuming we can omit taking the schedule lock for selecting the new processor.

In restore_vcpu_affinity() we should be careful when applying affinity
as the cpu might not have come back to life. This in turn enables us to even support affinity_broken across suspend/resume.

Quoted 8 lines

Avoid all other scheduler dealloc - alloc dance when doing suspend and
resume, too. It is enough to react on cpus failing to come up on resume
again.

Ok, I think this patch is fine.

I guess you have tested both cpu off/on-lining and suspend/resume, or do you need help with that? (One of my testboxes that I have here, should be able to do suspend)

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Software Engineer @ SUSE https://www.suse.com/

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#39 lore raw

Re: [PATCH 6/6] xen/sched: don't disable scheduler on cpus during suspend

Quoted 25 lines · Dario Faggioli
Quoted 16 lines · Juergen Gross

Today there is special handling in cpu_disable_scheduler() for suspend
by forcing all vcpus to the boot cpu. In fact there is no need for that
as during resume the vcpus are put on the correct cpus again.

So we can just omit the call of cpu_disable_scheduler() when offlining
a cpu due to suspend and on resuming we can omit taking the schedule lock for selecting the new processor.

In restore_vcpu_affinity() we should be careful when applying affinity
as the cpu might not have come back to life. This in turn enables us to even support affinity_broken across suspend/resume.

Quoted 8 lines

Avoid all other scheduler dealloc - alloc dance when doing suspend and
resume, too. It is enough to react on cpus failing to come up on resume
again.

Quoted 7 lines

Ok, I think this patch is fine.

I guess you have tested both cpu off/on-lining and suspend/resume, or do you need help with that? (One of my testboxes that I have here, should be able to do suspend)

I've tested suspend/resume.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#40 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:18, <[email protected]> wrote:
Quoted 15 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Quoted 6 lines
Quoted 1 line

Did you look into the patch? I did this by testing system_state.

I think there's a wider problem here: enable_nonboot_cpus() only brings back up the CPUs that were previously online. Parked ones would be left alone, yet after resume they'd need to be put back into parked state.

I can add that handling in the respin of the series.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#41 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 19 lines · Juergen Gross
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:18, <[email protected]> wrote:
Quoted 15 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Did you look into the patch? I did this by testing system_state.

I think there's a wider problem here: enable_nonboot_cpus() only brings back up the CPUs that were previously online. Parked ones would be left alone, yet after resume they'd need to be put back into parked state.

I can add that handling in the respin of the series.

Looking deeper into that mess I believe that should be a series of its own. Cpu parking needs to be handled for cpu hotplug and core parking (XENPF_core_parking), too.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#42 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 28.03.19 at 07:59, <[email protected]> wrote:
Quoted 26 lines · Juergen Gross
Quoted 24 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:18, <[email protected]> wrote:
Quoted 9 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

Quoted 8 lines
Quoted 6 lines

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Did you look into the patch? I did this by testing system_state.

I think there's a wider problem here: enable_nonboot_cpus() only brings back up the CPUs that were previously online. Parked ones would be left alone, yet after resume they'd need to be put back into parked state.

Quoted 5 lines
Quoted 1 line

I can add that handling in the respin of the series.

Looking deeper into that mess I believe that should be a series of its own. Cpu parking needs to be handled for cpu hotplug and core parking (XENPF_core_parking), too.

What issue do you see for CPU hotplug? cpu_up_helper() has been modified by the parking series.

For core parking I wonder whether core_parking_helper() shouldn't, first of all, invoke cpu_{up,down}_helper(). This wouldn't be enough, though - the policy hooks need to honor opt_smt as well.

As to this wanting to be a patch / series of its own - I don't mind, but preferably it would come ahead of your changes here, so that it can be backported independently and (sufficiently) easily (unless of course there's really no collision between the two).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#43 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 28.03.19 at 09:03, <[email protected]> wrote:

For core parking I wonder whether core_parking_helper() shouldn't, first of all, invoke cpu_{up,down}_helper(). This wouldn't be enough, though - the policy hooks need to honor opt_smt as well.

Actually no, there was no problem at the time there: With opt_smt set to false, no secondary thread would ever have made it into core_parking_cpunum[] (that's where CPU numbers to be passed to cpu_up() get taken from). A problem here was introduced only by Andrew's 2bed1bc241, making it possible for opt_smt to change at runtime. I think I'll make a patch to have smt_up_down_helper() call into core-parking code to purge CPUs from core_parking_cpunum[] as needed.

The interaction of core-parking and xen-hptool activities is up for discussion anyway, I think. At least to me it's not immediately clear which of the two should take priority. Allowing admins to shoot themselves in the foot (as we appear to do now) is a reasonable possibility, but not the only one, the more that the platform is liable to notice higher power consumption and to subsequently request offlining of CPUs again anyway.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#44 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 28.03.19 at 07:59, <[email protected]> wrote:
Quoted 26 lines · Juergen Gross
Quoted 24 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:18, <[email protected]> wrote:
Quoted 9 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

Quoted 8 lines
Quoted 6 lines

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Did you look into the patch? I did this by testing system_state.

I think there's a wider problem here: enable_nonboot_cpus() only brings back up the CPUs that were previously online. Parked ones would be left alone, yet after resume they'd need to be put back into parked state.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I can add that handling in the respin of the series.

Looking deeper into that mess I believe that should be a series of its own. Cpu parking needs to be handled for cpu hotplug and core parking (XENPF_core_parking), too.

What issue do you see for CPU hotplug? cpu_up_helper() has been modified by the parking series.

I was thinking of hot unplug. cpu_down() won't do the job for a parked cpu.

Quoted 4 lines

For core parking I wonder whether core_parking_helper() shouldn't, first of all, invoke cpu_{up,down}_helper(). This wouldn't be enough, though - the policy hooks need to honor opt_smt as well.

Right.

Quoted 5 lines

As to this wanting to be a patch / series of its own - I don't mind, but preferably it would come ahead of your changes here, so that it can be backported independently and (sufficiently) easily (unless of course there's really no collision between the two).

In case there is a collision it should be fairly minimal.

I'd prefer not to block my series as it is a prerequisite for my core scheduling series, which I believe should go in rather sooner than later as it probably should see lot of testing before the next release.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#45 lore raw

Re: [PATCH 4/6] xen: don't free percpu areas during suspend

Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 28.03.19 at 09:35, <[email protected]> wrote:
Quoted 34 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 28.03.19 at 07:59, <[email protected]> wrote:
Quoted 19 lines · Juergen Gross
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.03.19 at 17:18, <[email protected]> wrote:
Quoted 15 lines · Andrew Cooper
Quoted 5 lines · Juergen Gross

Instead of freeing percpu areas during suspend and allocating them again when resuming keep them. Only free an area in case a cpu didn't come up again when resuming.

Hmm - this is slightly problematic, given the dual nature of this code.

I agree that it this change is beneficial for the suspend case, but it is a problem when we are parking an individual CPU for smt=0 or xen-hptool reasons.

Do we have any hint we can use when taking the CPU down as to whether we're expecting it to come straight back up again?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Did you look into the patch? I did this by testing system_state.

I think there's a wider problem here: enable_nonboot_cpus() only brings back up the CPUs that were previously online. Parked ones would be left alone, yet after resume they'd need to be put back into parked state.

I can add that handling in the respin of the series.

Looking deeper into that mess I believe that should be a series of its own. Cpu parking needs to be handled for cpu hotplug and core parking (XENPF_core_parking), too.

Quoted 5 lines
Quoted 2 lines

What issue do you see for CPU hotplug? cpu_up_helper() has been modified by the parking series.

I was thinking of hot unplug. cpu_down() won't do the job for a parked cpu.

There's nothing to be done when soft-offlining a CPU. And I'm not convinced physical CPU unplug was actually ever tested to work.

Quoted 11 lines
Quoted 5 lines

As to this wanting to be a patch / series of its own - I don't mind, but preferably it would come ahead of your changes here, so that it can be backported independently and (sufficiently) easily (unless of course there's really no collision between the two).

In case there is a collision it should be fairly minimal.

I'd prefer not to block my series as it is a prerequisite for my core scheduling series, which I believe should go in rather sooner than later as it probably should see lot of testing before the next release.

Understood.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel