vl.c: convert cpu_model to cpu type and set of global properties before machine_init()

All machines that support user specified cpu_model either call
cpu_generic_init() or cpu_class_by_name()/CPUClass::parse_features
to parse feature string and to get CPU type to create.

Which leads to code duplication and hard-codding default CPU model
within machine_foo_init() code. Which makes it impossible to
get CPU type before machine_init() is run.

So instead of setting default CPUs models and doing parsing in
target specific machine_foo_init() in various ways, provide
a generic data driven cpu_model parsing before machine_init()
is called.

in follow up per target patches, it will allow to:
* define default CPU type in consistent/generic manner
per machine type and drop custom code that fallbacks
to default if cpu_model is NULL
* drop custom features parsing in targets and do it
in centralized way.
* for cases of
cpu_generic_init(TYPE_BASE/DEFAULT_CPU, "some_cpu")
replace it with
cpu_create(machine->cpu_type) || cpu_create(TYPE_FOO)
depending if CPU type is user settable or not.
not doing useless parsing and clearly documenting where
CPU model is user settable or fixed one.

Patch allows machine subclasses to define default CPU type
per machine class at class_init() time and if that is set
generic code will parse cpu_model into a MachineState::cpu_type
which will be used to create CPUs for that machine instance
and allows gradual per board conversion.

Backports commit 6063d4c0f98b35a27ca018393d328a1825412a7e from qemu
This commit is contained in:
Igor Mammedov 2018-03-20 13:12:37 -04:00 committed by Lioncash
parent 555eeb4120
commit 733d60e6d7
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7
2 changed files with 11 additions and 0 deletions

View File

@ -62,6 +62,10 @@ MachineClass *find_default_machine(struct uc_struct *uc, int arch);
/** /**
* MachineClass: * MachineClass:
* @default_cpu_type:
* specifies default CPU_TYPE, which will be used for parsing target
* specific features and for creating CPUs if CPU name wasn't provided
* explicitly at CLI
* @minimum_page_bits: * @minimum_page_bits:
* If non-zero, the board promises never to create a CPU with a page size * If non-zero, the board promises never to create a CPU with a page size
* smaller than this, so QEMU can use a more efficient larger page * smaller than this, so QEMU can use a more efficient larger page
@ -91,6 +95,7 @@ struct MachineClass {
int max_cpus; int max_cpus;
int is_default; int is_default;
const char *default_cpu_type;
int arch; int arch;
int minimum_page_bits; int minimum_page_bits;
bool has_hotpluggable_cpus; bool has_hotpluggable_cpus;
@ -108,6 +113,7 @@ struct MachineState {
ram_addr_t ram_size; ram_addr_t ram_size;
ram_addr_t maxram_size; ram_addr_t maxram_size;
const char *cpu_model; const char *cpu_model;
const char *cpu_type;
struct uc_struct *uc; struct uc_struct *uc;
AccelState *accelerator; AccelState *accelerator;
}; };

View File

@ -164,6 +164,11 @@ int machine_initialize(struct uc_struct *uc)
current_machine->cpu_model = NULL; current_machine->cpu_model = NULL;
/* parse features once if machine provides default cpu_type */
if (machine_class->default_cpu_type) {
current_machine->cpu_type = machine_class->default_cpu_type;
}
return machine_class->init(uc, current_machine); return machine_class->init(uc, current_machine);
} }