Skip to contentSkip to conversation

pseries: Enforce homogeneous threads-per-core

PATCH Superseded David Gibson 3 participants 4 messages Mar 31, 2017 – Apr 2, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pseries: Enforce homogeneous threads-per-core

For reasons that may be useful in future, CPU core objects, as used on the pseries machine type have their own nr-threads property, potentially allowing cores with different numbers of threads in the same system.

If the user/management uses the values specified in query-hotpluggable-cpus as they're expected to do, this will never matter in pratice. But that's not actually enforced - it's possible to manually specify a core with a different number of threads from that in -smp. That will confuse the platform - most immediately, this can be used to create a CPU thread with index above max_cpus which leads to an assertion failure in spapr_cpu_core_realize().

For now, enforce that all cores must have the same, standard, number of threads. While we're at it, also enforce that the core ids are correctly aligned based on that number of threads.

---
 hw/ppc/spapr_cpu_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_cpu_core.c +12 -0
index 6883f09..935ee62 100644
@@ -167,6 +167,18 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
     void *obj;
     int i, j;
 
+    if (cc->nr_threads != smp_threads) {
+        error_setg(errp,
+                   "Invalid nr-threads=%d of CPU[core-id: %d], must be %d",
+                   cc->nr_threads, cc->core_id, smp_threads);
+        return;
+    }
+    if ((cc->core_id % smp_threads) != 0) {
+        error_setg(errp, "Invalid CPU core-id=%d, must be a multiple of %d",
+                   cc->core_id, smp_threads);
+        return;
+    }
+
     sc->threads = g_malloc0(size * cc->nr_threads);
     for (i = 0; i < cc->nr_threads; i++) {
         int node_id;
Signature · 1 line
2.9.3
#1 lore raw
Quoted 4 lines · David Gibson

For reasons that may be useful in future, CPU core objects, as used on the pseries machine type have their own nr-threads property, potentially allowing cores with different numbers of threads in the same system.

I remember we retained this flexibility to support heterogenous systems in future ? I think we can go with this enforcement now and relax it later if we ever reach there.

Quoted 25 lines

If the user/management uses the values specified in query-hotpluggable-cpus as they're expected to do, this will never matter in pratice. But that's not actually enforced - it's possible to manually specify a core with a different number of threads from that in -smp. That will confuse the platform - most immediately, this can be used to create a CPU thread with index above max_cpus which leads to an assertion failure in spapr_cpu_core_realize().

For now, enforce that all cores must have the same, standard, number of threads. While we're at it, also enforce that the core ids are correctly aligned based on that number of threads.

---
 hw/ppc/spapr_cpu_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_cpu_core.c +0 -0
index 6883f09..935ee62 100644
@@ -167,6 +167,18 @@ static void spapr_cpu_core_realize(DeviceState *dev,
 Error **errp)
     void *obj;

hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize(DeviceState *dev, · line 178

Quoted 10 lines
hw/ppc/spapr_cpu_core.c +6 -0
     int i, j;
 
+    if (cc->nr_threads != smp_threads) {
+        error_setg(errp,
+                   "Invalid nr-threads=%d of CPU[core-id: %d], must be
 %d",
+                   cc->nr_threads, cc->core_id, smp_threads);
+        return;
+    }
 

The above check should move to pre_plug handler.

hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) · line 180

Quoted 7 lines
hw/ppc/spapr_cpu_core.c +2 -0
+    if ((cc->core_id % smp_threads) != 0) {
+        error_setg(errp, "Invalid CPU core-id=%d, must be a multiple of

%d",

hw/ppc/spapr_cpu_core.c +3 -0
+                   cc->core_id, smp_threads);
+        return;
+    }

Not sure when you will hit this as the same check is already present in pre_plug handler.

Regards,
Bharata.

#2 lore raw
Quoted 40 lines · On Fri, 31 Mar 2017 11:04:55 +0530 Bharata B Rao <[email protected]> wrote:
Quoted 4 lines · David Gibson

For reasons that may be useful in future, CPU core objects, as used on the pseries machine type have their own nr-threads property, potentially allowing cores with different numbers of threads in the same system.

I remember we retained this flexibility to support heterogenous systems in future ? I think we can go with this enforcement now and relax it later if we ever reach there.

Quoted 27 lines

If the user/management uses the values specified in query-hotpluggable-cpus as they're expected to do, this will never matter in pratice. But that's not actually enforced - it's possible to manually specify a core with a different number of threads from that in -smp. That will confuse the platform - most immediately, this can be used to create a CPU thread with index above max_cpus which leads to an assertion failure in spapr_cpu_core_realize().

For now, enforce that all cores must have the same, standard, number of threads. While we're at it, also enforce that the core ids are correctly aligned based on that number of threads.

---
 hw/ppc/spapr_cpu_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_cpu_core.c +0 -0
index 6883f09..935ee62 100644
@@ -167,6 +167,18 @@ static void spapr_cpu_core_realize(DeviceState *dev,
 Error **errp)
     void *obj;
     int i, j;
 
Quoted 10 lines

hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)

Quoted 8 lines
hw/ppc/spapr_cpu_core.c +6 -0
+    if (cc->nr_threads != smp_threads) {
+        error_setg(errp,
+                   "Invalid nr-threads=%d of CPU[core-id: %d], must be
 %d",
+                   cc->nr_threads, cc->core_id, smp_threads);
+        return;
+    }
 

The above check should move to pre_plug handler.

Agreed,
this property validation should be done at machine level (pre_plug)

Quoted 15 lines

hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) · line 180

Quoted 9 lines
hw/ppc/spapr_cpu_core.c +2 -0
+    if ((cc->core_id % smp_threads) != 0) {
+        error_setg(errp, "Invalid CPU core-id=%d, must be a multiple of

%d",

hw/ppc/spapr_cpu_core.c +3 -0
+                   cc->core_id, smp_threads);
+        return;
+    }

Not sure when you will hit this as the same check is already present in pre_plug handler.

Regards,
Bharata.

#3 lore raw
In reply to Bharata B Rao
Quoted 40 lines · Bharata B Rao
Quoted 4 lines · David Gibson

For reasons that may be useful in future, CPU core objects, as used on the pseries machine type have their own nr-threads property, potentially allowing cores with different numbers of threads in the same system.

I remember we retained this flexibility to support heterogenous systems in future ? I think we can go with this enforcement now and relax it later if we ever reach there.

Quoted 27 lines

If the user/management uses the values specified in query-hotpluggable-cpus as they're expected to do, this will never matter in pratice. But that's not actually enforced - it's possible to manually specify a core with a different number of threads from that in -smp. That will confuse the platform - most immediately, this can be used to create a CPU thread with index above max_cpus which leads to an assertion failure in spapr_cpu_core_realize().

For now, enforce that all cores must have the same, standard, number of threads. While we're at it, also enforce that the core ids are correctly aligned based on that number of threads.

---
 hw/ppc/spapr_cpu_core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/ppc/spapr_cpu_core.c +0 -0
index 6883f09..935ee62 100644
@@ -167,6 +167,18 @@ static void spapr_cpu_core_realize(DeviceState *dev,
 Error **errp)
     void *obj;
     int i, j;
 
Quoted 10 lines

hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)

Quoted 8 lines
hw/ppc/spapr_cpu_core.c +6 -0
+    if (cc->nr_threads != smp_threads) {
+        error_setg(errp,
+                   "Invalid nr-threads=%d of CPU[core-id: %d], must be
 %d",
+                   cc->nr_threads, cc->core_id, smp_threads);
+        return;
+    }
 

The above check should move to pre_plug handler.

Ah, good point.

Quoted 10 lines

hw/ppc/spapr_cpu_core.c static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) · line 180

Quoted 7 lines
hw/ppc/spapr_cpu_core.c +2 -0
+    if ((cc->core_id % smp_threads) != 0) {
+        error_setg(errp, "Invalid CPU core-id=%d, must be a multiple of

%d",

hw/ppc/spapr_cpu_core.c +3 -0
+                   cc->core_id, smp_threads);
+        return;
+    }

Not sure when you will hit this as the same check is already present in pre_plug handler.

Oops, yes, didn't spot that.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson