On Tue, Apr 16, 2019 at 11:59:41PM -0300, Eduardo Habkost wrote: > The new function will be useful in user mode, when we already > have a CPU model and don't need to parse any extra options. > > Signed-off-by: Eduardo Habkost <ehabk...@redhat.com>
Reviewed-by: David Gibson <da...@gibson.dropbear.id.au> > --- > include/qom/cpu.h | 9 +++++++++ > exec.c | 22 ++++++++++++---------- > 2 files changed, 21 insertions(+), 10 deletions(-) > > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index d28c690b27..e11b14d9ac 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -699,6 +699,15 @@ CPUState *cpu_create(const char *typename); > */ > const char *parse_cpu_option(const char *cpu_option); > > +/** > + * lookup_cpu_class: > + * @cpu_model: CPU model name > + * > + * Look up CPU class corresponding to a given CPU model name. > + */ > +CPUClass *lookup_cpu_class(const char *cpu_model, Error **errp); > + > + > /** > * cpu_has_work: > * @cpu: The vCPU to check. > diff --git a/exec.c b/exec.c > index 840677f15f..d359e709a6 100644 > --- a/exec.c > +++ b/exec.c > @@ -982,24 +982,26 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) > #endif > } > > +CPUClass *lookup_cpu_class(const char *cpu_model, Error **errp) > +{ > + ObjectClass *oc = cpu_class_by_name(CPU_RESOLVING_TYPE, cpu_model); > + if (oc == NULL) { > + error_setg(errp, "unable to find CPU model '%s'", cpu_model); > + return NULL; > + } > + return CPU_CLASS(oc); > +} > + > const char *parse_cpu_option(const char *cpu_option) > { > - ObjectClass *oc; > CPUClass *cc; > gchar **model_pieces; > const char *cpu_type; > > model_pieces = g_strsplit(cpu_option, ",", 2); > > - oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]); > - if (oc == NULL) { > - error_report("unable to find CPU model '%s'", model_pieces[0]); > - g_strfreev(model_pieces); > - exit(EXIT_FAILURE); > - } > - > - cpu_type = object_class_get_name(oc); > - cc = CPU_CLASS(oc); > + cc = lookup_cpu_class(model_pieces[0], &error_fatal); > + cpu_type = object_class_get_name(OBJECT_CLASS(cc)); > cc->parse_features(cpu_type, model_pieces[1], &error_fatal); > g_strfreev(model_pieces); > return cpu_type; -- 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
signature.asc
Description: PGP signature