arm: virt: Parse cpu_model only once

Considering that features are converted to global properties and
global properties are automatically applied to every new instance
of created CPU (at object_new() time), there is no point in
parsing cpu_model string every time a CPU created. So move
parsing outside CPU creation loop and do it only once.

Parsing also should be done before any CPU is created so that
features would affect the first CPU a well.

Backports commit 09f71b054a95161950a03fafc9023637929bd404 from qemu
This commit is contained in:
Igor Mammedov 2018-03-20 12:04:32 -04:00 committed by Lioncash
parent 87db6e033b
commit d5a14f8232
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -62,6 +62,10 @@ static int machvirt_init(struct uc_struct *uc, MachineState *machine)
{ {
const char *cpu_model = machine->cpu_model; const char *cpu_model = machine->cpu_model;
char **cpustr; char **cpustr;
ObjectClass *oc;
const char *typename;
CPUClass *cc;
Error *err = NULL;
int n; int n;
if (!cpu_model) { if (!cpu_model) {
@ -73,28 +77,28 @@ static int machvirt_init(struct uc_struct *uc, MachineState *machine)
/* Separate the actual CPU model name from any appended features */ /* Separate the actual CPU model name from any appended features */
cpustr = g_strsplit(cpu_model, ",", 2); cpustr = g_strsplit(cpu_model, ",", 2);
oc = cpu_class_by_name(uc, TYPE_ARM_CPU, cpustr[0]);
if (!oc) {
fprintf(stderr, "Unable to find CPU definition");
return -1;
}
typename = object_class_get_name(oc);
/* convert -smp CPU options specified by the user into global props */
cc = CPU_CLASS(uc, oc);
cc->parse_features(uc, typename, cpustr[1], &err);
g_strfreev(cpustr);
if (err) {
fprintf(stderr, "Error parsing cpu features");
return -1;
}
for (n = 0; n < smp_cpus; n++) { for (n = 0; n < smp_cpus; n++) {
ObjectClass *oc = cpu_class_by_name(uc, TYPE_ARM_CPU, cpustr[0]); Object *cpuobj = object_new(uc, typename);
char *cpuopts = g_strdup(cpustr[1]);
CPUClass *cc = CPU_CLASS(uc, oc);
Object *cpuobj;
Error *err = NULL;
const char *typename = object_class_get_name(oc);
if (!oc) {
fprintf(stderr, "Unable to find CPU definition\n");
return -1;
}
/* convert -smp CPU options specified by the user into global props */
cc->parse_features(uc, typename, cpuopts, &err);
cpuobj = object_new(uc, typename);
uc->cpu = CPU(cpuobj); uc->cpu = CPU(cpuobj);
object_property_set_bool(uc, cpuobj, true, "realized", NULL); object_property_set_bool(uc, cpuobj, true, "realized", NULL);
g_free(cpuopts);
} }
g_strfreev(cpustr);
return 0; return 0;
} }