Add a valid_cpu_types property
Subsystems (3)
v5 cover Add a valid_cpu_types property
There are numorous QEMU machines that only have a single or a handful of valid CPU options. To simplyfy the management of specificying which CPU is/isn't valid let's create a property that can be set in the machine init. We can then check to see if the user supplied CPU is in that list or not.
I have added the valid_cpu_types for some ARM machines only at the moment.
Here is what specifying the CPUs looks like now:
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m3" -S QEMU 2.10.50 monitor - type 'help' for more information (qemu) info cpus * CPU #0: thread_id=24175 (qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m4" -S QEMU 2.10.50 monitor - type 'help' for more information (qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m5" -S qemu-system-aarch64: unable to find CPU model 'cortex-m5'
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-a9" -S qemu-system-aarch64: Invalid CPU type: cortex-a9-arm-cpu The valid models are: cortex-m3, cortex-m4
V5:
- Use cpu_model instead of cpu_type
V4:
- Rebase
- Remove spaces
V3:
- Make the varialbes static
V2:
- Rebase
- Reorder patches
- Add a Raspberry Pi 2 CPU fix
V1:
- Small fixes to prepare a series instead of RFC
- Add commit messages for the commits
- Expand the machine support to ARM machines
RFC v2:
- Rebase on Igor's work
- Use more QEMUisms inside the code
- List the supported machines in a NULL terminated array
Alistair Francis (6):
machine: Convert the valid cpu types to use cpu_model
netduino2: Specify the valid CPUs
bcm2836: Use the Cortex-A7 instead of Cortex-A15
raspi: Specify the valid CPUs
xlnx-zcu102: Specify the valid CPUs
xilinx_zynq: Specify the valid CPUs
hw/arm/bcm2836.c | 2 +- hw/arm/netduino2.c | 10 +++++++++- hw/arm/raspi.c | 7 +++++++ hw/arm/xilinx_zynq.c | 6 ++++++ hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++ hw/core/machine.c | 11 +++++------ 6 files changed, 45 insertions(+), 8 deletions(-)
Signature · 1 line
2.14.1
PATCH v5 1/6 machine: Convert the valid cpu types to use cpu_model
As cpu_type is not a user visible string let's convert the valid_cpu_types to compare against cpu_model instead. This way we have a user friendly string to report back.
Once we have a cpu_type to cpu_model conversion this patch should be reverted and we should use cpu_type instead.
---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/core/machine.c +5 -6
@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ -if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {/* The user specificed CPU is in the valid field, we are * good to go. */
@@ -792,8 +791,8 @@ void machine_run_board_init(MachineState *machine)if (!machine_class->valid_cpu_types[i]) {/* The user specified CPU is not valid */ -error_report ("Invalid CPU type: %s" , machine->cpu_type); -error_printf ("The valid types are: %s" , +error_report ("Invalid CPU model: %s" , machine->cpu_model); +error_printf ("The valid models are: %s" , machine_class->valid_cpu_types[0 ]);for (i =1 ; machine_class->valid_cpu_types[i]; i++) {error_printf (", %s" , machine_class->valid_cpu_types[i]);
Signature · 1 line
2.14.1
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */
hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {
I would rename valid_cpu_types to valid_cpu_models to make the new semantics clearer.
Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove MachineState::cpu_model, so this conflicts with his series. Now parse_cpu_model() will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Use cpu_create(type) instead of cpu_init(cpu_model)".
The good news is that I think we can fix this very easily if validation is done at the same place where parse_cpu_model() is called. e.g.:
current_machine->cpu_type = machine_class->default_cpu_type;
if (cpu_model) {
current_machine->cpu_type = parse_cpu_model(cpu_model);
if (machine_class->valid_cpu_models) {
ObjectClass *class = object_class_by_name(machine->cpu_type);
int i;
for (i = 0; machine_class->valid_cpu_models[i]; i++) {
const char *valid_model = machine_class->valid_cpu_models[i];
ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model);
if (object_class_dynamic_cast(class,
object_class_get_name(valid_class))) {
/* Valid CPU type, we're good to go */
break;
}
}
if (!machine_class->valid_cpu_models[i]) {
error_report("Invalid CPU model: %s", cpu_model);
error_printf("The valid CPU models are: %s",
machine_class->valid_cpu_models[0]);
for (i = 1; machine_class->valid_cpu_models[i]; i++) {
error_printf(", %s", machine_class->valid_cpu_models[i]);
}
error_printf("\n");
exit(1);
}
}
}This can be done inside main(), or moved inside machine_run_board_init() if main() pass cpu_model as argument to the function.
On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
Quoted 18 lines
hw/core/machine.c +2
-2/* The user specificed CPU is in the valid field, we are * good to go. */ @@ -792,8 +791,8 @@ void machine_run_board_init(MachineState *machine)if (!machine_class->valid_cpu_types[i]) {/* The user specified CPU is not valid */ -error_report ("Invalid CPU type: %s" , machine->cpu_type); -error_printf ("The valid types are: %s" , +error_report ("Invalid CPU model: %s" , machine->cpu_model); +error_printf ("The valid models are: %s" , machine_class->valid_cpu_types[0 ]);for (i =1 ; machine_class->valid_cpu_types[i]; i++) {error_printf (", %s" , machine_class->valid_cpu_types[i]);Signature · 1 line
2.14.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }
Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents ms->cpu_model creeping back into boards code.
But I still dislike (hate) an idea of new code adding non canonized cpu_model strings back in the boards code. It's just a matter of time when someone would use them and cpu_model parsing will creep back into boards.
It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char *cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:
target/arm/cpu.h +2 -0
@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu) return cpu->el_change_hook_opaque; } +char *arm_cpu_name_by_type_name (const char *typename); +#endif
hw/arm/netduino2.c +1 -0
@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name: }DEFINE_MACHINE ("netduino2" , netduino2_machine_init)
target/arm/cpu.c +5 -0
@@ -928,6 +928,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) acc->parent_realize (dev, errp); } +char *arm_cpu_name_by_type_name (const char *typename) +{ +return g_strndup (typename,strlen (typename) -strlen ("-" TYPE_ARM_CPU )); +} +static ObjectClass *arm_cpu_class_by_name (const char *cpu_model) {ObjectClass *oc;
target/arm/helper.c +2 -3
@@ -5373,7 +5373,7 @@ static void arm_cpu_list_entry(gpointer data, gpointer user_data)char *name; typename =object_class_get_name (oc); - name =g_strndup (typename,strlen (typename) -strlen ("-" TYPE_ARM_CPU )); + name =arm_cpu_name_by_type_name (typename); (*s->cpu_fprintf)(s->file," %s\n" , name);g_free (name);
@@ -5410,8 +5410,7 @@ static void arm_cpu_add_definition(gpointer data, gpointer user_data) typename =object_class_get_name (oc); info =g_malloc0 (sizeof (*info)); - info->name =g_strndup (typename, -strlen (typename) -strlen ("-" TYPE_ARM_CPU )); + info->name =arm_cpu_name_by_type_name (typename); info->q_typename =g_strdup (typename); entry =g_malloc0 (sizeof (*entry));
vl.c +5 -0
@@ -4646,6 +4646,11 @@ int main(int argc, char **argv, char **envp)if (cpu_model) { current_machine->cpu_type =cpu_parse_cpu_model (machine_class->default_cpu_type, cpu_model); + + if !is_valid_cpu(current_machine->cpu_type) + print("valid cpu types: ") + for_each_valid_type + print(machine_class->cpu_name_by_type_name()) } }
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 119 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +2
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu) return cpu->el_change_hook_opaque; } +char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +0
-0
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 4 lines
hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:
I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
I agree it would be better if we had a cpu_name_by_type_name() function, but I would like to have it implemented cleanly.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }
Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
unfortunately cpu_model (cpu name part) is target specific and it's translation to type and back is target specific mayhem.
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global cpu_name_by_type_name() instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.
Quoted 2 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.
In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid putting cpu_model names back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.
(seeing this series reposted with cpu_model names in boards code, it doesn't looks like author would like to implement tree-wide generalization first)
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 131 lines · Igor Mammedov
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
Quoted 2 lines
unfortunately
cpu_model(cpu name part) is target specific and it's translation to type and back is target specific mayhem.
Why can't the model<->type translation be represented as data? We could have simple cpu_type_name_suffix + an alias table.
We have at least 4 arches that return a constant at class_by_name. We have at least 10 arches that simply add a suffix to the CPU model name. We must make them use common code instead of requiring them to implement yet another hook[1].
In addition to the ones above, we have 3 that seem to just need an alias table (cris, superh, alpha). ppc can probably also use an alias table for the ppc_cpu_class_by_pvr() stuff. sparc just needs whitespaces translated to '-' (sparc), which can be done using an alias table.
In the end I couldn't find any example that can't be represented by a suffix + alias table.
Quoted 7 lines
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global
cpu_name_by_type_name()instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.
I don't mind letting a few targets override default behavior with a hook if really necessary, but I have a problem with requiring all targets to implement what's basically the same boilerplate code to add/remove a string suffix and translating aliases.
Quoted 12 lines
Quoted 3 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid puttingcpu_modelnames back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.
Quoted 3 lines
(seeing this series reposted with
cpu_modelnames in boards code, it doesn't looks like author would like to implement tree-wide generalization first)
Well, if nobody is willing to generalize all target-specific code right now, I don't see the harm in having cpu_model-based tables in a few boards in the meantime (as this patch series does). But I do see harm in requiring all our 20 targets to implement yet another hook and increasing the costs of cleaning up the mess later.
---
[1] Really, this amount of duplication is insane:
static char *mips_cpu_type_name(const char *cpu_model)
{
return g_strdup_printf(MIPS_CPU_TYPE_NAME("%s"), cpu_model);
}static ObjectClass *mips_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = mips_cpu_type_name(cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
return oc;
}static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(TRICORE_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU) ||
object_class_is_abstract(oc)) {
return NULL;
}
return oc;
}static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(UNICORE32_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
object_class_is_abstract(oc))) {
oc = NULL;
}
return oc;
}static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc == NULL || !object_class_dynamic_cast(oc, TYPE_XTENSA_CPU) ||
object_class_is_abstract(oc)) {
return NULL;
}
return oc;
}static char *x86_cpu_type_name(const char *model_name)
{
return g_strdup_printf(X86_CPU_TYPE_NAME("%s"), model_name);
}static ObjectClass *x86_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
if (cpu_model == NULL) {
return NULL;
}
typename = x86_cpu_type_name(cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
return oc;
}static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
char **cpuname;
cpuname = g_strsplit(cpu_model, ",", 1);
typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpuname[0]);
oc = object_class_by_name(typename);
g_strfreev(cpuname);
g_free(typename);
if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) ||
object_class_is_abstract(oc)) {
return NULL;
}
return oc;
}static ObjectClass *lm32_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(LM32_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_LM32_CPU) ||
object_class_is_abstract(oc))) {
oc = NULL;
}
return oc;
}static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
object_class_is_abstract(oc))) {
return NULL;
}
return oc;
}static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
object_class_is_abstract(oc))) {
return NULL;
}
return oc;
}static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
typename = g_strdup_printf(OPENRISC_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU) ||
object_class_is_abstract(oc))) {
return NULL;
}
return oc;
}Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 135 lines · On Mon, 5 Feb 2018 20:42:05 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 131 lines · Igor Mammedov
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
Quoted 2 lines
unfortunately
cpu_model(cpu name part) is target specific and it's translation to type and back is target specific mayhem.
Quoted 7 lines
Why can't the model<->type translation be represented as data? We could have simple
cpu_type_name_suffix+ an alias table.We have at least 4 arches that return a constant at
class_by_name. We have at least 10 arches that simply add a suffix to the CPU model name. We must make them use common code instead of requiring them to implement yet another hook[1].
True, some of them could use generic hook and reduce code duplication greatly, we should do it regardless of whether table or target specific func approach is used.
Quoted 8 lines
In addition to the ones above, we have 3 that seem to just need an alias table (cris, superh, alpha). ppc can probably also use an alias table for the
ppc_cpu_class_by_pvr()stuff. sparc just needs whitespaces translated to '-' (sparc), which can be done using an alias table.In the end I couldn't find any example that can't be represented by a suffix + alias table.
Table based approach is possible but it won't be as simple as you've just pictured it.
From what I recall from cpu_class_by_name cleanups table should be able
to describe cases like (sometimes combination of them):
* 1:1 mapping - where cpu_model == cpu_type
* cpu_model <==> cpu_model + suffix - most common usecase
* cpu_model <==> prefix cpu_model - riscv patches on list are trying to add such cpu types
* NULL => some_fixed type
* case (in) sensitive flag
* garbage => some_fixed type
* substitutions
* aliases (sometimes dynamic depending on --enable-kvm (PPC))
Maybe something else.
We can think about it at leisure but I can't say if new approach complexity it's worth of the effort.
It would be nice see impl, but it's a lot of refactoring that's clearly out of scope of this series.
I'd prefer small incremental refactoring (if possible) that won't scare people of and easy to review vs a huge one.
Quoted 11 lines
Quoted 6 lines
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global
cpu_name_by_type_name()instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.I don't mind letting a few targets override default behavior with a hook if really necessary, but I have a problem with requiring all targets to implement what's basically the same boilerplate code to add/remove a string suffix and translating aliases.
it could be generic helper if target does the same plus not mandatory at that (in case target/board doesn't care about valid cpus).
Quoted 15 lines
Quoted 11 lines
Quoted 2 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid puttingcpu_modelnames back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.Quoted 3 lines
(seeing this series reposted with
cpu_modelnames in boards code, it doesn't looks like author would like to implement tree-wide generalization first)
Quoted 6 lines
Well, if nobody is willing to generalize all target-specific code right now, I don't see the harm in having cpu_model-based tables in a few boards in the meantime (as this patch series does). But I do see harm in requiring all our 20 targets to implement yet another hook and increasing the costs of cleaning up the mess later.
If we use MachineClass hook then it might be done per target on demand, so no one would require that every target should implement it.
Also there could be a generic helper for targets that do the same. Machine which needs to enable valid_cpus, will have to use generic hook impl or provide target specific if it's special case.
Though I do see harm in adding cpu_model tables in boards code vs target specific hooks on demand as that will be copy-pasted in other boards afterwards (number of which is bigger compared to targets count) and ultimately it would duplicate cpu_name strings in every board vs hook approach where cpu_model could be calculated from cpu_type by a function (generic or target specific).
Good thing about hook is that it's non intrusive and isolates(consolidates) existing cpu_type -> cpu_model conversion in multiple places into one place. Then later it would be easier to generalize if someone decides to do it.
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Hi Igor, Eduardo,
Quoted 232 lines · Igor Mammedov
Quoted 135 lines · On Mon, 5 Feb 2018 20:42:05 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 131 lines · Igor Mammedov
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
Quoted 2 lines
unfortunately
cpu_model(cpu name part) is target specific and it's translation to type and back is target specific mayhem.Quoted 7 lines
Why can't the model<->type translation be represented as data? We could have simple
cpu_type_name_suffix+ an alias table.We have at least 4 arches that return a constant at
class_by_name. We have at least 10 arches that simply add a suffix to the CPU model name. We must make them use common code instead of requiring them to implement yet another hook[1].True, some of them could use generic hook and reduce code duplication greatly, we should do it regardless of whether table or target specific func approach is used.
Quoted 8 lines
In addition to the ones above, we have 3 that seem to just need an alias table (cris, superh, alpha). ppc can probably also use an alias table for the
ppc_cpu_class_by_pvr()stuff. sparc just needs whitespaces translated to '-' (sparc), which can be done using an alias table.In the end I couldn't find any example that can't be represented by a suffix + alias table.
Table based approach is possible but it won't be as simple as you've just pictured it.
From what I recall from
cpu_class_by_namecleanups table should be able
to describe cases like (sometimes combination of them):
* 1:1 mapping - wherecpu_model==cpu_type
*cpu_model<==>cpu_model+ suffix - most common usecase
*cpu_model<==> prefixcpu_model- riscv patches on list are trying to add such cpu types
* NULL =>some_fixedtype
* case (in) sensitive flag
* garbage =>some_fixedtype
* substitutions
* aliases (sometimes dynamic depending on --enable-kvm (PPC))
Maybe something else.We can think about it at leisure but I can't say if new approach complexity it's worth of the effort.
It would be nice see impl, but it's a lot of refactoring that's clearly out of scope of this series.
I'd prefer small incremental refactoring (if possible) that won't scare people of and easy to review vs a huge one.Quoted 11 lines
Quoted 6 lines
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global
cpu_name_by_type_name()instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.I don't mind letting a few targets override default behavior with a hook if really necessary, but I have a problem with requiring all targets to implement what's basically the same boilerplate code to add/remove a string suffix and translating aliases.
it could be generic helper if target does the same plus not mandatory at that (in case target/board doesn't care about valid cpus).
Quoted 15 lines
Quoted 11 lines
Quoted 2 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid puttingcpu_modelnames back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.Quoted 3 lines
(seeing this series reposted with
cpu_modelnames in boards code, it doesn't looks like author would like to implement tree-wide generalization first)Quoted 6 lines
Well, if nobody is willing to generalize all target-specific code right now, I don't see the harm in having cpu_model-based tables in a few boards in the meantime (as this patch series does). But I do see harm in requiring all our 20 targets to implement yet another hook and increasing the costs of cleaning up the mess later.
If we use MachineClass hook then it might be done per target on demand, so no one would require that every target should implement it.
Also there could be a generic helper for targets that do the same. Machine which needs to enablevalid_cpus, will have to use generic hook impl or provide target specific if it's special case.Though I do see harm in adding
cpu_modeltables in boards code vs target specific hooks on demand as that will be copy-pasted in other boards afterwards (number of which is bigger compared to targets count) and ultimately it would duplicatecpu_namestrings in every board vs hook approach wherecpu_modelcould be calculated fromcpu_typeby a function (generic or target specific).
Quoted 5 lines
Good thing about hook is that it's non intrusive and isolates(consolidates) existing
cpu_type->cpu_modelconversion in multiple places into one place. Then later it would be easier to generalize if someone decides to do it.
I wonder how you want to proceed with this series, the first patch got merged (c9cf636d48f) but after your "CPU model name" rework, this commit seems now not very complete/usable.
Rebasing this series, i.e. with this snippet:
-- >8 --
hw/arm/netduino2.c +7 -2
@@ -34,7 +34,7 @@ static void netduino2_init(MachineState *machine)DeviceState *dev; dev =qdev_create (NULL ,TYPE_STM32F205_SOC ); -qdev_prop_set_string (dev,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m3" )); +qdev_prop_set_string (dev,"cpu-type" , machine->cpu_type);object_property_set_bool (OBJECT (dev), true,"realized" , &error_fatal); armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
@@ -43,8 +43,14 @@ static void netduino2_init(MachineState *machine)static void netduino2_machine_init (MachineClass *mc) { +static const char *valid_cpus[] = { +ARM_CPU_TYPE_NAME ("cortex-m3" ), +ARM_CPU_TYPE_NAME ("cortex-m4" ), +NULL + }; mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; + mc->valid_cpu_types = valid_cpus; mc->ignore_memory_transaction_failures = true; } ---
We get cpu names with suffix:
$ arm-softmmu/qemu-system-arm -M netduino2 -cpu arm926 qemu-system-arm: Invalid CPU type: arm926-arm-cpu The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpu
I understand you won't want a global cpu_name_by_type_name, how do you want to do then?
Should we define an automatically expanded TARGET_CPU_TYPE_SUFFIX? Then we could have generic machine code to parse the names.
Thanks,
Phil.
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
On Mon, Jun 17, 2019 at 07:09:59AM +0200, Philippe Mathieu-Daudé wrote:
[...]
Quoted 9 lines
We get cpu names with suffix:
$ arm-softmmu/qemu-system-arm -M netduino2 -cpu arm926 qemu-system-arm: Invalid CPU type: arm926-arm-cpu The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpuI understand you won't want a global
cpu_name_by_type_name, how do you want to do then?
I would like having a global cpu_name_by_type_name() function. I wouldn't want to force each architecture to provide yet another string conversion/parsing function, though.
Quoted 3 lines
Should we define an automatically expanded
TARGET_CPU_TYPE_SUFFIX? Then we could have generic machine code to parse the names.
I think we could do that, but with a CPUClass field instead of a preprocessor macro.
For a reference on existing corner cases of CPU model name parsing that might get in the way, see this series:
https://www.mail-archive.com/[email protected]/msg611813.html
If you are interested, I have work in progress for a generic CPU model listing function at:
https://github.com/ehabkost/qemu-hacks/commits/work/cpu-generic-list
https://github.com/ehabkost/qemu-hacks/commit/df122e7e47476d7e2b7b809a4b4120537f50c137
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
In reply to Philippe Mathieu-DaudéQuoted 283 lines · On Mon, 17 Jun 2019 07:09:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Hi Igor, Eduardo,
Quoted 232 lines · Igor Mammedov
Quoted 135 lines · On Mon, 5 Feb 2018 20:42:05 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 131 lines · Igor Mammedov
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
Quoted 2 lines
unfortunately
cpu_model(cpu name part) is target specific and it's translation to type and back is target specific mayhem.Quoted 7 lines
Why can't the model<->type translation be represented as data? We could have simple
cpu_type_name_suffix+ an alias table.We have at least 4 arches that return a constant at
class_by_name. We have at least 10 arches that simply add a suffix to the CPU model name. We must make them use common code instead of requiring them to implement yet another hook[1].True, some of them could use generic hook and reduce code duplication greatly, we should do it regardless of whether table or target specific func approach is used.
Quoted 8 lines
In addition to the ones above, we have 3 that seem to just need an alias table (cris, superh, alpha). ppc can probably also use an alias table for the
ppc_cpu_class_by_pvr()stuff. sparc just needs whitespaces translated to '-' (sparc), which can be done using an alias table.In the end I couldn't find any example that can't be represented by a suffix + alias table.
Table based approach is possible but it won't be as simple as you've just pictured it.
From what I recall from
cpu_class_by_namecleanups table should be able
to describe cases like (sometimes combination of them):
* 1:1 mapping - wherecpu_model==cpu_type
*cpu_model<==>cpu_model+ suffix - most common usecase
*cpu_model<==> prefixcpu_model- riscv patches on list are trying to add such cpu types
* NULL =>some_fixedtype
* case (in) sensitive flag
* garbage =>some_fixedtype
* substitutions
* aliases (sometimes dynamic depending on --enable-kvm (PPC))
Maybe something else.We can think about it at leisure but I can't say if new approach complexity it's worth of the effort.
It would be nice see impl, but it's a lot of refactoring that's clearly out of scope of this series.
I'd prefer small incremental refactoring (if possible) that won't scare people of and easy to review vs a huge one.Quoted 11 lines
Quoted 6 lines
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global
cpu_name_by_type_name()instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.I don't mind letting a few targets override default behavior with a hook if really necessary, but I have a problem with requiring all targets to implement what's basically the same boilerplate code to add/remove a string suffix and translating aliases.
it could be generic helper if target does the same plus not mandatory at that (in case target/board doesn't care about valid cpus).
Quoted 15 lines
Quoted 11 lines
Quoted 2 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid puttingcpu_modelnames back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.Quoted 3 lines
(seeing this series reposted with
cpu_modelnames in boards code, it doesn't looks like author would like to implement tree-wide generalization first)Quoted 6 lines
Well, if nobody is willing to generalize all target-specific code right now, I don't see the harm in having cpu_model-based tables in a few boards in the meantime (as this patch series does). But I do see harm in requiring all our 20 targets to implement yet another hook and increasing the costs of cleaning up the mess later.
If we use MachineClass hook then it might be done per target on demand, so no one would require that every target should implement it.
Also there could be a generic helper for targets that do the same. Machine which needs to enablevalid_cpus, will have to use generic hook impl or provide target specific if it's special case.Though I do see harm in adding
cpu_modeltables in boards code vs target specific hooks on demand as that will be copy-pasted in other boards afterwards (number of which is bigger compared to targets count) and ultimately it would duplicatecpu_namestrings in every board vs hook approach wherecpu_modelcould be calculated fromcpu_typeby a function (generic or target specific).Quoted 5 lines
Good thing about hook is that it's non intrusive and isolates(consolidates) existing
cpu_type->cpu_modelconversion in multiple places into one place. Then later it would be easier to generalize if someone decides to do it.I wonder how you want to proceed with this series, the first patch got merged (
c9cf636d48f) but after your "CPU model name" rework, this commit seems now not very complete/usable.Rebasing this series, i.e. with this snippet:
-- >8 --
hw/arm/netduino2.c +7
-2@@ -34,7 +34,7 @@ static void netduino2_init(MachineState *machine)DeviceState *dev; dev =qdev_create (NULL ,TYPE_STM32F205_SOC ); -qdev_prop_set_string (dev,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m3" )); +qdev_prop_set_string (dev,"cpu-type" , machine->cpu_type);object_property_set_bool (OBJECT (dev), true,"realized" , &error_fatal); armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,@@ -43,8 +43,14 @@ static void netduino2_init(MachineState *machine)static void netduino2_machine_init (MachineClass *mc) { +static const char *valid_cpus[] = { +ARM_CPU_TYPE_NAME ("cortex-m3" ), +ARM_CPU_TYPE_NAME ("cortex-m4" ), +NULL + }; mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; + mc->valid_cpu_types = valid_cpus; mc->ignore_memory_transaction_failures = true; } ---We get cpu names with suffix:
$ arm-softmmu/qemu-system-arm -M netduino2 -cpu arm926 qemu-system-arm: Invalid CPU type: arm926-arm-cpu The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpu
Quoted 5 lines
I understand you won't want a global
cpu_name_by_type_name, how do you want to do then?Should we define an automatically expanded
TARGET_CPU_TYPE_SUFFIX? Then we could have generic machine code to parse the names.
It would work only for some cases,
problem is that we have a zoo of naming schemes. Considering that cpus models are used widely we probably can't deprecate it outright (for versioned machine types).
Instead of wasting resources on translating cpu-type => 'cpu-name', (hook or lookup tables) how about simplifying code and making all boards accept full typenames?
It could be handled in generic way and then printing error with full type names would be acceptable since user would be able to feed it to -cpu.
'-cpu help' - would need some work to display types as well (also could be generic)
Perhaps with it we could deprecate cpu_models for non versioned machines/targets, which in most cases would allow us to drop special suffix/prefix/nonsense/case-sensitive/substitutions and whatever else is already existing and keep exiting translation routines (hooks) only for versioned machine types as necessary evil.
Quoted 3 lines
Thanks,
Phil.
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 304 lines · Igor Mammedov
Quoted 283 lines · On Mon, 17 Jun 2019 07:09:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Hi Igor, Eduardo,
Quoted 232 lines · Igor Mammedov
Quoted 135 lines · On Mon, 5 Feb 2018 20:42:05 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 131 lines · Igor Mammedov
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
Quoted 2 lines
unfortunately
cpu_model(cpu name part) is target specific and it's translation to type and back is target specific mayhem.Quoted 7 lines
Why can't the model<->type translation be represented as data? We could have simple
cpu_type_name_suffix+ an alias table.We have at least 4 arches that return a constant at
class_by_name. We have at least 10 arches that simply add a suffix to the CPU model name. We must make them use common code instead of requiring them to implement yet another hook[1].True, some of them could use generic hook and reduce code duplication greatly, we should do it regardless of whether table or target specific func approach is used.
Quoted 8 lines
In addition to the ones above, we have 3 that seem to just need an alias table (cris, superh, alpha). ppc can probably also use an alias table for the
ppc_cpu_class_by_pvr()stuff. sparc just needs whitespaces translated to '-' (sparc), which can be done using an alias table.In the end I couldn't find any example that can't be represented by a suffix + alias table.
Table based approach is possible but it won't be as simple as you've just pictured it.
From what I recall from
cpu_class_by_namecleanups table should be able
to describe cases like (sometimes combination of them):
* 1:1 mapping - wherecpu_model==cpu_type
*cpu_model<==>cpu_model+ suffix - most common usecase
*cpu_model<==> prefixcpu_model- riscv patches on list are trying to add such cpu types
* NULL =>some_fixedtype
* case (in) sensitive flag
* garbage =>some_fixedtype
* substitutions
* aliases (sometimes dynamic depending on --enable-kvm (PPC))
Maybe something else.We can think about it at leisure but I can't say if new approach complexity it's worth of the effort.
It would be nice see impl, but it's a lot of refactoring that's clearly out of scope of this series.
I'd prefer small incremental refactoring (if possible) that won't scare people of and easy to review vs a huge one.Quoted 11 lines
Quoted 6 lines
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global
cpu_name_by_type_name()instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.I don't mind letting a few targets override default behavior with a hook if really necessary, but I have a problem with requiring all targets to implement what's basically the same boilerplate code to add/remove a string suffix and translating aliases.
it could be generic helper if target does the same plus not mandatory at that (in case target/board doesn't care about valid cpus).
Quoted 15 lines
Quoted 11 lines
Quoted 2 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid puttingcpu_modelnames back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.Quoted 3 lines
(seeing this series reposted with
cpu_modelnames in boards code, it doesn't looks like author would like to implement tree-wide generalization first)Quoted 6 lines
Well, if nobody is willing to generalize all target-specific code right now, I don't see the harm in having cpu_model-based tables in a few boards in the meantime (as this patch series does). But I do see harm in requiring all our 20 targets to implement yet another hook and increasing the costs of cleaning up the mess later.
If we use MachineClass hook then it might be done per target on demand, so no one would require that every target should implement it.
Also there could be a generic helper for targets that do the same. Machine which needs to enablevalid_cpus, will have to use generic hook impl or provide target specific if it's special case.Though I do see harm in adding
cpu_modeltables in boards code vs target specific hooks on demand as that will be copy-pasted in other boards afterwards (number of which is bigger compared to targets count) and ultimately it would duplicatecpu_namestrings in every board vs hook approach wherecpu_modelcould be calculated fromcpu_typeby a function (generic or target specific).Quoted 5 lines
Good thing about hook is that it's non intrusive and isolates(consolidates) existing
cpu_type->cpu_modelconversion in multiple places into one place. Then later it would be easier to generalize if someone decides to do it.I wonder how you want to proceed with this series, the first patch got merged (
c9cf636d48f) but after your "CPU model name" rework, this commit seems now not very complete/usable.Rebasing this series, i.e. with this snippet:
-- >8 --
hw/arm/netduino2.c +7
-2@@ -34,7 +34,7 @@ static void netduino2_init(MachineState *machine)DeviceState *dev; dev =qdev_create (NULL ,TYPE_STM32F205_SOC ); -qdev_prop_set_string (dev,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m3" )); +qdev_prop_set_string (dev,"cpu-type" , machine->cpu_type);object_property_set_bool (OBJECT (dev), true,"realized" , &error_fatal); armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,@@ -43,8 +43,14 @@ static void netduino2_init(MachineState *machine)static void netduino2_machine_init (MachineClass *mc) { +static const char *valid_cpus[] = { +ARM_CPU_TYPE_NAME ("cortex-m3" ), +ARM_CPU_TYPE_NAME ("cortex-m4" ), +NULL + }; mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; + mc->valid_cpu_types = valid_cpus; mc->ignore_memory_transaction_failures = true; } ---We get cpu names with suffix:
$ arm-softmmu/qemu-system-arm -M netduino2 -cpu arm926 qemu-system-arm: Invalid CPU type: arm926-arm-cpu The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpuQuoted 5 lines
I understand you won't want a global
cpu_name_by_type_name, how do you want to do then?Should we define an automatically expanded
TARGET_CPU_TYPE_SUFFIX? Then we could have generic machine code to parse the names.It would work only for some cases,
problem is that we have a zoo of naming schemes. Considering that cpus models are used widely we probably can't deprecate it outright (for versioned machine types).Instead of wasting resources on translating cpu-type => 'cpu-name', (hook or lookup tables) how about simplifying code and making all boards accept full typenames?
It could be handled in generic way and then printing error with full type names would be acceptable since user would be able to feed it to -cpu.
Quoted 7 lines
'-cpu help' - would need some work to display types as well (also could be generic)
Perhaps with it we could deprecate
cpu_modelsfor non versioned machines/targets, which in most cases would allow us to drop special suffix/prefix/nonsense/case-sensitive/substitutions and whatever else is already existing and keep exiting translation routines (hooks) only for versioned machine types as necessary evil.
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
I feel concerned because:
1/ Alistair series is very helpful to new users, and
2/ As the RX architecture series showed, today it is not very clear how to correctly use cpu_models.
Eduardo is working on a series, I'll wait for his work.
Regards,
Phil.
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 305 lines · On Mon, 17 Jun 2019 17:15:21 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 304 lines · Igor Mammedov
Quoted 283 lines · On Mon, 17 Jun 2019 07:09:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Hi Igor, Eduardo,
Quoted 232 lines · Igor Mammedov
Quoted 135 lines · On Mon, 5 Feb 2018 20:42:05 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 131 lines · Igor Mammedov
Quoted 112 lines · On Mon, 5 Feb 2018 11:54:01 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 111 lines · Igor Mammedov
Quoted 78 lines · On Fri, 2 Feb 2018 16:23:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 21 lines · Alistair Francis
As
cpu_typeis not a user visible string let's convert thevalid_cpu_typesto compare againstcpu_modelinstead. This way we have a user friendly string to report back.Once we have a
cpu_typetocpu_modelconversion this patch should be reverted and we should usecpu_typeinstead.Signed-off-by Alistair Francis <[email protected]>---
hw/core/machine.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/core/machine.c +0
-0@@ -776,13 +776,12 @@ void machine_run_board_init(MachineState *machine)/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */ hw/core/machine.c void machine_run_board_init(MachineState *machine) · line 784
Quoted 10 lines
hw/core/machine.c +3
-4-if (machine_class->valid_cpu_types && machine->cpu_type) { -ObjectClass *class =object_class_by_name (machine->cpu_type); +if (machine_class->valid_cpu_types && machine->cpu_model) {int i;for (i =0 ; machine_class->valid_cpu_types[i]; i++) { -if (object_class_dynamic_cast (class, - machine_class->valid_cpu_types[i])) { +if (!strcmp (machine->cpu_model, + machine_class->valid_cpu_types[i])) {I would rename
valid_cpu_typestovalid_cpu_modelsto make the new semantics clearer.Anyway, I have bad and good news:
The bad news is Igor already sent patches last week that remove
MachineState::cpu_model, so this conflicts with his series. Nowparse_cpu_model()will be the only place where the original CPU model name is available, but the function needs to work on *-user too. See:
"[PATCH v3 23/25] Usecpu_create(type)instead ofcpu_init(cpu_model)".The good news is that I think we can fix this very easily if validation is done at the same place where
parse_cpu_model()is called. e.g.:current_machine->cpu_type = machine_class->default_cpu_type; if (cpu_model) { current_machine->cpu_type = parse_cpu_model(cpu_model); if (machine_class->valid_cpu_models) { ObjectClass *class = object_class_by_name(machine->cpu_type); int i; for (i = 0; machine_class->valid_cpu_models[i]; i++) { const char *valid_model = machine_class->valid_cpu_models[i]; ObjectClass *valid_class = cpu_class_by_name(machine->cpu_type, valid_model); if (object_class_dynamic_cast(class, object_class_get_name(valid_class))) { /* Valid CPU type, we're good to go */ break; } } if (!machine_class->valid_cpu_models[i]) { error_report("Invalid CPU model: %s", cpu_model); error_printf("The valid CPU models are: %s", machine_class->valid_cpu_models[0]); for (i = 1; machine_class->valid_cpu_models[i]; i++) { error_printf(", %s", machine_class->valid_cpu_models[i]); } error_printf("\n"); exit(1); } } }Quoted 8 lines
This can be done inside
main(), or moved insidemachine_run_board_init()ifmain()passcpu_modelas argument to the function.On either case, I think it's a good idea to do validation and printing of error messages closer to the code that parses the command-line options. This way we separate parsing/validation from initialization.
I agree it's better like you suggest as at least it prevents
ms->cpu_modelcreeping back into boards code.But I still dislike (hate) an idea of new code adding non canonized
cpu_modelstrings back in the boards code. It's just a matter of time when someone would use them andcpu_modelparsing will creep back into boards.It would be much better to if we add
char *MachineClass::cpu_name_by_type_name(char*cpu_type)
callback and let machines in this patchset to set it, something along following lines which is not much of refactoring and allows for gradual conversion:target/arm/cpu.h +0
-0@@ -2885,4 +2885,6 @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu)return cpu->el_change_hook_opaque; }Quoted 16 lines
hw/arm/netduino2.c static void netduino2_machine_init(MachineClass *mc) · line 49
Quoted 12 lines
target/arm/cpu.h +2
-0+char *arm_cpu_name_by_type_name (const char *typename); +#endif hw/arm/netduino2.c +1
-0@@ -46,6 +46,7 @@ static void netduino2_machine_init(MachineClass *mc) mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->cpu_name_by_type_name = arm_cpu_name_by_type_name:I really don't want to introduce a new arch-specific hook just for that. We should move CPU type lookup logic to common code and make it unnecessary to write new hooks.
Quoted 2 lines
unfortunately
cpu_model(cpu name part) is target specific and it's translation to type and back is target specific mayhem.Quoted 7 lines
Why can't the model<->type translation be represented as data? We could have simple
cpu_type_name_suffix+ an alias table.We have at least 4 arches that return a constant at
class_by_name. We have at least 10 arches that simply add a suffix to the CPU model name. We must make them use common code instead of requiring them to implement yet another hook[1].True, some of them could use generic hook and reduce code duplication greatly, we should do it regardless of whether table or target specific func approach is used.
Quoted 8 lines
In addition to the ones above, we have 3 that seem to just need an alias table (cris, superh, alpha). ppc can probably also use an alias table for the
ppc_cpu_class_by_pvr()stuff. sparc just needs whitespaces translated to '-' (sparc), which can be done using an alias table.In the end I couldn't find any example that can't be represented by a suffix + alias table.
Table based approach is possible but it won't be as simple as you've just pictured it.
From what I recall from
cpu_class_by_namecleanups table should be able
to describe cases like (sometimes combination of them):
* 1:1 mapping - wherecpu_model==cpu_type
*cpu_model<==>cpu_model+ suffix - most common usecase
*cpu_model<==> prefixcpu_model- riscv patches on list are trying to add such cpu types
* NULL =>some_fixedtype
* case (in) sensitive flag
* garbage =>some_fixedtype
* substitutions
* aliases (sometimes dynamic depending on --enable-kvm (PPC))
Maybe something else.We can think about it at leisure but I can't say if new approach complexity it's worth of the effort.
It would be nice see impl, but it's a lot of refactoring that's clearly out of scope of this series.
I'd prefer small incremental refactoring (if possible) that won't scare people of and easy to review vs a huge one.Quoted 11 lines
Quoted 6 lines
So I'd prefer having both back and forth functions together in one place. And common code to call them when necessary.
We could do global
cpu_name_by_type_name()instead of hook, which I'd prefer even more but then conversion can't be done only for one target but rather for all targets at once.I don't mind letting a few targets override default behavior with a hook if really necessary, but I have a problem with requiring all targets to implement what's basically the same boilerplate code to add/remove a string suffix and translating aliases.
it could be generic helper if target does the same plus not mandatory at that (in case target/board doesn't care about valid cpus).
Quoted 15 lines
Quoted 11 lines
Quoted 2 lines
I agree it would be better if we had a
cpu_name_by_type_name()function, but I would like to have it implemented cleanly.In some cases(targets) it can be common helper, but in other
cases it's not so.
My suggestion though allows to do gradual conversion and
avoid puttingcpu_modelnames back in board's code (which I just manged to remove). Once all targets converted and relevant code is isolated
we can attempt to generalize it if it's possible or at least
make of it global per target helper to get rid of
temporary machine hook.Quoted 3 lines
(seeing this series reposted with
cpu_modelnames in boards code, it doesn't looks like author would like to implement tree-wide generalization first)Quoted 6 lines
Well, if nobody is willing to generalize all target-specific code right now, I don't see the harm in having cpu_model-based tables in a few boards in the meantime (as this patch series does). But I do see harm in requiring all our 20 targets to implement yet another hook and increasing the costs of cleaning up the mess later.
If we use MachineClass hook then it might be done per target on demand, so no one would require that every target should implement it.
Also there could be a generic helper for targets that do the same. Machine which needs to enablevalid_cpus, will have to use generic hook impl or provide target specific if it's special case.Though I do see harm in adding
cpu_modeltables in boards code vs target specific hooks on demand as that will be copy-pasted in other boards afterwards (number of which is bigger compared to targets count) and ultimately it would duplicatecpu_namestrings in every board vs hook approach wherecpu_modelcould be calculated fromcpu_typeby a function (generic or target specific).Quoted 5 lines
Good thing about hook is that it's non intrusive and isolates(consolidates) existing
cpu_type->cpu_modelconversion in multiple places into one place. Then later it would be easier to generalize if someone decides to do it.I wonder how you want to proceed with this series, the first patch got merged (
c9cf636d48f) but after your "CPU model name" rework, this commit seems now not very complete/usable.Rebasing this series, i.e. with this snippet:
-- >8 --
hw/arm/netduino2.c +7
-2@@ -34,7 +34,7 @@ static void netduino2_init(MachineState *machine)DeviceState *dev; dev =qdev_create (NULL ,TYPE_STM32F205_SOC ); -qdev_prop_set_string (dev,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m3" )); +qdev_prop_set_string (dev,"cpu-type" , machine->cpu_type);object_property_set_bool (OBJECT (dev), true,"realized" , &error_fatal); armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,@@ -43,8 +43,14 @@ static void netduino2_init(MachineState *machine)static void netduino2_machine_init (MachineClass *mc) { +static const char *valid_cpus[] = { +ARM_CPU_TYPE_NAME ("cortex-m3" ), +ARM_CPU_TYPE_NAME ("cortex-m4" ), +NULL + }; mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; + mc->valid_cpu_types = valid_cpus; mc->ignore_memory_transaction_failures = true; } ---We get cpu names with suffix:
$ arm-softmmu/qemu-system-arm -M netduino2 -cpu arm926 qemu-system-arm: Invalid CPU type: arm926-arm-cpu The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpuQuoted 5 lines
I understand you won't want a global
cpu_name_by_type_name, how do you want to do then?Should we define an automatically expanded
TARGET_CPU_TYPE_SUFFIX? Then we could have generic machine code to parse the names.It would work only for some cases,
problem is that we have a zoo of naming schemes. Considering that cpus models are used widely we probably can't deprecate it outright (for versioned machine types).Instead of wasting resources on translating cpu-type => 'cpu-name', (hook or lookup tables) how about simplifying code and making all boards accept full typenames?
It could be handled in generic way and then printing error with full type names would be acceptable since user would be able to feed it to -cpu.
Quoted 7 lines
Quoted 7 lines
'-cpu help' - would need some work to display types as well (also could be generic)
Perhaps with it we could deprecate
cpu_modelsfor non versioned machines/targets, which in most cases would allow us to drop special suffix/prefix/nonsense/case-sensitive/substitutions and whatever else is already existing and keep exiting translation routines (hooks) only for versioned machine types as necessary evil.
Maybe we don't even need to keep it versioned machine types, considering change mapping is static and doesn't influence ABI/migration. Management interface could just translate cpu_model to type name for new QEMU.
That would allow us to remove quite a bit target specific code that deals with all permutations of CPU model and replace a bunch of '-cpu help' target specific handlers with a generic enumeration of built-in CPU types.
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of class_by_name callbacks to find out current state.
Quoted 4 lines
I feel concerned because:
1/ Alistair series is very helpful to new users, and
2/ As the RX architecture series showed, today it is not very clear how to correctly usecpu_models.
That's why I'm pushing for supporting only type names whenever possible so there won't be confusion anymore. Using types is consistent with -device and some QMP interfaces, enforces strict error checking so user would get error on nonsense input.
Quoted 5 lines
Eduardo is working on a series, I'll wait for his work.
Regards,
Phil.
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:
[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.
See this message for a summary of existing class_by_name quirks:
https://www.mail-archive.com/[email protected]/msg615503.html
Date: Wed, 08 May 2019 10:34:44 +0200
Message-ID: <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16 *_cpu_class_by_name() functions
I'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 16 lines · On Mon, 17 Jun 2019 13:27:00 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.See this message for a summary of existing
class_by_namequirks:https://www.mail-archive.com/[email protected]/msg615503.html
Date: Wed, 08 May 2019 10:34:44 +0200
Message-ID: <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16*_cpu_class_by_name()functions
Quoted 4 lines
I'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
as far as we have cpu_class_by_name, we have to watch over that new patches/targets won't add some custom handling/fallbac/whatnot.
On contrary -device works just with type names for all devices, applying the same to -cpu which is basically translator
model->type[,-global type.foo,...]
would be consistent with -device and less confusing for everyone (not counting significant code reduction).
It would certainly simplify contributing new targets as contributor won't have to care about cpu model naming and do something about it.
This option wasn't considered before because we didn't have deprecation back then, but now it opens possibility to simplify qemu and consolidate naming. (we probably would be able to fold '-cpu help' into '-device help' as well).
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 19 lines · Igor Mammedov
Quoted 16 lines · On Mon, 17 Jun 2019 13:27:00 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.See this message for a summary of existing
class_by_namequirks:https://www.mail-archive.com/[email protected]/msg615503.html
Date: Wed, 08 May 2019 10:34:44 +0200
Message-ID: <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16*_cpu_class_by_name()functions
Quoted 6 lines
Quoted 4 lines
I'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
as far as we have
cpu_class_by_name, we have to watch over that new patches/targets won't add some custom handling/fallbac/whatnot.
We can get rid of CPUClass::cpu_class_by_name() without changing the external interfaces provided by QEMU.
I don't have a strong opinion about using only QOM types at -cpu, yet. But first we need to get rid of the arch-specific CPU model name exceptions enumerated at the URL above (which would be very welcome).
Quoted 14 lines
On contrary -device works just with type names for all devices, applying the same to -cpu which is basically translator
model->type[,-global type.foo,...]
would be consistent with -device and less confusing for everyone (not counting significant code reduction).
It would certainly simplify contributing new targets as contributor won't have to care about cpu model naming and do something about it.This option wasn't considered before because we didn't have deprecation back then, but now it opens possibility to simplify qemu and consolidate naming. (we probably would be able to fold '-cpu help' into '-device help' as well).
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 24 lines · On Tue, 18 Jun 2019 10:55:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 23 lines · Igor Mammedov
Quoted 20 lines · On Mon, 17 Jun 2019 13:27:00 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.See this message for a summary of existing
class_by_namequirks:https://www.mail-archive.com/[email protected]/msg615503.html
Date: Wed, 08 May 2019 10:34:44 +0200
Message-ID: <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16*_cpu_class_by_name()functionsI'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
Quoted 5 lines
Quoted 2 lines
as far as we have
cpu_class_by_name, we have to watch over that new patches/targets won't add some custom handling/fallbac/whatnot.We can get rid of
CPUClass::cpu_class_by_name()without changing the external interfaces provided by QEMU.
if you mean QMP, than it is possible to keep model there where it already exists. Based on experiment [1](x86) I did, it's local to affected target and doesn't pollute other code.
Quoted 4 lines
I don't have a strong opinion about using only QOM types at -cpu, yet. But first we need to get rid of the arch-specific CPU model name exceptions enumerated at the URL above (which would be very welcome).
One way to get rid of them is to deprecate them in favor of strict match (no fallback/substitutions/aliases) to typename and when we drop it make switch type based naming only.
1) I've just took a quick look at how much of duplicated/confusing code we could get rid off if we drop cpu_class_by_name/*_cpu_list. It amounts to >800LOC of trivial removal (not counting ppc/s390 that depend on model naming heavily and in need of some non trivial refactoring)
Quoted 16 lines
Quoted 15 lines
On contrary -device works just with type names for all devices, applying the same to -cpu which is basically translator
model->type[,-global type.foo,...]
would be consistent with -device and less confusing for everyone (not counting significant code reduction).
It would certainly simplify contributing new targets as contributor won't have to care about cpu model naming and do something about it.This option wasn't considered before because we didn't have deprecation back then, but now it opens possibility to simplify qemu and consolidate naming. (we probably would be able to fold '-cpu help' into '-device help' as well).
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 27 lines · Igor Mammedov
Quoted 24 lines · On Tue, 18 Jun 2019 10:55:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 23 lines · Igor Mammedov
Quoted 20 lines · On Mon, 17 Jun 2019 13:27:00 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.See this message for a summary of existing
class_by_namequirks:https://www.mail-archive.com/[email protected]/msg615503.html
Date: Wed, 08 May 2019 10:34:44 +0200
Message-ID: <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16*_cpu_class_by_name()functionsI'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
as far as we have
cpu_class_by_name, we have to watch over that new patches/targets won't add some custom handling/fallbac/whatnot.We can get rid of
CPUClass::cpu_class_by_name()without changing the external interfaces provided by QEMU.if you mean QMP, than it is possible to keep model there where it already exists. Based on experiment [1](x86) I did, it's local to affected target and doesn't pollute other code.
I mean both command line and QMP.
Quoted 8 lines
Quoted 5 lines
I don't have a strong opinion about using only QOM types at -cpu, yet. But first we need to get rid of the arch-specific CPU model name exceptions enumerated at the URL above (which would be very welcome).
One way to get rid of them is to deprecate them in favor of strict match (no fallback/substitutions/aliases) to typename and when we drop it make switch type based naming only.
This is true, but is it desirable? Aren't we just moving complexity elsewhere? Management software would still need to translate CPU models from existing VM configurations to QOM type names.
Quoted 6 lines
1) I've just took a quick look at how much of duplicated/confusing code we could get rid off if we drop cpu_class_by_name/*_cpu_list. It amounts to >800LOC of trivial removal (not counting ppc/s390 that depend on model naming heavily and in need of some non trivial refactoring)
Removing the code might be trivial. Coordinating with the maintainers of all architectures to confirm this is really something everybody wants is the difficult part.
If you really want to do it, please make sure all the architecture maintainers (and libvirt developers) are involved in the discussion.
Quoted 18 lines
Quoted 17 lines
Quoted 16 lines
On contrary -device works just with type names for all devices, applying the same to -cpu which is basically translator
model->type[,-global type.foo,...]
would be consistent with -device and less confusing for everyone (not counting significant code reduction).
It would certainly simplify contributing new targets as contributor won't have to care about cpu model naming and do something about it.This option wasn't considered before because we didn't have deprecation back then, but now it opens possibility to simplify qemu and consolidate naming. (we probably would be able to fold '-cpu help' into '-device help' as well).
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 60 lines · Eduardo Habkost
Quoted 27 lines · Igor Mammedov
Quoted 24 lines · On Tue, 18 Jun 2019 10:55:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 23 lines · Igor Mammedov
Quoted 20 lines · On Mon, 17 Jun 2019 13:27:00 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.See this message for a summary of existing
class_by_namequirks:https://www.mail-archive.com/[email protected]/msg615503.html Date: Wed, 08 May 2019 10:34:44 +0200 Message-ID: <[email protected]> Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16 *_cpu_class_by_name() functionsI'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
as far as we have
cpu_class_by_name, we have to watch over that new patches/targets won't add some custom handling/fallbac/whatnot.We can get rid of
CPUClass::cpu_class_by_name()without changing the external interfaces provided by QEMU.if you mean QMP, than it is possible to keep model there where it already exists. Based on experiment [1](x86) I did, it's local to affected target and doesn't pollute other code.
I mean both command line and QMP.
Quoted 8 lines
Quoted 5 lines
I don't have a strong opinion about using only QOM types at -cpu, yet. But first we need to get rid of the arch-specific CPU model name exceptions enumerated at the URL above (which would be very welcome).
One way to get rid of them is to deprecate them in favor of strict match (no fallback/substitutions/aliases) to typename and when we drop it make switch type based naming only.
This is true, but is it desirable? Aren't we just moving complexity elsewhere? Management software would still need to translate CPU models from existing VM configurations to QOM type names.
Quoted 6 lines
1) I've just took a quick look at how much of duplicated/confusing code we could get rid off if we drop cpu_class_by_name/*_cpu_list. It amounts to >800LOC of trivial removal (not counting ppc/s390 that depend on model naming heavily and in need of some non trivial refactoring)
Quoted 7 lines
Removing the code might be trivial. Coordinating with the maintainers of all architectures to confirm this is really something everybody wants is the difficult part.
If you really want to do it, please make sure all the architecture maintainers (and libvirt developers) are involved in the discussion.
From the previous link (summary of existing class_by_name quirks):
https://www.mail-archive.com/[email protected]/msg615737.html
"Deprecating unwanted stuff now is likely to make a
later cleanup so much easier."
This was 8 months ago :/
IIUC we need to restart this topic addressing the libvirt community first, then see with the QEMU one?
Quoted 20 lines
Quoted 19 lines
Quoted 18 lines
Quoted 17 lines
On contrary -device works just with type names for all devices, applying the same to -cpu which is basically translator
model->type[,-global type.foo,...]would be consistent with -device and less confusing for everyone (not counting significant code reduction).
It would certainly simplify contributing new targets as contributor won't have to care about cpu model naming and do something about it.This option wasn't considered before because we didn't have deprecation back then, but now it opens possibility to simplify qemu and consolidate naming. (we probably would be able to fold '-cpu help' into '-device help' as well).
Re: [Qemu-devel] [PATCH v5 1/6] machine: Convert the valid cpu types to use cpu_model
Quoted 71 lines · Philippe Mathieu-Daudé
Quoted 59 lines · Eduardo Habkost
Quoted 26 lines · Igor Mammedov
Quoted 23 lines · On Tue, 18 Jun 2019 10:55:16 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 22 lines · Igor Mammedov
Quoted 20 lines · On Mon, 17 Jun 2019 13:27:00 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov
On Mon, 17 Jun 2019 17:15:21 +0200
Philippe Mathieu-Daudé <[email protected]> wrote:[...]
Quoted 4 lines
Quoted 2 lines
Yes. Eduardo and you should write some lines to explain this, and then we will follow :)
Unfortunately I don't recall details anymore. One could check out all implementations of
class_by_namecallbacks to find out current state.See this message for a summary of existing
class_by_namequirks:https://www.mail-archive.com/[email protected]/msg615503.html Date: Wed, 08 May 2019 10:34:44 +0200 Message-ID: <[email protected]> Subject: Re: [Qemu-devel] [PATCH 0/7] Delete 16 *_cpu_class_by_name() functionsI'm unsure about Igor's suggestion to get rid of CPU model names and use only QOM type names in external interfaces. In either case, we can still simplify the rules rules and reduce the amount of arch-specific code.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
as far as we have
cpu_class_by_name, we have to watch over that new patches/targets won't add some custom handling/fallbac/whatnot.We can get rid of
CPUClass::cpu_class_by_name()without changing the external interfaces provided by QEMU.if you mean QMP, than it is possible to keep model there where it already exists. Based on experiment [1](x86) I did, it's local to affected target and doesn't pollute other code.
I mean both command line and QMP.
Quoted 8 lines
Quoted 5 lines
I don't have a strong opinion about using only QOM types at -cpu, yet. But first we need to get rid of the arch-specific CPU model name exceptions enumerated at the URL above (which would be very welcome).
One way to get rid of them is to deprecate them in favor of strict match (no fallback/substitutions/aliases) to typename and when we drop it make switch type based naming only.
This is true, but is it desirable? Aren't we just moving complexity elsewhere? Management software would still need to translate CPU models from existing VM configurations to QOM type names.
Quoted 6 lines
1) I've just took a quick look at how much of duplicated/confusing code we could get rid off if we drop cpu_class_by_name/*_cpu_list. It amounts to >800LOC of trivial removal (not counting ppc/s390 that depend on model naming heavily and in need of some non trivial refactoring)
Quoted 7 lines
Removing the code might be trivial. Coordinating with the maintainers of all architectures to confirm this is really something everybody wants is the difficult part.
If you really want to do it, please make sure all the architecture maintainers (and libvirt developers) are involved in the discussion.
From the previous link (summary of existing
class_by_namequirks):
https://www.mail-archive.com/[email protected]/msg615737.html
Quoted 7 lines
"Deprecating unwanted stuff now is likely to make a
later cleanup so much easier."This was 8 months ago :/
IIUC we need to restart this topic addressing the libvirt community first, then see with the QEMU one?
The next step is to deprecate the weird and pointless exceptions
listed at the URL you mentioned. Not all exceptions will affect libvirt (maybe most won't).
In either case, we can just use qemu-deprecated.texi to communicate this to libvirt developers. MAINTAINERS already has a "R: libvir-list" line for qemu-deprecated.texi.
Signature · 1 line
Eduardo
PATCH v5 2/6 netduino2: Specify the valid CPUs
In reply to Alistair FrancisList all possible valid CPU options.
Although the board only ever has a Cortex-M3 we mark the Cortex-M4 as supported because the Netduino2 Plus supports the Cortex-M4 and the Netduino2 Plus is similar to the Netduino2.
---
V5:
- Use cpu_model names
V3:
- Add static property
V2:
- Fixup allignment
RFC v2:
- Use a NULL terminated list
- Add the Cortex-M4 for testing
hw/arm/netduino2.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
hw/arm/netduino2.c +9 -1
@@ -34,18 +34,26 @@ static void netduino2_init(MachineState *machine)DeviceState *dev; dev =qdev_create (NULL ,TYPE_STM32F205_SOC ); -qdev_prop_set_string (dev,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m3" )); +qdev_prop_set_string (dev,"cpu-type" , machine->cpu_type);object_property_set_bool (OBJECT (dev), true,"realized" , &error_fatal);armv7m_load_kernel (ARM_CPU (first_cpu), machine->kernel_filename,FLASH_SIZE ); } +static const char *netduino_valid_cpus[] = { +"cortex-m3" , +"cortex-m4" , +NULL +}; +static void netduino2_machine_init (MachineClass *mc) { mc->desc ="Netduino 2 Machine" ; mc->init = netduino2_init; mc->ignore_memory_transaction_failures = true; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m3" ); + mc->valid_cpu_types = netduino_valid_cpus; }DEFINE_MACHINE ("netduino2" , netduino2_machine_init)
Signature · 1 line
2.14.1
PATCH v5 3/6 bcm2836: Use the Cortex-A7 instead of Cortex-A15
In reply to Alistair FrancisThe BCM2836 uses a Cortex-A7 not a Cortex-A15. Update the device to use the correct CPU.
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf
---
V3:
- Use ARM_CPU_TYPE_NAME() macro
V2:
- Fix the BCM2836 CPU
hw/arm/bcm2836.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/bcm2836.c +1 -1
@@ -30,7 +30,7 @@ static void bcm2836_init(Object *obj)for (n =0 ; n <BCM2836_NCPUS ; n++) {object_initialize (&s->cpus[n],sizeof (s->cpus[n]), -"cortex-a15-" TYPE_ARM_CPU ); +ARM_CPU_TYPE_NAME ("cortex-a7" ));object_property_add_child (obj,"cpu[*]" ,OBJECT (&s->cpus[n]), &error_abort); }
Signature · 1 line
2.14.1
Re: [Qemu-devel] [PATCH v5 3/6] bcm2836: Use the Cortex-A7 instead of Cortex-A15
Hi Peter,
Quoted 3 lines · Alistair Francis
The BCM2836 uses a Cortex-A7 not a Cortex-A15. Update the device to use the correct CPU.
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf
Can you add these lines with reference to the commits?
When the BCM2836 was introduced (bad5623690b) the Cortex-A7 was not available, so the very similar Cortex-A15 was used.
Since dcf578ed8ce we can model the correct core.
Thanks!
Phil.
Quoted 26 lines
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Igor Mammedov <[email protected]>---
V3:
- UseARM_CPU_TYPE_NAME()macro
V2:
- Fix the BCM2836 CPUhw/arm/bcm2836.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/bcm2836.c +1
-1@@ -30,7 +30,7 @@ static void bcm2836_init(Object *obj)for (n =0 ; n <BCM2836_NCPUS ; n++) {object_initialize (&s->cpus[n],sizeof (s->cpus[n]), -"cortex-a15-" TYPE_ARM_CPU ); +ARM_CPU_TYPE_NAME ("cortex-a7" ));object_property_add_child (obj,"cpu[*]" ,OBJECT (&s->cpus[n]), &error_abort); }
Re: [Qemu-devel] [PATCH v5 3/6] bcm2836: Use the Cortex-A7 instead of Cortex-A15
Quoted 7 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 3 lines · Alistair Francis
The BCM2836 uses a Cortex-A7 not a Cortex-A15. Update the device to use the correct CPU.
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf
Quoted 8 lines
Can you add these lines with reference to the commits?
When the BCM2836 was introduced (
bad5623690b) the Cortex-A7 was not available, so the very similar Cortex-A15 was used.Since
dcf578ed8cewe can model the correct core.Thanks!
Added!
I'm not sure when I'll send the next version out though.
Alistair
Quoted 29 lines
Phil.
Quoted 26 lines
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Igor Mammedov <[email protected]>---
V3:
- UseARM_CPU_TYPE_NAME()macro
V2:
- Fix the BCM2836 CPUhw/arm/bcm2836.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/bcm2836.c +1
-1@@ -30,7 +30,7 @@ static void bcm2836_init(Object *obj)for (n =0 ; n <BCM2836_NCPUS ; n++) {object_initialize (&s->cpus[n],sizeof (s->cpus[n]), -"cortex-a15-" TYPE_ARM_CPU ); +ARM_CPU_TYPE_NAME ("cortex-a7" ));object_property_add_child (obj,"cpu[*]" ,OBJECT (&s->cpus[n]), &error_abort); }
PATCH v5 4/6 raspi: Specify the valid CPUs
In reply to Alistair FrancisList all possible valid CPU options.
---
V5:
- Use cpu_model names
V4:
- Remove spaces
V3:
- Add static property
V2:
- Fix the indentation
hw/arm/raspi.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/arm/raspi.c +7 -0
@@ -158,6 +158,11 @@ static void raspi2_init(MachineState *machine)setup_boot (machine,2 , machine->ram_size - vcram_size); } +static const char *raspi2_valid_cpus[] = { +"cortex-a7" , +NULL +}; +static void raspi2_machine_init (MachineClass *mc) { mc->desc ="Raspberry Pi 2" ;
@@ -171,5 +176,7 @@ static void raspi2_machine_init(MachineClass *mc) mc->default_cpus =BCM2836_NCPUS ; mc->default_ram_size =1024 *1024 *1024 ; mc->ignore_memory_transaction_failures = true; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + mc->valid_cpu_types = raspi2_valid_cpus; };DEFINE_MACHINE ("raspi2" , raspi2_machine_init)
Signature · 1 line
2.14.1
Re: [Qemu-devel] [PATCH v5 4/6] raspi: Specify the valid CPUs
Quoted 23 lines · Alistair Francis
List all possible valid CPU options.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
V5:
- Usecpu_modelnames
V4:
- Remove spaces
V3:
- Add static property
V2:
- Fix the indentationhw/arm/raspi.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/arm/raspi.c +0
-0
hw/arm/raspi.c static void raspi2_init(MachineState *machine) · line 164
Quoted 7 lines
hw/arm/raspi.c +4
-0@@ -158,6 +158,11 @@ static void raspi2_init(MachineState *machine)setup_boot (machine,2 , machine->ram_size - vcram_size); } +static const char *raspi2_valid_cpus[] = { +"cortex-a7" , +NULL +};
Is this definitely right? Looking at the code, the raspi2 board creates a TYPE_BCM2836, and that creates cortex-a15 CPUs...
thanks
-- PMM
Re: [Qemu-devel] [PATCH v5 4/6] raspi: Specify the valid CPUs
Hi Peter,
Quoted 28 lines · Peter Maydell
Quoted 26 lines · Alistair Francis
List all possible valid CPU options.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
V5:
- Usecpu_modelnames
V4:
- Remove spaces
V3:
- Add static property
V2:
- Fix the indentationhw/arm/raspi.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/arm/raspi.c +0
-0@@ -158,6 +158,11 @@ static void raspi2_init(MachineState *machine)setup_boot (machine,2 , machine->ram_size - vcram_size); }
Quoted 7 lines
hw/arm/raspi.c static void raspi2_init(MachineState *machine) · line 164
Quoted 4 lines
hw/arm/raspi.c +4
-0+static const char *raspi2_valid_cpus[] = { +"cortex-a7" , +NULL +};Is this definitely right? Looking at the code, the raspi2 board creates a
TYPE_BCM2836, and that creates cortex-a15 CPUs...
The BCM2836 use a cortex-a7 but this cpu was not available at the time of this commit (bad5623690b) and was added later in dcf578ed8ce "The A7 is very similar to the A15."
I can prepare a patch for it to apply before this series.
Quoted 4 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH v5 4/6] raspi: Specify the valid CPUs
Quoted 39 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 28 lines · Peter Maydell
Quoted 26 lines · Alistair Francis
List all possible valid CPU options.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
V5:
- Usecpu_modelnames
V4:
- Remove spaces
V3:
- Add static property
V2:
- Fix the indentationhw/arm/raspi.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/arm/raspi.c +0
-0@@ -158,6 +158,11 @@ static void raspi2_init(MachineState *machine)setup_boot (machine,2 , machine->ram_size - vcram_size); }Quoted 7 lines
hw/arm/raspi.c static void raspi2_init(MachineState *machine) · line 164
Quoted 4 lines
hw/arm/raspi.c +4
-0+static const char *raspi2_valid_cpus[] = { +"cortex-a7" , +NULL +};Is this definitely right? Looking at the code, the raspi2 board creates a
TYPE_BCM2836, and that creates cortex-a15 CPUs...
Quoted 5 lines
The BCM2836 use a cortex-a7 but this cpu was not available at the time of this commit (
bad5623690b) and was added later indcf578ed8ce"The A7 is very similar to the A15."I can prepare a patch for it to apply before this series.
I noticed after I'd written that comment that patch 3 in this series does exactly the change to cortex-a7...
thanks
-- PMM
Re: [Qemu-devel] [PATCH v5 4/6] raspi: Specify the valid CPUs
Quoted 40 lines · On Thu, 15 Feb 2018 13:17:50 +0000 Peter Maydell <[email protected]>…
Quoted 39 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 35 lines · Peter Maydell
Quoted 23 lines · Alistair Francis
List all possible valid CPU options.
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
V5:
- Usecpu_modelnames
V4:
- Remove spaces
V3:
- Add static property
V2:
- Fix the indentationhw/arm/raspi.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/arm/raspi.c +0
-0hw/arm/raspi.c static void raspi2_init(MachineState *machine) · line 164
Quoted 7 lines
hw/arm/raspi.c +4
-0@@ -158,6 +158,11 @@ static void raspi2_init(MachineState *machine)setup_boot (machine,2 , machine->ram_size - vcram_size); } +static const char *raspi2_valid_cpus[] = { +"cortex-a7" , +NULL +};Is this definitely right? Looking at the code, the raspi2 board creates a
TYPE_BCM2836, and that creates cortex-a15 CPUs...
Quoted 8 lines
Quoted 5 lines
The BCM2836 use a cortex-a7 but this cpu was not available at the time of this commit (
bad5623690b) and was added later indcf578ed8ce"The A7 is very similar to the A15."I can prepare a patch for it to apply before this series.
I noticed after I'd written that comment that patch 3 in this series does exactly the change to cortex-a7...
anyways this series, needs not to depend MachineState::cpu_model, removal of which is queued in Eduardo's tree.
It seems we can't find consensus on how to deal with cpu_model names in boards code [1/6].
Quoted 3 lines
thanks
-- PMM
PATCH v5 5/6 xlnx-zcu102: Specify the valid CPUs
In reply to Alistair FrancisList all possible valid CPU options.
---
An implementation for single CPU machines is still being discussed. A solution proposed by Eduardo is this:
1) Change the default on TYPE_MACHINE to:
mc->valid_cpu_types = { TYPE_CPU, NULL };This will keep the existing behavior for all boards.
2) mc->valid_cpu_types=NULL be interpreted as "no CPU model except the default is accepted" or "-cpu is not accepted" in machine_run_board_init() (I prefer the former, but both options would be correct)
3) Boards like xlnx_zynqmp could then just do this:
static void xxx_class_init(...) {
mc->default_cpu_type = MY_CPU_TYPE;
/* Reason: XXX_init() is hardcoded to MY_CPU_TYPE */
mc->valid_cpu_types = NULL;
}V5:
- Use cpu_model names
V4:
- Remove spaces
V3:
- Make variable static
V2:
- Don't use the users -cpu
- Fixup allignment
hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/arm/xlnx-zcu102.c +17 -0
@@ -184,6 +184,11 @@ static void xlnx_zynqmp_init(XlnxZCU102 *s, MachineState *machine)arm_load_kernel (s->soc.boot_cpu_ptr, &xlnx_zcu102_binfo); } +static const char *xlnx_zynqmp_valid_cpus[] = { +"cortex-a53" , +NULL +}; +static void xlnx_ep108_init (MachineState *machine) {XlnxZCU102 *s =EP108_MACHINE (machine);
@@ -216,6 +221,12 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a53" ); +/* The ZynqMP SoC is always a Cortex-A53. We add this here to give +* users a sane error if they specify a different CPU, but we never +* use their CPU choice. +*/ + mc->valid_cpu_types = xlnx_zynqmp_valid_cpus; }static const TypeInfo xlnx_ep108_machine_init_typeinfo = {
@@ -274,6 +285,12 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a53" ); +/* The ZynqMP SoC is always a Cortex-A53. We add this here to give +* users a sane error if they specify a different CPU, but we never +* use their CPU choice. +*/ + mc->valid_cpu_types = xlnx_zynqmp_valid_cpus; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {
Signature · 1 line
2.14.1
PATCH v5 6/6 xilinx_zynq: Specify the valid CPUs
In reply to Alistair FrancisList all possible valid CPU options.
---
V5:
- Use cpu_model names
V4:
- Remove spaces
V3:
- Make variable static
V2:
- Fixup alignment
hw/arm/xilinx_zynq.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/arm/xilinx_zynq.c +6 -0
@@ -313,6 +313,11 @@ static void zynq_init(MachineState *machine)arm_load_kernel (ARM_CPU (first_cpu), &zynq_binfo); } +static const char *xlnx_zynq_7000_valid_cpus[] = { +"cortex-a9" , +NULL +}; +static void zynq_machine_init (MachineClass *mc) { mc->desc ="Xilinx Zynq Platform Baseboard for Cortex-A9" ;
@@ -321,6 +326,7 @@ static void zynq_machine_init(MachineClass *mc) mc->no_sdcard =1 ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a9" ); + mc->valid_cpu_types = xlnx_zynq_7000_valid_cpus; }DEFINE_MACHINE ("xilinx-zynq-a9" , zynq_machine_init)
Signature · 1 line
2.14.1
Quoted 6 lines · Alistair Francis
There are numorous QEMU machines that only have a single or a handful of valid CPU options. To simplyfy the management of specificying which CPU is/isn't valid let's create a property that can be set in the machine init. We can then check to see if the user supplied CPU is in that list or not.
Sadly this series missed the 2.12 train.
Quoted 61 lines
I have added the
valid_cpu_typesfor some ARM machines only at the moment.Here is what specifying the CPUs looks like now:
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m3" -S QEMU 2.10.50 monitor - type 'help' for more information (qemu) info cpus * CPU #0: thread_id=24175 (qemu) q$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m4" -S QEMU 2.10.50 monitor - type 'help' for more information (qemu) q$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m5" -S qemu-system-aarch64: unable to find CPU model 'cortex-m5'$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-a9" -S qemu-system-aarch64: Invalid CPU type: cortex-a9-arm-cpu The valid models are: cortex-m3, cortex-m4V5:
- Usecpu_modelinstead ofcpu_type
V4:
- Rebase
- Remove spaces
V3:
- Make the varialbes static
V2:
- Rebase
- Reorder patches
- Add a Raspberry Pi 2 CPU fix
V1:
- Small fixes to prepare a series instead of RFC
- Add commit messages for the commits
- Expand the machine support to ARM machines
RFC v2:
- Rebase on Igor's work
- Use more QEMUisms inside the code
- List the supported machines in a NULL terminated arrayAlistair Francis (6):
machine: Convert the valid cpu types to usecpu_model
netduino2: Specify the valid CPUs
bcm2836: Use the Cortex-A7 instead of Cortex-A15
raspi: Specify the valid CPUs
xlnx-zcu102: Specify the valid CPUs
xilinx_zynq: Specify the valid CPUshw/arm/bcm2836.c | 2 +- hw/arm/netduino2.c | 10 +++++++++- hw/arm/raspi.c | 7 +++++++ hw/arm/xilinx_zynq.c | 6 ++++++ hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++ hw/core/machine.c | 11 +++++------ 6 files changed, 45 insertions(+), 8 deletions(-)
Quoted 9 lines · On Wed, 14 Mar 2018 00:13:40 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 6 lines · Alistair Francis
There are numorous QEMU machines that only have a single or a handful of valid CPU options. To simplyfy the management of specificying which CPU is/isn't valid let's create a property that can be set in the machine init. We can then check to see if the user supplied CPU is in that list or not.
Sadly this series missed the 2.12 train.
problematic part here is 'cpu_type -> cpu_model' conversion without introducing back cpu model names in boards code.
Each target sort of already has this code 'cpu_list' for printing supported CPU models. What we need is to generalize it as most of the targets implement it the same way. And then reuse generic code for 'cpu_type -> cpu_model' so that boards won't have to be involved in it.
So currently cpu_list needs a volunteer who would be able to generalize it and cleanup all targets across the the tree.