Skip to contentSkip to conversation

target-ppc: Register CPU class per family only when needed

RFC PATCH In review Alexey Kardashevskiy 3 participants 7 messages Mar 5, 2015 – Jul 8, 2015

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 target-ppc: Register CPU class per family only when needed

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

---
 target-ppc/cpu-qom.h        |  1 +
 target-ppc/kvm.c            | 11 ++++++-----
 target-ppc/translate_init.c |  2 ++
 3 files changed, 9 insertions(+), 5 deletions(-)
target-ppc/cpu-qom.h +1 -0
index 6967a80..4b471d7 100644
@@ -55,6 +55,7 @@ typedef struct PowerPCCPUClass {
     DeviceRealize parent_realize;
     void (*parent_reset)(CPUState *cpu);
 
+    const char *common_cpu_name;
     uint32_t pvr;
     bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr);
     uint64_t pcr_mask;
target-ppc/kvm.c +6 -5
index b479471..3f2df65 100644
@@ -2221,7 +2221,6 @@ static int kvm_ppc_register_host_cpu_type(void)
     };
     uint32_t host_pvr = mfpvr();
     PowerPCCPUClass *pvr_pcc;
-    DeviceClass *dc;
 
     pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
     if (pvr_pcc == NULL) {
@@ -2235,10 +2234,12 @@ static int kvm_ppc_register_host_cpu_type(void)
 
     /* Register generic family CPU class for a family */
     pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
-    dc = DEVICE_CLASS(pvr_pcc);
-    type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
-    type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU, dc->desc);
-    type_register(&type_info);
+    if (pvr_pcc->common_cpu_name) {
+        type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
+        type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU,
+                                         pvr_pcc->common_cpu_name);
+        type_register(&type_info);
+    }
 
     return 0;
 }
target-ppc/translate_init.c +2 -0
index df1a62c..3d0be66 100644
@@ -8117,6 +8117,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
     dc->fw_name = "PowerPC,POWER7";
     dc->desc = "POWER7";
     dc->props = powerpc_servercpu_properties;
+    pcc->common_cpu_name = "POWER7";
     pcc->pvr_match = ppc_pvr_match_power7;
     pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER7;
@@ -8193,6 +8194,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
     dc->fw_name = "PowerPC,POWER8";
     dc->desc = "POWER8";
     dc->props = powerpc_servercpu_properties;
+    pcc->common_cpu_name = "POWER8";
     pcc->pvr_match = ppc_pvr_match_power8;
     pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER8;
Signature · 1 line
2.0.0
#1 lore raw
Quoted 10 lines · Alexey Kardashevskiy

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

Quoted 6 lines

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

LGTM. Andreas, do you agree?

Alex

Quoted 68 lines
---
 target-ppc/cpu-qom.h        |  1 +
 target-ppc/kvm.c            | 11 ++++++-----
 target-ppc/translate_init.c |  2 ++
 3 files changed, 9 insertions(+), 5 deletions(-)
target-ppc/cpu-qom.h +1 -0
index 6967a80..4b471d7 100644
@@ -55,6 +55,7 @@ typedef struct PowerPCCPUClass {
     DeviceRealize parent_realize;
     void (*parent_reset)(CPUState *cpu);
 
+    const char *common_cpu_name;
     uint32_t pvr;
     bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr);
     uint64_t pcr_mask;
target-ppc/kvm.c +6 -5
index b479471..3f2df65 100644
@@ -2221,7 +2221,6 @@ static int kvm_ppc_register_host_cpu_type(void)
     };
     uint32_t host_pvr = mfpvr();
     PowerPCCPUClass *pvr_pcc;
-    DeviceClass *dc;
 
     pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
     if (pvr_pcc == NULL) {
@@ -2235,10 +2234,12 @@ static int kvm_ppc_register_host_cpu_type(void)
 
     /* Register generic family CPU class for a family */
     pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
-    dc = DEVICE_CLASS(pvr_pcc);
-    type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
-    type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU, dc->desc);
-    type_register(&type_info);
+    if (pvr_pcc->common_cpu_name) {
+        type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
+        type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU,
+                                         pvr_pcc->common_cpu_name);
+        type_register(&type_info);
+    }
 
     return 0;
 }
target-ppc/translate_init.c +2 -0
index df1a62c..3d0be66 100644
@@ -8117,6 +8117,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
     dc->fw_name = "PowerPC,POWER7";
     dc->desc = "POWER7";
     dc->props = powerpc_servercpu_properties;
+    pcc->common_cpu_name = "POWER7";
     pcc->pvr_match = ppc_pvr_match_power7;
     pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER7;
@@ -8193,6 +8194,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
     dc->fw_name = "PowerPC,POWER8";
     dc->desc = "POWER8";
     dc->props = powerpc_servercpu_properties;
+    pcc->common_cpu_name = "POWER8";
     pcc->pvr_match = ppc_pvr_match_power8;
     pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
     pcc->init_proc = init_proc_POWER8;
#2 lore raw
Quoted 13 lines · Alexander Graf
Quoted 10 lines · Alexey Kardashevskiy

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

Quoted 8 lines
Quoted 6 lines

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

LGTM. Andreas, do you agree?

Ping?

Quoted 73 lines

Alex

Quoted 68 lines
---
  target-ppc/cpu-qom.h        |  1 +
  target-ppc/kvm.c            | 11 ++++++-----
  target-ppc/translate_init.c |  2 ++
  3 files changed, 9 insertions(+), 5 deletions(-)
target-ppc/cpu-qom.h +1 -0
index 6967a80..4b471d7 100644
@@ -55,6 +55,7 @@ typedef struct PowerPCCPUClass {
      DeviceRealize parent_realize;
      void (*parent_reset)(CPUState *cpu);
 
+    const char *common_cpu_name;
      uint32_t pvr;
      bool (*pvr_match)(struct PowerPCCPUClass *pcc, uint32_t pvr);
      uint64_t pcr_mask;
target-ppc/kvm.c +6 -5
index b479471..3f2df65 100644
@@ -2221,7 +2221,6 @@ static int kvm_ppc_register_host_cpu_type(void)
      };
      uint32_t host_pvr = mfpvr();
      PowerPCCPUClass *pvr_pcc;
-    DeviceClass *dc;
 
      pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
      if (pvr_pcc == NULL) {
@@ -2235,10 +2234,12 @@ static int kvm_ppc_register_host_cpu_type(void)
 
      /* Register generic family CPU class for a family */
      pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
-    dc = DEVICE_CLASS(pvr_pcc);
-    type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
-    type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU, dc->desc);
-    type_register(&type_info);
+    if (pvr_pcc->common_cpu_name) {
+        type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
+        type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU,
+                                         pvr_pcc->common_cpu_name);
+        type_register(&type_info);
+    }
 
      return 0;
  }
target-ppc/translate_init.c +2 -0
index df1a62c..3d0be66 100644
@@ -8117,6 +8117,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data)
      dc->fw_name = "PowerPC,POWER7";
      dc->desc = "POWER7";
      dc->props = powerpc_servercpu_properties;
+    pcc->common_cpu_name = "POWER7";
      pcc->pvr_match = ppc_pvr_match_power7;
      pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
      pcc->init_proc = init_proc_POWER7;
@@ -8193,6 +8194,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)
      dc->fw_name = "PowerPC,POWER8";
      dc->desc = "POWER8";
      dc->props = powerpc_servercpu_properties;
+    pcc->common_cpu_name = "POWER8";
      pcc->pvr_match = ppc_pvr_match_power8;
      pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;
      pcc->init_proc = init_proc_POWER8;
Signature · 1 line
Alexey
#3 lore raw

Am 16.03.2015 um 05:58 schrieb Alexey Kardashevskiy:

Quoted 17 lines · Alexander Graf
Quoted 16 lines · Alexey Kardashevskiy
Quoted 15 lines

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

LGTM. Andreas, do you agree?

Ping?

No, I don't agree. Inventing a new class field just to distinguish POWER7/POWER8 here seems like a weird idea, and the code placement is not fixed either.

I gathered that you want -cpu POWER7 and -cpu POWER8 to work on POWER8 hardware and -cpu POWER7 on POWER7, for migration purposes, correct?

What exact PVRs have you tested on and why does it not work without those types despite the PVR masking? To investigate I need a test case.

Is this just a question of the generic family type being abstract and needing an updated PVR value? Which other fields are actually used?

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
#4 lore raw
Quoted 20 lines · Andreas Färber

Am 16.03.2015 um 05:58 schrieb Alexey Kardashevskiy:

Quoted 19 lines · Alexander Graf
Quoted 18 lines · Alexey Kardashevskiy
Quoted 16 lines

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

LGTM. Andreas, do you agree?

Ping?

No, I don't agree. Inventing a new class field just to distinguish POWER7/POWER8 here seems like a weird idea,

As weird as PVR itself :)

Quoted 1 line

and the code placement is not fixed either.

What is wrong with the code placement?

Quoted 5 lines

I gathered that you want -cpu POWER7 and -cpu POWER8 to work on POWER8 hardware and -cpu POWER7 on POWER7, for migration purposes, correct?

What exact PVRs have you tested on and why does it not work without those types despite the PVR masking? To investigate I need a test case.

The real host is 003f 0201. -cpu POWER7 will fail without my patches as POWER7 is alias of 003f 0203.

Or real host 004b 0201 - -cpu POWER8 will try 004d 0100 and fail.

Quoted 2 lines

Is this just a question of the generic family type being abstract and needing an updated PVR value?

May be. That could help too I suppose.

Quoted 1 line

Which other fields are actually used?

Sorry, used where? :)

Signature · 1 line
Alexey
#5 lore raw

Adding David to this old conversation.

Quoted 59 lines · Alexey Kardashevskiy
Quoted 20 lines · Andreas Färber

Am 16.03.2015 um 05:58 schrieb Alexey Kardashevskiy:

Quoted 19 lines · Alexander Graf
Quoted 18 lines · Alexey Kardashevskiy
Quoted 16 lines

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

LGTM. Andreas, do you agree?

Ping?

No, I don't agree. Inventing a new class field just to distinguish POWER7/POWER8 here seems like a weird idea,

As weird as PVR itself :)

Quoted 1 line

and the code placement is not fixed either.

What is wrong with the code placement?

Quoted 5 lines

I gathered that you want -cpu POWER7 and -cpu POWER8 to work on POWER8 hardware and -cpu POWER7 on POWER7, for migration purposes, correct?

What exact PVRs have you tested on and why does it not work without those types despite the PVR masking? To investigate I need a test case.

The real host is 003f 0201. -cpu POWER7 will fail without my patches as POWER7 is alias of 003f 0203.

Or real host 004b 0201 - -cpu POWER8 will try 004d 0100 and fail.

Quoted 2 lines

Is this just a question of the generic family type being abstract and needing an updated PVR value?

May be. That could help too I suppose.

Quoted 1 line

Which other fields are actually used?

Sorry, used where? :)

Signature · 1 line
Alexey
#6 lore raw
Quoted 1 line · Alexey Kardashevskiy

Adding David to this old conversation.

This is the patch:
http://patchwork.ozlabs.org/patch/446544/

Quoted 63 lines · Alexey Kardashevskiy
Quoted 59 lines · Andreas Färber
Quoted 20 lines

Am 16.03.2015 um 05:58 schrieb Alexey Kardashevskiy:

Quoted 19 lines · Alexander Graf
Quoted 18 lines · Alexey Kardashevskiy
Quoted 16 lines

At the moment when running in KVM mode, QEMU registers "host" class to match the current CPU PVR value. It also registers another CPU class with a CPU family name os if we run QEMU on POWER7 machine, "host" and "POWER7" classes are created, this way we can always use "-cpu POWER7" on the actual POWER7 machine.

The existing code uses DeviceClass::desc field of the CPU class as a source for the class name; it was pointed out that it is wrong to use user-visible string as a type name.

This adds a common CPU class name into PowerPCCPUClass struct. This makes registration of a CPU named after the family conditional - PowerPCCPUClass::common_cpu_name has to be non-zero. Only POWER7/POWER8 families have this field initialized by now.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

LGTM. Andreas, do you agree?

Ping?

No, I don't agree. Inventing a new class field just to distinguish POWER7/POWER8 here seems like a weird idea,

As weird as PVR itself :)

Quoted 1 line

and the code placement is not fixed either.

What is wrong with the code placement?

Quoted 5 lines

I gathered that you want -cpu POWER7 and -cpu POWER8 to work on POWER8 hardware and -cpu POWER7 on POWER7, for migration purposes, correct?

What exact PVRs have you tested on and why does it not work without those types despite the PVR masking? To investigate I need a test case.

The real host is 003f 0201. -cpu POWER7 will fail without my patches as POWER7 is alias of 003f 0203.

Or real host 004b 0201 - -cpu POWER8 will try 004d 0100 and fail.

Quoted 2 lines

Is this just a question of the generic family type being abstract and needing an updated PVR value?

May be. That could help too I suppose.

Quoted 1 line

Which other fields are actually used?

Sorry, used where? :)

Signature · 1 line
Alexey