All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Tim Deegan <tim@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Dario Faggioli <dfaggioli@suse.com>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [PATCH RFC 05/49] xen/cpupool: simplify suspend/resume handling
Date: Fri, 29 Mar 2019 16:08:50 +0100	[thread overview]
Message-ID: <20190329150934.17694-6-jgross@suse.com> (raw)
In-Reply-To: <20190329150934.17694-1-jgross@suse.com>

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

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Dario Faggioli <dfaggioli@suse.com>
---
V2:
- add comment (George Dunlap)
---
 xen/common/cpupool.c       | 131 ++++++++++++++++++---------------------------
 xen/include/xen/sched-if.h |   1 -
 2 files changed, 52 insertions(+), 80 deletions(-)

diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c
index e89bb67e71..31ac323e40 100644
--- a/xen/common/cpupool.c
+++ b/xen/common/cpupool.c
@@ -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,16 @@ 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);
+        /* Suspend/Resume don't change assignments of cpus to cpupools. */
+        if ( system_state <= SYS_STATE_active )
+            rc = cpupool_cpu_remove(cpu);
+        break;
+    case CPU_RESUME_FAILED:
+        cpupool_cpu_remove_forced(cpu);
         break;
     default:
         break;
diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h
index 9596eae1e2..92bc7a0365 100644
--- a/xen/include/xen/sched-if.h
+++ b/xen/include/xen/sched-if.h
@@ -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;
-- 
2.16.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-03-29 15:09 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-29 15:08 [PATCH RFC 00/49] xen: add core scheduling support Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 01/49] xen/sched: call cpu_disable_scheduler() via cpu notifier Juergen Gross
2019-04-01  9:21   ` Julien Grall
2019-04-01  9:40     ` Juergen Gross
2019-04-01 10:29       ` Julien Grall
2019-04-01 10:37         ` Juergen Gross
2019-04-01 13:21           ` Julien Grall
2019-04-01 13:33             ` Juergen Gross
2019-04-01 14:01               ` Julien Grall
2019-04-01 14:23                 ` Juergen Gross
2019-04-01 15:15                   ` Julien Grall
2019-04-01 16:00                     ` Juergen Gross
2019-04-01 17:17                       ` Julien Grall
2019-04-16 19:34         ` Stefano Stabellini
2019-04-16 19:34           ` [Xen-devel] " Stefano Stabellini
2019-03-29 15:08 ` [PATCH RFC 02/49] xen: add helper for calling notifier_call_chain() to common/cpu.c Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 03/49] xen: add new cpu notifier action CPU_RESUME_FAILED Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 04/49] xen: don't free percpu areas during suspend Juergen Gross
2019-03-29 15:08 ` Juergen Gross [this message]
2019-03-29 15:08 ` [PATCH RFC 06/49] xen/sched: don't disable scheduler on cpus " Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 07/49] xen/sched: fix credit2 smt idle handling Juergen Gross
2019-03-29 18:22   ` Dario Faggioli
2019-03-29 15:08 ` [PATCH RFC 08/49] xen/sched: use new sched_item instead of vcpu in scheduler interfaces Juergen Gross
2019-03-29 18:42   ` Andrew Cooper
2019-03-30 10:24     ` Juergen Gross
2019-04-01  6:06       ` Juergen Gross
2019-04-01  7:05         ` Dario Faggioli
2019-04-01  8:19           ` Andrew Cooper
2019-04-01  8:49             ` Juergen Gross
2019-04-01 15:15             ` Dario Faggioli
2019-03-29 15:08 ` [PATCH RFC 09/49] xen/sched: alloc struct sched_item for each vcpu Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 10/49] xen/sched: move per-vcpu scheduler private data pointer to sched_item Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 11/49] xen/sched: build a linked list of struct sched_item Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 12/49] xen/sched: introduce struct sched_resource Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 13/49] xen/sched: let pick_cpu return a scheduler resource Juergen Gross
2019-03-29 15:08 ` [PATCH RFC 14/49] xen/sched: switch schedule_data.curr to point at sched_item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 15/49] xen/sched: move per cpu scheduler private data into struct sched_resource Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 16/49] xen/sched: switch vcpu_schedule_lock to item_schedule_lock Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 17/49] xen/sched: move some per-vcpu items to struct sched_item Juergen Gross
2019-03-29 21:33   ` Andrew Cooper
2019-03-30  9:59     ` Juergen Gross
2019-04-01  5:59       ` Juergen Gross
2019-04-01  8:05         ` Jan Beulich
2019-04-01  8:26           ` Andrew Cooper
2019-04-01  8:41             ` Jan Beulich
2019-04-01  8:45             ` Juergen Gross
2019-04-01  8:01       ` Jan Beulich
2019-04-01  8:33         ` Andrew Cooper
2019-04-01  8:44           ` Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 18/49] xen/sched: add scheduler helpers hiding vcpu Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 19/49] xen/sched: add domain pointer to struct sched_item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 20/49] xen/sched: add id " Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 21/49] xen/sched: rename scheduler related perf counters Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 22/49] xen/sched: switch struct task_slice from vcpu to sched_item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 23/49] xen/sched: move is_running indicator to struct sched_item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 24/49] xen/sched: make null scheduler vcpu agnostic Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 25/49] xen/sched: make rt " Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 26/49] xen/sched: make credit " Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 27/49] xen/sched: make credit2 " Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 28/49] xen/sched: make arinc653 " Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 29/49] xen: add sched_item_pause_nosync() and sched_item_unpause() Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 30/49] xen: let vcpu_create() select processor Juergen Gross
2019-03-29 19:17   ` Andrew Cooper
2019-03-30 10:23     ` Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 31/49] xen/sched: use sched_resource cpu instead smp_processor_id in schedulers Juergen Gross
2019-03-29 19:36   ` Andrew Cooper
2019-03-30 10:22     ` Juergen Gross
2019-04-01  8:10       ` Jan Beulich
2019-03-29 15:09 ` [PATCH RFC 32/49] xen/sched: switch schedule() from vcpus to sched_items Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 33/49] xen/sched: switch sched_move_irqs() to take sched_item as parameter Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 34/49] xen: switch from for_each_vcpu() to for_each_sched_item() Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 35/49] xen/sched: add runstate counters to struct sched_item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 36/49] xen/sched: rework and rename vcpu_force_reschedule() Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 37/49] xen/sched: Change vcpu_migrate_*() to operate on schedule item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 38/49] xen/sched: move struct task_slice into struct sched_item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 39/49] xen/sched: add code to sync scheduling of all vcpus of a sched item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 40/49] xen/sched: add support for multiple vcpus per sched item where missing Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 41/49] x86: make loading of GDT at context switch more modular Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 42/49] xen/sched: add support for guest vcpu idle Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 43/49] xen/sched: modify cpupool_domain_cpumask() to be an item mask Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 44/49] xen: round up max vcpus to scheduling granularity Juergen Gross
2019-04-01  8:50   ` Andrew Cooper
2019-04-01  9:47     ` Juergen Gross
2019-04-02  7:49       ` Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 45/49] xen/sched: support allocating multiple vcpus into one sched item Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 46/49] xen/sched: add a scheduler_percpu_init() function Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 47/49] xen/sched: support core scheduling in continue_running() Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 48/49] xen/sched: make vcpu_wake() core scheduling aware Juergen Gross
2019-03-29 15:09 ` [PATCH RFC 49/49] xen/sched: add scheduling granularity enum Juergen Gross
2019-03-29 15:37 ` [PATCH RFC 00/49] xen: add core scheduling support Juergen Gross
2019-03-29 15:39 ` Jan Beulich
     [not found] ` <5C9E3C3D0200007800222FB0@suse.com>
2019-03-29 15:46   ` Juergen Gross
2019-03-29 16:56     ` Dario Faggioli
2019-03-29 17:00       ` Juergen Gross
2019-03-29 17:29         ` Dario Faggioli
2019-03-29 17:39         ` Rian Quinn
2019-03-29 17:48           ` Andrew Cooper
2019-03-29 18:35             ` Rian Quinn
2019-03-29 18:16 ` Dario Faggioli
2019-03-30  9:55   ` Juergen Gross
2019-04-11  0:34   ` Dario Faggioli
2019-04-11  0:34     ` [Xen-devel] " Dario Faggioli
2019-04-11  7:16     ` Juergen Gross
2019-04-11  7:16       ` [Xen-devel] " Juergen Gross
2019-04-11 13:28       ` Dario Faggioli
2019-04-11 13:28         ` [Xen-devel] " Dario Faggioli
2019-04-01  6:41 ` Jan Beulich
     [not found] ` <5CA1B285020000780022361D@suse.com>
2019-04-01  6:49   ` Juergen Gross
2019-04-01  7:10     ` Dario Faggioli
2019-04-01  7:15       ` Juergen Gross
2019-04-01  7:13     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190329150934.17694-6-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dfaggioli@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.