Skip to contentSkip to conversation

cpu: add suboptions support

PATCH In review Alexey Kardashevskiy 3 participants 7 messages Dec 3, 2013 – Feb 20, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 cpu: add suboptions support

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

---
Changes:
v4:
* moved QemuOpts logic to qeom/cpu.c
* added cpu_opt_get() as the machine init code wants to know the CPU name to create a CPU object

---
 include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++
 qom/cpu.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c              | 23 +++++++++++++++++++++++
 3 files changed, 113 insertions(+)
include/qom/cpu.h +41 -0
index 7739e00..07330e1 100644
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif
 
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ *
+ * Parses CPU options if the CPU class has a custom handler defined.
+ *
+ * Returns: -1 if a custom handler is defined and failed, 0 otherwise.
+ */
+static inline int cpu_parse_options(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);
+
+/**
+ * cpu_get_opt:
+ * @name: The parameter name
+ *
+ * Returns: a CPU parameter value.
+ */
+const char *cpu_opt_get(const char *name);
+
+/**
  * cpu_reset:
  * @cpu: The CPU whose state is to be reset.
  */
qom/cpu.c +49 -0

58 lines not on this page · raw message

vl.c +23 -0
index 8d5d874..f7c4c0a 100644
@@ -433,6 +433,16 @@ static QemuOptsList qemu_machine_opts = {
     },
 };
 
+static QemuOptsList qemu_cpu_opts = {
+    .name = "cpu",
+    .implied_opt_name = "type",
+    .merge_lists = true,
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_cpu_opts.head),
+    .desc = {
+        { /* End of list */ }
+    },
+};
+
 static QemuOptsList qemu_boot_opts = {
     .name = "boot-opts",
     .implied_opt_name = "order",
@@ -2880,6 +2890,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_trace_opts);
     qemu_add_opts(&qemu_option_rom_opts);
     qemu_add_opts(&qemu_machine_opts);
+    qemu_add_opts(&qemu_cpu_opts);
     qemu_add_opts(&qemu_smp_opts);
     qemu_add_opts(&qemu_boot_opts);
     qemu_add_opts(&qemu_sandbox_opts);
@@ -2975,7 +2986,19 @@ int main(int argc, char **argv, char **envp)
             }
             case QEMU_OPTION_cpu:
                 /* hw initialization will check this */
+
+                /* Store cpu_model for old style parser */
                 cpu_model = optarg;
+
+                /*
+                 * Parse and save options in the cpu options list
+                 * for a new parser
+                 */
+                olist = qemu_find_opts("cpu");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
                 break;
             case QEMU_OPTION_hda:
                 {
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 31 lines · On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy <[email protected]> wrote:

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

---
Changes:
v4:
* moved QemuOpts logic to qeom/cpu.c
* added cpu_opt_get() as the machine init code wants to know the CPU name to create a CPU object

---
 include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++
 qom/cpu.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c              | 23 +++++++++++++++++++++++
 3 files changed, 113 insertions(+)
include/qom/cpu.h +1 -0
index 7739e00..07330e1 100644
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 338

Quoted 10 lines
include/qom/cpu.h +8 -0
 
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ *
+ * Parses CPU options if the CPU class has a custom handler defined.
+ *
+ * Returns: -1 if a custom handler is defined and failed, 0 otherwise.
+ */
+static inline int cpu_parse_options(CPUState *cpu)

why not pass up the stack errp, vs returning -1?

And of cause, there should be a patch that demonstrates an actual user of cpu_parse_options().

Quoted 12 lines
include/qom/cpu.h +12 -0
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 360

Quoted 10 lines
include/qom/cpu.h +10 -0
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);

where is it used?
Maybe it should be static inside of qom/cpu.c
and assigned in cpu_class_init() for TYPE_CPU.

Quoted 126 lines
include/qom/cpu.h +10 -0
+
+/**
+ * cpu_get_opt:
+ * @name: The parameter name
+ *
+ * Returns: a CPU parameter value.
+ */
+const char *cpu_opt_get(const char *name);
+
+/**
  * cpu_reset:
  * @cpu: The CPU whose state is to be reset.
  */
qom/cpu.c +49 -0
index 818fb26..fb95cb4 100644
@@ -24,6 +24,8 @@
 #include "qemu/notify.h"
 #include "qemu/log.h"
 #include "sysemu/sysemu.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/config-file.h"
 
 bool cpu_exists(int64_t id)
 {
@@ -273,3 +275,50 @@ static void cpu_register_types(void)
 }
 
 type_init(cpu_register_types)
+
+static int cpu_set_property(const char *name, const char *value, void *opaque)
+{
+    Error *err = NULL;
+
+    if (strcmp(name, "type") == 0) {
+        return 0;
+    }
+
+    object_property_parse(opaque, value, name, &err);
+    if (err != NULL) {
+        qerror_report_err(err);
+        error_free(err);
+        return -1;
+    }
+
+    return 0;
+}
+
+static QemuOpts *cpu_get_opts(void)
+{
+    QemuOptsList *list;
+
+    list = qemu_find_opts("cpu");
+    assert(list);
+    return qemu_opts_find(list, NULL);
+}
+
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp)
+{
+    QemuOpts *opts = cpu_get_opts();
+
+    if (opts && qemu_opt_foreach(opts, cpu_set_property, cpu, 1)) {
+        error_setg(errp, "Bad option");
+    }
+}
+
+const char *cpu_opt_get(const char *name)
+{
+    QemuOpts *opts = cpu_get_opts();
+
+    if (!opts) {
+        return NULL;
+    }
+
+    return qemu_opt_get(cpu_get_opts(), name);
+}
vl.c +23 -0
index 8d5d874..f7c4c0a 100644
@@ -433,6 +433,16 @@ static QemuOptsList qemu_machine_opts = {
     },
 };
 
+static QemuOptsList qemu_cpu_opts = {
+    .name = "cpu",
+    .implied_opt_name = "type",
+    .merge_lists = true,
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_cpu_opts.head),
+    .desc = {
+        { /* End of list */ }
+    },
+};
+
 static QemuOptsList qemu_boot_opts = {
     .name = "boot-opts",
     .implied_opt_name = "order",
@@ -2880,6 +2890,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_trace_opts);
     qemu_add_opts(&qemu_option_rom_opts);
     qemu_add_opts(&qemu_machine_opts);
+    qemu_add_opts(&qemu_cpu_opts);
     qemu_add_opts(&qemu_smp_opts);
     qemu_add_opts(&qemu_boot_opts);
     qemu_add_opts(&qemu_sandbox_opts);
@@ -2975,7 +2986,19 @@ int main(int argc, char **argv, char **envp)
             }
             case QEMU_OPTION_cpu:
                 /* hw initialization will check this */
+
+                /* Store cpu_model for old style parser */
                 cpu_model = optarg;
+
+                /*
+                 * Parse and save options in the cpu options list
+                 * for a new parser
+                 */
+                olist = qemu_find_opts("cpu");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
                 break;
             case QEMU_OPTION_hda:
                 {
#2 lore raw
Quoted 35 lines · Igor Mammedov
Quoted 32 lines · On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy <[email protected]> wrote:

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

---
Changes:
v4:
* moved QemuOpts logic to qeom/cpu.c
* added cpu_opt_get() as the machine init code wants to know the CPU name to create a CPU object

---
 include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++
 qom/cpu.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c              | 23 +++++++++++++++++++++++
 3 files changed, 113 insertions(+)
include/qom/cpu.h +1 -0
index 7739e00..07330e1 100644
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif
 
Quoted 10 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 338

Quoted 9 lines
include/qom/cpu.h +8 -0
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ *
+ * Parses CPU options if the CPU class has a custom handler defined.
+ *
+ * Returns: -1 if a custom handler is defined and failed, 0 otherwise.
+ */
+static inline int cpu_parse_options(CPUState *cpu)

why not pass up the stack errp, vs returning -1?

Oh. Overlooked it. Not sure if we really need Error** here, do we?

object_property_parse() will print an error anyway and QEMU then exits and qemu_opt_foreach() cannot carry Error** to the caller so I'll better drop it on this level.

Quoted 20 lines

And of cause, there should be a patch that demonstrates an actual user of cpu_parse_options().

Quoted 17 lines
include/qom/cpu.h +17 -0
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
Quoted 8 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 360

Quoted 5 lines
include/qom/cpu.h +5 -0
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);

where is it used?
Maybe it should be static inside of qom/cpu.c
and assigned in cpu_class_init() for TYPE_CPU.

It is assigned for TYPE_POWERPC_CPU as I really do not want to switch every single CPU in QEMU to use this so this is why it is not static.

Below is how I use it for POWERPC. Next time I'll post these patches together, sorry for inconvenience.

hw/ppc/spapr.c +4 -1
index d93abdc..7e0fb68 100644
@@ -33,6 +33,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
+#include "qom/cpu.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
@@ -1111,7 +1112,7 @@ static SaveVMHandlers savevm_htab_handlers = {
 static void ppc_spapr_init(QEMUMachineInitArgs *args)
 {
     ram_addr_t ram_size = args->ram_size;
-    const char *cpu_model = args->cpu_model;
+    const char *cpu_model;
     const char *kernel_filename = args->kernel_filename;
     const char *kernel_cmdline = args->kernel_cmdline;
     const char *initrd_filename = args->initrd_filename;
@@ -1131,6 +1132,8 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 
     msi_supported = true;
 
+    cpu_model = cpu_opt_get("type");
+
     spapr = g_malloc0(sizeof(*spapr));
     QLIST_INIT(&spapr->phbs);
 
target-ppc/translate_init.c +4 -0
index 1b0ff38..d24920b 100644
@@ -7381,6 +7381,10 @@ static void init_ppc_proc(PowerPCCPU *cpu)
     /* PowerPC implementation specific initialisations (SPRs, timers, ...) */
     (*pcc->init_proc)(env);
 
+    if (cpu_parse_options(CPU(cpu))) {
+        exit(1);
+    }
+
     /* MSR bits & flags consistency checks */
     if (env->msr_mask & (1 << 25)) {
         switch (env->flags & (POWERPC_FLAG_SPE | POWERPC_FLAG_VRE)) {
@@ -8676,6 +8680,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void

*data)
#endif

     dc->fw_name = "PowerPC,UNKNOWN";

+ cc->parse_options = cpu_default_parse_options_func;
}

static const TypeInfo ppc_cpu_type_info = {

Signature · 1 line
Alexey
#3 lore raw
Quoted 9 lines · Alexey Kardashevskiy
Quoted 8 lines · Igor Mammedov
Quoted 5 lines · On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy <[email protected]> wrote:

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

Ping, anyone?
Patch is too bad? Any new idea how to rework it? Someone else is coming with a new patch?

Thanks

Quoted 141 lines
Quoted 27 lines
Quoted 27 lines

---
Changes:
v4:
* moved QemuOpts logic to qeom/cpu.c
* added cpu_opt_get() as the machine init code wants to know the CPU name to create a CPU object

---
 include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++
 qom/cpu.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c              | 23 +++++++++++++++++++++++
 3 files changed, 113 insertions(+)
include/qom/cpu.h +1 -0
index 7739e00..07330e1 100644
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif
 
Quoted 10 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 338

Quoted 9 lines
include/qom/cpu.h +8 -0
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ *
+ * Parses CPU options if the CPU class has a custom handler defined.
+ *
+ * Returns: -1 if a custom handler is defined and failed, 0 otherwise.
+ */
+static inline int cpu_parse_options(CPUState *cpu)

why not pass up the stack errp, vs returning -1?

Oh. Overlooked it. Not sure if we really need Error** here, do we?

object_property_parse() will print an error anyway and QEMU then exits and qemu_opt_foreach() cannot carry Error** to the caller so I'll better drop it on this level.

Quoted 20 lines

And of cause, there should be a patch that demonstrates an actual user of cpu_parse_options().

Quoted 17 lines
include/qom/cpu.h +17 -0
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
Quoted 8 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 360

Quoted 5 lines
include/qom/cpu.h +5 -0
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);

where is it used?
Maybe it should be static inside of qom/cpu.c
and assigned in cpu_class_init() for TYPE_CPU.

It is assigned for TYPE_POWERPC_CPU as I really do not want to switch every single CPU in QEMU to use this so this is why it is not static.

Below is how I use it for POWERPC. Next time I'll post these patches together, sorry for inconvenience.

hw/ppc/spapr.c +4 -1
index d93abdc..7e0fb68 100644
@@ -33,6 +33,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
+#include "qom/cpu.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
@@ -1111,7 +1112,7 @@ static SaveVMHandlers savevm_htab_handlers = {
 static void ppc_spapr_init(QEMUMachineInitArgs *args)
 {
     ram_addr_t ram_size = args->ram_size;
-    const char *cpu_model = args->cpu_model;
+    const char *cpu_model;
     const char *kernel_filename = args->kernel_filename;
     const char *kernel_cmdline = args->kernel_cmdline;
     const char *initrd_filename = args->initrd_filename;
@@ -1131,6 +1132,8 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 
     msi_supported = true;
 
+    cpu_model = cpu_opt_get("type");
+
     spapr = g_malloc0(sizeof(*spapr));
     QLIST_INIT(&spapr->phbs);
 
target-ppc/translate_init.c +5 -0
index 1b0ff38..d24920b 100644
@@ -7381,6 +7381,10 @@ static void init_ppc_proc(PowerPCCPU *cpu)
     /* PowerPC implementation specific initialisations (SPRs, timers, ...) */
     (*pcc->init_proc)(env);
 
+    if (cpu_parse_options(CPU(cpu))) {
+        exit(1);
+    }
+
     /* MSR bits & flags consistency checks */
     if (env->msr_mask & (1 << 25)) {
         switch (env->flags & (POWERPC_FLAG_SPE | POWERPC_FLAG_VRE)) {
@@ -8676,6 +8680,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void
 *data)
 #endif
 
     dc->fw_name = "PowerPC,UNKNOWN";
+    cc->parse_options = cpu_default_parse_options_func;
 }
 

static const TypeInfo ppc_cpu_type_info = {

Signature · 1 line
Alexey
#4 lore raw
Quoted 8 lines · Alexey Kardashevskiy
Quoted 7 lines · Alexey Kardashevskiy
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy <[email protected]> wrote:

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Ping, anyone?
Patch is too bad? Any new idea how to rework it? Someone else is coming with a new patch?

Andreas, is that what you asked me to ping you about? :)

I guess it is outdated and I have to rework it, I just did not have chance yet...

Quoted 147 lines

Thanks

Quoted 141 lines
Quoted 27 lines
Quoted 27 lines

---
Changes:
v4:
* moved QemuOpts logic to qeom/cpu.c
* added cpu_opt_get() as the machine init code wants to know the CPU name to create a CPU object

---
 include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++
 qom/cpu.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c              | 23 +++++++++++++++++++++++
 3 files changed, 113 insertions(+)
include/qom/cpu.h +1 -0
index 7739e00..07330e1 100644
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif
 
Quoted 10 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 338

Quoted 9 lines
include/qom/cpu.h +8 -0
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ *
+ * Parses CPU options if the CPU class has a custom handler defined.
+ *
+ * Returns: -1 if a custom handler is defined and failed, 0 otherwise.
+ */
+static inline int cpu_parse_options(CPUState *cpu)

why not pass up the stack errp, vs returning -1?

Oh. Overlooked it. Not sure if we really need Error** here, do we?

object_property_parse() will print an error anyway and QEMU then exits and qemu_opt_foreach() cannot carry Error** to the caller so I'll better drop it on this level.

Quoted 20 lines

And of cause, there should be a patch that demonstrates an actual user of cpu_parse_options().

Quoted 17 lines
include/qom/cpu.h +17 -0
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
Quoted 8 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 360

Quoted 5 lines
include/qom/cpu.h +5 -0
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);

where is it used?
Maybe it should be static inside of qom/cpu.c
and assigned in cpu_class_init() for TYPE_CPU.

It is assigned for TYPE_POWERPC_CPU as I really do not want to switch every single CPU in QEMU to use this so this is why it is not static.

Below is how I use it for POWERPC. Next time I'll post these patches together, sorry for inconvenience.

hw/ppc/spapr.c +4 -1
index d93abdc..7e0fb68 100644
@@ -33,6 +33,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
+#include "qom/cpu.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
@@ -1111,7 +1112,7 @@ static SaveVMHandlers savevm_htab_handlers = {
 static void ppc_spapr_init(QEMUMachineInitArgs *args)
 {
     ram_addr_t ram_size = args->ram_size;
-    const char *cpu_model = args->cpu_model;
+    const char *cpu_model;
     const char *kernel_filename = args->kernel_filename;
     const char *kernel_cmdline = args->kernel_cmdline;
     const char *initrd_filename = args->initrd_filename;
@@ -1131,6 +1132,8 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 
     msi_supported = true;
 
+    cpu_model = cpu_opt_get("type");
+
     spapr = g_malloc0(sizeof(*spapr));
     QLIST_INIT(&spapr->phbs);
 
target-ppc/translate_init.c +5 -0
index 1b0ff38..d24920b 100644
@@ -7381,6 +7381,10 @@ static void init_ppc_proc(PowerPCCPU *cpu)
     /* PowerPC implementation specific initialisations (SPRs, timers, ...) */
     (*pcc->init_proc)(env);
 
+    if (cpu_parse_options(CPU(cpu))) {
+        exit(1);
+    }
+
     /* MSR bits & flags consistency checks */
     if (env->msr_mask & (1 << 25)) {
         switch (env->flags & (POWERPC_FLAG_SPE | POWERPC_FLAG_VRE)) {
@@ -8676,6 +8680,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void
 *data)
 #endif
 
     dc->fw_name = "PowerPC,UNKNOWN";
+    cc->parse_options = cpu_default_parse_options_func;
 }
 

static const TypeInfo ppc_cpu_type_info = {

Signature · 1 line
Alexey
#5 lore raw
Quoted 18 lines · Alexey Kardashevskiy
Quoted 8 lines · Alexey Kardashevskiy
Quoted 7 lines · Alexey Kardashevskiy
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy <[email protected]> wrote:

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Ping, anyone?
Patch is too bad? Any new idea how to rework it? Someone else is coming with a new patch?

Quoted 4 lines

Andreas, is that what you asked me to ping you about? :)

I guess it is outdated and I have to rework it, I just did not have chance yet...

Makes sense to repost it against current upstream or not yet?

Quoted 151 lines
Quoted 149 lines

Thanks

Quoted 141 lines
Quoted 27 lines
Quoted 27 lines

---
Changes:
v4:
* moved QemuOpts logic to qeom/cpu.c
* added cpu_opt_get() as the machine init code wants to know the CPU name to create a CPU object

---
 include/qom/cpu.h | 41 +++++++++++++++++++++++++++++++++++++++++
 qom/cpu.c         | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c              | 23 +++++++++++++++++++++++
 3 files changed, 113 insertions(+)
include/qom/cpu.h +1 -0
index 7739e00..07330e1 100644
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,46 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif
 
Quoted 10 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 338

Quoted 9 lines
include/qom/cpu.h +8 -0
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ *
+ * Parses CPU options if the CPU class has a custom handler defined.
+ *
+ * Returns: -1 if a custom handler is defined and failed, 0 otherwise.
+ */
+static inline int cpu_parse_options(CPUState *cpu)

why not pass up the stack errp, vs returning -1?

Oh. Overlooked it. Not sure if we really need Error** here, do we?

object_property_parse() will print an error anyway and QEMU then exits and qemu_opt_foreach() cannot carry Error** to the caller so I'll better drop it on this level.

Quoted 20 lines

And of cause, there should be a patch that demonstrates an actual user of cpu_parse_options().

Quoted 17 lines
include/qom/cpu.h +17 -0
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
Quoted 8 lines

include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 360

Quoted 5 lines
include/qom/cpu.h +5 -0
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);

where is it used?
Maybe it should be static inside of qom/cpu.c
and assigned in cpu_class_init() for TYPE_CPU.

It is assigned for TYPE_POWERPC_CPU as I really do not want to switch every single CPU in QEMU to use this so this is why it is not static.

Below is how I use it for POWERPC. Next time I'll post these patches together, sorry for inconvenience.

hw/ppc/spapr.c +4 -1
index d93abdc..7e0fb68 100644
@@ -33,6 +33,7 @@
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
+#include "qom/cpu.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
@@ -1111,7 +1112,7 @@ static SaveVMHandlers savevm_htab_handlers = {
 static void ppc_spapr_init(QEMUMachineInitArgs *args)
 {
     ram_addr_t ram_size = args->ram_size;
-    const char *cpu_model = args->cpu_model;
+    const char *cpu_model;
     const char *kernel_filename = args->kernel_filename;
     const char *kernel_cmdline = args->kernel_cmdline;
     const char *initrd_filename = args->initrd_filename;
@@ -1131,6 +1132,8 @@ static void ppc_spapr_init(QEMUMachineInitArgs *args)
 
     msi_supported = true;
 
+    cpu_model = cpu_opt_get("type");
+
     spapr = g_malloc0(sizeof(*spapr));
     QLIST_INIT(&spapr->phbs);
 
target-ppc/translate_init.c +5 -0
index 1b0ff38..d24920b 100644
@@ -7381,6 +7381,10 @@ static void init_ppc_proc(PowerPCCPU *cpu)
     /* PowerPC implementation specific initialisations (SPRs, timers, ...) */
     (*pcc->init_proc)(env);
 
+    if (cpu_parse_options(CPU(cpu))) {
+        exit(1);
+    }
+
     /* MSR bits & flags consistency checks */
     if (env->msr_mask & (1 << 25)) {
         switch (env->flags & (POWERPC_FLAG_SPE | POWERPC_FLAG_VRE)) {
@@ -8676,6 +8680,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void
 *data)
 #endif
 
     dc->fw_name = "PowerPC,UNKNOWN";
+    cc->parse_options = cpu_default_parse_options_func;
 }
 

static const TypeInfo ppc_cpu_type_info = {

Signature · 1 line
Alexey
#6 lore raw

Am 20.02.2014 14:24, schrieb Alexey Kardashevskiy:

Quoted 19 lines · Alexey Kardashevskiy
Quoted 18 lines · Alexey Kardashevskiy
Quoted 15 lines · Alexey Kardashevskiy
Quoted 9 lines · Igor Mammedov
Quoted 8 lines
Quoted 5 lines · On Tue, 3 Dec 2013 14:42:48 +1100 Alexey Kardashevskiy <[email protected]> wrote:

This adds suboptions support for -cpu. This keeps @cpu_model in order not to break the existing architectures/machines.

Ping, anyone?
Patch is too bad? Any new idea how to rework it? Someone else is coming with a new patch?

Quoted 6 lines
Quoted 4 lines

Andreas, is that what you asked me to ping you about? :)

I guess it is outdated and I have to rework it, I just did not have chance yet...

Makes sense to repost it against current upstream or not yet?

No, I just mentioned on IRC today that I have it on my TODO list after X86CPU subclasses, to rework in a linux-user compatible way (which does not use QemuOpts but an environment variable). Sorry for the delays.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg