Skip to contentSkip to conversation

Boot time cpupools

PATCH Superseded Luca Fancellu 2 participants 11 messages Apr 21, 2022 – May 6, 2022

lore
Share & tools
lore
#0 lore raw

v8 cover Boot time cpupools

This serie introduces a feature for Xen to create cpu pools at boot time, the feature is enabled using a configurable that is disabled by default. The boot time cpupool feature relies on the device tree to describe the cpu pools.
Another feature is introduced by the serie, the possibility to assign a dom0less guest to a cpupool at boot time.

Here follows an example, Xen is built with CONFIG_BOOT_TIME_CPUPOOLS=y.

From the DT:

[...]

  a72_0: cpu@0 {
    compatible = "arm,cortex-a72";
    reg = <0x0 0x0>;
    device_type = "cpu";
    [...]
  };

  a72_1: cpu@1 {
    compatible = "arm,cortex-a72";
    reg = <0x0 0x1>;
    device_type = "cpu";
    [...]
  };

  a53_0: cpu@100 {
    compatible = "arm,cortex-a53";
    reg = <0x0 0x100>;
    device_type = "cpu";
    [...]
  };

  a53_1: cpu@101 {
    compatible = "arm,cortex-a53";
    reg = <0x0 0x101>;
    device_type = "cpu";
    [...]
  };

  a53_2: cpu@102 {
    compatible = "arm,cortex-a53";
    reg = <0x0 0x102>;
    device_type = "cpu";
    [...]
  };

  a53_3: cpu@103 {
    compatible = "arm,cortex-a53";
    reg = <0x0 0x103>;
    device_type = "cpu";
    [...]
  };

  chosen {
    #size-cells = <0x1>;
    #address-cells = <0x1>;
    xen,dom0-bootargs = "...";
    xen,xen-bootargs = "...";
    cpupool0 {
      compatible = "xen,cpupool";
      cpupool-cpus = <&a72_0 &a72_1>;
      cpupool-sched = "credit2";
    };

    cp1: cpupool1 {
      compatible = "xen,cpupool";
      cpupool-cpus = <&a53_0 &a53_1 &a53_2 &a53_3>;
      cpupool-sched = "null";
    };

    module@0 {
      reg = <0x80080000 0x1300000>;
      compatible = "multiboot,module";
    };

    domU1 {
      #size-cells = <0x1>;
      #address-cells = <0x1>;
      compatible = "xen,domain";
      cpus = <1>;
      memory = <0 0xC0000>;
      vpl011;
      domain-cpupool = <&cp1>;

      module@92000000 {
        compatible = "multiboot,kernel", "multiboot,module";
        reg = <0x92000000 0x1ffffff>;
        bootargs = "...";
      };
    };

};

[...]

The example DT is instructing Xen to have two cpu pools, one having two phisical cpus and the one having 4 phisical cpus, the last mentioned cpu pool uses the null scheduler and from the /chosen node we can see that a dom0less guest will be started on that cpu pool.

In this particular case Xen must boot with different type of cpus, so the boot argument hmp_unsafe must be enabled.

Luca Fancellu (7):
tools/cpupools: Give a name to unnamed cpupools xen/sched: create public function for cpupools creation xen/sched: retrieve scheduler id by name xen/cpupool: Create different cpupools at boot time xen/cpupool: Don't allow removing cpu0 from cpupool0 arm/dom0less: assign dom0less guests to cpupools xen/cpupool: Allow cpupool0 to use different scheduler

 MAINTAINERS                            |   2 +-
 docs/misc/arm/device-tree/booting.txt  |   5 +
 docs/misc/arm/device-tree/cpupools.txt | 140 +++++++++++++++
 tools/helpers/xen-init-dom0.c          |  37 +++-
 tools/libs/light/libxl_utils.c         |   3 +-
 xen/arch/arm/domain_build.c            |  19 +-
 xen/arch/arm/include/asm/smp.h         |   3 +
 xen/common/domain.c                    |   2 +-
 xen/common/sched/Kconfig               |   7 +
 xen/common/sched/Makefile              |   1 +
 xen/common/sched/boot-cpupool.c        | 234 +++++++++++++++++++++++++
 xen/common/sched/core.c                |  40 +++--
 xen/common/sched/cpupool.c             |  43 ++++-
 xen/include/public/domctl.h            |   5 +-
 xen/include/xen/sched.h                |  53 ++++++
 15 files changed, 563 insertions(+), 31 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/cpupools.txt
 create mode 100644 xen/common/sched/boot-cpupool.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v8 1/7 tools/cpupools: Give a name to unnamed cpupools

With the introduction of boot time cpupools, Xen can create many different cpupools at boot time other than cpupool with id 0.

Since these newly created cpupools can't have an entry in Xenstore, create the entry using xen-init-dom0 helper with the usual convention: Pool-<cpupool id>.

Given the change, remove the check for poolid == 0 from libxl_cpupoolid_to_name(...).

---
Changes in v8:
- no changes
Changes in v7:
- Add R-by from Anthony
Changes in v6:
- Reworked loop to have only one error path (Anthony) Changes in v5:
- no changes
Changes in v4:
- no changes
Changes in v3:
- no changes, add R-by
Changes in v2:
- Remove unused variable, moved xc_cpupool_infofree ahead to simplify the code, use asprintf (Juergen)

---
 tools/helpers/xen-init-dom0.c  | 37 +++++++++++++++++++++++++++++++++-
 tools/libs/light/libxl_utils.c |  3 +--
 2 files changed, 37 insertions(+), 3 deletions(-)
tools/helpers/xen-init-dom0.c +36 -1
index c99224a4b607..37eff8868f25 100644
@@ -43,7 +43,10 @@ int main(int argc, char **argv)
     int rc;
     struct xs_handle *xsh = NULL;
     xc_interface *xch = NULL;
-    char *domname_string = NULL, *domid_string = NULL;
+    char *domname_string = NULL, *domid_string = NULL,
+         *pool_path = NULL, *pool_name = NULL;
+    xc_cpupoolinfo_t *xcinfo;
+    unsigned int pool_id = 0;
     libxl_uuid uuid;
 
     /* Accept 0 or 1 argument */
@@ -114,9 +117,41 @@ int main(int argc, char **argv)
         goto out;
     }
 
+    /* Create an entry in xenstore for each cpupool on the system */
+    do {
+        xcinfo = xc_cpupool_getinfo(xch, pool_id);
+        if (xcinfo != NULL) {
+            if (xcinfo->cpupool_id != pool_id)
+                pool_id = xcinfo->cpupool_id;
+            xc_cpupool_infofree(xch, xcinfo);
+            if (asprintf(&pool_path, "/local/pool/%d/name", pool_id) <= 0) {
+                fprintf(stderr, "cannot allocate memory for pool path\n");
+                rc = 1;
+                goto out;
+            }
+            if (asprintf(&pool_name, "Pool-%d", pool_id) <= 0) {
+                fprintf(stderr, "cannot allocate memory for pool name\n");
+                rc = 1;
+                goto out;
+            }
+            pool_id++;
+            if (!xs_write(xsh, XBT_NULL, pool_path, pool_name,
+                          strlen(pool_name))) {
+                fprintf(stderr, "cannot set pool name\n");
+                rc = 1;
+                goto out;
+            }
+            free(pool_name);
+            free(pool_path);
+            pool_path = pool_name = NULL;
+        }
+    } while(xcinfo != NULL);
+
     printf("Done setting up Dom0\n");
 
 out:
+    free(pool_path);
+    free(pool_name);
     free(domid_string);
     free(domname_string);
     xs_close(xsh);
tools/libs/light/libxl_utils.c +1 -2
index b91c2cafa223..81780da3ff40 100644
@@ -151,8 +151,7 @@ char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid)
 
     snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
     s = xs_read(ctx->xsh, XBT_NULL, path, &len);
-    if (!s && (poolid == 0))
-        return strdup("Pool-0");
+
     return s;
 }
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH v8 2/7 xen/sched: create public function for cpupools creation

In reply to Luca Fancellu

Create new public function to create cpupools, can take as parameter the scheduler id or a negative value that means the default Xen scheduler will be used.

---
Changes in v8:
- no changes
Changes in v7:
- no changes
Changes in v6:
- add R-by
Changes in v5:
- no changes
Changes in v4:
- no changes
Changes in v3:
- Fixed comment (Andrew)
Changes in v2:
- cpupool_create_pool doesn't check anymore for pool id uniqueness before calling cpupool_create. Modified commit message accordingly

---
 xen/common/sched/cpupool.c | 15 +++++++++++++++
 xen/include/xen/sched.h    | 16 ++++++++++++++++
 2 files changed, 31 insertions(+)
xen/common/sched/cpupool.c +15 -0
index a6da4970506a..89a891af7076 100644
@@ -1219,6 +1219,21 @@ static void cpupool_hypfs_init(void)
 
 #endif /* CONFIG_HYPFS */
 
+struct cpupool *__init cpupool_create_pool(unsigned int pool_id, int sched_id)
+{
+    struct cpupool *pool;
+
+    if ( sched_id < 0 )
+        sched_id = scheduler_get_default()->sched_id;
+
+    pool = cpupool_create(pool_id, sched_id);
+
+    BUG_ON(IS_ERR(pool));
+    cpupool_put(pool);
+
+    return pool;
+}
+
 static int __init cf_check cpupool_init(void)
 {
     unsigned int cpu;
xen/include/xen/sched.h +16 -0
index ed8539f6d297..0164db996b8b 100644
@@ -1153,6 +1153,22 @@ int cpupool_move_domain(struct domain *d, struct cpupool *c);
 int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op);
 unsigned int cpupool_get_id(const struct domain *d);
 const cpumask_t *cpupool_valid_cpus(const struct cpupool *pool);
+
+/*
+ * cpupool_create_pool - Creates a cpupool
+ * @pool_id: id of the pool to be created
+ * @sched_id: id of the scheduler to be used for the pool
+ *
+ * Creates a cpupool with pool_id id.
+ * The sched_id parameter identifies the scheduler to be used, if it is
+ * negative, the default scheduler of Xen will be used.
+ *
+ * returns:
+ *     pointer to the struct cpupool just created, or Xen will panic in case of
+ *     error
+ */
+struct cpupool *cpupool_create_pool(unsigned int pool_id, int sched_id);
+
 extern void cf_check dump_runq(unsigned char key);
 
 void arch_do_physinfo(struct xen_sysctl_physinfo *pi);
Signature · 1 line
2.17.1
#3 lore raw

PATCH v8 3/7 xen/sched: retrieve scheduler id by name

In reply to Luca Fancellu

Add a static function to retrieve the scheduler pointer using the scheduler name.

Add a public function to retrieve the scheduler id by the scheduler name that makes use of the new static function.

Take the occasion to replace open coded scheduler search with the new static function in scheduler_init.

---
Changes in v8:
- no changes
Changes in v7:
- Add R-by (Dario)
Changes in v6:
- no changes
Changes in v5:
- no changes
Changes in v4:
- no changes
Changes in v3:
- add R-by
Changes in v2:
- replace open coded scheduler search in scheduler_init (Juergen)

---
 xen/common/sched/core.c | 40 ++++++++++++++++++++++++++--------------
 xen/include/xen/sched.h | 11 +++++++++++
 2 files changed, 37 insertions(+), 14 deletions(-)
xen/common/sched/core.c +26 -14
index 19ab67818106..48ee01420fb8 100644
@@ -2947,10 +2947,30 @@ void scheduler_enable(void)
     scheduler_active = true;
 }
 
+static inline
+const struct scheduler *__init sched_get_by_name(const char *sched_name)
+{
+    unsigned int i;
+
+    for ( i = 0; i < NUM_SCHEDULERS; i++ )
+        if ( schedulers[i] && !strcmp(schedulers[i]->opt_name, sched_name) )
+            return schedulers[i];
+
+    return NULL;
+}
+
+int __init sched_get_id_by_name(const char *sched_name)
+{
+    const struct scheduler *scheduler = sched_get_by_name(sched_name);
+
+    return scheduler ? scheduler->sched_id : -1;
+}
+
 /* Initialise the data structures. */
 void __init scheduler_init(void)
 {
     struct domain *idle_domain;
+    const struct scheduler *scheduler;
     int i;
 
     scheduler_enable();
@@ -2981,25 +3001,17 @@ void __init scheduler_init(void)
                    schedulers[i]->opt_name);
             schedulers[i] = NULL;
         }
-
-        if ( schedulers[i] && !ops.name &&
-             !strcmp(schedulers[i]->opt_name, opt_sched) )
-            ops = *schedulers[i];
     }
 
-    if ( !ops.name )
+    scheduler = sched_get_by_name(opt_sched);
+    if ( !scheduler )
     {
         printk("Could not find scheduler: %s\n", opt_sched);
-        for ( i = 0; i < NUM_SCHEDULERS; i++ )
-            if ( schedulers[i] &&
-                 !strcmp(schedulers[i]->opt_name, CONFIG_SCHED_DEFAULT) )
-            {
-                ops = *schedulers[i];
-                break;
-            }
-        BUG_ON(!ops.name);
-        printk("Using '%s' (%s)\n", ops.name, ops.opt_name);
+        scheduler = sched_get_by_name(CONFIG_SCHED_DEFAULT);
+        BUG_ON(!scheduler);
+        printk("Using '%s' (%s)\n", scheduler->name, scheduler->opt_name);
     }
+    ops = *scheduler;
 
     if ( cpu_schedule_up(0) )
         BUG();
xen/include/xen/sched.h +11 -0
index 0164db996b8b..4442a1940c25 100644
@@ -764,6 +764,17 @@ void sched_destroy_domain(struct domain *d);
 long sched_adjust(struct domain *, struct xen_domctl_scheduler_op *);
 long sched_adjust_global(struct xen_sysctl_scheduler_op *);
 int  sched_id(void);
+
+/*
+ * sched_get_id_by_name - retrieves a scheduler id given a scheduler name
+ * @sched_name: scheduler name as a string
+ *
+ * returns:
+ *     positive value being the scheduler id, on success
+ *     negative value if the scheduler name is not found.
+ */
+int sched_get_id_by_name(const char *sched_name);
+
 void vcpu_wake(struct vcpu *v);
 long vcpu_yield(void);
 void vcpu_sleep_nosync(struct vcpu *v);
Signature · 1 line
2.17.1
#4 lore raw

PATCH v8 4/7 xen/cpupool: Create different cpupools at boot time

In reply to Luca Fancellu

Introduce a way to create different cpupools at boot time, this is particularly useful on ARM big.LITTLE system where there might be the need to have different cpupools for each type of core, but also systems using NUMA can have different cpu pools for each node.

The feature on arm relies on a specification of the cpupools from the device tree to build pools and assign cpus to them.

ACPI is not supported for this feature.

With this patch, cpupool0 can now have less cpus than the number of online ones, so update the default case for opt_dom0_max_vcpus.

Documentation is created to explain the feature.

---
Changes in v8:
- moved Kconfig parameter from xen/common/Kconfig to xen/common/sched/Kconfig (Jan)
- Add R-by (Stefano)
Changes in v7:
- rename xen/common/boot_cpupools.c to xen/common/sched/boot-cpupool.c (Jan)
- reverted xen/common/Makefile, add entry in xen/common/sched/Makefile
- changed line in MAINTAINERS under CPU POOLS section (Dario)
- Fix documentation, update opt_dom0_max_vcpus to the number of cpu in cpupool0 (Julien)
Changes in v6:
- Changed docs, return if booted with ACPI in btcpupools_dtb_parse, panic if /chosen does not exists. Changed commit message (Julien)
- Add Juergen R-by for the xen/common/sched part that didn't change Changes in v5:
- Fixed wrong variable name, swapped schedulers, add scheduler info in the printk (Stefano)
- introduce assert in cpupool_init and btcpupools_get_cpupool_id to harden the code
Changes in v4:
- modify Makefile to put in *.init.o, fixed stubs and macro (Jan)
- fixed docs, fix brakets (Stefano)
- keep cpu0 in Pool-0 (Julien)
- moved printk from btcpupools_allocate_pools to btcpupools_get_cpupool_id
- Add to docs constraint about cpu0 and Pool-0
Changes in v3:
- Add newline to cpupools.txt and removed "default n" from Kconfig (Jan)
- Fixed comment, moved defines, used global cpu_online_map, use HAS_DEVICE_TREE instead of ARM and place arch specific code in header (Juergen)
- Fix brakets, x86 code only panic, get rid of scheduler dt node, don't save pool pointer and look for it from the pool list (Stefano)
- Changed data structures to allow modification to the code. Changes in v2:
- Move feature to common code (Juergen)
- Try to decouple dtb parse and cpupool creation to allow
more way to specify cpupools (for example command line)
- Created standalone dt node for the scheduler so it can
be used in future work to set scheduler specific
parameters
- Use only auto generated ids for cpupools

---
 MAINTAINERS                            |   2 +-
 docs/misc/arm/device-tree/cpupools.txt | 140 +++++++++++++++++
 xen/arch/arm/domain_build.c            |   5 +-
 xen/arch/arm/include/asm/smp.h         |   3 +
 xen/common/sched/Kconfig               |   7 +
 xen/common/sched/Makefile              |   1 +
 xen/common/sched/boot-cpupool.c        | 207 +++++++++++++++++++++++++
 xen/common/sched/cpupool.c             |  12 +-
 xen/include/xen/sched.h                |  14 ++
 9 files changed, 388 insertions(+), 3 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/cpupools.txt
 create mode 100644 xen/common/sched/boot-cpupool.c
MAINTAINERS +1 -1
index 2a47fafe8580..38fc3243d1a1 100644
@@ -273,7 +273,7 @@ CPU POOLS
 M:	Juergen Gross <[email protected]>
 M:	Dario Faggioli <[email protected]>
 S:	Supported
-F:	xen/common/sched/cpupool.c
+F:	xen/common/sched/*cpupool.c
 
 DEVICE TREE
 M:	Stefano Stabellini <[email protected]>
docs/misc/arm/device-tree/cpupools.txt new file +140 -0

140 lines not on this page · raw message

xen/arch/arm/domain_build.c +4 -1
index 1472ca4972b0..5df5c8ffb8ba 100644
@@ -73,7 +73,10 @@ custom_param("dom0_mem", parse_dom0_mem);
 unsigned int __init dom0_max_vcpus(void)
 {
     if ( opt_dom0_max_vcpus == 0 )
-        opt_dom0_max_vcpus = num_online_cpus();
+    {
+        ASSERT(cpupool0);
+        opt_dom0_max_vcpus = cpumask_weight(cpupool_valid_cpus(cpupool0));
+    }
     if ( opt_dom0_max_vcpus > MAX_VIRT_CPUS )
         opt_dom0_max_vcpus = MAX_VIRT_CPUS;
 
xen/arch/arm/include/asm/smp.h +3 -0
index af5a2fe65266..83c0cd69767b 100644
@@ -34,6 +34,9 @@ extern void init_secondary(void);
 extern void smp_init_cpus(void);
 extern void smp_clear_cpu_maps (void);
 extern int smp_get_max_cpus (void);
+
+#define cpu_physical_id(cpu) cpu_logical_map(cpu)
+
 #endif
 
 /*
xen/common/sched/Kconfig +7 -0
index 3d9f9214b8cc..b2ef0c99a3f8 100644
@@ -64,3 +64,10 @@ config SCHED_DEFAULT
 	default "credit2"
 
 endmenu
+
+config BOOT_TIME_CPUPOOLS
+	bool "Create cpupools at boot time"
+	depends on HAS_DEVICE_TREE
+	help
+	  Creates cpupools during boot time and assigns cpus to them. Cpupools
+	  options can be specified in the device tree.
xen/common/sched/Makefile +1 -0
index 3537f2a68d69..697bd54bfe93 100644
@@ -1,3 +1,4 @@
+obj-$(CONFIG_BOOT_TIME_CPUPOOLS) += boot-cpupool.init.o
 obj-y += cpupool.o
 obj-$(CONFIG_SCHED_ARINC653) += arinc653.o
 obj-$(CONFIG_SCHED_CREDIT) += credit.o
xen/common/sched/boot-cpupool.c new file +207 -0

207 lines not on this page · raw message

xen/common/sched/cpupool.c +11 -1
index 89a891af7076..86a175f99cd5 100644
@@ -1247,12 +1247,22 @@ static int __init cf_check cpupool_init(void)
     cpupool_put(cpupool0);
     register_cpu_notifier(&cpu_nfb);
 
+    btcpupools_dtb_parse();
+
+    btcpupools_allocate_pools();
+
     spin_lock(&cpupool_lock);
 
     cpumask_copy(&cpupool_free_cpus, &cpu_online_map);
 
     for_each_cpu ( cpu, &cpupool_free_cpus )
-        cpupool_assign_cpu_locked(cpupool0, cpu);
+    {
+        unsigned int pool_id = btcpupools_get_cpupool_id(cpu);
+        struct cpupool *pool = cpupool_find_by_id(pool_id);
+
+        ASSERT(pool);
+        cpupool_assign_cpu_locked(pool, cpu);
+    }
 
     spin_unlock(&cpupool_lock);
 
xen/include/xen/sched.h +14 -0
index 4442a1940c25..74b3aae10b94 100644
@@ -1184,6 +1184,20 @@ extern void cf_check dump_runq(unsigned char key);
 
 void arch_do_physinfo(struct xen_sysctl_physinfo *pi);
 
+#ifdef CONFIG_BOOT_TIME_CPUPOOLS
+void btcpupools_allocate_pools(void);
+unsigned int btcpupools_get_cpupool_id(unsigned int cpu);
+void btcpupools_dtb_parse(void);
+
+#else /* !CONFIG_BOOT_TIME_CPUPOOLS */
+static inline void btcpupools_allocate_pools(void) {}
+static inline void btcpupools_dtb_parse(void) {}
+static inline unsigned int btcpupools_get_cpupool_id(unsigned int cpu)
+{
+    return 0;
+}
+#endif
+
 #endif /* __SCHED_H__ */
 
 /*
Signature · 1 line
2.17.1
#5 lore raw

PATCH v8 5/7 xen/cpupool: Don't allow removing cpu0 from cpupool0

In reply to Luca Fancellu

Cpu0 must remain in cpupool0, otherwise some operations like moving cpus between cpupools, cpu hotplug, destroying cpupools, shutdown of the host, might not work in a sane way.

---
Changes in v8:
- Add R-by (Juergen)
Changes in v7:
- new patch

---
 xen/common/sched/cpupool.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/common/sched/cpupool.c +7 -1
index 86a175f99cd5..0a93bcc631bf 100644
@@ -572,6 +572,7 @@ static long cf_check cpupool_unassign_cpu_helper(void *info)
  * possible failures:
  * - last cpu and still active domains in cpupool
  * - cpu just being unplugged
+ * - Attempt to remove boot cpu from cpupool0
  */
 static int cpupool_unassign_cpu(struct cpupool *c, unsigned int cpu)
 {
@@ -582,7 +583,12 @@ static int cpupool_unassign_cpu(struct cpupool *c, unsigned int cpu)
     debugtrace_printk("cpupool_unassign_cpu(pool=%u,cpu=%d)\n",
                       c->cpupool_id, cpu);
 
-    if ( !cpu_online(cpu) )
+    /*
+     * Cpu0 must remain in cpupool0, otherwise some operations like moving cpus
+     * between cpupools, cpu hotplug, destroying cpupools, shutdown of the host,
+     * might not work in a sane way.
+     */
+    if ( (!c->cpupool_id && !cpu) || !cpu_online(cpu) )
         return -EINVAL;
 
     master_cpu = sched_get_resource_cpu(cpu);
Signature · 1 line
2.17.1
#6 lore raw

PATCH v8 6/7 arm/dom0less: assign dom0less guests to cpupools

In reply to Luca Fancellu

Introduce domain-cpupool property of a xen,domain device tree node, that specifies the cpupool device tree handle of a xen,cpupool node that identifies a cpupool created at boot time where the guest will be assigned on creation.

Add member to the xen_domctl_createdomain public interface so the XEN_DOMCTL_INTERFACE_VERSION version is bumped.

Add public function to retrieve a pool id from the device tree cpupool node.

Update documentation about the property.

---
Changes in v8:
- no changes
Changes in v7:
- Add comment for cpupool_id struct member. (Jan) Changes in v6:
- no changes
Changes in v5:
- no changes
Changes in v4:
- no changes
- add R-by
Changes in v3:
- Use explicitely sized integer for struct xen_domctl_createdomain cpupool_id member. (Stefano)
- Changed code due to previous commit code changes Changes in v2:
- Moved cpupool_id from arch specific to common part (Juergen)
- Implemented functions to retrieve the cpupool id from the cpupool dtb node.

---
 docs/misc/arm/device-tree/booting.txt |  5 +++++
 xen/arch/arm/domain_build.c           | 14 +++++++++++++-
 xen/common/domain.c                   |  2 +-
 xen/common/sched/boot-cpupool.c       | 24 ++++++++++++++++++++++++
 xen/include/public/domctl.h           |  5 ++++-
 xen/include/xen/sched.h               |  9 +++++++++
 6 files changed, 56 insertions(+), 3 deletions(-)
docs/misc/arm/device-tree/booting.txt +5 -0
index a94125394e35..7b4a29a2c293 100644
@@ -188,6 +188,11 @@ with the following properties:
     An empty property to request the memory of the domain to be
     direct-map (guest physical address == physical address).
 
+- domain-cpupool
+
+    Optional. Handle to a xen,cpupool device tree node that identifies the
+    cpupool where the guest will be started at boot.
+
 Under the "xen,domain" compatible node, one or more sub-nodes are present
 for the DomU kernel and ramdisk.
 
xen/arch/arm/domain_build.c +13 -1
index 5df5c8ffb8ba..aa777741bdd0 100644
@@ -3174,7 +3174,8 @@ static int __init construct_domU(struct domain *d,
 void __init create_domUs(void)
 {
     struct dt_device_node *node;
-    const struct dt_device_node *chosen = dt_find_node_by_path("/chosen");
+    const struct dt_device_node *cpupool_node,
+                                *chosen = dt_find_node_by_path("/chosen");
 
     BUG_ON(chosen == NULL);
     dt_for_each_child_node(chosen, node)
@@ -3243,6 +3244,17 @@ void __init create_domUs(void)
                                          vpl011_virq - 32 + 1);
         }
 
+        /* Get the optional property domain-cpupool */
+        cpupool_node = dt_parse_phandle(node, "domain-cpupool", 0);
+        if ( cpupool_node )
+        {
+            int pool_id = btcpupools_get_domain_pool_id(cpupool_node);
+            if ( pool_id < 0 )
+                panic("Error getting cpupool id from domain-cpupool (%d)\n",
+                      pool_id);
+            d_cfg.cpupool_id = pool_id;
+        }
+
         /*
          * The variable max_init_domid is initialized with zero, so here it's
          * very important to use the pre-increment operator to call
xen/common/domain.c +1 -1
index 351029f8b239..0827400f4f49 100644
@@ -698,7 +698,7 @@ struct domain *domain_create(domid_t domid,
         if ( !d->pbuf )
             goto fail;
 
-        if ( (err = sched_init_domain(d, 0)) != 0 )
+        if ( (err = sched_init_domain(d, config->cpupool_id)) != 0 )
             goto fail;
 
         if ( (err = late_hwdom_init(d)) != 0 )
xen/common/sched/boot-cpupool.c +24 -0
index 9429a5025fc4..240bae4cebb8 100644
@@ -22,6 +22,8 @@ static unsigned int __initdata next_pool_id;
 
 #define BTCPUPOOLS_DT_NODE_NO_REG     (-1)
 #define BTCPUPOOLS_DT_NODE_NO_LOG_CPU (-2)
+#define BTCPUPOOLS_DT_WRONG_NODE      (-3)
+#define BTCPUPOOLS_DT_CORRUPTED_NODE  (-4)
 
 static int __init get_logical_cpu_from_hw_id(unsigned int hwid)
 {
@@ -56,6 +58,28 @@ get_logical_cpu_from_cpu_node(const struct dt_device_node *cpu_node)
     return cpu_num;
 }
 
+int __init btcpupools_get_domain_pool_id(const struct dt_device_node *node)
+{
+    const struct dt_device_node *phandle_node;
+    int cpu_num;
+
+    if ( !dt_device_is_compatible(node, "xen,cpupool") )
+        return BTCPUPOOLS_DT_WRONG_NODE;
+    /*
+     * Get first cpu listed in the cpupool, from its reg it's possible to
+     * retrieve the cpupool id.
+     */
+    phandle_node = dt_parse_phandle(node, "cpupool-cpus", 0);
+    if ( !phandle_node )
+        return BTCPUPOOLS_DT_CORRUPTED_NODE;
+
+    cpu_num = get_logical_cpu_from_cpu_node(phandle_node);
+    if ( cpu_num < 0 )
+        return cpu_num;
+
+    return pool_cpu_map[cpu_num];
+}
+
 static int __init check_and_get_sched_id(const char* scheduler_name)
 {
     int sched_id = sched_get_id_by_name(scheduler_name);
xen/include/public/domctl.h +4 -1
index b85e6170b0aa..84e75829b980 100644
@@ -38,7 +38,7 @@
 #include "hvm/save.h"
 #include "memory.h"
 
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000014
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000015
 
 /*
  * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
@@ -106,6 +106,9 @@ struct xen_domctl_createdomain {
     /* Per-vCPU buffer size in bytes.  0 to disable. */
     uint32_t vmtrace_size;
 
+    /* CPU pool to use; specify 0 or a specific existing pool */
+    uint32_t cpupool_id;
+
     struct xen_arch_domainconfig arch;
 };
 
xen/include/xen/sched.h +9 -0
index 74b3aae10b94..32d2a6294b6d 100644
@@ -1188,6 +1188,7 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi);
 void btcpupools_allocate_pools(void);
 unsigned int btcpupools_get_cpupool_id(unsigned int cpu);
 void btcpupools_dtb_parse(void);
+int btcpupools_get_domain_pool_id(const struct dt_device_node *node);
 
 #else /* !CONFIG_BOOT_TIME_CPUPOOLS */
 static inline void btcpupools_allocate_pools(void) {}
@@ -1196,6 +1197,14 @@ static inline unsigned int btcpupools_get_cpupool_id(unsigned int cpu)
 {
     return 0;
 }
+#ifdef CONFIG_HAS_DEVICE_TREE
+static inline int
+btcpupools_get_domain_pool_id(const struct dt_device_node *node)
+{
+    return 0;
+}
+#endif
+
 #endif
 
 #endif /* __SCHED_H__ */
Signature · 1 line
2.17.1
#7 lore raw

PATCH v8 7/7 xen/cpupool: Allow cpupool0 to use different scheduler

In reply to Luca Fancellu

Currently cpupool0 can use only the default scheduler, and cpupool_create has an hardcoded behavior when creating the pool 0 that doesn't allocate new memory for the scheduler, but uses the default scheduler structure in memory.

With this commit it is possible to allocate a different scheduler for the cpupool0 when using the boot time cpupool.
To achieve this the hardcoded behavior in cpupool_create is removed and the cpupool0 creation is moved.

When compiling without boot time cpupools enabled, the current behavior is maintained (except that cpupool0 scheduler memory will be allocated).

---
Changes in v8:
- no changes
Changes in v7:
- no changes
Changes in v6:
- Add R-by
Changes in v5:
- no changes
Changes in v4:
- no changes
Changes in v3:
- fix typo in commit message (Juergen)
- rebase changes
Changes in v2:
- new patch

---
 xen/common/sched/boot-cpupool.c | 5 ++++-
 xen/common/sched/cpupool.c      | 8 +-------
 xen/include/xen/sched.h         | 5 ++++-
 3 files changed, 9 insertions(+), 9 deletions(-)
xen/common/sched/boot-cpupool.c +4 -1
index 240bae4cebb8..5955e6f9a98b 100644
@@ -205,8 +205,11 @@ void __init btcpupools_allocate_pools(void)
     if ( add_extra_cpupool )
         next_pool_id++;
 
+    /* Keep track of cpupool id 0 with the global cpupool0 */
+    cpupool0 = cpupool_create_pool(0, pool_sched_map[0]);
+
     /* Create cpupools with selected schedulers */
-    for ( i = 0; i < next_pool_id; i++ )
+    for ( i = 1; i < next_pool_id; i++ )
         cpupool_create_pool(i, pool_sched_map[i]);
 }
 
xen/common/sched/cpupool.c +1 -7
index 0a93bcc631bf..f6e3d97e5288 100644
@@ -312,10 +312,7 @@ static struct cpupool *cpupool_create(unsigned int poolid,
         c->cpupool_id = q->cpupool_id + 1;
     }
 
-    if ( poolid == 0 )
-        c->sched = scheduler_get_default();
-    else
-        c->sched = scheduler_alloc(sched_id);
+    c->sched = scheduler_alloc(sched_id);
     if ( IS_ERR(c->sched) )
     {
         ret = PTR_ERR(c->sched);
@@ -1248,9 +1245,6 @@ static int __init cf_check cpupool_init(void)
 
     cpupool_hypfs_init();
 
-    cpupool0 = cpupool_create(0, 0);
-    BUG_ON(IS_ERR(cpupool0));
-    cpupool_put(cpupool0);
     register_cpu_notifier(&cpu_nfb);
 
     btcpupools_dtb_parse();
xen/include/xen/sched.h +4 -1
index 32d2a6294b6d..6040fa3b3830 100644
@@ -1191,7 +1191,10 @@ void btcpupools_dtb_parse(void);
 int btcpupools_get_domain_pool_id(const struct dt_device_node *node);
 
 #else /* !CONFIG_BOOT_TIME_CPUPOOLS */
-static inline void btcpupools_allocate_pools(void) {}
+static inline void btcpupools_allocate_pools(void)
+{
+    cpupool0 = cpupool_create_pool(0, -1);
+}
 static inline void btcpupools_dtb_parse(void) {}
 static inline unsigned int btcpupools_get_cpupool_id(unsigned int cpu)
 {
Signature · 1 line
2.17.1
#8 lore raw
In reply to Luca Fancellu
Quoted 34 lines

The example DT is instructing Xen to have two cpu pools, one having two phisical cpus and the one having 4 phisical cpus, the last mentioned cpu pool uses the null scheduler and from the /chosen node we can see that a dom0less guest will be started on that cpu pool.

In this particular case Xen must boot with different type of cpus, so the boot argument hmp_unsafe must be enabled.

Luca Fancellu (7):
tools/cpupools: Give a name to unnamed cpupools xen/sched: create public function for cpupools creation xen/sched: retrieve scheduler id by name xen/cpupool: Create different cpupools at boot time xen/cpupool: Don't allow removing cpu0 from cpupool0 arm/dom0less: assign dom0less guests to cpupools xen/cpupool: Allow cpupool0 to use different scheduler

MAINTAINERS                            |   2 +-
docs/misc/arm/device-tree/booting.txt  |   5 +
docs/misc/arm/device-tree/cpupools.txt | 140 +++++++++++++++
tools/helpers/xen-init-dom0.c          |  37 +++-
tools/libs/light/libxl_utils.c         |   3 +-
xen/arch/arm/domain_build.c            |  19 +-
xen/arch/arm/include/asm/smp.h         |   3 +
xen/common/domain.c                    |   2 +-
xen/common/sched/Kconfig               |   7 +
xen/common/sched/Makefile              |   1 +
xen/common/sched/boot-cpupool.c        | 234 +++++++++++++++++++++++++
xen/common/sched/core.c                |  40 +++--
xen/common/sched/cpupool.c             |  43 ++++-
xen/include/public/domctl.h            |   5 +-
xen/include/xen/sched.h                |  53 ++++++
15 files changed, 563 insertions(+), 31 deletions(-)
Quoted 6 lines

create mode 100644 docs/misc/arm/device-tree/cpupools.txt create mode 100644 xen/common/sched/boot-cpupool.c

Signature · 1 line
2.17.1

Ping?

The v8 seems to be reviewed for all patch

https://patchwork.kernel.org/project/xen-devel/list/?series=634064

Any other thought about that?

Cheers,
Luca

#9 lore raw

Hi Luca,

Quoted 37 lines · Luca Fancellu
Quoted 37 lines

The example DT is instructing Xen to have two cpu pools, one having two phisical cpus and the one having 4 phisical cpus, the last mentioned cpu pool uses the null scheduler and from the /chosen node we can see that a dom0less guest will be started on that cpu pool.

In this particular case Xen must boot with different type of cpus, so the boot argument hmp_unsafe must be enabled.

Luca Fancellu (7):
tools/cpupools: Give a name to unnamed cpupools xen/sched: create public function for cpupools creation xen/sched: retrieve scheduler id by name xen/cpupool: Create different cpupools at boot time xen/cpupool: Don't allow removing cpu0 from cpupool0 arm/dom0less: assign dom0less guests to cpupools xen/cpupool: Allow cpupool0 to use different scheduler

MAINTAINERS                            |   2 +-
docs/misc/arm/device-tree/booting.txt  |   5 +
docs/misc/arm/device-tree/cpupools.txt | 140 +++++++++++++++
tools/helpers/xen-init-dom0.c          |  37 +++-
tools/libs/light/libxl_utils.c         |   3 +-
xen/arch/arm/domain_build.c            |  19 +-
xen/arch/arm/include/asm/smp.h         |   3 +
xen/common/domain.c                    |   2 +-
xen/common/sched/Kconfig               |   7 +
xen/common/sched/Makefile              |   1 +
xen/common/sched/boot-cpupool.c        | 234 +++++++++++++++++++++++++
xen/common/sched/core.c                |  40 +++--
xen/common/sched/cpupool.c             |  43 ++++-
xen/include/public/domctl.h            |   5 +-
xen/include/xen/sched.h                |  53 ++++++
15 files changed, 563 insertions(+), 31 deletions(-)

create mode 100644 docs/misc/arm/device-tree/cpupools.txt create mode 100644 xen/common/sched/boot-cpupool.c

Quoted 5 lines
Quoted 3 lines
Signature · 1 line
2.17.1

Ping?

You seemed to have forgotten to CC the relevant maintainers on each patch and the cover letter. I only got this e-mail because I have a filter for some keywords.

Quoted 4 lines

The v8 seems to be reviewed for all patch

https://patchwork.kernel.org/project/xen-devel/list/?series=634064

AFAICT, patchwork only tells you the number of reviewed-by tag. It doesn't tell you whether the patch was suitably reviewed.

Looking through the patches:
#1: Ready
#2: Ready
#3: Ready
#4: Missing review from the cpupool maintainers (Juergen or Dario) #5: Ready
#6: Missing review from the cpupool maintainers
#7: Ready

Cheers,

Signature · 1 line
Julien Grall
#10 lore raw
Quoted 41 lines
Quoted 29 lines
Quoted 29 lines

Luca Fancellu (7):
tools/cpupools: Give a name to unnamed cpupools xen/sched: create public function for cpupools creation xen/sched: retrieve scheduler id by name xen/cpupool: Create different cpupools at boot time xen/cpupool: Don't allow removing cpu0 from cpupool0 arm/dom0less: assign dom0less guests to cpupools xen/cpupool: Allow cpupool0 to use different scheduler

MAINTAINERS | 2 +- docs/misc/arm/device-tree/booting.txt | 5 + docs/misc/arm/device-tree/cpupools.txt | 140 +++++++++++++++ tools/helpers/xen-init-dom0.c | 37 +++- tools/libs/light/libxl_utils.c | 3 +- xen/arch/arm/domain_build.c | 19 +- xen/arch/arm/include/asm/smp.h | 3 + xen/common/domain.c | 2 +-
xen/common/sched/Kconfig | 7 + xen/common/sched/Makefile | 1 + xen/common/sched/boot-cpupool.c | 234 +++++++++++++++++++++++++ xen/common/sched/core.c | 40 +++-- xen/common/sched/cpupool.c | 43 ++++- xen/include/public/domctl.h | 5 +- xen/include/xen/sched.h | 53 ++++++

15 files changed, 563 insertions(+), 31 deletions(-)

create mode 100644 docs/misc/arm/device-tree/cpupools.txt create mode 100644 xen/common/sched/boot-cpupool.c

Quoted 4 lines
Quoted 3 lines
Signature · 1 line
2.17.1

Ping?

You seemed to have forgotten to CC the relevant maintainers on each patch and the cover letter. I only got this e-mail because I have a filter for some keywords.

Quoted 2 lines

The v8 seems to be reviewed for all patch
https://patchwork.kernel.org/project/xen-devel/list/?series=634064

AFAICT, patchwork only tells you the number of reviewed-by tag. It doesn't tell you whether the patch was suitably reviewed.

Quoted 9 lines

Looking through the patches:
#1: Ready
#2: Ready
#3: Ready
#4: Missing review from the cpupool maintainers (Juergen or Dario) #5: Ready
#6: Missing review from the cpupool maintainers
#7: Ready

Thanks Julien, indeed my ping didn’t CC the maintainers, I will ping separately on the #4 and #6 patches.

Cheers,
Luca

Quoted 4 lines

Cheers,

Signature · 1 line
Julien Grall