Skip to contentSkip to conversation

generalize parsing of cpu_model (part 4)

PATCH Superseded Igor Mammedov 8 participants 53 messages Jan 17, 2018 – Jan 19, 2018

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover generalize parsing of cpu_model (part 4)

Series is finishing work on generalizing cpu_model parsing and limiting parts that deal with inconsistent cpu_model naming to "-cpu" CLI option processing in vl.c/*-user.main.c and FOO_cpu_class_by_name() callbacks.

It introduces TARGET_DEFAULT_CPU_TYPE which must be defined by each target and is used setting default cpu type for linux/bsd-user targets and as anchor point to pick cpu class that provides target specific FOO_cpu_class_by_name() callback for cpu_parse_cpu_model() in null-machine.c which is compiled for all targets that have system mode emulation.

After TARGET_DEFAULT_CPU_TYPE is provided by each target, patches 20-21/24 switch null-machine.c and *-user.main.c to use TARGET_DEFAULT_CPU_TYPE and using
cpu_parse_cpu_model()/cpu_create()
instead of
cpu_init()/cpu_generic_init()
so nor more users of later remains and boards/targets deal only with cpu types (in similar/consistent manner).

Finishing patches 22-24/24 remove not used anymore
cpu_init()/cpu_generic_init()
API so cpu_model won't be introduced back in boards code in the future (23/24 removes cpu_generic_init user that managed to slip in this merge window).

CC Laurent Vivier <[email protected]>

Igor Mammedov (24):
arm: cpu: add TARGET_DEFAULT_CPU_TYPE macro
alpha: cpu: add TARGET_DEFAULT_CPU_TYPE macro
cris: cpu: add TARGET_DEFAULT_CPU_TYPE macro
lm32: cpu: add TARGET_DEFAULT_CPU_TYPE macro
m68k: cpu: add TARGET_DEFAULT_CPU_TYPE macro
microblaze: cpu: add TARGET_DEFAULT_CPU_TYPE macro
mips: cpu: add TARGET_DEFAULT_CPU_TYPE macro
moxie: cpu: add TARGET_DEFAULT_CPU_TYPE macro
nios2: cpu: add TARGET_DEFAULT_CPU_TYPE macro
openrisc: cpu: add TARGET_DEFAULT_CPU_TYPE macro
ppc: cpu: add TARGET_DEFAULT_CPU_TYPE macro
s390x: cpu: add TARGET_DEFAULT_CPU_TYPE macro
sh4: cpu: add TARGET_DEFAULT_CPU_TYPE macro
sparc: cpu: add TARGET_DEFAULT_CPU_TYPE macro
tricore: cpu: add TARGET_DEFAULT_CPU_TYPE macro
unicore32: cpu: add TARGET_DEFAULT_CPU_TYPE macro
xtensa: cpu: rename XTENSA_DEFAULT_CPU_TYPE to TARGET_DEFAULT_CPU_TYPE
hppa: cpu: add TARGET_DEFAULT_CPU_TYPE macro
tilegx: cpu: add TARGET_DEFAULT_CPU_TYPE macro
machine: drop MachineState::cpu_model
linux/bsd-user: drop cpu_init() and use cpu_create() instead
cpu: get rid of unused cpu_init() defines
nios2: 10m50_devboard: replace cpu_model with cpu_type
cpu: get rid of cpu_generic_init()

 include/hw/boards.h       |  1 -
 include/qom/cpu.h         | 11 ----------
 target/alpha/cpu.h        |  3 +--
 target/arm/cpu.h          |  3 +--
 target/cris/cpu.h         |  3 +--
 target/hppa/cpu.h         |  2 +-
 target/i386/cpu.h         |  2 --
 target/lm32/cpu.h         |  3 +--
 target/m68k/cpu.h         |  3 +--
 target/microblaze/cpu.h   |  2 +-
 target/mips/cpu.h         |  8 ++++++--
 target/moxie/cpu.h        |  3 +--
 target/nios2/cpu.h        |  2 +-
 target/openrisc/cpu.h     |  3 +--
 target/ppc/cpu.h          |  8 ++++++--
 target/s390x/cpu.h        |  3 +--
 target/sh4/cpu.h          |  3 +--
 target/sparc/cpu.h        | 10 +++++----
 target/tilegx/cpu.h       |  2 +-
 target/tricore/cpu.h      |  3 +--
 target/unicore32/cpu.h    |  3 +--
 target/xtensa/cpu.h       |  4 +---
 bsd-user/main.c           | 26 ++++--------------------
 hw/core/null-machine.c    | 10 ++++++---
 hw/nios2/10m50_devboard.c |  2 +-
 hw/xtensa/sim.c           |  2 +-
 hw/xtensa/xtfpga.c        |  8 ++++----
 linux-user/main.c         | 52 +++++------------------------------------------
 qom/cpu.c                 | 25 ++---------------------
 vl.c                      |  8 +++++++-
 30 files changed, 65 insertions(+), 153 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/24 arm: cpu: add TARGET_DEFAULT_CPU_TYPE macro

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to replace a bunch of ifdefs *-user/main.c that set default cpu_model with cpu type.

With the later in mind set it to 'any', which is current default for ARM targets.

While at it, default cpu_model for ARM is set to 'any' under TARGET_ARM, however there is catch all ifdef which also sets cpu_model to 'any'. Drop unnecessary TARGET_ARM ifdef and use catch all #else to set default value.

---
CC: Riku Voipio <[email protected]>
CC: Laurent Vivier <[email protected]>
CC: Peter Maydell <[email protected]>
CC: Andrew Jones <[email protected]>
CC: [email protected]

---
 target/arm/cpu.h  | 1 +
 linux-user/main.c | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)
target/arm/cpu.h +1 -0
index 9631670..c87bb76 100644
@@ -2171,6 +2171,7 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
 
 #define ARM_CPU_TYPE_SUFFIX "-" TYPE_ARM_CPU
 #define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX)
+#define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any")
 
 #define cpu_signal_handler cpu_arm_signal_handler
 #define cpu_list arm_cpu_list
linux-user/main.c +0 -2
index 450eb3c..a35477e 100644
@@ -4325,8 +4325,6 @@ int main(int argc, char **argv, char **envp)
 #else
         cpu_model = "qemu32";
 #endif
-#elif defined(TARGET_ARM)
-        cpu_model = "any";
 #elif defined(TARGET_UNICORE32)
         cpu_model = "any";
 #elif defined(TARGET_M68K)
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/24 alpha: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

With the later in mind set it to 'ev67', which is what alpha_cpu_class_by_name() returns if user provided a garbage (including default "any" cpu_model that *-user targets set in catch all) in case of Alpha.

---
CC: Richard Henderson <[email protected]>

---
 target/alpha/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/alpha/cpu.h +1 -0
index 0a9ad35..c8dd560 100644
@@ -472,6 +472,7 @@ void alpha_translate_init(void);
 
 #define ALPHA_CPU_TYPE_SUFFIX "-" TYPE_ALPHA_CPU
 #define ALPHA_CPU_TYPE_NAME(model) model ALPHA_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE ALPHA_CPU_TYPE_NAME("ev67")
 
 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 /* you can call this signal handler from your SIGBUS and SIGSEGV
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/24 cris: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

With the later in mind set it to 'crisv32', which is what cris_cpu_class_by_name() returns if user provided "any" cpu_model including default that *-user targets set in catch all in case of Cris.

---
CC: "Edgar E. Iglesias" <[email protected]>

---
 target/cris/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/cris/cpu.h +1 -0
index b64fa35..8feabb4 100644
@@ -271,6 +271,7 @@ enum {
 
 #define CRIS_CPU_TYPE_SUFFIX "-" TYPE_CRIS_CPU
 #define CRIS_CPU_TYPE_NAME(name) (name CRIS_CPU_TYPE_SUFFIX)
+#define TARGET_DEFAULT_CPU_TYPE CRIS_CPU_TYPE_NAME("crisv32")
 
 #define cpu_signal_handler cpu_cris_signal_handler
 
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/24 lm32: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model).
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

LM32 however doesn't have working default in *-user targets which defaults to catch all 'any'. So I arbitraraly picked 'lm32-basic' cpu model to serve as the default.

---
CC: Michael Walle <[email protected]>

---
 target/lm32/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/lm32/cpu.h +1 -0
index 2279594..65f58f5 100644
@@ -259,6 +259,7 @@ bool lm32_cpu_do_semihosting(CPUState *cs);
 
 #define LM32_CPU_TYPE_SUFFIX "-" TYPE_LM32_CPU
 #define LM32_CPU_TYPE_NAME(model) model LM32_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE LM32_CPU_TYPE_NAME("lm32-basic")
 
 #define cpu_list lm32_cpu_list
 #define cpu_signal_handler cpu_lm32_signal_handler
Signature · 1 line
2.7.4
#5 lore raw

PATCH 5/24 m68k: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

With the later in mind set it to 'any', which is current default for M68K targets.

While at it, drop redundant ifdef in linux-user, as catch all #else sets default to the same 'any' model.

---
CC: Riku Voipio <[email protected]>
CC: Laurent Vivier <[email protected]>

---
 target/m68k/cpu.h | 1 +
 linux-user/main.c | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)
target/m68k/cpu.h +1 -0
index 2985b03..193e8f8 100644
@@ -405,6 +405,7 @@ void register_m68k_insns (CPUM68KState *env);
 
 #define M68K_CPU_TYPE_SUFFIX "-" TYPE_M68K_CPU
 #define M68K_CPU_TYPE_NAME(model) model M68K_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE M68K_CPU_TYPE_NAME("any")
 
 #define cpu_signal_handler cpu_m68k_signal_handler
 #define cpu_list m68k_cpu_list
linux-user/main.c +0 -2
index a35477e..54e8aac 100644
@@ -4327,8 +4327,6 @@ int main(int argc, char **argv, char **envp)
 #endif
 #elif defined(TARGET_UNICORE32)
         cpu_model = "any";
-#elif defined(TARGET_M68K)
-        cpu_model = "any";
 #elif defined(TARGET_SPARC)
 #ifdef TARGET_SPARC64
         cpu_model = "TI UltraSparc II";
Signature · 1 line
2.7.4
#6 lore raw

PATCH 6/24 microblaze: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

For the later default is set to bogus 'any', and mb_cpu_class_by_name() always returns TYPE_MICROBLAZE_CPU class regardless of cpu_model value. So use this type for default.

---
CC: "Edgar E. Iglesias" <[email protected]>

---
 target/microblaze/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/microblaze/cpu.h +1 -0
index 52b6b6a..f244efa 100644
@@ -344,6 +344,7 @@ int cpu_mb_signal_handler(int host_signum, void *pinfo,
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_MICROBLAZE_CPU, cpu_model)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_MICROBLAZE_CPU
 
 #define cpu_signal_handler cpu_mb_signal_handler
 
Signature · 1 line
2.7.4
#7 lore raw

PATCH 7/24 mips: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Take defaults types from linux-user and use them as TARGET_DEFAULT_CPU_TYPE, which should work for *-user targets.

---
CC: Aurelien Jarno <[email protected]>
CC: Yongbok Kim <[email protected]>

---
 target/mips/cpu.h | 6 ++++++
 1 file changed, 6 insertions(+)
target/mips/cpu.h +6 -0
index 7f8ba5f..c5ee894 100644
@@ -744,6 +744,12 @@ int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
 #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
 #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
 
+#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
+#define TARGET_DEFAULT_CPU_TYPE MIPS_CPU_TYPE_NAME("5KEf")
+#else
+#define TARGET_DEFAULT_CPU_TYPE MIPS_CPU_TYPE_NAME("24Kf")
+#endif
+
 bool cpu_supports_cps_smp(const char *cpu_type);
 bool cpu_supports_isa(const char *cpu_type, unsigned int isa);
 void cpu_set_exception_base(int vp_index, target_ulong address);
Signature · 1 line
2.7.4
#8 lore raw

PATCH 8/24 moxie: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

With the later in mind set it to 'any', which is current default for target.

---
CC: Anthony Green <[email protected]>

---
 target/moxie/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/moxie/cpu.h +1 -0
index d37e6a5..9fabb93 100644
@@ -124,6 +124,7 @@ int cpu_moxie_signal_handler(int host_signum, void *pinfo,
 
 #define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU
 #define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE MOXIE_CPU_TYPE_NAME("any")
 
 #define cpu_signal_handler cpu_moxie_signal_handler
 
Signature · 1 line
2.7.4
#9 lore raw

PATCH 9/24 nios2: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

For the later default is set to bogus 'any', and nios2_cpu_class_by_name() always returns TYPE_NIOS2_CPU class regardless of cpu_model value. So use this type for default.

---
CC: Chris Wulff <[email protected]>
CC: Marek Vasut <[email protected]>

---
 target/nios2/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/nios2/cpu.h +1 -0
index 88823a6..2d03958 100644
@@ -232,6 +232,7 @@ void nios2_check_interrupts(CPUNios2State *env);
 #endif
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_NIOS2_CPU, cpu_model)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_NIOS2_CPU
 
 #define cpu_gen_code cpu_nios2_gen_code
 #define cpu_signal_handler cpu_nios2_signal_handler
Signature · 1 line
2.7.4
#10 lore raw

PATCH 10/24 openrisc: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Take default type from linux-user and use it as TARGET_DEFAULT_CPU_TYPE, which should work for *-user targets.

---
CC: Stafford Horne <[email protected]>

---
 target/openrisc/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/openrisc/cpu.h +1 -0
index cc22dc8..8d1a87e 100644
@@ -394,6 +394,7 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
 
 #define OPENRISC_CPU_TYPE_SUFFIX "-" TYPE_OPENRISC_CPU
 #define OPENRISC_CPU_TYPE_NAME(model) model OPENRISC_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE OPENRISC_CPU_TYPE_NAME("or1200")
 
 #include "exec/cpu-all.h"
 
Signature · 1 line
2.7.4
#11 lore raw

PATCH 11/24 ppc: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default values from linux-user for TARGET_DEFAULT_CPU_TYPE. While at it fixup linux-user to use corresponding cpu models instead of aliases.

---
CC: Riku Voipio <[email protected]>
CC: Laurent Vivier <[email protected]>
CC: David Gibson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: [email protected]

---
 target/ppc/cpu.h  | 6 ++++++
 linux-user/main.c | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)
target/ppc/cpu.h +6 -0
index a5e49f2..4af4aff 100644
@@ -1377,6 +1377,12 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
 #define POWERPC_CPU_TYPE_SUFFIX "-" TYPE_POWERPC_CPU
 #define POWERPC_CPU_TYPE_NAME(model) model POWERPC_CPU_TYPE_SUFFIX
 
+#ifdef TARGET_PPC64
+#define TARGET_DEFAULT_CPU_TYPE POWERPC_CPU_TYPE_NAME("power8_v2.0")
+#else
+#define TARGET_DEFAULT_CPU_TYPE POWERPC_CPU_TYPE_NAME("750_v3.1")
+#endif
+
 #define cpu_signal_handler cpu_ppc_signal_handler
 #define cpu_list ppc_cpu_list
 
linux-user/main.c +2 -2
index 54e8aac..279cd97 100644
@@ -4343,9 +4343,9 @@ int main(int argc, char **argv, char **envp)
         cpu_model = "or1200";
 #elif defined(TARGET_PPC)
 # ifdef TARGET_PPC64
-        cpu_model = "POWER8";
+        cpu_model = "power8_v2.0";
 # else
-        cpu_model = "750";
+        cpu_model = "750_v3.1";
 # endif
 #elif defined TARGET_SH4
         cpu_model = "sh7785";
Signature · 1 line
2.7.4
Acked-by on v1 11/24
#12 lore raw

Re: [Qemu-devel] [PATCH 11/24] ppc: cpu: add TARGET_DEFAULT_CPU_TYPE macro

Quoted 11 lines · Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default values from linux-user for TARGET_DEFAULT_CPU_TYPE. While at it fixup linux-user to use corresponding cpu models instead of aliases.

Quoted 44 lines

---
CC: Riku Voipio <[email protected]>
CC: Laurent Vivier <[email protected]>
CC: David Gibson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: [email protected]

---
 target/ppc/cpu.h  | 6 ++++++
 linux-user/main.c | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)
target/ppc/cpu.h +6 -0
index a5e49f2..4af4aff 100644
@@ -1377,6 +1377,12 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
 #define POWERPC_CPU_TYPE_SUFFIX "-" TYPE_POWERPC_CPU
 #define POWERPC_CPU_TYPE_NAME(model) model POWERPC_CPU_TYPE_SUFFIX
 
+#ifdef TARGET_PPC64
+#define TARGET_DEFAULT_CPU_TYPE POWERPC_CPU_TYPE_NAME("power8_v2.0")
+#else
+#define TARGET_DEFAULT_CPU_TYPE POWERPC_CPU_TYPE_NAME("750_v3.1")
+#endif
+
 #define cpu_signal_handler cpu_ppc_signal_handler
 #define cpu_list ppc_cpu_list
 
linux-user/main.c +2 -2
index 54e8aac..279cd97 100644
@@ -4343,9 +4343,9 @@ int main(int argc, char **argv, char **envp)
         cpu_model = "or1200";
 #elif defined(TARGET_PPC)
 # ifdef TARGET_PPC64
-        cpu_model = "POWER8";
+        cpu_model = "power8_v2.0";
 # else
-        cpu_model = "750";
+        cpu_model = "750_v3.1";
 # endif
 #elif defined TARGET_SH4
         cpu_model = "sh7785";
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#13 lore raw

PATCH 12/24 s390x: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default value from linux-user for TARGET_DEFAULT_CPU_TYPE.

---
CC: Richard Henderson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: [email protected]

---
 target/s390x/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/s390x/cpu.h +1 -0
index 1a8b6b9..174624a 100644
@@ -731,6 +731,7 @@ void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
+#define TARGET_DEFAULT_CPU_TYPE S390_CPU_TYPE_NAME("qemu")
 
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
Signature · 1 line
2.7.4
Reviewed-by on v1 12/24
#14 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH 12/24] s390x: cpu: add TARGET_DEFAULT_CPU_TYPE macro

Quoted 23 lines · Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default value from linux-user for TARGET_DEFAULT_CPU_TYPE.

---
CC: Richard Henderson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: [email protected]

---
 target/s390x/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/s390x/cpu.h +0 -0
index 1a8b6b9..174624a 100644

target/s390x/cpu.h void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga, · line 737

Quoted 7 lines
target/s390x/cpu.h +1 -0
@@ -731,6 +731,7 @@ void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
+#define TARGET_DEFAULT_CPU_TYPE S390_CPU_TYPE_NAME("qemu")
 
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero

At least from a !KVM perspective this is correct. And that is at least relevant for linux-user. I doubt that this is relevant for KVM. The "none" machine cannot be used either way and CPU models are sensed via qmp.

Signature · 3 lines
Thanks,

David / dhildenb
#15 lore raw

Re: [Qemu-devel] [qemu-s390x] [PATCH 12/24] s390x: cpu: add TARGET_DEFAULT_CPU_TYPE macro

Quoted 28 lines · On Wed, 17 Jan 2018 17:04:31 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 27 lines · Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default value from linux-user for TARGET_DEFAULT_CPU_TYPE.

---
CC: Richard Henderson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: [email protected]

---
 target/s390x/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/s390x/cpu.h +1 -0
index 1a8b6b9..174624a 100644
@@ -731,6 +731,7 @@ void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
+#define TARGET_DEFAULT_CPU_TYPE S390_CPU_TYPE_NAME("qemu")
 
Quoted 7 lines

target/s390x/cpu.h void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga, · line 737

Quoted 3 lines
target/s390x/cpu.h +0 -0
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero

At least from a !KVM perspective this is correct. And that is at least relevant for linux-user. I doubt that this is relevant for KVM. The "none" machine cannot be used either way and CPU models are sensed via qmp.

If you look at cpu_parse_cpu_model() impl., you'll see that TARGET_DEFAULT_CPU_TYPE isn't used as actual CPU type but as a proxy to get access to CPUClass::class_by_name() callback which is implemented by every target. So accelerator doesn't have any effect here.

Quoted 1 line

Thanks!

#16 lore raw

PATCH 13/24 sh4: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default value from linux-user for TARGET_DEFAULT_CPU_TYPE.

---
CC: Aurelien Jarno <[email protected]>

---
 target/sh4/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/sh4/cpu.h +1 -0
index a2c26e0..203d212 100644
@@ -278,6 +278,7 @@ void cpu_load_tlb(CPUSH4State * env);
 
 #define SUPERH_CPU_TYPE_SUFFIX "-" TYPE_SUPERH_CPU
 #define SUPERH_CPU_TYPE_NAME(model) model SUPERH_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE SUPERH_CPU_TYPE_NAME("sh7785")
 
 #define cpu_signal_handler cpu_sh4_signal_handler
 #define cpu_list sh4_cpu_list
Signature · 1 line
2.7.4
#17 lore raw

PATCH 14/24 sparc: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default values from linux-user for TARGET_DEFAULT_CPU_TYPE.

---
CC: Mark Cave-Ayland <[email protected]>
CC: Artyom Tarasenko <[email protected]>

---
 target/sparc/cpu.h | 6 ++++++
 1 file changed, 6 insertions(+)
target/sparc/cpu.h +6 -0
index 9fde547..02c55ad 100644
@@ -661,6 +661,12 @@ int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 #define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
 #define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
 
+#ifdef TARGET_SPARC64
+#define TARGET_DEFAULT_CPU_TYPE SPARC_CPU_TYPE_NAME("TI-UltraSparc-II")
+#else
+#define TARGET_DEFAULT_CPU_TYPE SPARC_CPU_TYPE_NAME("Fujitsu-MB86904")
+#endif
+
 #define cpu_signal_handler cpu_sparc_signal_handler
 #define cpu_list sparc_cpu_list
 
Signature · 1 line
2.7.4
#18 lore raw

PATCH 15/24 tricore: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

linux-user defaults to catch all 'any' which is bogus and results into error. Pick arbitrary model "tc1796" for TARGET_DEFAULT_CPU_TYPE to use and it would fix missing default when *-user is switched to using types instead of cpu_model.

---
CC: Bastian Koppelmann <[email protected]>

---
 target/tricore/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/tricore/cpu.h +1 -0
index f41d2ce..835d51a 100644
@@ -415,6 +415,7 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
 
 #define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
 #define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE TRICORE_CPU_TYPE_NAME("tc1796")
 
 /* helpers.c */
 int cpu_tricore_handle_mmu_fault(CPUState *cpu, target_ulong address,
Signature · 1 line
2.7.4
Reviewed-by on v1 15/24
#19 lore raw

Re: [Qemu-devel] [PATCH 15/24] tricore: cpu: add TARGET_DEFAULT_CPU_TYPE macro

Quoted 12 lines · Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

linux-user defaults to catch all 'any' which is bogus and results into error. Pick arbitrary model "tc1796" for TARGET_DEFAULT_CPU_TYPE to use and it would fix missing default when *-user is switched to using types instead of cpu_model.

Quoted 6 lines

---
CC: Bastian Koppelmann <[email protected]>

---
 target/tricore/cpu.h | 1 +
 1 file changed, 1 insertion(+)

Cheers,
Bastian

#20 lore raw

PATCH 16/24 unicore32: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

it will be used for for 2 purposes, 1st is to
provide to cpu name resolving class for machine 'none'
cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model)
and later to drop a bunch of ifdefs *-user/main.c that set default cpu_model.

Use default value from linux-user for TARGET_DEFAULT_CPU_TYPE. While at it drop redundant ifdef and let catch all #else set default to the same 'any' model.

---
CC: Riku Voipio <[email protected]>
CC: Laurent Vivier <[email protected]>
CC: Guan Xuetao <[email protected]>

---
 target/unicore32/cpu.h | 1 +
 linux-user/main.c      | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)
target/unicore32/cpu.h +1 -0
index 3dc6fbc..fd3fa81 100644
@@ -169,6 +169,7 @@ static inline int cpu_mmu_index(CPUUniCore32State *env, bool ifetch)
 
 #define UNICORE32_CPU_TYPE_SUFFIX "-" TYPE_UNICORE32_CPU
 #define UNICORE32_CPU_TYPE_NAME(model) model UNICORE32_CPU_TYPE_SUFFIX
+#define TARGET_DEFAULT_CPU_TYPE UNICORE32_CPU_TYPE_NAME("any")
 
 static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc,
                                         target_ulong *cs_base, uint32_t *flags)
linux-user/main.c +0 -2
index 279cd97..1cd5033 100644
@@ -4325,8 +4325,6 @@ int main(int argc, char **argv, char **envp)
 #else
         cpu_model = "qemu32";
 #endif
-#elif defined(TARGET_UNICORE32)
-        cpu_model = "any";
 #elif defined(TARGET_SPARC)
 #ifdef TARGET_SPARC64
         cpu_model = "TI UltraSparc II";
Signature · 1 line
2.7.4
#21 lore raw

PATCH 17/24 xtensa: cpu: rename XTENSA_DEFAULT_CPU_TYPE to TARGET_DEFAULT_CPU_TYPE

In reply to Igor Mammedov

so naming would be in line with other targets and null-machine.c which uses the later would compile.

Later it also would be used as default for *-user targets which is currently bogus cpu model 'any', that errors out.

---
CC: Max Filippov <[email protected]>

---
 target/xtensa/cpu.h | 2 +-
 hw/xtensa/sim.c     | 2 +-
 hw/xtensa/xtfpga.c  | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
target/xtensa/cpu.h +1 -1
index d9404aa..537e151 100644
@@ -506,7 +506,7 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 #else
 #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
 #endif
-#define XTENSA_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
+#define TARGET_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
 
hw/xtensa/sim.c +1 -1
index 2bb883b..58a79bd 100644
@@ -128,7 +128,7 @@ static void xtensa_sim_machine_init(MachineClass *mc)
     mc->init = xtensa_sim_init;
     mc->max_cpus = 4;
     mc->no_serial = 1;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
 }
 
 DEFINE_MACHINE("sim", xtensa_sim_machine_init)
hw/xtensa/xtfpga.c +4 -4
index 1971ecf..c2b0aa4 100644
@@ -449,7 +449,7 @@ static void xtensa_lx60_class_init(ObjectClass *oc, void *data)
     mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_lx60_init;
     mc->max_cpus = 4;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_lx60_type = {
@@ -465,7 +465,7 @@ static void xtensa_lx200_class_init(ObjectClass *oc, void *data)
     mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_lx200_init;
     mc->max_cpus = 4;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_lx200_type = {
@@ -481,7 +481,7 @@ static void xtensa_ml605_class_init(ObjectClass *oc, void *data)
     mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_ml605_init;
     mc->max_cpus = 4;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_ml605_type = {
@@ -497,7 +497,7 @@ static void xtensa_kc705_class_init(ObjectClass *oc, void *data)
     mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
     mc->init = xtensa_kc705_init;
     mc->max_cpus = 4;
-    mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
 }
 
 static const TypeInfo xtensa_kc705_type = {
Signature · 1 line
2.7.4
Acked-by on v1 17/24
#22 lore raw

Re: [Qemu-devel] [PATCH 17/24] xtensa: cpu: rename XTENSA_DEFAULT_CPU_TYPE to TARGET_DEFAULT_CPU_TYPE

Quoted 6 lines · Igor Mammedov

so naming would be in line with other targets and null-machine.c which uses the later would compile.

Later it also would be used as default for *-user targets which is currently bogus cpu model 'any', that errors out.

Quoted 8 lines

---
CC: Max Filippov <[email protected]>

---
 target/xtensa/cpu.h | 2 +-
 hw/xtensa/sim.c     | 2 +-
 hw/xtensa/xtfpga.c  | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
Thanks.
-- Max
#23 lore raw

PATCH 18/24 hppa: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

It will be used to drop a bunch of ifdefs *-user/main.c that set default cpu_model in favor of using type names directly.

---
CC: Richard Henderson <[email protected]>

---
 target/hppa/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/hppa/cpu.h +1 -0
index 8d14077..04625f7 100644
@@ -113,6 +113,7 @@ static inline int cpu_mmu_index(CPUHPPAState *env, bool ifetch)
 void hppa_translate_init(void);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_HPPA_CPU, cpu_model)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_HPPA_CPU
 
 void hppa_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 
Signature · 1 line
2.7.4
#24 lore raw

PATCH 19/24 tilegx: cpu: add TARGET_DEFAULT_CPU_TYPE macro

In reply to Igor Mammedov

It will be used to drop a bunch of ifdefs *-user/main.c that set default cpu_model in favor of using type names directly.

For tilegx, *-user defaulted to bogus 'any', however tilegx_cpu_class_by_name() is ignoring invalid values and always returns TYPE_TILEGX_CPU, so use it for TARGET_DEFAULT_CPU_TYPE

---
CC: Eduardo Habkost <[email protected]>

---
 target/tilegx/cpu.h | 1 +
 1 file changed, 1 insertion(+)
target/tilegx/cpu.h +1 -0
index 71cea04..67de53e 100644
@@ -165,6 +165,7 @@ void tilegx_tcg_init(void);
 int cpu_tilegx_signal_handler(int host_signum, void *pinfo, void *puc);
 
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_TILEGX_CPU, cpu_model)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_TILEGX_CPU
 
 #define cpu_signal_handler cpu_tilegx_signal_handler
 
Signature · 1 line
2.7.4
#25 lore raw

PATCH 20/24 machine: drop MachineState::cpu_model

In reply to Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

We could compare pointers of MachineState::cpu_type and MachineClass::default_cpu_type to check for the same condition, and drop cpu_model concept completly from machine/boards code So that no one would try to reuse obsolete field and only place to deal with cpu model would be vl.c and foo_cpu_class_by_name() callbacks.

---
CC: Eduardo Habkost <[email protected]>
CC: Marcel Apfelbaum <[email protected]>
CC: Paolo Bonzini <[email protected]>

---
 include/hw/boards.h    |  1 -
 hw/core/null-machine.c | 10 +++++++---
 vl.c                   |  8 +++++++-
 3 files changed, 14 insertions(+), 5 deletions(-)
include/hw/boards.h +0 -1
index 156b16f..decd0ec 100644
@@ -246,7 +246,6 @@ struct MachineState {
     char *kernel_filename;
     char *kernel_cmdline;
     char *initrd_filename;
-    const char *cpu_model;
     const char *cpu_type;
     AccelState *accelerator;
     CPUArchIdList *possible_cpus;
hw/core/null-machine.c +7 -3
index 864832d..c2e466c 100644
@@ -23,10 +23,13 @@
 static void machine_none_init(MachineState *mch)
 {
     CPUState *cpu = NULL;
+    MachineClass *mc = MACHINE_GET_CLASS(mch);
 
-    /* Initialize CPU (if a model has been specified) */
-    if (mch->cpu_model) {
-        cpu = cpu_init(mch->cpu_model);
+    /* Initialize CPU if cpu_type pointer is user provided
+     * (i.e. != to pointer tot static default cpu type string)
+     */
+    if (mch->cpu_type != mc->default_cpu_type) {
+        cpu = cpu_create(mch->cpu_type);
         if (!cpu) {
             error_report("Unable to initialize CPU");
             exit(1);
@@ -54,6 +57,7 @@ static void machine_none_machine_init(MachineClass *mc)
     mc->init = machine_none_init;
     mc->max_cpus = 1;
     mc->default_ram_size = 0;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
 }
 
 DEFINE_MACHINE("none", machine_none_machine_init)
vl.c +7 -1
index 2586f25..8aa0131 100644
@@ -4609,7 +4609,6 @@ int main(int argc, char **argv, char **envp)
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
     current_machine->boot_order = boot_order;
-    current_machine->cpu_model = cpu_model;
 
     parse_numa_opts(current_machine);
 
@@ -4619,6 +4618,13 @@ 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);
+
+            /* machine 'none' depends on default cpu type pointer not being
+             * equal to resolved type name pointer to fugure out if type was
+             * user provided, make sure that if it becomes not true in future
+             * it won't beark silently */
+            g_assert(
+                current_machine->cpu_type != machine_class->default_cpu_type);
         }
     }
 
Signature · 1 line
2.7.4
#26 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 41 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

We could compare pointers of MachineState::cpu_type and MachineClass::default_cpu_type to check for the same condition, and drop cpu_model concept completly from machine/boards code So that no one would try to reuse obsolete field and only place to deal with cpu model would be vl.c and foo_cpu_class_by_name() callbacks.

---
CC: Eduardo Habkost <[email protected]>
CC: Marcel Apfelbaum <[email protected]>
CC: Paolo Bonzini <[email protected]>

---
 include/hw/boards.h    |  1 -
 hw/core/null-machine.c | 10 +++++++---
 vl.c                   |  8 +++++++-
 3 files changed, 14 insertions(+), 5 deletions(-)
include/hw/boards.h +0 -1
index 156b16f..decd0ec 100644
@@ -246,7 +246,6 @@ struct MachineState {
     char *kernel_filename;
     char *kernel_cmdline;
     char *initrd_filename;
-    const char *cpu_model;
     const char *cpu_type;
     AccelState *accelerator;
     CPUArchIdList *possible_cpus;
hw/core/null-machine.c +0 -0
index 864832d..c2e466c 100644
@@ -23,10 +23,13 @@
 static void machine_none_init(MachineState *mch)
 {
     CPUState *cpu = NULL;

hw/core/null-machine.c line 32

Quoted 10 lines
hw/core/null-machine.c +6 -3
+    MachineClass *mc = MACHINE_GET_CLASS(mch);
 
-    /* Initialize CPU (if a model has been specified) */
-    if (mch->cpu_model) {
-        cpu = cpu_init(mch->cpu_model);
+    /* Initialize CPU if cpu_type pointer is user provided
+     * (i.e. != to pointer tot static default cpu type string)
+     */
+    if (mch->cpu_type != mc->default_cpu_type) {
+        cpu = cpu_create(mch->cpu_type);

This is a big assumption about the code that sets mch->cpu_type. A simple g_strdup(machine_class->default_cpu_type) would break this silently (as it won't trigger the assert() below).

hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 60

Quoted 8 lines
hw/core/null-machine.c +1 -0
         if (!cpu) {
             error_report("Unable to initialize CPU");
             exit(1);
@@ -54,6 +57,7 @@ static void machine_none_machine_init(MachineClass *mc)
     mc->init = machine_none_init;
     mc->max_cpus = 1;
     mc->default_ram_size = 0;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;

Why do you need this? Isn't it simpler to just leave default_cpu_type=NULL here?

Quoted 32 lines
hw/core/null-machine.c +0 -0
 }
 
 DEFINE_MACHINE("none", machine_none_machine_init)
vl.c +7 -1
index 2586f25..8aa0131 100644
@@ -4609,7 +4609,6 @@ int main(int argc, char **argv, char **envp)
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
     current_machine->boot_order = boot_order;
-    current_machine->cpu_model = cpu_model;
 
     parse_numa_opts(current_machine);
 
@@ -4619,6 +4618,13 @@ 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);
+
+            /* machine 'none' depends on default cpu type pointer not being
+             * equal to resolved type name pointer to fugure out if type was
+             * user provided, make sure that if it becomes not true in future
+             * it won't beark silently */
+            g_assert(
+                current_machine->cpu_type != machine_class->default_cpu_type);
         }
     }
 
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#27 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 44 lines · On Wed, 17 Jan 2018 23:48:46 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 43 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

We could compare pointers of MachineState::cpu_type and MachineClass::default_cpu_type to check for the same condition, and drop cpu_model concept completly from machine/boards code So that no one would try to reuse obsolete field and only place to deal with cpu model would be vl.c and foo_cpu_class_by_name() callbacks.

---
CC: Eduardo Habkost <[email protected]>
CC: Marcel Apfelbaum <[email protected]>
CC: Paolo Bonzini <[email protected]>

---
 include/hw/boards.h    |  1 -
 hw/core/null-machine.c | 10 +++++++---
 vl.c                   |  8 +++++++-
 3 files changed, 14 insertions(+), 5 deletions(-)
include/hw/boards.h +0 -1
index 156b16f..decd0ec 100644
@@ -246,7 +246,6 @@ struct MachineState {
     char *kernel_filename;
     char *kernel_cmdline;
     char *initrd_filename;
-    const char *cpu_model;
     const char *cpu_type;
     AccelState *accelerator;
     CPUArchIdList *possible_cpus;
hw/core/null-machine.c +1 -0
index 864832d..c2e466c 100644
@@ -23,10 +23,13 @@
 static void machine_none_init(MachineState *mch)
 {
     CPUState *cpu = NULL;
+    MachineClass *mc = MACHINE_GET_CLASS(mch);
 
Quoted 12 lines

hw/core/null-machine.c line 32

Quoted 8 lines
hw/core/null-machine.c +5 -3
-    /* Initialize CPU (if a model has been specified) */
-    if (mch->cpu_model) {
-        cpu = cpu_init(mch->cpu_model);
+    /* Initialize CPU if cpu_type pointer is user provided
+     * (i.e. != to pointer tot static default cpu type string)
+     */
+    if (mch->cpu_type != mc->default_cpu_type) {
+        cpu = cpu_create(mch->cpu_type);  

This is a big assumption about the code that sets mch->cpu_type. A simple g_strdup(machine_class->default_cpu_type) would break this silently (as it won't trigger the assert() below).

Yes, it's a bit of a hack to figure out is user has requested cpu type explicitly. But so far there isn't need to do
g_strdup(machine_class->default_cpu_type)
when copying default in vl.c and guarding against it looks like overkill currently.

Cleaner way would be to make cpu_type property, add new property API to set/check flags and use that here, there are other places that would benefit from such API as well.
But it looks beyond scope of this series, so I used simple hackish way to make it work with current code.

I can amend comment here:
/* Initialize CPU if cpu_type pointer is user provided
* (i.e. != to pointer to static default cpu type string)
* MachineClass::default_cpu_type must be assigned to
* MachineState::cpu_type directly for this to work.
* TODO:
* - make cpu_type a property
* - add API to add/check user_set flag to property
* - use new API to check if property was user set
*/

Quoted 13 lines

hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 60

Quoted 10 lines
hw/core/null-machine.c +1 -0
         if (!cpu) {
             error_report("Unable to initialize CPU");
             exit(1);
@@ -54,6 +57,7 @@ static void machine_none_machine_init(MachineClass *mc)
     mc->init = machine_none_init;
     mc->max_cpus = 1;
     mc->default_ram_size = 0;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;  

Why do you need this? Isn't it simpler to just leave default_cpu_type=NULL here?

vl.c "-cpu" parsing depends on default_cpu_type being set
...
if (machine_class->default_cpu_type) {
...
}
when we get rid of requirement for proxy type in
cpu_parse_cpu_model()
we can drop this ugliness in null-machine.

I'm doing it dirty way to prevent cpu_model resurgence in boards code as it happened with nios2, even though I've tried to monitor list for such patches.

Quoted 33 lines
Quoted 32 lines
hw/core/null-machine.c +0 -0
 }
 
 DEFINE_MACHINE("none", machine_none_machine_init)
vl.c +7 -1
index 2586f25..8aa0131 100644
@@ -4609,7 +4609,6 @@ int main(int argc, char **argv, char **envp)
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
     current_machine->boot_order = boot_order;
-    current_machine->cpu_model = cpu_model;
 
     parse_numa_opts(current_machine);
 
@@ -4619,6 +4618,13 @@ 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);
+
+            /* machine 'none' depends on default cpu type pointer not being
+             * equal to resolved type name pointer to fugure out if type was
+             * user provided, make sure that if it becomes not true in future
+             * it won't beark silently */
+            g_assert(
+                current_machine->cpu_type != machine_class->default_cpu_type);
         }
     }
 
Signature · 1 line
2.7.4
#28 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 95 lines · Igor Mammedov
Quoted 44 lines · On Wed, 17 Jan 2018 23:48:46 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 43 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

We could compare pointers of MachineState::cpu_type and MachineClass::default_cpu_type to check for the same condition, and drop cpu_model concept completly from machine/boards code So that no one would try to reuse obsolete field and only place to deal with cpu model would be vl.c and foo_cpu_class_by_name() callbacks.

---
CC: Eduardo Habkost <[email protected]>
CC: Marcel Apfelbaum <[email protected]>
CC: Paolo Bonzini <[email protected]>

---
 include/hw/boards.h    |  1 -
 hw/core/null-machine.c | 10 +++++++---
 vl.c                   |  8 +++++++-
 3 files changed, 14 insertions(+), 5 deletions(-)
include/hw/boards.h +0 -1
index 156b16f..decd0ec 100644
@@ -246,7 +246,6 @@ struct MachineState {
     char *kernel_filename;
     char *kernel_cmdline;
     char *initrd_filename;
-    const char *cpu_model;
     const char *cpu_type;
     AccelState *accelerator;
     CPUArchIdList *possible_cpus;
hw/core/null-machine.c +1 -0
index 864832d..c2e466c 100644
@@ -23,10 +23,13 @@
 static void machine_none_init(MachineState *mch)
 {
     CPUState *cpu = NULL;
+    MachineClass *mc = MACHINE_GET_CLASS(mch);
 
Quoted 12 lines

hw/core/null-machine.c line 32

Quoted 8 lines
hw/core/null-machine.c +5 -3
-    /* Initialize CPU (if a model has been specified) */
-    if (mch->cpu_model) {
-        cpu = cpu_init(mch->cpu_model);
+    /* Initialize CPU if cpu_type pointer is user provided
+     * (i.e. != to pointer tot static default cpu type string)
+     */
+    if (mch->cpu_type != mc->default_cpu_type) {
+        cpu = cpu_create(mch->cpu_type);  

This is a big assumption about the code that sets mch->cpu_type. A simple g_strdup(machine_class->default_cpu_type) would break this silently (as it won't trigger the assert() below).

Yes, it's a bit of a hack to figure out is user has requested cpu type explicitly. But so far there isn't need to do
g_strdup(machine_class->default_cpu_type)
when copying default in vl.c and guarding against it looks like overkill currently.

Cleaner way would be to make cpu_type property, add new property API to set/check flags and use that here, there are other places that would benefit from such API as well.
But it looks beyond scope of this series, so I used simple hackish way to make it work with current code.

I can amend comment here:
/* Initialize CPU if cpu_type pointer is user provided
* (i.e. != to pointer to static default cpu type string)
* MachineClass::default_cpu_type must be assigned to
* MachineState::cpu_type directly for this to work.
* TODO:
* - make cpu_type a property
* - add API to add/check user_set flag to property
* - use new API to check if property was user set
*/

Quoted 13 lines

hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 60

Quoted 10 lines
hw/core/null-machine.c +1 -0
         if (!cpu) {
             error_report("Unable to initialize CPU");
             exit(1);
@@ -54,6 +57,7 @@ static void machine_none_machine_init(MachineClass *mc)
     mc->init = machine_none_init;
     mc->max_cpus = 1;
     mc->default_ram_size = 0;
+    mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;  

Why do you need this? Isn't it simpler to just leave default_cpu_type=NULL here?

Quoted 5 lines

vl.c "-cpu" parsing depends on default_cpu_type being set
...

 if (machine_class->default_cpu_type) {
   ...

}

Right, this makes sense now.

It looks like default_cpu_type is being overloaded for two different roles: 1) specifying the default CPU type; 2) finding the arch-specific class to be used to parse -cpu.

In the case of null-machine, these two roles conflict with each other. I believe we can find other solutions instead of this hack that involves lying on MachineClass::default_cpu_type (and then having to work around the lie on machine_none_init()).

I see multiple options: adding a new MachineClass field for that (e.g. resolving_cpu_type, which defaults to default_cpu_type if NULL); moving the CPU parsing code to arch_init.c (so it could use CPU_RESOLVING_TYPE or something similar); adding a optional MachineClass::parse_cpu_model hook. We could even try to get rid of CPUClass::parse_features completely

Quoted 3 lines

when we get rid of requirement for proxy type in
cpu_parse_cpu_model()
we can drop this ugliness in null-machine.

I'd prefer to not introduce this ugliness in the first place.

Quoted 4 lines

I'm doing it dirty way to prevent cpu_model resurgence in boards code as it happened with nios2, even though I've tried to monitor list for such patches.

To be honest, I don't think the harm in having new code using MachineState::cpu_model is so big to justify this hack.

Quoted 35 lines
Quoted 34 lines
Quoted 33 lines
hw/core/null-machine.c +0 -0
 }
 
 DEFINE_MACHINE("none", machine_none_machine_init)
vl.c +7 -1
index 2586f25..8aa0131 100644
@@ -4609,7 +4609,6 @@ int main(int argc, char **argv, char **envp)
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
     current_machine->boot_order = boot_order;
-    current_machine->cpu_model = cpu_model;
 
     parse_numa_opts(current_machine);
 
@@ -4619,6 +4618,13 @@ 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);
+
+            /* machine 'none' depends on default cpu type pointer not being
+             * equal to resolved type name pointer to fugure out if type was
+             * user provided, make sure that if it becomes not true in future
+             * it won't beark silently */
+            g_assert(
+                current_machine->cpu_type != machine_class->default_cpu_type);
         }
     }
 
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
#29 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 7 lines · On Thu, 18 Jan 2018 17:18:09 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 17 Jan 2018 23:48:46 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

[...]

Quoted 9 lines

It looks like default_cpu_type is being overloaded for two different roles: 1) specifying the default CPU type; 2) finding the arch-specific class to be used to parse -cpu.

In the case of null-machine, these two roles conflict with each other. I believe we can find other solutions instead of this hack that involves lying on MachineClass::default_cpu_type (and then having to work around the lie on machine_none_init()).

Quoted 6 lines

I see multiple options: adding a new MachineClass field for that (e.g. resolving_cpu_type, which defaults to default_cpu_type if NULL); moving the CPU parsing code to arch_init.c (so it could use CPU_RESOLVING_TYPE or something similar); adding a optional MachineClass::parse_cpu_model hook. We could even try to get rid of CPUClass::parse_features completely

Adding hooks just for the sake on null-machine seems to be overkill, I'd go for arch_init.c but it won't work for linux-user, how about exec.c as following:

include/qom/cpu.h +0 -0
index 93bd546..0185589 100644
@@ -661,8 +661,7 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);

[...]

exec.c +23 -0
index d28fc0c..4543f06 100644
@@ -817,6 +817,29 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 #endif
 }
 
+const char *parse_cpu_model(const char *cpu_model)
+{
+    ObjectClass *oc;
+    CPUClass *cc;
+    gchar **model_pieces;
+    const char *cpu_type;
+
+    model_pieces = g_strsplit(cpu_model, ",", 2);
+
+    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+    if (oc == NULL) {
+        error_report("unable to find CPU model '%s'", model_pieces[0]);
+        g_strfreev(model_pieces);
+        exit(EXIT_FAILURE);
+    }
+
+    cpu_type = object_class_get_name(oc);
+    cc = CPU_CLASS(oc);
+    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
+    g_strfreev(model_pieces);
+    return cpu_type;
+}
+
 #if defined(CONFIG_USER_ONLY)
 static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
 {
hw/core/null-machine.c +3 -3
index 864832d..cde4d3e 100644
@@ -24,9 +24,9 @@ static void machine_none_init(MachineState *mch)
 {
     CPUState *cpu = NULL;
 
-    /* Initialize CPU (if a model has been specified) */
-    if (mch->cpu_model) {
-        cpu = cpu_init(mch->cpu_model);
+    /* Initialize CPU (if user asked for it) */
+    if (mch->cpu_type) {
+        cpu = cpu_create(mch->cpu_type);
         if (!cpu) {
             error_report("Unable to initialize CPU");
             exit(1);
linux-user/main.c +4 -1
index a35477e..0afb3f4 100644
@@ -4357,10 +4358,13 @@ int main(int argc, char **argv, char **envp)
         cpu_model = "any";
 #endif
     }
+    cpu_type = parse_cpu_model(cpu_model);
+
     tcg_exec_init(0);
     /* NOTE: we need to init the CPU at this stage to get
        qemu_host_page_size */
-    cpu = cpu_init(cpu_model);
+
+    cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
     cpu_reset(cpu);
 
qom/cpu.c +0 -2
index e42d9a7..aab8437 100644
@@ -67,37 +67,6 @@ CPUState *cpu_create(const char *typename)
     return cpu;
 }
 
-const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model)
-{

[...]
-}
-
-CPUState *cpu_generic_init(const char *typename, const char *cpu_model) -{
[...]
-}
-
bool cpu_paging_enabled(const CPUState *cpu)

 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
vl.c +3 -7
index 2586f25..178bca3 100644
@@ -4609,17 +4609,13 @@ int main(int argc, char **argv, char **envp)
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
     current_machine->boot_order = boot_order;
-    current_machine->cpu_model = cpu_model;
 
     parse_numa_opts(current_machine);
 
     /* parse features once if machine provides default cpu_type */
-    if (machine_class->default_cpu_type) {
-        current_machine->cpu_type = machine_class->default_cpu_type;
-        if (cpu_model) {
-            current_machine->cpu_type =
-                cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model);
-        }
+    current_machine->cpu_type = machine_class->default_cpu_type;
+    if (cpu_model) {
+        current_machine->cpu_type = parse_cpu_model(cpu_model);
     }
 
     machine_run_board_init(current_machine);
#30 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 58 lines · Igor Mammedov
Quoted 7 lines · On Thu, 18 Jan 2018 17:18:09 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 17 Jan 2018 23:48:46 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

[...]

Quoted 9 lines

It looks like default_cpu_type is being overloaded for two different roles: 1) specifying the default CPU type; 2) finding the arch-specific class to be used to parse -cpu.

In the case of null-machine, these two roles conflict with each other. I believe we can find other solutions instead of this hack that involves lying on MachineClass::default_cpu_type (and then having to work around the lie on machine_none_init()).

Quoted 6 lines

I see multiple options: adding a new MachineClass field for that (e.g. resolving_cpu_type, which defaults to default_cpu_type if NULL); moving the CPU parsing code to arch_init.c (so it could use CPU_RESOLVING_TYPE or something similar); adding a optional MachineClass::parse_cpu_model hook. We could even try to get rid of CPUClass::parse_features completely

Adding hooks just for the sake on null-machine seems to be overkill, I'd go for arch_init.c but it won't work for linux-user, how about exec.c as following:

include/qom/cpu.h +0 -0
index 93bd546..0185589 100644
@@ -661,8 +661,7 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
[...]
exec.c +12 -0
index d28fc0c..4543f06 100644
@@ -817,6 +817,29 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 #endif
 }
 
+const char *parse_cpu_model(const char *cpu_model)
+{
+    ObjectClass *oc;
+    CPUClass *cc;
+    gchar **model_pieces;
+    const char *cpu_type;
+
+    model_pieces = g_strsplit(cpu_model, ",", 2);
+
+    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+    if (oc == NULL) {
+        error_report("unable to find CPU model '%s'", model_pieces[0]);

exec.c void cpu_exec_realizefn(CPUState *cpu, Error **errp) · line 841

Quoted 10 lines
exec.c +10 -0
+        g_strfreev(model_pieces);
+        exit(EXIT_FAILURE);
+    }
+
+    cpu_type = object_class_get_name(oc);
+    cc = CPU_CLASS(oc);
+    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
+    g_strfreev(model_pieces);
+    return cpu_type;
+}

Sounds good to me. Only two comments:

This looks like duplication of cpu_parse_cpu_model(). Should this function body be replaced with:
cpu_parse_cpu_model(CPU_RESOLVING_TYPE, cpu_model)
?

I would move this to arch_init.c, because that's where existing target-dependent initialization code lives.

Quoted 1 line

[...]

Signature · 1 line
Eduardo
#31 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 72 lines · On Fri, 19 Jan 2018 11:14:30 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 7 lines · On Thu, 18 Jan 2018 17:18:09 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 17 Jan 2018 23:48:46 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

[...]

Quoted 9 lines

It looks like default_cpu_type is being overloaded for two different roles: 1) specifying the default CPU type; 2) finding the arch-specific class to be used to parse -cpu.

In the case of null-machine, these two roles conflict with each other. I believe we can find other solutions instead of this hack that involves lying on MachineClass::default_cpu_type (and then having to work around the lie on machine_none_init()).

Quoted 6 lines

I see multiple options: adding a new MachineClass field for that (e.g. resolving_cpu_type, which defaults to default_cpu_type if NULL); moving the CPU parsing code to arch_init.c (so it could use CPU_RESOLVING_TYPE or something similar); adding a optional MachineClass::parse_cpu_model hook. We could even try to get rid of CPUClass::parse_features completely

Adding hooks just for the sake on null-machine seems to be overkill, I'd go for arch_init.c but it won't work for linux-user, how about exec.c as following:

include/qom/cpu.h +0 -0
index 93bd546..0185589 100644
@@ -661,8 +661,7 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
[...]
exec.c +12 -0
index d28fc0c..4543f06 100644
@@ -817,6 +817,29 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 #endif
 }
 
+const char *parse_cpu_model(const char *cpu_model)
+{
+    ObjectClass *oc;
+    CPUClass *cc;
+    gchar **model_pieces;
+    const char *cpu_type;
+
+    model_pieces = g_strsplit(cpu_model, ",", 2);
+
+    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+    if (oc == NULL) {
+        error_report("unable to find CPU model '%s'", model_pieces[0]);

exec.c void cpu_exec_realizefn(CPUState *cpu, Error **errp) · line 841

Quoted 10 lines
exec.c +10 -0
+        g_strfreev(model_pieces);
+        exit(EXIT_FAILURE);
+    }
+
+    cpu_type = object_class_get_name(oc);
+    cc = CPU_CLASS(oc);
+    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
+    g_strfreev(model_pieces);
+    return cpu_type;
+}

Sounds good to me. Only two comments:

Quoted 3 lines

This looks like duplication of cpu_parse_cpu_model(). Should this function body be replaced with:
cpu_parse_cpu_model(CPU_RESOLVING_TYPE, cpu_model)

it's cpu_parse_cpu_model() which is moved to exec.c
and first typename argument is replaced by inline CPU_RESOLVING_TYPE

Quoted 2 lines

I would move this to arch_init.c, because that's where existing target-dependent initialization code lives.

arch_init.c doesn't fit linux-user, it has only sys emulation code while exec.c is used by both and still target depended so CPU_RESOLVING_TYPE could be used there

Quoted 4 lines
Quoted 3 lines

[...]

#32 lore raw

Re: [Qemu-devel] [PATCH 20/24] machine: drop MachineState::cpu_model

Quoted 82 lines · Igor Mammedov
Quoted 72 lines · On Fri, 19 Jan 2018 11:14:30 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 7 lines · On Thu, 18 Jan 2018 17:18:09 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Wed, 17 Jan 2018 23:48:46 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

The last user of it was machine type 'none', which used field to create CPU id user requested it on CLI with -cpu option.

[...]

Quoted 9 lines

It looks like default_cpu_type is being overloaded for two different roles: 1) specifying the default CPU type; 2) finding the arch-specific class to be used to parse -cpu.

In the case of null-machine, these two roles conflict with each other. I believe we can find other solutions instead of this hack that involves lying on MachineClass::default_cpu_type (and then having to work around the lie on machine_none_init()).

Quoted 6 lines

I see multiple options: adding a new MachineClass field for that (e.g. resolving_cpu_type, which defaults to default_cpu_type if NULL); moving the CPU parsing code to arch_init.c (so it could use CPU_RESOLVING_TYPE or something similar); adding a optional MachineClass::parse_cpu_model hook. We could even try to get rid of CPUClass::parse_features completely

Adding hooks just for the sake on null-machine seems to be overkill, I'd go for arch_init.c but it won't work for linux-user, how about exec.c as following:

include/qom/cpu.h +0 -0
index 93bd546..0185589 100644
@@ -661,8 +661,7 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
[...]
exec.c +12 -0
index d28fc0c..4543f06 100644
@@ -817,6 +817,29 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 #endif
 }
 
+const char *parse_cpu_model(const char *cpu_model)
+{
+    ObjectClass *oc;
+    CPUClass *cc;
+    gchar **model_pieces;
+    const char *cpu_type;
+
+    model_pieces = g_strsplit(cpu_model, ",", 2);
+
+    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
+    if (oc == NULL) {
+        error_report("unable to find CPU model '%s'", model_pieces[0]);

exec.c void cpu_exec_realizefn(CPUState *cpu, Error **errp) · line 841

Quoted 10 lines
exec.c +10 -0
+        g_strfreev(model_pieces);
+        exit(EXIT_FAILURE);
+    }
+
+    cpu_type = object_class_get_name(oc);
+    cc = CPU_CLASS(oc);
+    cc->parse_features(cpu_type, model_pieces[1], &error_fatal);
+    g_strfreev(model_pieces);
+    return cpu_type;
+}

Sounds good to me. Only two comments:

Quoted 3 lines

This looks like duplication of cpu_parse_cpu_model(). Should this function body be replaced with:
cpu_parse_cpu_model(CPU_RESOLVING_TYPE, cpu_model)

it's cpu_parse_cpu_model() which is moved to exec.c
and first typename argument is replaced by inline CPU_RESOLVING_TYPE

Quoted 5 lines
Quoted 2 lines

I would move this to arch_init.c, because that's where existing target-dependent initialization code lives.

arch_init.c doesn't fit linux-user, it has only sys emulation code while exec.c is used by both and still target depended so CPU_RESOLVING_TYPE could be used there

I don't really like adding more code to the mess that is exec.c, but this looks like the simplest solution.

Signature · 1 line
Eduardo
#33 lore raw

PATCH 21/24 linux/bsd-user: drop cpu_init() and use cpu_create() instead

In reply to Igor Mammedov

*-user were the last users of cpu_init() macro, which were used to create a cpu instance using cpu_model name.

Now since all targets provide TARGET_DEFAULT_CPU_TYPE, cpu_init() can be replaced with one call:
cpu_type = cpu_parse_cpu_model(TARGET_DEFAULT_CPU_TYPE, cpu_model)
when '-cpu' CLI option is parsed and
cpu = create_cpu(cpu_type)
whenever a cpu instance needs to be created.

Also drop ifdef-ed definitions of default cpu_model and use target provided TARGET_DEFAULT_CPU_TYPE for it, this way linux/bsd-user targets will become consistent in handling defaults and won't go out off sync as it happened current code.

---
CC: Riku Voipio <[email protected]>
CC: Laurent Vivier <[email protected]>

---
 bsd-user/main.c   | 26 ++++----------------------
 linux-user/main.c | 46 +++++-----------------------------------------
 2 files changed, 9 insertions(+), 63 deletions(-)
bsd-user/main.c +4 -22
index efef5ff..d52ff22 100644
@@ -722,7 +722,7 @@ void init_task_state(TaskState *ts)
 int main(int argc, char **argv)
 {
     const char *filename;
-    const char *cpu_model;
+    const char *cpu_type = TARGET_DEFAULT_CPU_TYPE;
     const char *log_file = NULL;
     const char *log_mask = NULL;
     struct target_pt_regs regs1, *regs = &regs1;
@@ -752,8 +752,6 @@ int main(int argc, char **argv)
         (void) envlist_setenv(envlist, *wrk);
     }
 
-    cpu_model = NULL;
-
     qemu_add_opts(&qemu_trace_opts);
 
     optind = 1;
@@ -811,7 +809,7 @@ int main(int argc, char **argv)
         } else if (!strcmp(r, "r")) {
             qemu_uname_release = argv[optind++];
         } else if (!strcmp(r, "cpu")) {
-            cpu_model = argv[optind++];
+            const char *cpu_model = argv[optind++];
             if (is_help_option(cpu_model)) {
 /* XXX: implement xxx_cpu_list for targets that still miss it */
 #if defined(cpu_list)
@@ -819,6 +817,7 @@ int main(int argc, char **argv)
 #endif
                 exit(1);
             }
+            cpu_type = cpu_parse_cpu_model(TARGET_DEFAULT_CPU_TYPE, cpu_model);
         } else if (!strcmp(r, "B")) {
            guest_base = strtol(argv[optind++], NULL, 0);
            have_guest_base = 1;
@@ -880,27 +879,10 @@ int main(int argc, char **argv)
     /* Scan interp_prefix dir for replacement files. */
     init_paths(interp_prefix);
 
-    if (cpu_model == NULL) {
-#if defined(TARGET_I386)
-#ifdef TARGET_X86_64
-        cpu_model = "qemu64";
-#else
-        cpu_model = "qemu32";
-#endif
-#elif defined(TARGET_SPARC)
-#ifdef TARGET_SPARC64
-        cpu_model = "TI UltraSparc II";
-#else
-        cpu_model = "Fujitsu MB86904";
-#endif
-#else
-        cpu_model = "any";
-#endif
-    }
     tcg_exec_init(0);
     /* NOTE: we need to init the CPU at this stage to get
        qemu_host_page_size */
-    cpu = cpu_init(cpu_model);
+    cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
     cpu_reset(cpu);
linux-user/main.c +5 -41

85 lines not on this page · raw message

Signature · 1 line
2.7.4
#34 lore raw

PATCH 22/24 cpu: get rid of unused cpu_init() defines

In reply to Igor Mammedov

cpu_init(cpu_model) were replaced by cpu_create(cpu_type) so no users are left, remove it.

---
CC: Richard Henderson <[email protected]> (maintainer:Alpha)
CC: Peter Maydell <[email protected]>
CC: "Edgar E. Iglesias" <[email protected]>
CC: Eduardo Habkost <[email protected]>
CC: Michael Walle <[email protected]>
CC: Laurent Vivier <[email protected]>
CC: Aurelien Jarno <[email protected]>
CC: Yongbok Kim <[email protected]>
CC: Anthony Green <[email protected]>
CC: Chris Wulff <[email protected]>
CC: Marek Vasut <[email protected]>
CC: Stafford Horne <[email protected]>
CC: David Gibson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: Mark Cave-Ayland <[email protected]>
CC: Artyom Tarasenko <[email protected]>
CC: Bastian Koppelmann <[email protected]>
CC: Guan Xuetao <[email protected]>
CC: Max Filippov <[email protected]>
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 target/alpha/cpu.h      | 2 --
 target/arm/cpu.h        | 2 --
 target/cris/cpu.h       | 2 --
 target/hppa/cpu.h       | 1 -
 target/i386/cpu.h       | 2 --
 target/lm32/cpu.h       | 2 --
 target/m68k/cpu.h       | 2 --
 target/microblaze/cpu.h | 1 -
 target/mips/cpu.h       | 2 --
 target/moxie/cpu.h      | 2 --
 target/nios2/cpu.h      | 1 -
 target/openrisc/cpu.h   | 2 --
 target/ppc/cpu.h        | 2 --
 target/s390x/cpu.h      | 2 --
 target/sh4/cpu.h        | 2 --
 target/sparc/cpu.h      | 4 ----
 target/tilegx/cpu.h     | 1 -
 target/tricore/cpu.h    | 2 --
 target/unicore32/cpu.h  | 2 --
 target/xtensa/cpu.h     | 2 --
 20 files changed, 38 deletions(-)
target/alpha/cpu.h +0 -2
index c8dd560..1a1d9a0 100644
@@ -468,8 +468,6 @@ enum {
 
 void alpha_translate_init(void);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_ALPHA_CPU, cpu_model)
-
 #define ALPHA_CPU_TYPE_SUFFIX "-" TYPE_ALPHA_CPU
 #define ALPHA_CPU_TYPE_NAME(model) model ALPHA_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE ALPHA_CPU_TYPE_NAME("ev67")
target/arm/cpu.h +0 -2
index c87bb76..3c1e1aa 100644
@@ -2167,8 +2167,6 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
     return unmasked || pstate_unmasked;
 }
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_ARM_CPU, cpu_model)
-
 #define ARM_CPU_TYPE_SUFFIX "-" TYPE_ARM_CPU
 #define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX)
 #define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any")
target/cris/cpu.h +0 -2
index 8feabb4..9845d89 100644
@@ -267,8 +267,6 @@ enum {
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_CRIS_CPU, cpu_model)
-
 #define CRIS_CPU_TYPE_SUFFIX "-" TYPE_CRIS_CPU
 #define CRIS_CPU_TYPE_NAME(name) (name CRIS_CPU_TYPE_SUFFIX)
 #define TARGET_DEFAULT_CPU_TYPE CRIS_CPU_TYPE_NAME("crisv32")
target/hppa/cpu.h +0 -1
index 04625f7..7a6074e 100644
@@ -112,7 +112,6 @@ static inline int cpu_mmu_index(CPUHPPAState *env, bool ifetch)
 
 void hppa_translate_init(void);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_HPPA_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_HPPA_CPU
 
 void hppa_cpu_list(FILE *f, fprintf_function cpu_fprintf);
target/i386/cpu.h +0 -2
index f64e5ed..0b4563b 100644
@@ -1557,8 +1557,6 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 
 #define PHYS_ADDR_MASK MAKE_64BIT_MASK(0, TCG_PHYS_ADDR_BITS)
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_X86_CPU, cpu_model)
-
 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
 #define X86_CPU_TYPE_NAME(name) (name X86_CPU_TYPE_SUFFIX)
 
target/lm32/cpu.h +0 -2
index 65f58f5..ec9efa7 100644
@@ -255,8 +255,6 @@ void lm32_watchpoint_insert(CPULM32State *env, int index, target_ulong address,
 void lm32_watchpoint_remove(CPULM32State *env, int index);
 bool lm32_cpu_do_semihosting(CPUState *cs);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_LM32_CPU, cpu_model)
-
 #define LM32_CPU_TYPE_SUFFIX "-" TYPE_LM32_CPU
 #define LM32_CPU_TYPE_NAME(model) model LM32_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE LM32_CPU_TYPE_NAME("lm32-basic")
target/m68k/cpu.h +0 -2
index 193e8f8..da4171c 100644
@@ -401,8 +401,6 @@ void register_m68k_insns (CPUM68KState *env);
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_M68K_CPU, cpu_model)
-
 #define M68K_CPU_TYPE_SUFFIX "-" TYPE_M68K_CPU
 #define M68K_CPU_TYPE_NAME(model) model M68K_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE M68K_CPU_TYPE_NAME("any")
target/microblaze/cpu.h +0 -1
index f244efa..3ad1016 100644
@@ -343,7 +343,6 @@ int cpu_mb_signal_handler(int host_signum, void *pinfo,
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_MICROBLAZE_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_MICROBLAZE_CPU
 
 #define cpu_signal_handler cpu_mb_signal_handler
target/mips/cpu.h +0 -2
index c5ee894..7c66ec0 100644
@@ -739,8 +739,6 @@ enum {
 
 int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_MIPS_CPU, cpu_model)
-
 #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
 #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
 
target/moxie/cpu.h +0 -2
index 9fabb93..a3a1bba 100644
@@ -120,8 +120,6 @@ void moxie_translate_init(void);
 int cpu_moxie_signal_handler(int host_signum, void *pinfo,
                              void *puc);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_MOXIE_CPU, cpu_model)
-
 #define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU
 #define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE MOXIE_CPU_TYPE_NAME("any")
target/nios2/cpu.h +0 -1
index 2d03958..71a48b1 100644
@@ -231,7 +231,6 @@ void nios2_check_interrupts(CPUNios2State *env);
 # define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_NIOS2_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_NIOS2_CPU
 
 #define cpu_gen_code cpu_nios2_gen_code
target/openrisc/cpu.h +0 -2
index 8d1a87e..f2d2abb 100644
@@ -390,8 +390,6 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
                                int *prot, target_ulong address, int rw);
 #endif
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model)
-
 #define OPENRISC_CPU_TYPE_SUFFIX "-" TYPE_OPENRISC_CPU
 #define OPENRISC_CPU_TYPE_NAME(model) model OPENRISC_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE OPENRISC_CPU_TYPE_NAME("or1200")
target/ppc/cpu.h +0 -2
index 4af4aff..3dc0359 100644
@@ -1372,8 +1372,6 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
 int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp);
 int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_POWERPC_CPU, cpu_model)
-
 #define POWERPC_CPU_TYPE_SUFFIX "-" TYPE_POWERPC_CPU
 #define POWERPC_CPU_TYPE_NAME(model) model POWERPC_CPU_TYPE_SUFFIX
 
target/s390x/cpu.h +0 -2
index 174624a..3e647df 100644
@@ -727,8 +727,6 @@ void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
 
 /* helper.c */
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model)
-
 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
 #define TARGET_DEFAULT_CPU_TYPE S390_CPU_TYPE_NAME("qemu")
target/sh4/cpu.h +0 -2
index 203d212..ad58e24 100644
@@ -274,8 +274,6 @@ int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr);
 
 void cpu_load_tlb(CPUSH4State * env);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_SUPERH_CPU, cpu_model)
-
 #define SUPERH_CPU_TYPE_SUFFIX "-" TYPE_SUPERH_CPU
 #define SUPERH_CPU_TYPE_NAME(model) model SUPERH_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE SUPERH_CPU_TYPE_NAME("sh7785")
target/sparc/cpu.h +0 -4
index 02c55ad..54b3dc7 100644
@@ -654,10 +654,6 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
 #endif
 int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#ifndef NO_CPU_IO_DEFS
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_SPARC_CPU, cpu_model)
-#endif
-
 #define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
 #define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
 
target/tilegx/cpu.h +0 -1
index 67de53e..6c89b05 100644
@@ -164,7 +164,6 @@ static inline TileGXCPU *tilegx_env_get_cpu(CPUTLGState *env)
 void tilegx_tcg_init(void);
 int cpu_tilegx_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_TILEGX_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_TILEGX_CPU
 
 #define cpu_signal_handler cpu_tilegx_signal_handler
target/tricore/cpu.h +0 -2
index 835d51a..8ed17e0 100644
@@ -411,8 +411,6 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
     *flags = 0;
 }
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_TRICORE_CPU, cpu_model)
-
 #define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
 #define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE TRICORE_CPU_TYPE_NAME("tc1796")
target/unicore32/cpu.h +0 -2
index fd3fa81..91b673a 100644
@@ -165,8 +165,6 @@ static inline int cpu_mmu_index(CPUUniCore32State *env, bool ifetch)
 
 #include "exec/cpu-all.h"
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model)
-
 #define UNICORE32_CPU_TYPE_SUFFIX "-" TYPE_UNICORE32_CPU
 #define UNICORE32_CPU_TYPE_NAME(model) model UNICORE32_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE UNICORE32_CPU_TYPE_NAME("any")
target/xtensa/cpu.h +0 -2
index 537e151..c21acf9 100644
@@ -508,8 +508,6 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 #endif
 #define TARGET_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
-
 void xtensa_translate_init(void);
 void xtensa_breakpoint_handler(CPUState *cs);
 void xtensa_finalize_config(XtensaConfig *config);
Signature · 1 line
2.7.4
Acked-by on v1 22/24
#35 lore raw

Re: [Qemu-arm] [PATCH 22/24] cpu: get rid of unused cpu_init() defines

Quoted 4 lines · Igor Mammedov

cpu_init(cpu_model) were replaced by cpu_create(cpu_type) so no users are left, remove it.

ppc part

Quoted 304 lines

---
CC: Richard Henderson <[email protected]> (maintainer:Alpha)
CC: Peter Maydell <[email protected]>
CC: "Edgar E. Iglesias" <[email protected]>
CC: Eduardo Habkost <[email protected]>
CC: Michael Walle <[email protected]>
CC: Laurent Vivier <[email protected]>
CC: Aurelien Jarno <[email protected]>
CC: Yongbok Kim <[email protected]>
CC: Anthony Green <[email protected]>
CC: Chris Wulff <[email protected]>
CC: Marek Vasut <[email protected]>
CC: Stafford Horne <[email protected]>
CC: David Gibson <[email protected]>
CC: Alexander Graf <[email protected]>
CC: Mark Cave-Ayland <[email protected]>
CC: Artyom Tarasenko <[email protected]>
CC: Bastian Koppelmann <[email protected]>
CC: Guan Xuetao <[email protected]>
CC: Max Filippov <[email protected]>
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 target/alpha/cpu.h      | 2 --
 target/arm/cpu.h        | 2 --
 target/cris/cpu.h       | 2 --
 target/hppa/cpu.h       | 1 -
 target/i386/cpu.h       | 2 --
 target/lm32/cpu.h       | 2 --
 target/m68k/cpu.h       | 2 --
 target/microblaze/cpu.h | 1 -
 target/mips/cpu.h       | 2 --
 target/moxie/cpu.h      | 2 --
 target/nios2/cpu.h      | 1 -
 target/openrisc/cpu.h   | 2 --
 target/ppc/cpu.h        | 2 --
 target/s390x/cpu.h      | 2 --
 target/sh4/cpu.h        | 2 --
 target/sparc/cpu.h      | 4 ----
 target/tilegx/cpu.h     | 1 -
 target/tricore/cpu.h    | 2 --
 target/unicore32/cpu.h  | 2 --
 target/xtensa/cpu.h     | 2 --
 20 files changed, 38 deletions(-)
target/alpha/cpu.h +0 -2
index c8dd560..1a1d9a0 100644
@@ -468,8 +468,6 @@ enum {
 
 void alpha_translate_init(void);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_ALPHA_CPU, cpu_model)
-
 #define ALPHA_CPU_TYPE_SUFFIX "-" TYPE_ALPHA_CPU
 #define ALPHA_CPU_TYPE_NAME(model) model ALPHA_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE ALPHA_CPU_TYPE_NAME("ev67")
target/arm/cpu.h +0 -2
index c87bb76..3c1e1aa 100644
@@ -2167,8 +2167,6 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
     return unmasked || pstate_unmasked;
 }
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_ARM_CPU, cpu_model)
-
 #define ARM_CPU_TYPE_SUFFIX "-" TYPE_ARM_CPU
 #define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX)
 #define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any")
target/cris/cpu.h +0 -2
index 8feabb4..9845d89 100644
@@ -267,8 +267,6 @@ enum {
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_CRIS_CPU, cpu_model)
-
 #define CRIS_CPU_TYPE_SUFFIX "-" TYPE_CRIS_CPU
 #define CRIS_CPU_TYPE_NAME(name) (name CRIS_CPU_TYPE_SUFFIX)
 #define TARGET_DEFAULT_CPU_TYPE CRIS_CPU_TYPE_NAME("crisv32")
target/hppa/cpu.h +0 -1
index 04625f7..7a6074e 100644
@@ -112,7 +112,6 @@ static inline int cpu_mmu_index(CPUHPPAState *env, bool ifetch)
 
 void hppa_translate_init(void);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_HPPA_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_HPPA_CPU
 
 void hppa_cpu_list(FILE *f, fprintf_function cpu_fprintf);
target/i386/cpu.h +0 -2
index f64e5ed..0b4563b 100644
@@ -1557,8 +1557,6 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 
 #define PHYS_ADDR_MASK MAKE_64BIT_MASK(0, TCG_PHYS_ADDR_BITS)
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_X86_CPU, cpu_model)
-
 #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
 #define X86_CPU_TYPE_NAME(name) (name X86_CPU_TYPE_SUFFIX)
 
target/lm32/cpu.h +0 -2
index 65f58f5..ec9efa7 100644
@@ -255,8 +255,6 @@ void lm32_watchpoint_insert(CPULM32State *env, int index, target_ulong address,
 void lm32_watchpoint_remove(CPULM32State *env, int index);
 bool lm32_cpu_do_semihosting(CPUState *cs);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_LM32_CPU, cpu_model)
-
 #define LM32_CPU_TYPE_SUFFIX "-" TYPE_LM32_CPU
 #define LM32_CPU_TYPE_NAME(model) model LM32_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE LM32_CPU_TYPE_NAME("lm32-basic")
target/m68k/cpu.h +0 -2
index 193e8f8..da4171c 100644
@@ -401,8 +401,6 @@ void register_m68k_insns (CPUM68KState *env);
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_M68K_CPU, cpu_model)
-
 #define M68K_CPU_TYPE_SUFFIX "-" TYPE_M68K_CPU
 #define M68K_CPU_TYPE_NAME(model) model M68K_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE M68K_CPU_TYPE_NAME("any")
target/microblaze/cpu.h +0 -1
index f244efa..3ad1016 100644
@@ -343,7 +343,6 @@ int cpu_mb_signal_handler(int host_signum, void *pinfo,
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_MICROBLAZE_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_MICROBLAZE_CPU
 
 #define cpu_signal_handler cpu_mb_signal_handler
target/mips/cpu.h +0 -2
index c5ee894..7c66ec0 100644
@@ -739,8 +739,6 @@ enum {
 
 int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_MIPS_CPU, cpu_model)
-
 #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
 #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
 
target/moxie/cpu.h +0 -2
index 9fabb93..a3a1bba 100644
@@ -120,8 +120,6 @@ void moxie_translate_init(void);
 int cpu_moxie_signal_handler(int host_signum, void *pinfo,
                              void *puc);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_MOXIE_CPU, cpu_model)
-
 #define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU
 #define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE MOXIE_CPU_TYPE_NAME("any")
target/nios2/cpu.h +0 -1
index 2d03958..71a48b1 100644
@@ -231,7 +231,6 @@ void nios2_check_interrupts(CPUNios2State *env);
 # define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_NIOS2_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_NIOS2_CPU
 
 #define cpu_gen_code cpu_nios2_gen_code
target/openrisc/cpu.h +0 -2
index 8d1a87e..f2d2abb 100644
@@ -390,8 +390,6 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
                                int *prot, target_ulong address, int rw);
 #endif
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model)
-
 #define OPENRISC_CPU_TYPE_SUFFIX "-" TYPE_OPENRISC_CPU
 #define OPENRISC_CPU_TYPE_NAME(model) model OPENRISC_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE OPENRISC_CPU_TYPE_NAME("or1200")
target/ppc/cpu.h +0 -2
index 4af4aff..3dc0359 100644
@@ -1372,8 +1372,6 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
 int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp);
 int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_POWERPC_CPU, cpu_model)
-
 #define POWERPC_CPU_TYPE_SUFFIX "-" TYPE_POWERPC_CPU
 #define POWERPC_CPU_TYPE_NAME(model) model POWERPC_CPU_TYPE_SUFFIX
 
target/s390x/cpu.h +0 -2
index 174624a..3e647df 100644
@@ -727,8 +727,6 @@ void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
 
 /* helper.c */
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model)
-
 #define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
 #define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
 #define TARGET_DEFAULT_CPU_TYPE S390_CPU_TYPE_NAME("qemu")
target/sh4/cpu.h +0 -2
index 203d212..ad58e24 100644
@@ -274,8 +274,6 @@ int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr);
 
 void cpu_load_tlb(CPUSH4State * env);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_SUPERH_CPU, cpu_model)
-
 #define SUPERH_CPU_TYPE_SUFFIX "-" TYPE_SUPERH_CPU
 #define SUPERH_CPU_TYPE_NAME(model) model SUPERH_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE SUPERH_CPU_TYPE_NAME("sh7785")
target/sparc/cpu.h +0 -4
index 02c55ad..54b3dc7 100644
@@ -654,10 +654,6 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
 #endif
 int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#ifndef NO_CPU_IO_DEFS
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_SPARC_CPU, cpu_model)
-#endif
-
 #define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
 #define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
 
target/tilegx/cpu.h +0 -1
index 67de53e..6c89b05 100644
@@ -164,7 +164,6 @@ static inline TileGXCPU *tilegx_env_get_cpu(CPUTLGState *env)
 void tilegx_tcg_init(void);
 int cpu_tilegx_signal_handler(int host_signum, void *pinfo, void *puc);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_TILEGX_CPU, cpu_model)
 #define TARGET_DEFAULT_CPU_TYPE TYPE_TILEGX_CPU
 
 #define cpu_signal_handler cpu_tilegx_signal_handler
target/tricore/cpu.h +0 -2
index 835d51a..8ed17e0 100644
@@ -411,8 +411,6 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
     *flags = 0;
 }
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_TRICORE_CPU, cpu_model)
-
 #define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
 #define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE TRICORE_CPU_TYPE_NAME("tc1796")
target/unicore32/cpu.h +0 -2
index fd3fa81..91b673a 100644
@@ -165,8 +165,6 @@ static inline int cpu_mmu_index(CPUUniCore32State *env, bool ifetch)
 
 #include "exec/cpu-all.h"
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model)
-
 #define UNICORE32_CPU_TYPE_SUFFIX "-" TYPE_UNICORE32_CPU
 #define UNICORE32_CPU_TYPE_NAME(model) model UNICORE32_CPU_TYPE_SUFFIX
 #define TARGET_DEFAULT_CPU_TYPE UNICORE32_CPU_TYPE_NAME("any")
target/xtensa/cpu.h +0 -2
index 537e151..c21acf9 100644
@@ -508,8 +508,6 @@ void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
 #endif
 #define TARGET_DEFAULT_CPU_TYPE XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_XTENSA_CPU, cpu_model)
-
 void xtensa_translate_init(void);
 void xtensa_breakpoint_handler(CPUState *cs);
 void xtensa_finalize_config(XtensaConfig *config);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#37 lore raw

PATCH 23/24 nios2: 10m50_devboard: replace cpu_model with cpu_type

In reply to Igor Mammedov

use cpu_create() instead of being removed cpu_generic_init()

---
CC: Chris Wulff <[email protected]>
CC: Marek Vasut <[email protected]>

---
 hw/nios2/10m50_devboard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nios2/10m50_devboard.c +1 -1
index e4007f6..42053b2 100644
@@ -75,7 +75,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
                                 phys_ram_alias);
 
     /* Create CPU -- FIXME */
-    cpu = NIOS2_CPU(cpu_generic_init(TYPE_NIOS2_CPU, "nios2"));
+    cpu = NIOS2_CPU(cpu_create(TYPE_NIOS2_CPU));
 
     /* Register: CPU interrupt controller (PIC) */
     cpu_irq = nios2_cpu_pic_init(cpu);
Signature · 1 line
2.7.4
#38 lore raw

PATCH 24/24 cpu: get rid of cpu_generic_init()

In reply to Igor Mammedov

There aren't any users of the helper left, remove it.

---
CC: Richard Henderson <[email protected]>
CC: "Emilio G. Cota" <[email protected]>
CC: Paolo Bonzini <[email protected]>
CC: Eduardo Habkost <[email protected]>
CC: "Alex Bennée" <[email protected]>
CC: "Philippe Mathieu-Daudé" <[email protected]>

---
 include/qom/cpu.h | 11 -----------
 qom/cpu.c         | 25 ++-----------------------
 2 files changed, 2 insertions(+), 34 deletions(-)
include/qom/cpu.h +0 -11
index 93bd546..5446040 100644
@@ -673,17 +673,6 @@ CPUState *cpu_create(const char *typename);
 const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model);
 
 /**
- * cpu_generic_init:
- * @typename: The CPU base type.
- * @cpu_model: The model string including optional parameters.
- *
- * Instantiates a CPU, processes optional parameters and realizes the CPU.
- *
- * Returns: A #CPUState or %NULL if an error occurred.
- */
-CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
-
-/**
  * cpu_has_work:
  * @cpu: The vCPU to check.
  *
qom/cpu.c +2 -23
index e42d9a7..7ab7c36 100644
@@ -90,14 +90,6 @@ const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model)
     return cpu_type;
 }
 
-CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
-{
-    /* TODO: all callers of cpu_generic_init() need to be converted to
-     * call cpu_parse_features() only once, before calling cpu_generic_init().
-     */
-    return cpu_create(cpu_parse_cpu_model(typename, cpu_model));
-}
-
 bool cpu_paging_enabled(const CPUState *cpu)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
@@ -335,22 +327,9 @@ static ObjectClass *cpu_common_class_by_name(const char *cpu_model)
 static void cpu_common_parse_features(const char *typename, char *features,
                                       Error **errp)
 {
-    char *featurestr; /* Single "key=value" string being parsed */
     char *val;
-    static bool cpu_globals_initialized;
-
-    /* TODO: all callers of ->parse_features() need to be changed to
-     * call it only once, so we can remove this check (or change it
-     * to assert(!cpu_globals_initialized).
-     * Current callers of ->parse_features() are:
-     * - cpu_generic_init()
-     */
-    if (cpu_globals_initialized) {
-        return;
-    }
-    cpu_globals_initialized = true;
-
-    featurestr = features ? strtok(features, ",") : NULL;
+    /* Single "key=value" string being parsed */
+    char *featurestr = features ? strtok(features, ",") : NULL;
 
     while (featurestr) {
         val = strchr(featurestr, '=');
Signature · 1 line
2.7.4
#39 lore raw
In reply to Igor Mammedov
Quoted 5 lines · Igor Mammedov

Series is finishing work on generalizing cpu_model parsing and limiting parts that deal with inconsistent cpu_model naming to "-cpu" CLI option processing in vl.c/*-user.main.c and FOO_cpu_class_by_name() callbacks.

Quoted 7 lines

It introduces TARGET_DEFAULT_CPU_TYPE which must be defined by each target and is used setting default cpu type for linux/bsd-user targets and as anchor point to pick cpu class that provides target specific FOO_cpu_class_by_name() callback for cpu_parse_cpu_model() in null-machine.c which is compiled for all targets that have system mode emulation.

I like moving this from being an ifdef ladder into per-cpu code, but I don't think the definition belongs in target/$ARCH. It's part of the choice usermode makes about how to handle binaries it's loading, so it should go in linux-user/$ARCH/target_cpu.h. target/$ARCH should really be for things that are properties of the architecture.

thanks
-- PMM

#40 lore raw
Quoted 14 lines · On Wed, 17 Jan 2018 16:12:09 +0000 Peter Maydell <[email protected]>…
Quoted 5 lines · Igor Mammedov

Series is finishing work on generalizing cpu_model parsing and limiting parts that deal with inconsistent cpu_model naming to "-cpu" CLI option processing in vl.c/*-user.main.c and FOO_cpu_class_by_name() callbacks.

Quoted 7 lines

It introduces TARGET_DEFAULT_CPU_TYPE which must be defined by each target and is used setting default cpu type for linux/bsd-user targets and as anchor point to pick cpu class that provides target specific FOO_cpu_class_by_name() callback for cpu_parse_cpu_model() in null-machine.c which is compiled for all targets that have system mode emulation.

Quoted 6 lines

I like moving this from being an ifdef ladder into per-cpu code, but I don't think the definition belongs in target/$ARCH. It's part of the choice usermode makes about how to handle binaries it's loading, so it should go in linux-user/$ARCH/target_cpu.h. target/$ARCH should really be for things that are properties of the architecture.

That's used not only by linux-user but also reused by null-machine.c to get access to a target specific cpu_class_by_name() callback. I admit that it's a convoluted API i.e. for cpu_parse_cpu_model() to require a target specific CPU type to resolve cpu_model name, but that's what we ended up with and have now.
It seemed logical to me to put YET_ANOTHER_CPU_TYPE to target/$ARCH/cpu.h along with other target specific CPU type macros'.

Main goal of this series is not TARGET_DEFAULT_CPU_TYPE and its abuse by null-machine.c, but rather getting rid of cpu_model handling across whole tree (which is easy to misuse due to existing APIs and its general availability) and limiting cpu_model translation to option parsing+target specific cpu_class_by_name() callbacks.

We can build on top of that linux-user specific extension
to pick CPU type based on ELF notes, the difference would
be that it will work with cpu types and not with cpu_model
as it were implemented in:
[PATCH v3 0/4] linux-user: select CPU type according ELF header values

Quoted 2 lines

thanks
-- PMM

#41 lore raw
Quoted 10 lines · Igor Mammedov
Quoted 6 lines · On Wed, 17 Jan 2018 16:12:09 +0000 Peter Maydell <[email protected]>…

I like moving this from being an ifdef ladder into per-cpu code, but I don't think the definition belongs in target/$ARCH. It's part of the choice usermode makes about how to handle binaries it's loading, so it should go in linux-user/$ARCH/target_cpu.h. target/$ARCH should really be for things that are properties of the architecture.

That's used not only by linux-user but also reused by null-machine.c to get access to a target specific cpu_class_by_name() callback.

That usage must want a different name, though, surely? For Arm the default CPU for linux-user is 'any' but that is usermode only and won't work for system emulation so null-machine.c will need to pick something else.

thanks
-- PMM

#42 lore raw
Quoted 9 lines · On Wed, 17 Jan 2018 20:30:14 +0000 Peter Maydell <[email protected]>…
Quoted 8 lines · Igor Mammedov
Quoted 6 lines · On Wed, 17 Jan 2018 16:12:09 +0000 Peter Maydell <[email protected]>…

I like moving this from being an ifdef ladder into per-cpu code, but I don't think the definition belongs in target/$ARCH. It's part of the choice usermode makes about how to handle binaries it's loading, so it should go in linux-user/$ARCH/target_cpu.h. target/$ARCH should really be for things that are properties of the architecture.

Quoted 7 lines
Quoted 2 lines

That's used not only by linux-user but also reused by null-machine.c to get access to a target specific cpu_class_by_name() callback.

That usage must want a different name, though, surely? For Arm the default CPU for linux-user is 'any' but that is usermode only and won't work for system emulation so null-machine.c will need to pick something else.

not really in general as boards set their own default types and secondly it applies only to null-machine. Though in both cases it work the same just fine because current API works like this (system emulation)
vl.c:

        current_machine->cpu_type = machine_class->default_cpu_type;             
        if (cpu_model) {                                                         
            current_machine->cpu_type =                                          
                cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model); 
            ...
        }

which would result for null-machine (patch 20/24) in:

cpu_parse_cpu_model(TARGET_DEFAULT_CPU_TYPE, cpu_model):
oc = cpu_class_by_name(TARGET_DEFAULT_CPU_TYPE, cpu_model):
cc = CPU_CLASS(object_class_by_name(TARGET_DEFAULT_CPU_TYPE)) cc->class_by_name(cpu_model)

so it doesn't really matter for system emulation what exact type is used as a proxy to reach callback, as each target implements only one cb in base CPU class and any leaf class will work fine to reach the same class_by_name() cb. So type that is default for linux-user can be abused for this purpose and could be used as linux-default at the same time.

Ugly and hackish, yes.
But it isolates cpu_model handling to a few places and series removes API that uses it, so we won't have to watch out for patches that would bring cpu_model back into boards code after that.

On top of that, we could work on making cpu_parse_cpu_model() API not to require proxy cpu type and that would affect only 3 remaining callers in vl.c,bsd/linux-user/main.c But that another re-factoring beyond the scope of this series, which is already big as it is.

Quoted 2 lines

thanks
-- PMM

#43 lore raw
Quoted 18 lines · Igor Mammedov
Quoted 4 lines · Peter Maydell

That usage must want a different name, though, surely? For Arm the default CPU for linux-user is 'any' but that is usermode only and won't work for system emulation so null-machine.c will need to pick something else.

not really in general as boards set their own default types and secondly it applies only to null-machine. Though in both cases it work the same just fine because current API works like this (system emulation)
vl.c:

        current_machine->cpu_type = machine_class->default_cpu_type;
        if (cpu_model) {
            current_machine->cpu_type =
                cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model);
            ...
        }
Quoted 6 lines

which would result for null-machine (patch 20/24) in:

cpu_parse_cpu_model(TARGET_DEFAULT_CPU_TYPE, cpu_model):
oc = cpu_class_by_name(TARGET_DEFAULT_CPU_TYPE, cpu_model):
cc = CPU_CLASS(object_class_by_name(TARGET_DEFAULT_CPU_TYPE)) cc->class_by_name(cpu_model)

In system emulation we don't define the "any" cpu type at all, so I would expect cpu_class_by_name() to always return an error here.

thanks
-- PMM

#44 lore raw
Quoted 21 lines · On Thu, 18 Jan 2018 10:50:19 +0000 Peter Maydell <[email protected]>…
Quoted 20 lines · Igor Mammedov
Quoted 4 lines · Peter Maydell

That usage must want a different name, though, surely? For Arm the default CPU for linux-user is 'any' but that is usermode only and won't work for system emulation so null-machine.c will need to pick something else.

not really in general as boards set their own default types and secondly it applies only to null-machine. Though in both cases it work the same just fine because current API works like this (system emulation)
vl.c:

        current_machine->cpu_type = machine_class->default_cpu_type;
        if (cpu_model) {
            current_machine->cpu_type =
                cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model);
            ...
        }

which would result for null-machine (patch 20/24) in:

Quoted 8 lines
Quoted 4 lines

cpu_parse_cpu_model(TARGET_DEFAULT_CPU_TYPE, cpu_model):
oc = cpu_class_by_name(TARGET_DEFAULT_CPU_TYPE, cpu_model):
cc = CPU_CLASS(object_class_by_name(TARGET_DEFAULT_CPU_TYPE)) cc->class_by_name(cpu_model)

In system emulation we don't define the "any" cpu type at all, so I would expect cpu_class_by_name() to always return an error here.

My bad, 'make check' was fine but it looks like we don't test null-machine with -cpu foo, I should add a patch for that along with series on respin.

I've looked and such case is rather an exception, I can fix it up in 2 ways:
1st:
target/arm/cpu.h
+#if !defined(CONFIG_USER_ONLY)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_ARM_CPU +else
+#define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any") +#endif

or 2nd is to compile in "any" type in system mode (which most targets do), roughly it would amount to:
target/arm/cpu.c

  @@ -1671,10 +1671,8 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "pxa270-b1",   .initfn = pxa270b1_initfn },
     { .name = "pxa270-c0",   .initfn = pxa270c0_initfn },
     { .name = "pxa270-c5",   .initfn = pxa270c5_initfn },
  -#ifdef CONFIG_USER_ONLY
     { .name = "any",         .initfn = arm_any_initfn },
   #endif
  -#endif
     { .name = NULL }

};

and it would allow us to drop/cleanup more ifdefs in target/arm/cpu.c I'd prefer 2nd approach, so code would be more consistent with other targets and as benefit with less ifdefs.

Quoted 2 lines

thanks
-- PMM

#45 lore raw
Quoted 9 lines · Igor Mammedov

I've looked and such case is rather an exception, I can fix it up in 2 ways:
1st:
target/arm/cpu.h
+#if !defined(CONFIG_USER_ONLY)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_ARM_CPU +else
+#define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any") +#endif

This is weird, because TYPE_ARM_CPU isn't really a sensible thing to use for anything, so you've really set it up as a "this is only of any use for null-machine.c", in which case you should just do that in null-machine.c.

Quoted 12 lines

or 2nd is to compile in "any" type in system mode (which most targets do), roughly it would amount to:
target/arm/cpu.c

  @@ -1671,10 +1671,8 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "pxa270-b1",   .initfn = pxa270b1_initfn },
     { .name = "pxa270-c0",   .initfn = pxa270c0_initfn },
     { .name = "pxa270-c5",   .initfn = pxa270c5_initfn },
  -#ifdef CONFIG_USER_ONLY
     { .name = "any",         .initfn = arm_any_initfn },
   #endif
  -#endif
     { .name = NULL }
Quoted 1 line

};

This is definitely wrong. We deliberately don't provide "any" in system mode, because it's not a sensible thing for users to try to use with board emulation. We disabled it some while back to avoid users trying it by accident and getting confused.

In general, for Arm you really need to know which CPU you want to use and why. So:
linux-user and bsd-user: should use "any"
board models: should use whatever CPU that board is designed for
null-machine: if it genuinely doesn't care, then pick one at random

But there is no single sensible "default CPU type" at an architecture level, which is why you can't define a TARGET_DEFAULT_CPU_TYPE in target/arm/cpu.h. Any code that thinks it wants that should instead be defining it own default that makes sense for that context.

thanks
-- PMM

#46 lore raw
Quoted 11 lines · On Thu, 18 Jan 2018 13:10:13 +0000 Peter Maydell <[email protected]>…
Quoted 9 lines · Igor Mammedov

I've looked and such case is rather an exception, I can fix it up in 2 ways:
1st:
target/arm/cpu.h
+#if !defined(CONFIG_USER_ONLY)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_ARM_CPU +else
+#define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any") +#endif

Quoted 4 lines

This is weird, because TYPE_ARM_CPU isn't really a sensible thing to use for anything, so you've really set it up as a "this is only of any use for null-machine.c", in which case you should just do that in null-machine.c.

yep, that would be only for null-machine.c use as proxy type, however null-machine.c is build for every target so this proxy type can't be defined null-machine.c unless we resort to ifdef ladder there.

How about adding to each $ARCH/cpu.h a null-machine dedicated define:

  #define CPU_RESOLVING_TYPE TYPE_FOO_CPU

using that in null machine and renaming

TARGET_DEFAULT_CPU_TYPE to USERONLY_DEFAULT_CPU_TYPE

but I'd still keep it within $ARCH/cpu.h so we won't have to create a bunch of new linux-user/$ARCH/target_elf.h files just for that and duplicate it to bsd-user/$ARCH/target_elf.h

Quoted 2 lines

thanks
-- PMM

#47 lore raw
Quoted 7 lines · Igor Mammedov

and renaming

TARGET_DEFAULT_CPU_TYPE to USERONLY_DEFAULT_CPU_TYPE

but I'd still keep it within $ARCH/cpu.h so we won't have to create a bunch of new linux-user/$ARCH/target_elf.h files just for that and duplicate it to bsd-user/$ARCH/target_elf.h

We already have linux-user/$ARCH/target_cpu.h, which is exactly for this kind of define.

thanks
-- PMM

#48 lore raw
Quoted 11 lines · On Thu, 18 Jan 2018 13:36:40 +0000 Peter Maydell <[email protected]>…
Quoted 7 lines · Igor Mammedov

and renaming

TARGET_DEFAULT_CPU_TYPE to USERONLY_DEFAULT_CPU_TYPE

but I'd still keep it within $ARCH/cpu.h so we won't have to create a bunch of new linux-user/$ARCH/target_elf.h files just for that and duplicate it to bsd-user/$ARCH/target_elf.h

We already have linux-user/$ARCH/target_cpu.h, which is exactly for this kind of define.

we don't have it for bsd-user though and it would be code duplication to add such.
Using $ARCH/cpu.h seems to be a better fit for sharing default across liux/bsd-user.

Quoted 2 lines

thanks
-- PMM

#49 lore raw
Quoted 12 lines · Igor Mammedov
Quoted 9 lines · On Thu, 18 Jan 2018 13:36:40 +0000 Peter Maydell <[email protected]>…
Quoted 7 lines · Igor Mammedov

and renaming

TARGET_DEFAULT_CPU_TYPE to USERONLY_DEFAULT_CPU_TYPE

but I'd still keep it within $ARCH/cpu.h so we won't have to create a bunch of new linux-user/$ARCH/target_elf.h files just for that and duplicate it to bsd-user/$ARCH/target_elf.h

Quoted 6 lines
Quoted 2 lines

We already have linux-user/$ARCH/target_cpu.h, which is exactly for this kind of define.

we don't have it for bsd-user though and it would be code duplication to add such.
Using $ARCH/cpu.h seems to be a better fit for sharing default across liux/bsd-user.

Yes, bsd-user is a bit unmaintained and behind linux-user in its structuring. I don't mind bsd-user being a bit of a mess, but I don't want problems in bsd-user to cause us to put code where it shouldn't be in other parts of the codebase. (It's not inherently the case that "best CPU choice for Linux user" is the same as "best CPU choice for bsd-user" either.)

thanks
-- PMM

#50 lore raw
Quoted 20 lines · On Thu, 18 Jan 2018 13:49:25 +0000 Peter Maydell <[email protected]>…
Quoted 12 lines · Igor Mammedov
Quoted 9 lines · On Thu, 18 Jan 2018 13:36:40 +0000 Peter Maydell <[email protected]>…
Quoted 7 lines · Igor Mammedov

and renaming

TARGET_DEFAULT_CPU_TYPE to USERONLY_DEFAULT_CPU_TYPE

but I'd still keep it within $ARCH/cpu.h so we won't have to create a bunch of new linux-user/$ARCH/target_elf.h files just for that and duplicate it to bsd-user/$ARCH/target_elf.h

Quoted 6 lines
Quoted 2 lines

We already have linux-user/$ARCH/target_cpu.h, which is exactly for this kind of define.

we don't have it for bsd-user though and it would be code duplication to add such.
Using $ARCH/cpu.h seems to be a better fit for sharing default across liux/bsd-user.

Quoted 6 lines

Yes, bsd-user is a bit unmaintained and behind linux-user in its structuring. I don't mind bsd-user being a bit of a mess, but I don't want problems in bsd-user to cause us to put code where it shouldn't be in other parts of the codebase. (It's not inherently the case that "best CPU choice for Linux user" is the same as "best CPU choice for bsd-user" either.)

Ok, if there isn't objections wrt above mentioned code duplication in *-user, I surely can implement it as far as I can remove cpu_model along with it.

Quoted 3 lines

thanks
-- PMM

#51 lore raw
In reply to Peter Maydell

(CC'ing linux-user maintainers)

Hi Peter, Igor,

Quoted 30 lines · Peter Maydell
Quoted 9 lines · Igor Mammedov

I've looked and such case is rather an exception, I can fix it up in 2 ways:
1st:
target/arm/cpu.h
+#if !defined(CONFIG_USER_ONLY)
+#define TARGET_DEFAULT_CPU_TYPE TYPE_ARM_CPU +else
+#define TARGET_DEFAULT_CPU_TYPE ARM_CPU_TYPE_NAME("any") +#endif

This is weird, because TYPE_ARM_CPU isn't really a sensible thing to use for anything, so you've really set it up as a "this is only of any use for null-machine.c", in which case you should just do that in null-machine.c.

Quoted 12 lines

or 2nd is to compile in "any" type in system mode (which most targets do), roughly it would amount to:
target/arm/cpu.c

  @@ -1671,10 +1671,8 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "pxa270-b1",   .initfn = pxa270b1_initfn },
     { .name = "pxa270-c0",   .initfn = pxa270c0_initfn },
     { .name = "pxa270-c5",   .initfn = pxa270c5_initfn },
  -#ifdef CONFIG_USER_ONLY
     { .name = "any",         .initfn = arm_any_initfn },
   #endif
  -#endif
     { .name = NULL }
Quoted 1 line

};

Quoted 8 lines

This is definitely wrong. We deliberately don't provide "any" in system mode, because it's not a sensible thing for users to try to use with board emulation. We disabled it some while back to avoid users trying it by accident and getting confused.

In general, for Arm you really need to know which CPU you want to use and why. So:
linux-user and bsd-user: should use "any"

I disagree on this, since userland binaries are compiled for a specific arch/ABI/FPU.
Even without worrying about the FPU, it is unlikely the "any" cpu can run indifferently ARMv6 and ARMv7 binaries.

IMHO ARMv5 should default to arm946, ARMv6 arm1176 and ARMv7 to cortex-a7.

I think we should do the same for linux-user than system and remove the 'any' cpu for ARM.

Quoted 2 lines

board models: should use whatever CPU that board is designed for
null-machine: if it genuinely doesn't care, then pick one at random

Should work :)

Maybe pick the latest/best implemented, hoping this has more features to cover?

Quoted 9 lines

But there is no single sensible "default CPU type" at an architecture level, which is why you can't define a TARGET_DEFAULT_CPU_TYPE in target/arm/cpu.h. Any code that thinks it wants that should instead be defining it own default that makes sense for that context.

thanks
-- PMM

#52 lore raw
Quoted 4 lines · Philippe Mathieu-Daudé

I disagree on this, since userland binaries are compiled for a specific arch/ABI/FPU.
Even without worrying about the FPU, it is unlikely the "any" cpu can run indifferently ARMv6 and ARMv7 binaries.

In practice this works fine. Generally for userspace the Arm architecture retains backwards compatibility. (This is not the case for kernel mode, obviously.)

thanks
-- PMM