Skip to contentSkip to conversation

hw/arm/fsl-imx: move cpus initialization to realize time after smp_cpus check

PATCH In review Like Xu 3 participants 3 messages Apr 30, 2019 – May 2, 2019 Arm i.MX and Layerscape

lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 hw/arm/fsl-imx: move cpus initialization to realize time after smp_cpus check

If "smp_cpus> FSL_IMX6_NUM_CPUS" fails in *_realize(), there is no need to initialize the CPUs in *_init(). So it could be better to create all cpus after the validity in *_realize(). On the other hand, it makes the usages of global variable smp_cpus more centrally for maintenance.

---
 hw/arm/fsl-imx6.c   | 13 +++++++------
 hw/arm/fsl-imx6ul.c | 12 ++++++------
 hw/arm/fsl-imx7.c   | 15 +++++++--------
 3 files changed, 20 insertions(+), 20 deletions(-)
hw/arm/fsl-imx6.c +7 -6
index 7b7b97f..14015a1 100644
@@ -37,12 +37,6 @@ static void fsl_imx6_init(Object *obj)
     char name[NAME_SIZE];
     int i;
 
-    for (i = 0; i < MIN(smp_cpus, FSL_IMX6_NUM_CPUS); i++) {
-        snprintf(name, NAME_SIZE, "cpu%d", i);
-        object_initialize_child(obj, name, &s->cpu[i], sizeof(s->cpu[i]),
-                                "cortex-a9-" TYPE_ARM_CPU, &error_abort, NULL);
-    }
-
     sysbus_init_child_obj(obj, "a9mpcore", &s->a9mpcore, sizeof(s->a9mpcore),
                           TYPE_A9MPCORE_PRIV);
 
@@ -95,6 +89,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
 {
     FslIMX6State *s = FSL_IMX6(dev);
     uint16_t i;
+    char name[NAME_SIZE];
     Error *err = NULL;
 
     if (smp_cpus > FSL_IMX6_NUM_CPUS) {
@@ -103,6 +98,12 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    for (i = 0; i < MIN(smp_cpus, FSL_IMX6_NUM_CPUS); i++) {
+        snprintf(name, NAME_SIZE, "cpu%d", i);
+        object_initialize_child(OBJECT(dev), name, &s->cpu[i],
+            sizeof(s->cpu[i]), "cortex-a9-" TYPE_ARM_CPU, &error_abort, NULL);
+    }
+
     for (i = 0; i < smp_cpus; i++) {
 
         /* On uniprocessor, the CBAR is set to 0 */
hw/arm/fsl-imx6ul.c +6 -6
index 4b56bfa..7f30eb7 100644
@@ -32,12 +32,6 @@ static void fsl_imx6ul_init(Object *obj)
     char name[NAME_SIZE];
     int i;
 
-    for (i = 0; i < MIN(smp_cpus, FSL_IMX6UL_NUM_CPUS); i++) {
-        snprintf(name, NAME_SIZE, "cpu%d", i);
-        object_initialize_child(obj, name, &s->cpu[i], sizeof(s->cpu[i]),
-                                "cortex-a7-" TYPE_ARM_CPU, &error_abort, NULL);
-    }
-
     /*
      * A7MPCORE
      */
@@ -167,6 +161,12 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    for (i = 0; i < MIN(smp_cpus, FSL_IMX6UL_NUM_CPUS); i++) {
+        snprintf(name, NAME_SIZE, "cpu%d", i);
+        object_initialize_child(OBJECT(dev), name, &s->cpu[i],
+            sizeof(s->cpu[i]), "cortex-a7-" TYPE_ARM_CPU, &error_abort, NULL);
+    }
+
     for (i = 0; i < smp_cpus; i++) {
         Object *o = OBJECT(&s->cpu[i]);
 
hw/arm/fsl-imx7.c +7 -8
index 7663ad6..2580348 100644
@@ -34,14 +34,6 @@ static void fsl_imx7_init(Object *obj)
     char name[NAME_SIZE];
     int i;
 
-
-    for (i = 0; i < MIN(smp_cpus, FSL_IMX7_NUM_CPUS); i++) {
-        snprintf(name, NAME_SIZE, "cpu%d", i);
-        object_initialize_child(obj, name, &s->cpu[i], sizeof(s->cpu[i]),
-                                ARM_CPU_TYPE_NAME("cortex-a7"), &error_abort,
-                                NULL);
-    }
-
     /*
      * A7MPCORE
      */
@@ -167,6 +159,13 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    for (i = 0; i < MIN(smp_cpus, FSL_IMX7_NUM_CPUS); i++) {
+        snprintf(name, NAME_SIZE, "cpu%d", i);
+        object_initialize_child(OBJECT(dev), name, &s->cpu[i],
+            sizeof(s->cpu[i]), ARM_CPU_TYPE_NAME("cortex-a7"),
+            &error_abort, NULL);
+    }
+
     for (i = 0; i < smp_cpus; i++) {
         o = OBJECT(&s->cpu[i]);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Like Xu

If "smp_cpus> FSL_IMX6_NUM_CPUS" fails in *_realize(), there is no need to initialize the CPUs in *_init(). So it could be better to create all cpus after the validity in *_realize(). On the other hand, it makes the usages of global variable smp_cpus more centrally for maintenance.

I'm not a great fan of this. I think that where possible we should init child objects in the parent's init function, and realize them in the realize function. There are a few cases where we're forced to do the child init in realize, but this doesn't seem like one of them.

thanks
-- PMM

#2 lore raw
Quoted 7 lines · On Tue, 30 Apr 2019 10:18:37 +0100 Peter Maydell <[email protected]>…
Quoted 5 lines · Like Xu

If "smp_cpus> FSL_IMX6_NUM_CPUS" fails in *_realize(), there is no need to initialize the CPUs in *_init(). So it could be better to create all cpus after the validity in *_realize(). On the other hand, it makes the usages of global variable smp_cpus more centrally for maintenance.

Quoted 5 lines

I'm not a great fan of this. I think that where possible we should init child objects in the parent's init function, and realize them in the realize function. There are a few cases where we're forced to do the child init in realize, but this doesn't seem like one of them.

well, if it were unconditional then initializing children in initfn would be fine, however here number of children to initialize depends on global smp_cpus. In order to get rid of global, we could move iniialization to realize time or init all FSL_IMX6_NUM_CPUS and realize only smp_cpus at realize time.

Quoted 3 lines

thanks
-- PMM